add two methods for the issue #56
authorYuntai Kyong <yuntai.kyong@gmail.com>
Fri, 20 Jul 2018 19:04:28 +0000 (04:04 +0900)
committerYuntai Kyong <yuntai.kyong@gmail.com>
Sun, 22 Jul 2018 06:19:20 +0000 (15:19 +0900)
peer_handler::get_peer_node_ids() get connected peers' node_id
router::get_addresses() to get network addresses by node_id

src/ln/peer_handler.rs
src/ln/router.rs

index faa0a06ad0674f1cee2972ff7b8643ee0f31b080..5adb07f691bb2dda97713bcc2e51c5b8dc3ca6b0 100644 (file)
@@ -121,6 +121,12 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
                }
        }
 
+       /// Get the list of known node ids
+       pub fn get_peer_node_ids(&self) -> Vec<PublicKey> {
+               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.
index 1b576502fd97dcf00d37b14785a3b78a82245197..10432b9a6d83e915a50551cb90bc1a99d5d512df 100644 (file)
@@ -338,6 +338,12 @@ impl Router {
                }
        }
 
+       /// Get network addresses by node id
+       pub fn get_addresses(&self, pubkey: &PublicKey) -> Option<Vec<NetAddress>> {
+               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