diff options
Diffstat (limited to 'src/config')
| -rw-r--r-- | src/config/mod.rs | 74 |
1 files changed, 66 insertions, 8 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs index e2557cd..5dae0c2 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -232,6 +232,14 @@ pub(crate) const OPTIONS: &[OptionSpec] = &[ None, "With store-root or store-id: a checkpoint of the store, by its ID (hex), from which the node reads its store whenever it starts, instead of from the root: once a store moved to a checkpoint, a node reading from the root could take what was grown anew from it since, by keys of versions long replaced (docs/federation.md, Checkpoints). The node finds it in its document, at heads a proposal names, built from their history as any node builds it; until then, it holds no store.", ), + #[cfg(feature = "federation")] + option( + "store-party", + Kind::Text, + "NAME", + None, + "With store-root or store-id, which need it: the party this node is of (docs/store.md, Members), named in its entry and its handshakes. Nodes of a swarm holding a store sync with the nodes its parties list, each as its party's, and with no others.", + ), option( "strict-keys", Kind::List, @@ -671,6 +679,8 @@ pub(crate) struct Settings { pub(crate) store_file: Option<PathBuf>, #[cfg(feature = "federation")] pub(crate) store_checkpoint: Option<String>, + #[cfg(feature = "federation")] + pub(crate) store_party: Option<String>, #[serde(default)] pub(crate) strict_keys: Vec<String>, @@ -1141,16 +1151,36 @@ impl Settings { } (Some(_), None) => "store-root", (None, Some(_)) => "store-id", - (None, None) if self.store_file.is_some() => { - bail!( - "store-file keeps what is the node's own of a store: set store-root or store-id" - ) - } - (None, None) if self.store_checkpoint.is_some() => { - bail!("store-checkpoint pins a checkpoint of a store: set store-root or store-id") + (None, None) => { + let of_a_store = [ + ("store-file", self.store_file.is_some()), + ("store-checkpoint", self.store_checkpoint.is_some()), + ("store-party", self.store_party.is_some()), + ]; + let set: Vec<&str> = of_a_store + .iter() + .filter(|(_, set)| *set) + .map(|(name, _)| *name) + .collect(); + if !set.is_empty() { + bail!( + "{} {} of a node of a swarm holding a store: set store-root or store-id", + set.join(", "), + if set.len() == 1 { "is" } else { "are" } + ); + } + return Ok(()); } - (None, None) => return Ok(()), }; + match &self.store_party { + None => bail!( + "{store}: set store-party, the party this node is of: in a swarm holding a store, nodes sync with the nodes its parties list, each as its party's" + ), + Some(party) if !crate::federation::version::is_party(party) => bail!( + "store-party: {party:?} isn't a party's name (1 to 64 of A-Z a-z 0-9 . _ @ -)" + ), + Some(_) => {} + } let first_change = [ ("genesis", self.genesis), ("bootstrap-users", !self.bootstrap_users.is_empty()), @@ -1206,6 +1236,8 @@ impl Settings { ("store-file", self.store_file.is_some()), #[cfg(feature = "federation")] ("store-checkpoint", self.store_checkpoint.is_some()), + #[cfg(feature = "federation")] + ("store-party", self.store_party.is_some()), ("alias", self.alias.is_some()), ("dashboard-url", self.dashboard_url.is_some()), ("debug-api", self.debug_api), @@ -2282,6 +2314,32 @@ mod tests { assert_eq!(names, supervised); } + /// A node of a swarm holding a store: started from the root or joined by the ID, of a + /// party, and nothing of a store without either. + #[cfg(feature = "federation")] + #[test] + fn a_store_node_is_of_a_party() { + let checked = |values: JsonValue| { + let mut values = values; + values["htpasswd"] = json!("u"); + values["node-key-file"] = json!("node.key"); + resolve(layer(values), Vec::new()).map(|_| ()) + }; + let id = "ab".repeat(32); + assert!(checked(json!({ "store-id": id, "store-party": "tv" })).is_ok()); + assert!(checked(json!({ "store-root": "root.json", "store-party": "tv" })).is_ok()); + assert!(checked(json!({ "store-id": id })).is_err()); + assert!(checked(json!({ "store-id": id, "store-party": "t v" })).is_err()); + assert!(checked(json!({ "store-id": "ab", "store-party": "tv" })).is_err()); + assert!(checked(json!({ "store-party": "tv" })).is_err()); + assert!(checked(json!({ "store-file": "store.json" })).is_err()); + assert!( + checked(json!({ "store-id": id, "store-root": "root.json", "store-party": "tv" })) + .is_err() + ); + assert!(checked(json!({ "store-id": id, "store-party": "tv", "genesis": true })).is_err()); + } + #[test] fn checks() { assert!(resolve(layer(json!({})), Vec::new()).is_err()); // htpasswd is required |
