Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

[client/network] remove peer entry from ephemeral_addresses #13084

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,16 @@ impl DiscoveryBehaviour {
/// If we didn't know this address before, also generates a `Discovered` event.
pub fn add_known_address(&mut self, peer_id: PeerId, addr: Multiaddr) {
let addrs_list = self.ephemeral_addresses.entry(peer_id).or_default();
if !addrs_list.iter().any(|a| *a == addr) {
if let Some(k) = self.kademlia.as_mut() {
k.add_address(&peer_id, addr.clone());
}
if addrs_list.contains(&addr) {
return
}

self.pending_events.push_back(DiscoveryOut::Discovered(peer_id));
addrs_list.push(addr);
if let Some(k) = self.kademlia.as_mut() {
k.add_address(&peer_id, addr.clone());
}

self.pending_events.push_back(DiscoveryOut::Discovered(peer_id));
addrs_list.push(addr);
}

/// Add a self-reported address of a remote peer to the k-buckets of the DHT
Expand Down Expand Up @@ -456,7 +458,7 @@ pub enum DiscoveryOut {

/// The DHT yielded results for the record request.
///
/// Returning the result grouped in (key, value) pairs as well as the request duration..
/// Returning the result grouped in (key, value) pairs as well as the request duration.
ValueFound(Vec<(record::Key, Vec<u8>)>, Duration),

/// The record requested was not found in the DHT.
Expand Down Expand Up @@ -539,6 +541,9 @@ impl NetworkBehaviour for DiscoveryBehaviour {
for (addr, _error) in errors {
list.retain(|a| a != addr);
}
if list.is_empty() {
self.ephemeral_addresses.remove(&peer_id);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ where
self.network_service.behaviour().user_protocol().num_sync_requests()
}

/// Adds an address for a node.
/// Adds an address known to a node.
pub fn add_known_address(&mut self, peer_id: PeerId, addr: Multiaddr) {
self.network_service.behaviour_mut().add_known_address(peer_id, addr);
}
Expand Down