diff options
| author | tv <tv@krebsco.de> | 2026-11-17 00:58:19 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-17 02:03:21 +0100 |
| commit | 0c25a28979ee6734fe26f9ac12839160b2dc33a2 (patch) | |
| tree | 8fb7b412500478a9e69eb050f986d54b37dc5854 /src/swarm | |
| parent | 283c6a131d0bbb8ea7b6ffe87da1a14d457fd63d (diff) | |
bootstrap: a node ready at once tries its seeds until they resolve
A node starting from a document, or as a swarm's genesis node, is ready at once, and
says HELLO to its seeds, members of its swarm that may be running. A seed that didn't
resolve then (the node, or the seed, not reachable yet) was tried no more, and a node
whose document names no member to reach, as one started from a store's root, stayed
alone. Now such seeds are tried again in the background, backing off as a joining node
does, until they resolve or the node stops.
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/bootstrap.rs | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index b280b38..ed0c5cc 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -66,7 +66,7 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start) state.mark_ready(swarm_id).await?; // Members of the swarm still running, if any: they merge with this node, or it // rejoins them if they moved on to a newer epoch. - resolve_seeds(state, &mut seeds.to_vec(), &mut HashSet::new()).await; + reach_seeds(state, seeds).await; return Ok(()); } if start == Start::Genesis { @@ -143,7 +143,7 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start) state.initial_sync_done.store(true, Ordering::Release); state.mark_ready(swarm_id).await?; // Remembered members, if any, to find those still running. - resolve_seeds(state, &mut seeds.to_vec(), &mut HashSet::new()).await; + reach_seeds(state, seeds).await; return Ok(()); } @@ -495,6 +495,31 @@ fn load_backup(path: &Path, files: &Files) -> Result<Document> { /// Resolves the seeds in `unresolved`, says HELLO to each that resolves, and keeps the /// rest for later. Warns once per seed that fails (`failing` remembers which), and says /// when such a seed resolves after all. +/// Resolves `seeds`, those of a node ready at once, and says HELLO to each; those that +/// don't resolve yet (the node, or they, not reachable yet) are tried again in the +/// background, backing off as a joining node does, until they resolve or the node stops. +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; + if unresolved.is_empty() { + return; + } + let state = state.clone(); + let mut closing = state.closing.subscribe(); + tokio::spawn(async move { + let mut retry = RESOLVE_RETRY; + while !unresolved.is_empty() { + tokio::select! { + () = tokio::time::sleep(retry) => {} + _ = closing.wait_for(|closing| *closing) => return, + } + resolve_seeds(&state, &mut unresolved, &mut failing).await; + retry = (retry * 2).min(RESOLVE_RETRY_MAX); + } + }); +} + async fn resolve_seeds( state: &AppState, unresolved: &mut Vec<String>, |
