diff options
| author | tv <tv@krebsco.de> | 2026-11-01 19:52:21 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 19:52:21 +0100 |
| commit | f26904fdd167b31566fd79cbffcbfc4bafae0c28 (patch) | |
| tree | bc1ae9006e8c3a7112b24077c58023c9486c1032 /src/transport | |
| parent | 5c5efb0440d50a91de942817f0886fcba6d5d3ae (diff) | |
libp2p: identify leaves out ignored externals
Identify no longer tells peers confirmed external addresses in ignored
ranges, unless they were announced.
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/libp2p/behaviour.rs | 2 | ||||
| -rw-r--r-- | src/transport/libp2p/ignore.rs | 16 | ||||
| -rw-r--r-- | src/transport/libp2p/mod.rs | 2 |
3 files changed, 18 insertions, 2 deletions
diff --git a/src/transport/libp2p/behaviour.rs b/src/transport/libp2p/behaviour.rs index a2e8e91..18d8011 100644 --- a/src/transport/libp2p/behaviour.rs +++ b/src/transport/libp2p/behaviour.rs @@ -276,6 +276,8 @@ impl Behaviour { identify: Identifying { inner: ::libp2p::identify::Behaviour::new(identify), ranges: ignored.clone(), + // Set by `Libp2pTransport::start`. + announced: Vec::new(), }, relay_client, relay: relay.into(), diff --git a/src/transport/libp2p/ignore.rs b/src/transport/libp2p/ignore.rs index 6062839..eca9342 100644 --- a/src/transport/libp2p/ignore.rs +++ b/src/transport/libp2p/ignore.rs @@ -215,11 +215,21 @@ impl ::libp2p::swarm::NetworkBehaviour for Ignoring { } } -/// libp2p's identify, not told our listen addresses in the ranges `libp2p-ignore` names: -/// peers would remember them, show them, and dial them in vain. +/// libp2p's identify, not told our listen addresses, nor external ones (found by UPnP, +/// AutoNAT, a relay), in the ranges `libp2p-ignore` names: peers would remember them, +/// show them, and dial them in vain. Announced addresses (`--libp2p-announce`) are told +/// whatever range they are in. pub(super) struct Identifying { pub(super) inner: ::libp2p::identify::Behaviour, pub(super) ranges: Vec<IpRange>, + pub(super) announced: Vec<Multiaddr>, +} + +impl Identifying { + /// An external address identify isn't told: in an ignored range, and not announced. + fn left_out(&self, address: &Multiaddr) -> bool { + ignored(&self.ranges, address) && !self.announced.contains(address) + } } impl ::libp2p::swarm::NetworkBehaviour for Identifying { @@ -289,6 +299,8 @@ impl ::libp2p::swarm::NetworkBehaviour for Identifying { match event { FromSwarm::NewListenAddr(new) if ignored(&self.ranges, new.addr) => {} FromSwarm::ExpiredListenAddr(expired) if ignored(&self.ranges, expired.addr) => {} + FromSwarm::ExternalAddrConfirmed(confirmed) if self.left_out(confirmed.addr) => {} + FromSwarm::ExternalAddrExpired(expired) if self.left_out(expired.addr) => {} _ => self.inner.on_swarm_event(event), } } diff --git a/src/transport/libp2p/mod.rs b/src/transport/libp2p/mod.rs index 477f1ba..0bbabc7 100644 --- a/src/transport/libp2p/mod.rs +++ b/src/transport/libp2p/mod.rs @@ -247,6 +247,8 @@ impl Libp2pTransport { .listen_on(address.clone()) .with_context(|| format!("Listening on {address}"))?; } + // Told peers whatever range they are in (`Identifying`). + swarm.behaviour_mut().identify.announced = config.announce.clone(); for address in &config.announce { // Identify tells peers these. swarm.add_external_address(address.clone()); |
