diff options
| author | tv <tv@krebsco.de> | 2026-11-01 20:34:59 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-01 20:34:59 +0100 |
| commit | 962fe4b43632822dc91fa6a4da6f6f295f4dba32 (patch) | |
| tree | 5dd0b5c144f9e2e93ea498cab1df9d2295d49f70 /src/swarm | |
| parent | bb0716c8f199f7efb0f89a711a649f89cb09931f (diff) | |
bootstrap: replace pull by progress notify
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/bootstrap.rs | 16 | ||||
| -rw-r--r-- | src/swarm/sync.rs | 1 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index 848201e..4f6c072 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -34,7 +34,6 @@ use crate::remake::snapshot; use crate::state::AppState; use crate::swarm::peer::{remember_peer, send_hello_once}; -const BOOTSTRAP_POLL: Duration = Duration::from_millis(500); /// How often a node that is still joining says why. const BOOTSTRAP_REPORT: Duration = Duration::from_secs(300); /// Retrying seeds that didn't resolve: first after this, doubling up to the maximum. @@ -112,6 +111,7 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start) let mut resolve_retry = RESOLVE_RETRY; let mut next_resolve = Instant::now(); let mut next_report = Instant::now() + BOOTSTRAP_REPORT; + state.transport.on_seeds_found(state.join_progress.clone()); loop { if let Some(swarm_id) = state.swarm_id().await { // A node joining a compacted swarm rejoins the newer epoch first; it is @@ -147,7 +147,19 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start) next_report = now + BOOTSTRAP_REPORT; report_joining(state, seeds, &unresolved).await; } - tokio::time::sleep(BOOTSTRAP_POLL).await; + // Until something changes (`join_progress`), or it's time to resolve or report. + let resolving = async { + if unresolved.is_empty() { + std::future::pending().await + } else { + tokio::time::sleep_until(next_resolve).await + } + }; + tokio::select! { + () = state.join_progress.notified() => {} + () = resolving => {} + () = tokio::time::sleep_until(next_report) => {} + } } } diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 46bdef6..c643004 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -425,6 +425,7 @@ pub(crate) async fn handle_sync( .stats .caught_up(state.traffic.total().received.sync.bytes); source::finished(state, peer); + state.join_progress.notify_one(); } state.notify_store_changed(); |
