Skip to content

Commit

Permalink
Clean up old addresses of a peer
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Nov 15, 2023
1 parent 6eadee7 commit 683f215
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/subspace-networking/src/node_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,22 @@ where
});

if full_kademlia_support {
let old_addresses = kademlia
.kbucket(peer_id)
.and_then(|peers| {
let key = peer_id.into();
peers.iter().find_map(|peer| {
(peer.node.key == &key).then_some(
peer.node
.value
.iter()
.filter(|address| info.listen_addrs.contains(address))
.cloned()
.collect::<Vec<_>>(),
)
})
})
.unwrap_or_default();
for address in info.listen_addrs {
if !self.allow_non_global_addresses_in_dht
&& !is_global_address_or_dns(&address)
Expand All @@ -742,8 +758,19 @@ where
protocol_names = ?kademlia.protocol_names(),
"Adding self-reported address to Kademlia DHT",
);

kademlia.add_address(&peer_id, address);
}
for old_address in old_addresses {
trace!(
%local_peer_id,
%peer_id,
%old_address,
"Removing old self-reported address from Kademlia DHT",
);

kademlia.remove_address(&peer_id, &old_address);
}
} else {
debug!(
%local_peer_id,
Expand Down

0 comments on commit 683f215

Please sign in to comment.