diff options
| author | tv <tv@krebsco.de> | 2026-11-01 23:08:48 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 23:08:48 +0100 |
| commit | 8fc0bb43e15e9ffa99777e478162c101557d505b (patch) | |
| tree | a6a9e5ef95821b1539b7d28b873781e4e2e98633 /src/transport | |
| parent | bc8e3afcd3eeb567661aa39d9d4cd6da1c57b29c (diff) | |
probe when reachable
Diffstat (limited to 'src/transport')
| -rw-r--r-- | src/transport/identity.rs | 4 | ||||
| -rw-r--r-- | src/transport/libp2p/book.rs | 3 | ||||
| -rw-r--r-- | src/transport/libp2p/driver.rs | 10 | ||||
| -rw-r--r-- | src/transport/libp2p/mod.rs | 4 | ||||
| -rw-r--r-- | src/transport/mod.rs | 7 | ||||
| -rw-r--r-- | src/transport/paths.rs | 7 | ||||
| -rw-r--r-- | src/transport/traffic.rs | 4 |
7 files changed, 39 insertions, 0 deletions
diff --git a/src/transport/identity.rs b/src/transport/identity.rs index 7b4a8c7..1df84ec 100644 --- a/src/transport/identity.rs +++ b/src/transport/identity.rs @@ -642,6 +642,10 @@ impl Transport for IdentityTransport { self.shared.paths.on_seeds_found(found) } + fn on_reachable(&self, reachable: std::sync::Arc<tokio::sync::Notify>) { + self.shared.paths.on_reachable(reachable) + } + /// A node ID resolves to itself if this node knows where it is; anything else is /// an address (`<scheme>:...`) or what one of the transports resolves to one (the /// first that does), asked WHO. diff --git a/src/transport/libp2p/book.rs b/src/transport/libp2p/book.rs index 3de8cef..0c61714 100644 --- a/src/transport/libp2p/book.rs +++ b/src/transport/libp2p/book.rs @@ -113,6 +113,9 @@ pub(super) struct Book { pub(super) discovered: Vec<Multiaddr>, /// Told when a seed is found (`Transport::on_seeds_found`). pub(super) seeds_found: Option<Arc<tokio::sync::Notify>>, + /// Told when others may reach this node where they couldn't before + /// (`Transport::on_reachable`). + pub(super) reachable: Option<Arc<tokio::sync::Notify>>, } /// What `Libp2pStats` counts since start. diff --git a/src/transport/libp2p/driver.rs b/src/transport/libp2p/driver.rs index 39a2a5d..6ef04e7 100644 --- a/src/transport/libp2p/driver.rs +++ b/src/transport/libp2p/driver.rs @@ -420,6 +420,10 @@ pub(super) async fn run( book.failed_relays.remove(&relay_peer_id); if !renewal { book.counts.slots_granted += 1; + // Peers that couldn't reach us may now, through it. + if let Some(reachable) = &book.reachable { + reachable.notify_one(); + } } } if !renewal { @@ -440,6 +444,12 @@ pub(super) async fn run( (Reachability::Public, Some(address.clone())) } }; + if matches!(new, NatStatus::Public(_)) + && !matches!(old, NatStatus::Public(_)) + && let Some(reachable) = &book.reachable + { + reachable.notify_one(); + } } nat = new; } diff --git a/src/transport/libp2p/mod.rs b/src/transport/libp2p/mod.rs index 3ebe7f6..056b1b2 100644 --- a/src/transport/libp2p/mod.rs +++ b/src/transport/libp2p/mod.rs @@ -500,6 +500,10 @@ impl Transport for Libp2pTransport { lock(&self.book).seeds_found = Some(found); } + fn on_reachable(&self, reachable: Arc<tokio::sync::Notify>) { + lock(&self.book).reachable = Some(reachable); + } + /// Nodes found on the LAN (mDNS) that speak continuum. fn discovered_seeds(&self) -> Vec<String> { std::mem::take(&mut lock(&self.book).discovered) diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 1de0633..96f7651 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -831,6 +831,13 @@ pub(crate) trait Transport: Send + Sync { let _ = found; } + /// Has the transport tell `reachable` whenever others may reach this node where they + /// couldn't before (libp2p: a relay granted it a slot, or AutoNAT found it public). + /// By default it never does. + fn on_reachable(&self, reachable: std::sync::Arc<tokio::sync::Notify>) { + let _ = reachable; + } + /// Whether this node has a way to reach `peer` at all: an address of it on one of /// its transports. Members it can't reach aren't its neighbours (`swarm::topology`). /// By default yes, as for `local_addresses`. diff --git a/src/transport/paths.rs b/src/transport/paths.rs index ba8581f..164574d 100644 --- a/src/transport/paths.rs +++ b/src/transport/paths.rs @@ -708,6 +708,13 @@ impl Paths { } } + /// Each transport's (`Transport::on_reachable`). + pub(crate) fn on_reachable(&self, reachable: std::sync::Arc<tokio::sync::Notify>) { + for link in &self.links { + link.inner.on_reachable(reachable.clone()); + } + } + /// The address of the node a seed leads to, as paths keep it: an address of ours /// (`<scheme>:...`) whose transport reads it at once; with a scheme of ours, what /// that transport resolves the rest to (an address the transport can't read as an diff --git a/src/transport/traffic.rs b/src/transport/traffic.rs index 21acca6..bf9438f 100644 --- a/src/transport/traffic.rs +++ b/src/transport/traffic.rs @@ -351,6 +351,10 @@ impl Transport for CountingTransport { self.inner.on_seeds_found(found) } + fn on_reachable(&self, reachable: std::sync::Arc<tokio::sync::Notify>) { + self.inner.on_reachable(reachable) + } + fn transports(&self) -> Vec<String> { self.inner.transports() } |
