aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/handshake.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 23:08:48 +0100
committertv <tv@krebsco.de>2026-11-01 23:08:48 +0100
commit8fc0bb43e15e9ffa99777e478162c101557d505b (patch)
treea6a9e5ef95821b1539b7d28b873781e4e2e98633 /src/swarm/peer/handshake.rs
parentbc8e3afcd3eeb567661aa39d9d4cd6da1c57b29c (diff)
probe when reachable
Diffstat (limited to 'src/swarm/peer/handshake.rs')
-rw-r--r--src/swarm/peer/handshake.rs24
1 files changed, 24 insertions, 0 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.