Skip to content

Commit d165c76

Browse files
committed
Expose peer addresses via get_peer_addresses
1 parent 760ab65 commit d165c76

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,25 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
744744
}).collect()
745745
}
746746

747+
/// Get a map from node id to node addresses for peers which have completed the initial handshake.
748+
///
749+
/// For outbound connections, the key will be the same as the `their_node_id` parameter passed in to
750+
/// `new_outbound_connection`, however entries will only appear once the initial handshake has
751+
/// completed and we are sure the remote peer has the private key for the given `node_id`.
752+
pub fn get_peer_addresses(&self) -> HashMap<PublicKey, NetAddress> {
753+
let mut peer_addrs = HashMap::new();
754+
755+
let peers = self.peers.read().unwrap();
756+
for peer_mutex in peers.values() {
757+
let p = peer_mutex.lock().unwrap();
758+
if p.channel_encryptor.is_ready_for_encryption() && p.their_features.is_some() &&
759+
p.their_node_id.is_some() && p.their_net_address.is_some() {
760+
peer_addrs.insert(p.their_node_id.unwrap(), p.their_net_address.clone().unwrap());
761+
}
762+
}
763+
peer_addrs
764+
}
765+
747766
fn get_ephemeral_key(&self) -> SecretKey {
748767
let mut ephemeral_hash = self.ephemeral_key_midstate.clone();
749768
let counter = self.peer_counter.get_increment();

0 commit comments

Comments
 (0)