diff options
| author | tv <tv@krebsco.de> | 2026-10-25 11:43:53 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-25 11:43:53 +0100 |
| commit | 9845a07960fa083db0b0c7e2312f98706e9684cb (patch) | |
| tree | c5df07227d4fbc75e817eada595cec6a819eee43 /src/swarm/bootstrap.rs | |
| parent | 680097c9e82d9140ca7e2421113d23cc644b0cc2 (diff) | |
This allows storing the swarm ID and additionally discovered seeds,
which prevents a formerly genesis node to start a new document.
Diffstat (limited to 'src/swarm/bootstrap.rs')
| -rw-r--r-- | src/swarm/bootstrap.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index 1ae5173..84ff156 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -31,8 +31,22 @@ const RESOLVE_RETRY_MAX: Duration = Duration::from_secs(300); pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], genesis: bool) -> Result<()> { if genesis { - let swarm_id = Uuid::new_v4().to_string(); - info!(swarm_id = %swarm_id, "Starting a new swarm as its genesis node (--genesis)"); + // A remembered swarm starts again under its ID: nodes of it still running then + // merge with this one instead of ending up in another swarm. + let swarm_id = match state.swarm_id().await { + Some(remembered) => { + warn!( + swarm_id = %remembered, + "--genesis with a remembered swarm: starting it again, empty; nodes of it still running merge with this one" + ); + remembered + } + None => { + let swarm_id = Uuid::new_v4().to_string(); + info!(swarm_id = %swarm_id, "Starting a new swarm as its genesis node (--genesis)"); + swarm_id + } + }; let recorded = JsonValue::String(swarm_id.clone()); state .mutate_doc(move |doc| store::write_path(doc, &swarm_id_path(), &recorded)) @@ -40,6 +54,8 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], genesis: bool) .context("Recording the swarm ID")?; 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()).await; return Ok(()); } |
