aboutsummaryrefslogtreecommitdiffstats
path: root/src/config
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-16 19:44:37 +0000
committertv <tv@krebsco.de>2026-11-16 21:25:59 +0100
commit0ba4c7363cfa2a9963ecd6a06392ea5c4dac3ad1 (patch)
treefa40cfbfda010601eff9f9db148c5aa793aca0b2 /src/config
parent3fccc4f6859cf0b4d93e7d166142e1ab9255723f (diff)
node: a swarm holding a store, started from its root or joined by its ID
Behind the `federation` feature, two options: * `--store-root PATH` starts a swarm holding a store, or goes on with one, from the store's root, as bytes in the file, which the federation must take as a root. With no document to start on, the node builds the genesis change from it, as every node given the root does, and is ready at once; a document to start on must be of the root's swarm. * `--store-id ID` joins one through seeds by its ID, the root's SHA-256 in hex. An empty document of the first epoch takes as its root only that store's genesis change, built again from the root it holds (`document::events::is_genesis`), whatever peers name: the root pin doesn't wait for seeds, nor is disputed. Either names the swarm the node joins, which a state file must remember too, and can't be combined with the other, nor with what makes a new swarm's first change (`--genesis`, `--bootstrap-users`, `--bootstrap-keys`, `--bootstrap-policy`, `--remake`, `--genesis-root`). The root is read as a file of its own kind (`store`), counted among the node's files.
Diffstat (limited to 'src/config')
-rw-r--r--src/config/mod.rs65
1 files changed, 65 insertions, 0 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 14bd984..ae6070f 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -200,6 +200,22 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[
None,
"The hash of the swarm's genesis change (hex, as its genesis node logs it and GET /admin/epochs shows it): joining with an empty document, the only root this node takes. Without, the one its peers name once each seed named one or ten seconds passed since the first did, none while they name different ones (docs/access.md).",
),
+ #[cfg(feature = "federation")]
+ option(
+ "store-root",
+ Kind::Text,
+ "PATH",
+ None,
+ "Start a swarm holding a store (docs/store.md), or go on with one, from the store's root, as bytes in this file: the node builds the swarm's genesis change from it, as every node given the root does, and is ready at once. The swarm's ID is the root's: its SHA-256, in hex. Can't be combined with store-id, genesis, or what makes a new swarm's first change (bootstrap-users, bootstrap-keys, bootstrap-policy, remake, genesis-root).",
+ ),
+ #[cfg(feature = "federation")]
+ option(
+ "store-id",
+ Kind::Text,
+ "ID",
+ None,
+ "Join a swarm holding a store (docs/store.md) through seeds, by its ID: its root's SHA-256, in hex. Joining with an empty document, the node takes as its root only that store's genesis change, built again from the root it holds. Can't be combined with store-root, genesis, or what makes a new swarm's first change.",
+ ),
option(
"strict-keys",
Kind::List,
@@ -631,6 +647,10 @@ pub(crate) struct Settings {
pub(crate) bootstrap_keys: Vec<String>,
pub(crate) bootstrap_policy: Option<String>,
pub(crate) genesis_root: Option<String>,
+ #[cfg(feature = "federation")]
+ pub(crate) store_root: Option<PathBuf>,
+ #[cfg(feature = "federation")]
+ pub(crate) store_id: Option<String>,
#[serde(default)]
pub(crate) strict_keys: Vec<String>,
@@ -953,6 +973,8 @@ impl Settings {
if self.genesis && self.recover_from.is_some() {
bail!("recover-from starts the swarm from a backup; it can't be combined with genesis");
}
+ #[cfg(feature = "federation")]
+ self.check_store()?;
if self.node_key_create && self.node_key_file.is_none() {
bail!("node-key-create creates the key at node-key-file; set that too");
}
@@ -1079,6 +1101,45 @@ impl Settings {
})
}
+ /// A swarm holding a store, started from its root or joined by its ID: one of them, and
+ /// nothing that makes a new swarm's first change.
+ #[cfg(feature = "federation")]
+ fn check_store(&self) -> Result<()> {
+ if let Some(id) = &self.store_id
+ && crate::federation::store::Id::from_hex(id).is_none()
+ {
+ bail!("store-id: {id:?} isn't a store's ID (64 hex digits)");
+ }
+ let store = match (&self.store_root, &self.store_id) {
+ (Some(_), Some(_)) => {
+ bail!("store-root names the store's ID itself; unset store-id")
+ }
+ (Some(_), None) => "store-root",
+ (None, Some(_)) => "store-id",
+ (None, None) => return Ok(()),
+ };
+ let first_change = [
+ ("genesis", self.genesis),
+ ("bootstrap-users", !self.bootstrap_users.is_empty()),
+ ("bootstrap-keys", !self.bootstrap_keys.is_empty()),
+ ("bootstrap-policy", self.bootstrap_policy.is_some()),
+ ("remake", self.remake.is_some()),
+ ("genesis-root", self.genesis_root.is_some()),
+ ];
+ let set: Vec<&str> = first_change
+ .iter()
+ .filter(|(_, set)| *set)
+ .map(|(name, _)| *name)
+ .collect();
+ if !set.is_empty() {
+ bail!(
+ "{store}: a swarm holding a store starts from its root's genesis change, so these don't apply: {}",
+ set.join(", ")
+ );
+ }
+ Ok(())
+ }
+
/// A relay that is no node: libp2p alone, dialable, with a key kept, and nothing
/// about a swarm or a document.
fn check_relay_only(&self) -> Result<()> {
@@ -1104,6 +1165,10 @@ impl Settings {
("bootstrap-users", !self.bootstrap_users.is_empty()),
("bootstrap-keys", !self.bootstrap_keys.is_empty()),
("bootstrap-policy", self.bootstrap_policy.is_some()),
+ #[cfg(feature = "federation")]
+ ("store-root", self.store_root.is_some()),
+ #[cfg(feature = "federation")]
+ ("store-id", self.store_id.is_some()),
("alias", self.alias.is_some()),
("dashboard-url", self.dashboard_url.is_some()),
("debug-api", self.debug_api),