Skip to content

Commit 903dc8d

Browse files
committed
Expose peer addresses via get_peer_node_ids
1 parent 137b77c commit 903dc8d

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -734,20 +734,23 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
734734
}
735735
}
736736

737-
/// Get the list of node ids for peers which have completed the initial handshake.
737+
/// Get a list of tuples mapping from node id to network addresses for peers which have
738+
/// completed the initial handshake.
738739
///
739-
/// For outbound connections, this will be the same as the their_node_id parameter passed in to
740-
/// new_outbound_connection, however entries will only appear once the initial handshake has
741-
/// completed and we are sure the remote peer has the private key for the given node_id.
742-
pub fn get_peer_node_ids(&self) -> Vec<PublicKey> {
740+
/// For outbound connections, the [`PublicKey`] will be the same as the `their_node_id` parameter
741+
/// passed in to [`Self::new_outbound_connection`], however entries will only appear once the initial
742+
/// handshake has completed and we are sure the remote peer has the private key for the given
743+
/// [`PublicKey`].
744+
pub fn get_peer_node_ids(&self) -> Vec<(PublicKey, Option<NetAddress>)> {
743745
let peers = self.peers.read().unwrap();
744746
peers.values().filter_map(|peer_mutex| {
745747
let p = peer_mutex.lock().unwrap();
746-
if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() {
748+
if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() ||
749+
p.their_node_id.is_none() {
747750
return None;
748751
}
749-
p.their_node_id
750-
}).map(|(node_id, _)| node_id).collect()
752+
Some((p.their_node_id.unwrap().0, p.their_net_address.clone()))
753+
}).collect()
751754
}
752755

753756
fn get_ephemeral_key(&self) -> SecretKey {
@@ -757,7 +760,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
757760
SecretKey::from_slice(&Sha256::from_engine(ephemeral_hash).into_inner()).expect("You broke SHA-256!")
758761
}
759762

760-
/// Indicates a new outbound connection has been established to a node with the given node_id
763+
/// Indicates a new outbound connection has been established to a node with the given `node_id`
761764
/// and an optional remote network address.
762765
///
763766
/// The remote network address adds the option to report a remote IP address back to a connecting

0 commit comments

Comments
 (0)