From: Yuntai Kyong Date: Fri, 20 Jul 2018 19:04:28 +0000 (+0900) Subject: add two methods for the issue #56 X-Git-Tag: v0.0.12~383^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=9679f708dc7536bca584ca3bacb34be4596f60a9;p=rust-lightning add two methods for the issue #56 peer_handler::get_peer_node_ids() get connected peers' node_id router::get_addresses() to get network addresses by node_id --- diff --git a/src/ln/peer_handler.rs b/src/ln/peer_handler.rs index faa0a06ad..5adb07f69 100644 --- a/src/ln/peer_handler.rs +++ b/src/ln/peer_handler.rs @@ -121,6 +121,12 @@ impl PeerManager { } } + /// Get the list of known node ids + pub fn get_peer_node_ids(&self) -> Vec { + let peers = self.peers.lock().unwrap(); + peers.peers.values().filter_map(|p| p.their_node_id).collect() + } + /// Indicates a new outbound connection has been established to a node with the given node_id. /// Note that if an Err is returned here you MUST NOT call disconnect_event for the new /// descriptor but must disconnect the connection immediately. diff --git a/src/ln/router.rs b/src/ln/router.rs index 1b576502f..10432b9a6 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -338,6 +338,12 @@ impl Router { } } + /// Get network addresses by node id + pub fn get_addresses(&self, pubkey: &PublicKey) -> Option> { + let network = self.network_map.read().unwrap(); + network.nodes.get(pubkey).map(|n| n.addresses.clone()) + } + /// Marks a node as having failed a route. This will avoid re-using the node in routes for now, /// with an expotnential decay in node "badness". Note that there is deliberately no /// mark_channel_bad as a node may simply lie and suggest that an upstream channel from it is