From 7f5abd6c7a16e7824c5e88cd392ef4b3f8507f07 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 20 Nov 2026 01:39:42 +0000 Subject: continuum-party found: the name optional, recommended Without `--name`, `found` writes a first version without a name, at the base revision or the one `--revision` names, as before names: such a federation differs from another by its parties, keys, nodes and rules alone, as two of one name do, and still founds where nodes don't know revision 2 yet. With it, revision 2 as before. The guide keeps `--name` in its example and recommends it. --- CHANGELOG.md | 3 +- docs/guides/federation/getting-started.md | 11 +++--- src/federation/party.rs | 56 ++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12be973..c37eb52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,8 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased -* `continuum-party found --name NAME` founds a federation by its name, at revision 2; +* `continuum-party found --name NAME` founds a federation by its name, at revision 2 + (without it, nameless, at the base revision or the one `--revision` names); `propose name NAME` names it anew, moving to revision 2 where it isn't yet; `status` says the name beside the store's ID ([`docs/guides/federation/getting-started.md`](docs/guides/federation/getting-started.md), diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md index fa81c94..aae3f06 100644 --- a/docs/guides/federation/getting-started.md +++ b/docs/guides/federation/getting-started.md @@ -49,9 +49,9 @@ printf '%s' 'secret' | argon2 "$(openssl rand -hex 16)" -id -e | sed 's/^/tv:/' ## The first version The founders agree on the first version, as a file. `continuum-party found` writes it -from the federation's name (`--name`), each party's keys (`PARTY=` an `authorized_keys` -line, or a file of them), its node list, and the rules in order (`--rule PATH=WRITER`), -each party writing in its namespace where no rule is given: +from the federation's name (`--name`, which we recommend), each party's keys (`PARTY=` an +`authorized_keys` line, or a file of them), its node list, and the rules in order +(`--rule PATH=WRITER`), each party writing in its namespace where no rule is given: ```sh continuum-party found --name krebs tv=tv.key.pub lass=lass.key.pub \ @@ -74,7 +74,10 @@ name is in the root, so a rehearsal named otherwise (`krebs-test`) is another fe though its parties, keys, nodes and rules are the same; a later version renames it, which changes what it is called, not which it is. It follows revision 2 of the federation, the first that gives a name; `--revision FEATURE` starts it on a later one -([`upgrades.md`](upgrades.md)). +([`upgrades.md`](upgrades.md)). Without `--name`, the federation has none, and follows +the base revision unless `--revision` says otherwise: it differs from another by its +parties, keys, nodes and rules alone, as two of one name do, and a name a later version +gives it changes that no more. ## The root diff --git a/src/federation/party.rs b/src/federation/party.rs index a46b492..9e9591b 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -217,10 +217,11 @@ fn command() -> Command { Arg::new("name") .long("name") .value_name("NAME") - .required(true) .help( - "The federation's name, in its root: a rehearsal named otherwise is \ - another federation. 1 to 64 of A-Z a-z 0-9 . _ @ -", + "The federation's name, in its root, at revision 2 or later: a \ + rehearsal named otherwise is another federation. 1 to 64 of A-Z \ + a-z 0-9 . _ @ -. Without it, two federations differ by their \ + parties, keys, nodes and rules alone", ), ) .arg( @@ -2307,12 +2308,13 @@ fn adding(name: &str) -> Result { Ok(feature.revision()) } -/// The first version of a federation, as `found`'s arguments `sub` say: its name +/// The first version of a federation, as `found`'s arguments `sub` say: its name, if any /// (`--name`); its parties, each with its keys (`PARTY=KEY|FILE`, again for more), `since` /// 0; their node lists (`--nodes PARTY=NODE,…`), empty where not given; its rules in order /// (`--rule PATH=WRITER`, `nobody` writing `false`), each party writing under -/// `home/{party}/` where none is given; and its revision (`--revision`), the one that gives -/// a name where none is given. Checked as a first version. +/// `home/{party}/` where none is given; and its revision (`--revision`), where none is given +/// the one that gives a name with a name, else the base revision. Checked as a first +/// version. fn founded(sub: &ArgMatches) -> Result { let mut keys: std::collections::BTreeMap> = Default::default(); for item in strings(sub, "parties") { @@ -2378,22 +2380,27 @@ fn founded(sub: &ArgMatches) -> Result { "nodes": given(&nodes, "nodes"), "rules": rules, }); + let name = sub.get_one::("name"); let revision = match sub.get_one::("revision") { Some(feature) => adding(feature)?, - None => Feature::FederationName.revision(), + None if name.is_some() => Feature::FederationName.revision(), + None => Revision::default(), }; - if !revision.has(Feature::FederationName) { - bail!( - "{revision} gives a version no name: {} does, and those after it", - Feature::FederationName.revision() - ); + if let Some(name) = name { + if !revision.has(Feature::FederationName) { + bail!( + "{revision} gives a version no name: {} does, and those after it", + Feature::FederationName.revision() + ); + } + if !super::version::is_party(name) { + bail!("{name:?} is no name: 1 to 64 of A-Z a-z 0-9 . _ @ -, as a party's"); + } + version["name"] = name.as_str().into(); } - version["revision"] = revision.id().to_string().into(); - let name = sub.get_one::("name").expect("required"); - if !super::version::is_party(name) { - bail!("{name:?} is no name: 1 to 64 of A-Z a-z 0-9 . _ @ -, as a party's"); + if revision != Revision::default() { + version["revision"] = revision.id().to_string().into(); } - version["name"] = name.as_str().into(); let read = Version::read(&client::json(&version).map_err(|why| anyhow!(why))?) .map_err(|why| anyhow!("no first version: {why}"))?; read.changes_validly(None) @@ -3053,8 +3060,9 @@ mod tests { }; let tv_key = format!("tv={}", tv.key_line()); let lass_key = format!("lass={}", lass_file.display()); + let nameless = founded; let named = ["--name".to_owned(), "krebs".to_owned()]; - let founded = |args: &[String]| founded(&[&named[..], args].concat()); + let founded = |args: &[String]| nameless(&[&named[..], args].concat()); let version = founded(&[ tv_key.clone(), lass_key.clone(), @@ -3096,8 +3104,16 @@ mod tests { ]) .unwrap_err(); assert!(why.to_string().contains("gives a version no name"), "{why}"); - let nameless = super::command().try_get_matches_from(["continuum-party", "found", &tv_key]); - assert!(nameless.is_err()); + // Without a name: none, at the base revision, or the revision given. + let unnamed = nameless(std::slice::from_ref(&tv_key)).unwrap(); + assert!(unnamed.get("name").is_none() && unnamed.get("revision").is_none()); + let merging = nameless(&[ + tv_key.clone(), + "--revision".to_owned(), + "merge-events".to_owned(), + ]) + .unwrap(); + assert!(merging.get("name").is_none() && merging.get("revision").is_some()); assert!(founded(&[tv_key.clone(), tv_key.clone()]).is_err()); assert!( founded(&[ -- cgit v1.3.1