aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-01 20:34:59 +0100
committertv <tv@krebsco.de>2026-11-01 20:34:59 +0100
commit7f018573730dc57f9608fe41faa54b44abba841d (patch)
tree1c77e9b4756dc92ce1088acb6e8d3e44eee712f9 /src/swarm
parent7b8a6c75a13547bc9e541a6a9fcba01b0df06188 (diff)
bootstrap: replace pull by progress notify
Diffstat (limited to 'src/swarm')
-rw-r--r--src/swarm/bootstrap.rs16
-rw-r--r--src/swarm/sync.rs1
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();