aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/bootstrap.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/bootstrap.rs')
-rw-r--r--src/swarm/bootstrap.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs
index 4384edb..6d3a4ad 100644
--- a/src/swarm/bootstrap.rs
+++ b/src/swarm/bootstrap.rs
@@ -150,6 +150,14 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start)
info!(seeds = seeds.len(), "Joining existing swarm");
}
+ // An empty document of the first epoch takes a root once its seeds named it, or a
+ // while after the first did (`swarm::roots`).
+ {
+ let replica = state.doc.read().await;
+ if replica.epoch.generation == 0 && replica.doc.get_heads().is_empty() {
+ crate::swarm::roots::await_seeds(state, seeds.len());
+ }
+ }
let mut unresolved: Vec<String> = seeds.to_vec();
let mut failing = HashSet::new();
let mut resolve_retry = RESOLVE_RETRY;
@@ -191,7 +199,10 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start)
next_report = now + BOOTSTRAP_REPORT;
report_joining(state, seeds, &unresolved).await;
}
- // Until something changes (`join_progress`), or it's time to resolve or report.
+ // The wait for the seeds to name the swarm's root, over by now?
+ crate::swarm::roots::repin(state);
+ // Until something changes (`join_progress`), or it's time to resolve, report or
+ // stop waiting for the seeds.
let resolving = async {
if unresolved.is_empty() {
std::future::pending().await
@@ -199,9 +210,16 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], start: Start)
tokio::time::sleep_until(next_resolve).await
}
};
+ let root_wait = async {
+ match crate::swarm::roots::waiting_until(state) {
+ Some(until) => tokio::time::sleep_until(until).await,
+ None => std::future::pending().await,
+ }
+ };
tokio::select! {
() = state.join_progress.notified() => {}
() = resolving => {}
+ () = root_wait => {}
() = tokio::time::sleep_until(next_report) => {}
}
}