From 9845a07960fa083db0b0c7e2312f98706e9684cb Mon Sep 17 00:00:00 2001 From: tv Date: Sun, 25 Oct 2026 11:43:53 +0100 Subject: add state file This allows storing the swarm ID and additionally discovered seeds, which prevents a formerly genesis node to start a new document. --- src/swarm/bootstrap.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'src/swarm/bootstrap.rs') 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(()); } -- cgit v1.3.1