aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 15:19:59 +0000
committertv <tv@krebsco.de>2026-11-30 15:19:59 +0000
commit37570a1fa4a87d9cbb95d6320847e5e8e8ae87da (patch)
tree541e9b343f4fa2562b6070aa575b2c60a17f691f /src/swarm
parent5e92406ba1da8a58455420a10a9dd5ca963fa8f3 (diff)
swarm: a seed whose HELLO failed is said HELLO again soon, a few times
What a node speaks is mostly known a moment after it proved where it is, and its HELLO goes as it proves: one in the oldest version, which can't say a kind other than Automerge's, didn't go. Such a seed is tried again after a quarter of a second, four times, before the wait that grows; it was five seconds each time a node on a set started.
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/bootstrap.rs24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index bc27239..b21b579 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -39,6 +39,11 @@ const BOOTSTRAP_REPORT: Duration = Duration::from_secs(300);
/// Retrying seeds that didn't resolve: first after this, doubling up to the maximum.
const RESOLVE_RETRY: Duration = Duration::from_secs(5);
const RESOLVE_RETRY_MAX: Duration = Duration::from_secs(300);
+/// A seed that resolved, and whose HELLO failed, is said HELLO again this soon, a few
+/// times (`HELLO_SOON`): what a node speaks is mostly known a moment after it proved
+/// where it is, and a HELLO in a version that can't say this node's kind didn't go.
+const HELLO_AGAIN: Duration = Duration::from_millis(250);
+const HELLO_SOON: u32 = 4;
/// How this node starts.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -588,7 +593,7 @@ fn load_backup(path: &Path, files: &Files) -> Result<Document> {
async fn reach_seeds(state: &AppState, seeds: &[String]) {
let mut unresolved = seeds.to_vec();
let mut failing = HashSet::new();
- resolve_seeds(state, &mut unresolved, &mut failing).await;
+ let mut unsaid = resolve_seeds(state, &mut unresolved, &mut failing).await;
if unresolved.is_empty() {
return;
}
@@ -596,13 +601,18 @@ async fn reach_seeds(state: &AppState, seeds: &[String]) {
let mut closing = state.closing.subscribe();
tokio::spawn(async move {
let mut retry = RESOLVE_RETRY;
+ let mut soon = 0;
while !unresolved.is_empty() {
tokio::select! {
- () = tokio::time::sleep(retry) => {}
+ () = tokio::time::sleep(if unsaid && soon < HELLO_SOON { HELLO_AGAIN } else { retry }) => {}
_ = closing.wait_for(|closing| *closing) => return,
}
- resolve_seeds(&state, &mut unresolved, &mut failing).await;
- retry = (retry * 2).min(RESOLVE_RETRY_MAX);
+ if unsaid && soon < HELLO_SOON {
+ soon += 1;
+ } else {
+ retry = (retry * 2).min(RESOLVE_RETRY_MAX);
+ }
+ unsaid = resolve_seeds(&state, &mut unresolved, &mut failing).await;
}
});
}
@@ -611,7 +621,9 @@ async fn resolve_seeds(
state: &AppState,
unresolved: &mut Vec<String>,
failing: &mut HashSet<String>,
-) {
+) -> bool {
+ // Whether a seed resolved and its HELLO failed.
+ let mut unsaid = false;
let mut still = Vec::new();
for seed in unresolved.drain(..) {
match state.transport.resolve_seed(&seed).await {
@@ -636,6 +648,7 @@ async fn resolve_seeds(
peer_state.hello_state = crate::state::HelloState::NotSent;
}
}
+ unsaid = true;
still.push(seed);
}
}
@@ -650,6 +663,7 @@ async fn resolve_seeds(
}
}
*unresolved = still;
+ unsaid
}
/// Why the node is still joining, for the log.