Skip to content

Commit a9296a5

Browse files
committed
f filter_map after all
1 parent d165c76 commit a9296a5

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

lightning/src/ln/peer_handler.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -750,17 +750,15 @@ impl<Descriptor: SocketDescriptor, CM: Deref, RM: Deref, OM: Deref, L: Deref, CM
750750
/// `new_outbound_connection`, however entries will only appear once the initial handshake has
751751
/// completed and we are sure the remote peer has the private key for the given `node_id`.
752752
pub fn get_peer_addresses(&self) -> HashMap<PublicKey, NetAddress> {
753-
let mut peer_addrs = HashMap::new();
754-
755753
let peers = self.peers.read().unwrap();
756-
for peer_mutex in peers.values() {
754+
peers.values().filter_map(|peer_mutex| {
757755
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());
756+
if !p.channel_encryptor.is_ready_for_encryption() || p.their_features.is_none() ||
757+
p.their_node_id.is_none() || p.their_net_address.is_none() {
758+
return None;
761759
}
762-
}
763-
peer_addrs
760+
Some((p.their_node_id.unwrap(), p.their_net_address.clone().unwrap()))
761+
}).collect()
764762
}
765763

766764
fn get_ephemeral_key(&self) -> SecretKey {

0 commit comments

Comments
 (0)