From dfd2a91578d826b5e46da7d9b141c7ff3d6c5075 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 22:05:01 +0100 Subject: libp2p: don't relay through ignored --- src/transport/libp2p/ignore.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/transport/libp2p/ignore.rs') diff --git a/src/transport/libp2p/ignore.rs b/src/transport/libp2p/ignore.rs index 51e1f45..ab59a3e 100644 --- a/src/transport/libp2p/ignore.rs +++ b/src/transport/libp2p/ignore.rs @@ -78,6 +78,21 @@ pub(super) fn ignored(ranges: &[IpRange], address: &Multiaddr) -> bool { ranges.iter().any(|range| range.contains(ip)) } +/// Whether `address` can only be reached over a range of `ranges`: a direct address +/// there, or one through a relay whose own address is there (dialling the relay is +/// refused, `Ignoring`). For what's kept and dialled; connections are judged by +/// `ignored`. +pub(super) fn left_out(ranges: &[IpRange], address: &Multiaddr) -> bool { + if !is_relayed(address) { + return ignored(ranges, address); + } + let relay: Multiaddr = address + .iter() + .take_while(|protocol| !matches!(protocol, Protocol::P2pCircuit)) + .collect(); + ignored(ranges, &without_peer(relay)) +} + /// Keeps connections off the address ranges `libp2p-ignore` names, whoever dialled: /// hole punching and identify bring addresses there too, and a peer may dial us there. pub(super) struct Ignoring { -- cgit v1.3.1