diff options
| -rw-r--r-- | CHANGELOG.md | 8 | ||||
| -rw-r--r-- | docs/guides/federation/common-changes.md | 7 | ||||
| -rw-r--r-- | docs/guides/federation/getting-started.md | 18 | ||||
| -rw-r--r-- | docs/guides/federation/watching.md | 5 | ||||
| -rw-r--r-- | share/bash-completion/completions/continuum-party | 7 | ||||
| -rw-r--r-- | src/federation/party.rs | 115 | ||||
| -rw-r--r-- | src/federation/party/status.rs | 21 |
7 files changed, 142 insertions, 39 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a666db..12be973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ 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; + `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), + [`docs/guides/federation/common-changes.md`](docs/guides/federation/common-changes.md), + [Naming the federation anew](docs/guides/federation/common-changes.md#naming-the-federation-anew); + [`src/federation/party.rs`](src/federation/party.rs)). + * Revision 2 of federation 1, `federation-name`: a version may give the federation a name, which a later one changes; the first version's, in the root, parts the federation from a rehearsal of the same parties, keys, nodes and rules named otherwise diff --git a/docs/guides/federation/common-changes.md b/docs/guides/federation/common-changes.md index 8a31080..51a6644 100644 --- a/docs/guides/federation/common-changes.md +++ b/docs/guides/federation/common-changes.md @@ -150,3 +150,10 @@ a node voting by itself backs no version naming a checkpoint that changes more. `propose revision FEATURE`: the next version, following the revision that adds the feature, once every party's nodes run a continuum that knows it ([`upgrades.md`](upgrades.md), [Moving to a revision](upgrades.md#moving-to-a-revision)). + +## Naming the federation anew + +`propose name NAME`: the next version, giving the federation another name, which changes +what it is called, not which it is: its root keeps the name it was founded with. Where +the current version follows a revision that gives no name, the next one follows revision +2 too, which takes every party's nodes running a continuum that knows it, as above. diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md index c2e1bc6..fa81c94 100644 --- a/docs/guides/federation/getting-started.md +++ b/docs/guides/federation/getting-started.md @@ -49,17 +49,18 @@ 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 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`), 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 tv=tv.key.pub lass=lass.key.pub \ +continuum-party found --name krebs tv=tv.key.pub lass=lass.key.pub \ --nodes tv=continuum:5be1… --nodes lass=continuum:9c07… > first.json ``` ```json -{ "federation": 1, "number": 0, "changes": null, +{ "federation": 1, "number": 0, "changes": null, "name": "krebs", + "revision": "<ID of revision 2>", "keys": { "tv": { "since": 0, "keys": ["ssh-ed25519 AAAA…"] }, "lass": { "since": 0, "keys": ["ssh-ed25519 AAAA…"] } }, "nodes": { "tv": { "since": 0, "nodes": ["continuum:5be1…"] }, @@ -68,8 +69,11 @@ continuum-party found tv=tv.key.pub lass=lass.key.pub \ ``` Each party writes in its namespace (`home/tv/…`), and nowhere else: no other rule gives -a place. Every change of the version takes two thirds of its parties: of two, both. -`--revision FEATURE` starts it on a later revision of the federation +a place. Every change of the version takes two thirds of its parties: of two, both. The +name is in the root, so a rehearsal named otherwise (`krebs-test`) is another federation, +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)). ## The root diff --git a/docs/guides/federation/watching.md b/docs/guides/federation/watching.md index 4bc062d..a60b1ab 100644 --- a/docs/guides/federation/watching.md +++ b/docs/guides/federation/watching.md @@ -11,7 +11,7 @@ store, through its API and its log. (`read`, `values`), with what needs a look in colour on a terminal: ``` -store 6d1e8a0c4f2b9d77… +store 6d1e8a0c4f2b9d77… (krebs) checkpoint 6d1e8a0c4f2b9d77… 3 heads, 120 events taken after the checkpoint the node continuum:9c07e2a4b6d8f0a1… (beta) @@ -49,7 +49,8 @@ you: tv ``` IDs and hashes are cut short here; the client writes them whole, the shortest prefix -naming a proposal in bold, and keys by their fingerprints. Every node goes by the name it +naming a proposal in bold, and keys by their fingerprints. The store goes by the name its +federation's current version gives it, where one does. Every node goes by the name it gave itself (`--alias`) where the node knows it, a node no party lists yet by its ID alone. It says of every party's nodes how long ago the node heard from each, and what each runs (its wire versions and the newest revision it knows: the nodes to upgrade before a diff --git a/share/bash-completion/completions/continuum-party b/share/bash-completion/completions/continuum-party index dbc8961..d13a5a1 100644 --- a/share/bash-completion/completions/continuum-party +++ b/share/bash-completion/completions/continuum-party @@ -82,7 +82,7 @@ _continuum_party() --unset --help --version' local commands='init write keys nodes next propose vote again restore found root fork check judge proposals show status values read twice help' - local intents='admit remove give take keys nodes checkpoint revision' + local intents='admit remove give take keys nodes checkpoint revision name' # The command, the intent of `propose` and `fork`, and the arguments after them that # are no options, as far as the word completed. @@ -146,7 +146,8 @@ _continuum_party() [[ $command == keys ]] && _continuum_party_files return ;; - --node | --token | --unset | --nodes | --founder | --rule | --at | --wait | --party) + --node | --token | --unset | --nodes | --founder | --rule | --at | --wait | --party | \ + --name) return ;; esac @@ -236,7 +237,7 @@ _continuum_party() [[ $cur == -* ]] && _continuum_party_words '--revision' ;; found) - [[ $cur == -* ]] && _continuum_party_words '--nodes --rule --revision' + [[ $cur == -* ]] && _continuum_party_words '--name --nodes --rule --revision' ;; root | check | twice) _continuum_party_files diff --git a/src/federation/party.rs b/src/federation/party.rs index 813b1e6..a46b492 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -11,7 +11,7 @@ //! * `init PARTY`: begins a record of `PARTY`, on the version current now; with `--root //! FILE`, from the file the store's swarm starts from, for a party that never voted in //! it: the record casts on every version, the first too; -//! * `write PATH VALUE`: writes `VALUE` (JSON) at `PATH`; +//! * `write PATH VALUE`: writes `VALUE` (JSON; with `-r`, a string as it is) at `PATH`; //! * `keys`, `nodes`: the party's key set (`authorized_keys` lines, each one argument, or //! files of them, their comments left out) or node list (node IDs) as it counts at the //! node, one a line (`--list`); or written: with `--add` and `--remove`, the set or list @@ -23,7 +23,7 @@ //! (`client::backable`), saying first what it does and asking on a terminal, and says //! the proposal's hash; with `--yes`, votes `true` on it too, as `vote` does; with //! `--print`, writes the version to standard output instead. `propose admit`, `remove`, -//! `give`, `take`, `keys`, `nodes`, `checkpoint` and `revision` propose the next +//! `give`, `take`, `keys`, `nodes`, `checkpoint`, `revision` and `name` propose the next //! version changed as they say (`Intent`), likewise; //! * `vote PROPOSAL yes|no`: votes on the proposal of hash `PROPOSAL` on the current //! version, by the record; with `--through`, through the node that votes for the @@ -48,8 +48,8 @@ //! where none are) by the version `FILE` holds, as the node builds it, with the events //! it keeps: the file the fork's founders start its swarm from, to standard output. //! `fork proposal PROPOSAL` forks by the version a proposal proposes, and `fork admit`, -//! `remove`, `give`, `take`, `keys`, `nodes` and `revision` by the next version changed -//! as they say, as `propose` does; at the heads `--at` names, `--founder PARTY=NODE,…` +//! `remove`, `give`, `take`, `keys`, `nodes`, `revision` and `name` by the next version +//! changed as they say, as `propose` does; at the heads `--at` names, `--founder PARTY=NODE,…` //! naming a party's node list anew in the fork; //! * `check FILE`: what the node finds of the fork whose root `FILE` holds: whether it //! builds it, what it holds that its heads lack, and the parties whose keys it gives @@ -74,7 +74,7 @@ use super::fold::Federation; use super::jcs::Json; use super::judge; use super::keys::{self, Key}; -use super::revision::{FEATURES, Revision}; +use super::revision::{FEATURES, Feature, Revision}; use super::store::Id; use super::store::memory::Store; use super::version::Version; @@ -211,7 +211,17 @@ fn command() -> Command { Command::new("found") .about( "The first version of a federation (JSON), to standard output, from its \ - parties' keys, node lists and rules: what root makes the root of", + name, its parties' keys, node lists and rules: what root makes the root of", + ) + .arg( + 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 . _ @ -", + ), ) .arg( Arg::new("parties") @@ -246,7 +256,10 @@ fn command() -> Command { Arg::new("revision") .long("revision") .value_name("FEATURE") - .help("Following the revision that adds FEATURE, as next --revision"), + .help( + "Following the revision that adds FEATURE, as next --revision: \ + federation-name or later, which give a name", + ), ), ) .subcommand( @@ -460,6 +473,12 @@ fn intents() -> Vec<Command> { federation): once every party's nodes run a continuum that knows it", ) .arg(required("feature")), + Command::new("name") + .about( + "Names the federation anew, which changes what it is called, not which it is; \ + following the revision that gives a name, where the current version doesn't", + ) + .arg(required("name")), ] } @@ -1109,6 +1128,7 @@ async fn intent_of(node: &Node, name: &str, given: &ArgMatches) -> Result<Intent }, "checkpoint" => Intent::Checkpoint(node.summary().await?.1), "revision" => Intent::Revision(one("feature")), + "name" => Intent::Name(one("name")), _ => unreachable!("every intent handled"), }) } @@ -2146,6 +2166,9 @@ enum Intent { Checkpoint(Vec<Id>), /// Follows the revision that adds this feature (`next`). Revision(String), + /// Names the federation anew, following the revision that gives a name where the + /// current version doesn't. + Name(String), } /// The version after `current` (`next`), changed as `intent` says: checked here where the @@ -2155,6 +2178,21 @@ fn intended(current: &Version, intent: &Intent) -> Result<JsonValue> { if let Intent::Revision(feature) = intent { return next(current, Some(feature)); } + if let Intent::Name(name) = intent { + 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 current.name.as_deref() == Some(name.as_str()) { + bail!("the federation is named {name} already"); + } + let giving = Feature::FederationName; + let mut next = next( + current, + (!current.revision.has(giving)).then_some(giving.name()), + )?; + next["name"] = name.as_str().into(); + return Ok(next); + } let mut next = next(current, None)?; let number = next["number"].clone(); let of = |party: &str| -> Result<()> { @@ -2225,7 +2263,7 @@ fn intended(current: &Version, intent: &Intent) -> Result<JsonValue> { heads.dedup(); next["checkpoint"] = heads.iter().map(Id::to_string).collect::<Vec<_>>().into(); } - Intent::Revision(_) => unreachable!("returned above"), + Intent::Revision(_) | Intent::Name(_) => unreachable!("returned above"), } Ok(next) } @@ -2269,11 +2307,12 @@ fn adding(name: &str) -> Result<Revision> { Ok(feature.revision()) } -/// The first version of a federation, as `found`'s arguments `sub` say: 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`). Checked as a first version. +/// The first version of a federation, as `found`'s arguments `sub` say: its name +/// (`--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. fn founded(sub: &ArgMatches) -> Result<JsonValue> { let mut keys: std::collections::BTreeMap<String, Vec<String>> = Default::default(); for item in strings(sub, "parties") { @@ -2339,12 +2378,22 @@ fn founded(sub: &ArgMatches) -> Result<JsonValue> { "nodes": given(&nodes, "nodes"), "rules": rules, }); - if let Some(name) = sub.get_one::<String>("revision") { - let revision = adding(name)?; - if revision != Revision::default() { - version["revision"] = revision.id().to_string().into(); - } + let revision = match sub.get_one::<String>("revision") { + Some(feature) => adding(feature)?, + None => Feature::FederationName.revision(), + }; + if !revision.has(Feature::FederationName) { + bail!( + "{revision} gives a version no name: {} does, and those after it", + Feature::FederationName.revision() + ); + } + version["revision"] = revision.id().to_string().into(); + let name = sub.get_one::<String>("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"); } + 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) @@ -2966,6 +3015,17 @@ mod tests { let revised = made(Intent::Revision("merge-events".to_owned())); assert_ne!(revised.revision, current.revision); + + // A name, following the revision that gives one where the current version doesn't. + let named = made(Intent::Name("krebs".to_owned())); + assert_eq!(named.name.as_deref(), Some("krebs")); + assert_eq!(named.revision, super::Feature::FederationName.revision()); + let renamed = intended(&named, &Intent::Name("krebs-test".to_owned())).unwrap(); + let renamed = client::backable(&named, &client::json(&renamed).unwrap()).unwrap(); + assert_eq!(renamed.name.as_deref(), Some("krebs-test")); + assert_eq!(renamed.revision, named.revision); + assert!(intended(&named, &Intent::Name("krebs".to_owned())).is_err()); + assert!(intended(¤t, &Intent::Name("a/b".to_owned())).is_err()); } /// `found` writes a first version from the parties' keys, node lists and rules: each @@ -2993,6 +3053,8 @@ mod tests { }; let tv_key = format!("tv={}", tv.key_line()); let lass_key = format!("lass={}", lass_file.display()); + let named = ["--name".to_owned(), "krebs".to_owned()]; + let founded = |args: &[String]| founded(&[&named[..], args].concat()); let version = founded(&[ tv_key.clone(), lass_key.clone(), @@ -3001,6 +3063,7 @@ mod tests { ]) .unwrap(); assert_eq!(version["number"], 0); + assert_eq!(version["name"], "krebs"); assert_eq!(version["keys"]["lass"]["keys"][0], lass.key_line().as_str()); assert_eq!(version["nodes"]["tv"]["nodes"][1], node_id(2).as_str()); assert_eq!(version["nodes"]["lass"]["nodes"], serde_json::json!([])); @@ -3009,7 +3072,9 @@ mod tests { serde_json::json!([{"path": "home/{party}/**", "writer": "{party}"}]) ); let json = crate::federation::client::json(&version).unwrap(); - Version::read(&json).unwrap().changes_validly(None).unwrap(); + let read = Version::read(&json).unwrap(); + read.changes_validly(None).unwrap(); + assert_eq!(read.revision, super::Feature::FederationName.revision()); let ruled = founded(&[ tv_key.clone(), @@ -3018,11 +3083,21 @@ mod tests { "--rule".to_owned(), "names/**=nobody".to_owned(), "--revision".to_owned(), - "merge-events".to_owned(), + "federation-name".to_owned(), ]) .unwrap(); assert_eq!(ruled["rules"][1]["writer"], false); assert!(ruled.get("revision").is_some()); + // A revision giving no name, or a name that is none, founds nothing. + let why = founded(&[ + tv_key.clone(), + "--revision".to_owned(), + "merge-events".to_owned(), + ]) + .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()); assert!(founded(&[tv_key.clone(), tv_key.clone()]).is_err()); assert!( founded(&[ diff --git a/src/federation/party/status.rs b/src/federation/party/status.rs index 6094a23..68953fe 100644 --- a/src/federation/party/status.rs +++ b/src/federation/party/status.rs @@ -1,9 +1,9 @@ //! `continuum-party status`: everything about the federation at a node but the values -//! (`values`, `read`). The store; the node; the current version; every party's keys and -//! nodes, when the node last heard from each and what each runs; the proposals on the -//! current version, how they stand and what each does; what the node refused of its own; -//! and the party the client works as: its key, its record against the node, what it signs -//! again; with what may keep votes away. +//! (`values`, `read`). The store, with the federation's name; the node; the current +//! version; every party's keys and nodes, when the node last heard from each and what each +//! runs; the proposals on the current version, how they stand and what each does; what +//! the node refused of its own; and the party the client works as: its key, its record +//! against the node, what it signs again; with what may keep votes away. //! //! As people read it, in colours on a terminal (`Paint`), which may change from release to //! release; with `--json`, the same as one JSON object (`model`), of a format versioned by @@ -124,6 +124,7 @@ async fn model(node: &Node, options: &Options, party: Option<&str>) -> Result<Js "version": { "number": current.number, "hash": current.hash.to_string(), + "name": current.name, "federation": counts["version"]["version"]["federation"], "revision": counts["version"]["revision"], "parties": current.parties.len(), @@ -422,8 +423,13 @@ fn render(model: &JsonValue, paint: &Paint) -> Vec<String> { let number = |value: &JsonValue| value.as_u64().unwrap_or_default(); let store = &model["store"]; + // The federation's name, as its current version gives it, after the store's ID. + let called = match model["version"]["name"].as_str() { + Some(name) => format!(" ({})", paint.paint(Style::Party, name)), + None => String::new(), + }; out.push(format!( - "{} {}", + "{} {}{called}", heading("store"), paint.paint(Style::Id, &text(&store["id"])) )); @@ -782,6 +788,7 @@ mod tests { "version": { "number": 3, "hash": "a7c2", + "name": "krebs", "federation": 1, "revision": {"named": "the base revision"}, "parties": 2, @@ -862,7 +869,7 @@ mod tests { lines.join("\n") ); }; - has("store 6d1e"); + has("store 6d1e (krebs)"); has("the node continuum:9c07 (beta)"); has(" lass's, voting for it by itself"); has("version 3 (a7c2)"); |
