From 2e8f73e52dc5ed5f5209d970870f2465fb4ef101 Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Tue, 7 Feb 2023 11:22:12 -0600 Subject: [PATCH] Expose peer addresses via `get_peer_node_ids` --- lightning/src/ln/peer_handler.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lightning/src/ln/peer_handler.rs b/lightning/src/ln/peer_handler.rs index 89862f29..4577e4a8 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