Skip to content

Commit 005975d

Browse files
author
Antoine Riard
committed
Expose NodeInfo through list_vertices
Make NodeInfo and its fields publics
1 parent 650a468 commit 005975d

File tree

1 file changed

+26
-8
lines changed

1 file changed

+26
-8
lines changed

lightning/src/ln/router.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,11 @@ impl_writeable!(ChannelInfo, 0, {
160160
announcement_message
161161
});
162162

163-
#[derive(PartialEq)]
164-
struct NodeInfo {
165-
node_id: PublicKey,
163+
/// Details of a node, as stored in NetworkMap, and returned by Router::list_vertices
164+
#[derive(Clone, PartialEq)]
165+
pub struct NodeInfo {
166+
/// The node id
167+
pub node_id: PublicKey,
166168
#[cfg(feature = "non_bitcoin_chain_hash_routing")]
167169
channels: Vec<(u64, Sha256dHash)>,
168170
#[cfg(not(feature = "non_bitcoin_chain_hash_routing"))]
@@ -171,14 +173,19 @@ struct NodeInfo {
171173
lowest_inbound_channel_fee_base_msat: u32,
172174
lowest_inbound_channel_fee_proportional_millionths: u32,
173175

174-
features: NodeFeatures,
176+
/// The node features
177+
pub features: NodeFeatures,
175178
/// Unlike for channels, we may have a NodeInfo entry before having received a node_update.
176179
/// Thus, we have to be able to capture "no update has been received", which we do with an
177180
/// Option here.
178-
last_update: Option<u32>,
179-
rgb: [u8; 3],
180-
alias: [u8; 32],
181-
addresses: Vec<NetAddress>,
181+
/// The last tine a node announcement has been received
182+
pub last_update: Option<u32>,
183+
/// The custom node color
184+
pub rgb: [u8; 3],
185+
/// The custom node alias
186+
pub alias: [u8; 32],
187+
/// The network addresses
188+
pub addresses: Vec<NetAddress>,
182189
//this is cached here so we can send out it later if required by route_init_sync
183190
//keep an eye on this to see if the extra memory is a problem
184191
announcement_message: Option<msgs::NodeAnnouncement>,
@@ -1089,6 +1096,17 @@ impl Router {
10891096
}
10901097
edges
10911098
}
1099+
1100+
/// Gets the list of announced nodes, in random order. See NodeInfo details field documentation for more information
1101+
pub fn list_vertices(&self) -> Vec<NodeInfo> {
1102+
let mut vertices = Vec::new();
1103+
let network = self.network_map.read().unwrap();
1104+
vertices.reserve(network.nodes.len());
1105+
for (_, node) in network.nodes.iter() {
1106+
vertices.push((*node).clone());
1107+
}
1108+
vertices
1109+
}
10921110
}
10931111

10941112
#[cfg(test)]

0 commit comments

Comments
 (0)