From 9f8feeab71ccb864606c336097e20dbb8e1d8c86 Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 1 Nov 2026 05:22:38 +0100 Subject: libp2p: autoignore unroutable address ranges --- src/transport/libp2p/mod.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/transport/libp2p/mod.rs') diff --git a/src/transport/libp2p/mod.rs b/src/transport/libp2p/mod.rs index 9d1dcc7..ace84c6 100644 --- a/src/transport/libp2p/mod.rs +++ b/src/transport/libp2p/mod.rs @@ -50,8 +50,12 @@ //! //! With `--libp2p-ignore`, address ranges are left out (VPNs): not published, not told //! peers by identify (`Identifying`), not offered for hole punching, not dialled, and -//! connections there refused (`Ignoring`). With `--libp2p-prefer`, addresses in the -//! ranges named come first, where only so many are kept (`Book::preference`). +//! connections there refused (`Ignoring`). Ranges this node has no route to are left +//! out alike, as long as it has none (`routes`): without IPv6 to the internet, peers' +//! public IPv6 addresses; and with `--libp2p-internet-hosts`, its own aren't published +//! then. With `--libp2p-prefer`, +//! addresses in the ranges named come first, where only so many are kept +//! (`Book::preference`). //! //! With `--libp2p-upnp`, a node asks its router to forward its listen ports (UPnP), and //! publishes the router's public address for them with its own (`Book::direct`): then @@ -101,6 +105,7 @@ mod driver; mod errors; mod ignore; mod relays; +mod routes; use behaviour::*; use book::*; @@ -109,6 +114,7 @@ use driver::*; use errors::*; use ignore::*; use relays::*; +use routes::*; /// The scheme of this transport's addresses (`transport::paths`). pub(crate) const SCHEME: &str = "libp2p"; @@ -251,6 +257,7 @@ impl Libp2pTransport { announced: config.announce, ignored: config.ignore.clone(), preferred: config.prefer.clone(), + routes: Routes::asking(config.internet_hosts.clone()), serving: config.relay, ..Book::default() }; @@ -288,13 +295,13 @@ impl Libp2pTransport { /// Connected to `peer`, if it can be had in time. async fn connect(&self, peer: PeerId) -> Result<()> { let addresses = { - let book = lock(&self.book); + let mut book = lock(&self.book); let mut known = book .addresses .get(&peer) .map(|known| dialable(known, self.peer_id)) .unwrap_or_default(); - known.retain(|address| !left_out(&book.ignored, address)); + known.retain(|address| !book.left_out(address)); if known.is_empty() { book.through_relays(peer, self.peer_id) } else { -- cgit v1.3.1