diff options
| -rw-r--r-- | src/swarm/bootstrap.rs | 24 |
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. |
