From 5728ce9ef83f933291d900be262fc4369f988233 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 19:52:21 +0100 Subject: libp2p: identify leaves out ignored externals Identify no longer tells peers confirmed external addresses in ignored ranges, unless they were announced. --- src/transport/libp2p/ignore.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/transport/libp2p/ignore.rs') 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, + pub(super) announced: Vec, +} + +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), } } -- cgit v1.3.1