Skip to content

Commit

Permalink
fix(manager): push new identify to just the connected peers
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Jan 21, 2025
1 parent 153edf1 commit bc9fad6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions ant-networking/src/event/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl SwarmDriver {
relay_manager.on_successful_reservation_by_client(
&relay_peer_id,
&mut self.swarm,
&self.live_connected_peers,
);
}
} else {
Expand Down
14 changes: 8 additions & 6 deletions ant-networking/src/relay_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use rand::Rng;
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
#[cfg(feature = "open-metrics")]
use std::sync::atomic::AtomicU64;
use std::time::Instant;
#[cfg(feature = "open-metrics")]
use std::{collections::btree_map::Entry, time::SystemTime};

Expand Down Expand Up @@ -229,6 +230,7 @@ impl RelayManager {
&mut self,
peer_id: &PeerId,
swarm: &mut Swarm<NodeBehaviour>,
live_connected_peers: &BTreeMap<ConnectionId, (PeerId, Multiaddr, Instant)>,
) {
match self.waiting_for_reservation.remove(peer_id) {
Some(addr) => {
Expand All @@ -243,12 +245,12 @@ impl RelayManager {

if self.connected_relay_servers.len() == MAX_CONCURRENT_RELAY_CONNECTIONS {
debug!("We have reached the maximum number of relay connections. Push new identify info to all connected peers");
// send identify to all peers
let mut all_peers = HashSet::new();
for bucket in swarm.behaviour_mut().kademlia.kbuckets() {
all_peers.extend(bucket.iter().map(|entry| entry.node.key.preimage()));
}
swarm.behaviour_mut().identify.push(all_peers);
// send identify to all connected peers.

swarm
.behaviour_mut()
.identify
.push(live_connected_peers.values().map(|(peer_id, ..)| *peer_id));
}
}

Expand Down

0 comments on commit bc9fad6

Please sign in to comment.