From: Elias Rohrer Date: Tue, 7 Feb 2023 17:22:12 +0000 (-0600) Subject: Expose peer addresses via `get_peer_node_ids` X-Git-Tag: v0.0.114-beta~23^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=2e8f73e52dc5ed5f5209d970870f2465fb4ef101;p=rust-lightning Expose peer addresses via `get_peer_node_ids` --- diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 89862f29f..4577e4a83 100644 --- a/lightning/src/ln/peer_handler.rs +++ b/lightning/src/ln/peer_handler.rs @@ -734,20 +734,26 @@ impl Vec { + /// For outbound connections, the [`PublicKey`] will be the same as the `their_node_id` parameter + /// passed in to [`Self::new_outbound_connection`], however entries will only appear once the initial + /// handshake has completed and we are sure the remote peer has the private key for the given + /// [`PublicKey`]. + /// + /// The returned `Option`s will only be `Some` if an address had been previously given via + /// [`Self::new_outbound_connection`] or [`Self::new_inbound_connection`]. + pub fn get_peer_node_ids(&self) -> Vec<(PublicKey, Option)> { let peers = self.peers.read().unwrap(); peers.values().filter_map(|peer_mutex| { let p = peer_mutex.lock().unwrap(); - if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() { + if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() || + p.their_node_id.is_none() { return None; } - p.their_node_id - }).map(|(node_id, _)| node_id).collect() + Some((p.their_node_id.unwrap().0, p.their_net_address.clone())) + }).collect() } fn get_ephemeral_key(&self) -> SecretKey { @@ -757,7 +763,7 @@ impl