diff options
| author | tv <tv@krebsco.de> | 2026-11-20 01:31:09 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-20 02:39:01 +0100 |
| commit | 6e5afca5a795f3bf5da43f20c81fb70216ae12d8 (patch) | |
| tree | 47ae258bd4c66b4c0deb1278c6086eaf7ff869a2 /src | |
| parent | 96a733e1ccbf6dab2d69f263d655e487ac54c20d (diff) | |
continuum-party: found by a name, propose name, the name in status
`found` takes the federation's name (`--name`, required), and founds at
revision 2, the first that gives one, unless `--revision` names a later
one; one naming an earlier is an error. `propose name NAME` (and `fork
name`) names the federation anew, the next version following revision 2
too where the current one doesn't, which the preview says. `status` says
the name its current version gives beside the store's ID.
Diffstat (limited to 'src')
| -rw-r--r-- | src/federation/party.rs | 115 | ||||
| -rw-r--r-- | src/federation/party/status.rs | 21 |
2 files changed, 109 insertions, 27 deletions
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)"); |
