From 011560a72ca895d8b516983485cfc45c9984cd45 Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 19 Nov 2026 20:55:59 +0000 Subject: continuum-party --party: the party it reads as, without a record A record is what votes go by, and what `again` signs anew from; for logging in as the party, and for `status`, it only named the party. So someone who only reads needed a record, begun with `init`, which should never vote beside the party's own. `--party NAME` (an option as node, key and record are, so party.toml holds it too) names the party where no record does (working_as): `init` the one it begins a record of, else the record's, else --party; --party naming another than these is an error. Commands that sign still take a record. --- CHANGELOG.md | 4 ++ docs/configuration.md | 12 +++- docs/guides/federation/running-a-node.md | 2 +- src/config/mod.rs | 7 ++ src/federation/party.rs | 116 +++++++++++++++++++++++++------ 5 files changed, 115 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d04acf..ae116bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ it from the release before ([`docs/operations.md`](docs/operations.md), ## Unreleased +* `continuum-party --party NAME` names the party it reads as where no record does: one who + only reads needs no record ([`docs/configuration.md`](docs/configuration.md), + [The party's client](docs/configuration.md#the-partys-client)). + * `continuum-party` logs in as its party by its key where `--node` names no user and no `--token` is given ([`docs/configuration.md`](docs/configuration.md), [The party's client](docs/configuration.md#the-partys-client); diff --git a/docs/configuration.md b/docs/configuration.md index ea401f5..0efdfc3 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -275,8 +275,16 @@ continuum-party vote 8d02 yes # krebs, the only one Where `node` names no user and no `token` is given, the client logs in to the node as its party, by `key`, where the federated node takes it: a party's session, which reads and puts events and nothing else ([`guides/federation/running-a-node.md`](guides/federation/running-a-node.md), -[Its API](guides/federation/running-a-node.md#its-api)). So `node = "https://node.example"` -and a key whose party a version names are all a party's people need. +[Its API](guides/federation/running-a-node.md#its-api)). The party is the one its record +names, or, without a record, `party`: a record is what votes go by, and what `again` +signs anew from, so one who only reads needs none. So a federation's directory with this +`party.toml` is all one of a party's people needs to read (`status`, `values`): + +```toml +node = "https://node.example" +key = "/home/alice/.ssh/laptop.pub" +party = "tv" +``` `key` is an OpenSSH private key file, or a public key an ssh-agent holds: the key itself (`key = "ecdsa-sha2-nistp256 AAAA…"`), or a file of such lines, whose first signs diff --git a/docs/guides/federation/running-a-node.md b/docs/guides/federation/running-a-node.md index 44b309a..164c00d 100644 --- a/docs/guides/federation/running-a-node.md +++ b/docs/guides/federation/running-a-node.md @@ -80,7 +80,7 @@ alone, so that a party listing many nodes can't be all of a node's neighbours. party's people, each with a key of its set, work with the federation through any node that holds it, as no operator has to let them in, and with nothing of an operator's powers. `continuum-party` logs in so by itself, where `--node` names no user and no - `--token` is given, as the party its record names. + `--token` is given, as the party its record names, or `--party` without one. * **The events** (`docs/openapi.yaml`, Events): `GET /events` (the store's ID, its checkpoint, its heads, how many events it took, the node's party, and whether it votes for it by itself), `POST /events` (an event, whoever signed it), `GET /events/{id}`, diff --git a/src/config/mod.rs b/src/config/mod.rs index 0b6a58a..1f6ad60 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -781,6 +781,13 @@ pub(crate) const PARTY_OPTIONS: &[OptionSpec] = &[ None, "The party's record of its votes, written before each vote is sent", ), + option( + "party", + Kind::Text, + "NAME", + None, + "The party it works as where no record names it, for reading: the one it logs in to the node as, by --key, where --node names no user and no --token is given", + ), ]; #[cfg(not(feature = "federation"))] const PARTY_OPTIONS: &[OptionSpec] = &[]; diff --git a/src/federation/party.rs b/src/federation/party.rs index 72c18e9..17769f3 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -3,9 +3,10 @@ //! key the ssh-agent at `SSH_AUTH_SOCK` holds, given itself or in a file), puts them //! through a node's API (`--node`, its user and password in the URL, or `--token`; with //! neither, as its party, logging in there by that key: `Node::log_in`), and keeps its -//! party's record (`--record`, `client::Record`), by which it votes, written -//! before a vote is sent. Its options may be set in configuration files as the node's are -//! (`--config`, `config::PARTY_OPTIONS`): the same format, imports and all. +//! party's record (`--record`, `client::Record`), by which it votes, written before a vote +//! is sent; without one, `--party` names the party it reads as. Its options may be set in +//! configuration files as the node's are (`--config`, `config::PARTY_OPTIONS`): the same +//! format, imports and all. //! //! * `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 @@ -86,6 +87,7 @@ struct Options { token: Option, key: Option, record: Option, + party: Option, } fn default_node() -> String { @@ -618,21 +620,14 @@ pub(crate) async fn main() -> Result<()> { return Ok(()); } let mut node = Node::new(&options)?; - // Without a user of the node or a token: as the party, by its key, where the record - // (or `init`) names the party. - if node.password.is_none() && node.token.is_none() && options.key.is_some() { - let party = match (name, &options.record) { - ("init", _) => sub.get_one::("party").cloned(), - (_, Some(path)) if Path::new(path).exists() => Some( - Record::load(Path::new(path)) - .map_err(|why| anyhow!(why))? - .party, - ), - _ => None, - }; - if let Some(party) = party { - node.log_in(&party, &signing_key(&options)?).await?; - } + let party = working_as(name, sub, &options)?; + // Without a user of the node or a token: as the party, by its key. + if node.password.is_none() + && node.token.is_none() + && options.key.is_some() + && let Some(party) = &party + { + node.log_in(party, &signing_key(&options)?).await?; } if name == "propose" && proposing_flags(sub).get_flag("print") { let current = node.current().await?; @@ -645,7 +640,7 @@ pub(crate) async fn main() -> Result<()> { return proposals(&node).await; } if name == "status" { - return status(&node, &options).await; + return status(&node, &options, party.as_deref()).await; } if name == "values" { return values(&node, sub).await; @@ -1526,13 +1521,43 @@ async fn again(node: &Node, signer: &Signer, record: &mut Record, path: &Path) - Ok(()) } +/// The party the client works as: for `init`, the one it begins a record of; else the +/// one its record names, where there is one, else `--party`; none where neither. `--party` +/// naming another than these is an error. +fn working_as(name: &str, sub: &ArgMatches, options: &Options) -> Result> { + let named = if name == "init" { + sub.get_one::("party").cloned() + } else { + options + .record + .as_ref() + .map(Path::new) + .filter(|path| path.exists()) + .map(|path| Record::load(path).map(|record| record.party)) + .transpose() + .map_err(|why| anyhow!(why))? + }; + match (named, &options.party) { + (Some(named), Some(given)) if named != *given => { + let whose = if name == "init" { + "init begins a record of" + } else { + "the record is" + }; + bail!("--party {given}, but {whose} {named}'s") + } + (Some(named), _) => Ok(Some(named)), + (None, given) => Ok(given.clone()), + } +} + /// What the node and the party's record say at a glance: the store, its checkpoint and /// heads; the current version, its federation and revision, and its parties; the party's /// keys and node list as they count, and whether the version names `--key`; the node's /// party, whether it votes for it by itself, and where it stopped; the proposals on the /// current version, each as `show` begins; the versions the node refused of its own; and /// what a move refused that the party signs again (`again`). -async fn status(node: &Node, options: &Options) -> Result<()> { +async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<()> { let summary = node.get("/events").await?; let counts = node.counts().await?; let current = current(&counts)?; @@ -1572,9 +1597,8 @@ async fn status(node: &Node, options: &Options) -> Result<()> { .filter(|path| path.exists()) .map(|path| Record::load(&path).map_err(|why| anyhow!(why))) .transpose()?; - let party = record - .as_ref() - .map(|record| record.party.clone()) + let party = party + .map(str::to_owned) .or_else(|| summary["party"].as_str().map(str::to_owned)); if let Some(party) = &party { let keys = listed(&counts, party, "keys"); @@ -2796,6 +2820,52 @@ mod tests { assert!(founded(&[tv_key, "--rule".to_owned(), "names/r/wiki=lass".to_owned()]).is_err()); } + /// The party the client works as: `init`'s, the record's, else `--party`; `--party` + /// naming another is an error. + #[test] + fn the_party_it_works_as() { + use crate::federation::client::Record; + use crate::federation::store::Id; + let dir = crate::files::scratch_dir("party-working-as"); + let record = dir.join("tv.record"); + Record::before(Id::of(b"a root"), "tv") + .save(&record) + .unwrap(); + let working_as = |args: &[&str], record: Option<&std::path::Path>, party: Option<&str>| { + let matches = super::command() + .try_get_matches_from(["continuum-party"].iter().chain(args)) + .unwrap(); + let (name, sub) = matches.subcommand().unwrap(); + let options = super::Options { + node: super::default_node(), + token: None, + key: None, + record: record.map(|path| path.display().to_string()), + party: party.map(str::to_owned), + }; + super::working_as(name, sub, &options) + }; + assert_eq!( + working_as(&["init", "tv"], None, None).unwrap().as_deref(), + Some("tv") + ); + assert!(working_as(&["init", "tv"], None, Some("lass")).is_err()); + assert_eq!( + working_as(&["status"], Some(&record), None) + .unwrap() + .as_deref(), + Some("tv") + ); + assert!(working_as(&["status"], Some(&record), Some("lass")).is_err()); + assert_eq!( + working_as(&["status"], Some(&dir.join("none")), Some("lass")) + .unwrap() + .as_deref(), + Some("lass") + ); + assert_eq!(working_as(&["status"], None, None).unwrap(), None); + } + /// `values` shows a place and those under it, not those beside it. #[test] fn places_under_a_path() { -- cgit v1.3.1