aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/peer/handshake.rs24
-rw-r--r--src/swarm/peer/mod.rs3
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};