Skip to content

Commit 4ce6474

Browse files
committed
Expose peer addresses via get_peer_node_ids
1 parent 760ab65 commit 4ce6474

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,22 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
728728
}
729729
}
730730

731-
/// Get the list of node ids for peers which have completed the initial handshake.
731+
/// Get a list of tuples mapping from node id to network addresses for peers which have
732+
/// completed the initial handshake.
732733
///
733-
/// For outbound connections, this will be the same as the their_node_id parameter passed in to
734-
/// new_outbound_connection, however entries will only appear once the initial handshake has
735-
/// completed and we are sure the remote peer has the private key for the given node_id.
736-
pub fn get_peer_node_ids(&self) -> Vec<PublicKey> {
734+
/// For outbound connections, the `PublicKey` will be the same as the `their_node_id` parameter
735+
/// passed in to [`new_outbound_connection`], however entries will only appear once the initial
736+
/// handshake has completed and we are sure the remote peer has the private key for the given
737+
/// `node_id`.
738+
pub fn get_peer_node_ids(&self) -> Vec<(PublicKey, Option<NetAddress>)> {
737739
let peers = self.peers.read().unwrap();
738740
peers.values().filter_map(|peer_mutex| {
739741
let p = peer_mutex.lock().unwrap();
740-
if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() {
742+
if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() ||
743+
p.their_node_id.is_none() {
741744
return None;
742745
}
743-
p.their_node_id
746+
Some((p.their_node_id.unwrap(), p.their_net_address.clone()))
744747
}).collect()
745748
}
746749

@@ -751,7 +754,7 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
751754
SecretKey::from_slice(&Sha256::from_engine(ephemeral_hash).into_inner()).expect("You broke SHA-256!")
752755
}
753756

754-
/// Indicates a new outbound connection has been established to a node with the given node_id
757+
/// Indicates a new outbound connection has been established to a node with the given `node_id`
755758
/// and an optional remote network address.
756759
///
757760
/// The remote network address adds the option to report a remote IP address back to a connecting

0 commit comments

Comments
 (0)