diff options
| author | tv <tv@krebsco.de> | 2026-10-25 11:30:15 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-25 11:30:15 +0100 |
| commit | 680097c9e82d9140ca7e2421113d23cc644b0cc2 (patch) | |
| tree | 3acfb80e80e19b53c76feb0b0df6eb570fb312cf /src/swarm | |
| parent | 65e0069baeb42deb69dd0616e97484bc5a568d7d (diff) | |
put swarm ID into the document
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/bootstrap.rs | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/src/swarm/bootstrap.rs b/src/swarm/bootstrap.rs index 767a85c..1ae5173 100644 --- a/src/swarm/bootstrap.rs +++ b/src/swarm/bootstrap.rs @@ -4,15 +4,21 @@ //! seeds and keeps trying until it is ready: seeds that don't resolve are resolved //! again with backoff, and HELLOs to resolved ones are retried by the peer worker. A //! node without seeds waits (nothing to join yet) and says so now and then. +//! +//! The genesis node records the swarm ID in the document (`_continuum/swarm`), so +//! snapshots carry it forward and every backup names its swarm. use std::sync::atomic::Ordering; use std::time::Duration; -use anyhow::Result; +use anyhow::{Context, Result}; +use serde_json::Value as JsonValue; use tokio::time::Instant; use tracing::{debug, info, warn}; use uuid::Uuid; +use crate::document::store; +use crate::remake::snapshot::{META_ROOT, SWARM}; use crate::state::AppState; use crate::swarm::peer::{remember_peer, send_hello_once}; @@ -25,9 +31,15 @@ const RESOLVE_RETRY_MAX: Duration = Duration::from_secs(300); pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], genesis: bool) -> Result<()> { if genesis { - info!("Starting a new swarm as its genesis node (--genesis)"); + let swarm_id = Uuid::new_v4().to_string(); + info!(swarm_id = %swarm_id, "Starting a new swarm as its genesis node (--genesis)"); + let recorded = JsonValue::String(swarm_id.clone()); + state + .mutate_doc(move |doc| store::write_path(doc, &swarm_id_path(), &recorded)) + .await + .context("Recording the swarm ID")?; state.initial_sync_done.store(true, Ordering::Release); - state.mark_ready(Uuid::new_v4().to_string()).await?; + state.mark_ready(swarm_id).await?; return Ok(()); } @@ -70,6 +82,10 @@ pub(crate) async fn bootstrap(state: &AppState, seeds: &[String], genesis: bool) } } +fn swarm_id_path() -> Vec<String> { + vec![META_ROOT.to_owned(), SWARM.to_owned()] +} + /// Resolves the seeds in `unresolved`, says HELLO to each that resolves, and keeps the /// rest for later. async fn resolve_seeds(state: &AppState, unresolved: &mut Vec<String>) { |
