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 | 8886bc09a05b0fb2dc3c84e4b0c816fe81851e14 (patch) | |
| tree | 6eb6b96dddfc4e31f599a0270a050196af1cf50e /src/swarm/bootstrap.rs | |
| parent | 38f3ef952cf4cdd7cf5e9acbc8d9b64eeca86d81 (diff) | |
add state file
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(()); } |
