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/swarm | |
| parent | bc8e3afcd3eeb567661aa39d9d4cd6da1c57b29c (diff) | |
probe when reachable
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/peer/handshake.rs | 24 | ||||
| -rw-r--r-- | src/swarm/peer/mod.rs | 3 |
2 files changed, 26 insertions, 1 deletions
diff --git a/src/swarm/peer/handshake.rs b/src/swarm/peer/handshake.rs index 6bd4784..072545b 100644 --- a/src/swarm/peer/handshake.rs +++ b/src/swarm/peer/handshake.rs @@ -304,6 +304,30 @@ pub(super) async fn discover_peers( } } +/// Whenever others may reach this node where they couldn't before +/// (`Transport::on_reachable`: a relay granted it a slot), the members it can't reach +/// are probed at once (`probe_now`): they may have given up on it meanwhile, waiting +/// for their next probe, up to `dormant-probe-max` away. Two nodes behind NATs that +/// restart together each fail to reach the other until it holds a slot; the second to +/// get one reaches the first this way. Runs for the node's life. +pub(crate) async fn probe_when_reachable(state: AppState, reachable: Arc<tokio::sync::Notify>) { + loop { + reachable.notified().await; + let mut probed = 0; + for (peer, _) in state.peers_snapshot().await { + if probe_now(&state, &peer).await { + probed += 1; + } + } + if probed > 0 { + debug!( + probed, + "Reachable anew; probing the members we can't reach now" + ); + } + } +} + /// Brings `peer`'s next probe forward to now, if it is a member we can't reach (dormant, /// or unanswered HELLOs) whose probe is pending: the peer worker sends it (woken for /// it). Whether it was. diff --git a/src/swarm/peer/mod.rs b/src/swarm/peer/mod.rs index d1dea9b..cf427a2 100644 --- a/src/swarm/peer/mod.rs +++ b/src/swarm/peer/mod.rs @@ -22,7 +22,8 @@ mod worker; pub(crate) use forget::{affects_forget_records, forget_unless_alive, forgotten_path}; pub(crate) use handshake::{ - apply_neighbour_change, peer_swarm, rehandshake, remember_peer, send_hello_once, + apply_neighbour_change, peer_swarm, probe_when_reachable, rehandshake, remember_peer, + send_hello_once, }; pub(crate) use inbound::handle_message; pub(crate) use keepalive::{announce, farewell, send_status}; |
