Skip to content

Commit

Permalink
fix relayed dial not performed if local peer listen on same relay
Browse files Browse the repository at this point in the history
  • Loading branch information
stormshield-frb committed Oct 24, 2024
1 parent f5f2241 commit 479b360
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions swarm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ pub use handler::{
ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerSelect, OneShotHandler,
OneShotHandlerConfig, StreamUpgradeError, SubstreamProtocol,
};
use libp2p_core::multiaddr::Protocol;
#[cfg(feature = "macros")]
pub use libp2p_swarm_derive::NetworkBehaviour;
pub use listen_opts::ListenOpts;
Expand Down Expand Up @@ -509,10 +510,22 @@ where
}
}

let mut unique_addresses = HashSet::new();
let mut unique_addresses: HashSet<_> = HashSet::new();
addresses_from_opts.retain(|addr| {
!self.listened_addrs.values().flatten().any(|a| a == addr)
&& unique_addresses.insert(addr.clone())
if !unique_addresses.insert(addr.clone()) {
// Address already added, don't dial it twice.
false
} else {

Check failure on line 518 in swarm/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy (1.80.0)

this `else { if .. }` block can be collapsed
if addr.iter().any(|p| p == Protocol::P2pCircuit) {
// Address is relayed. It's ok to dial a peer that listens
// on the same relay that the local peer does.
true
} else {
// Address is not relayed. Prevent dial on any addresses
// the local peer listens on.
!self.listened_addrs.values().flatten().any(|a| a == addr)
}
}
});

if addresses_from_opts.is_empty() {
Expand Down

0 comments on commit 479b360

Please sign in to comment.