diff options
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/mod.rs | 65 |
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), |
