diff options
| author | tv <tv@krebsco.de> | 2026-11-19 20:58:40 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-19 22:10:16 +0100 |
| commit | 59cc0283117be6b4195afbe857d702e7f8ddba6e (patch) | |
| tree | e16ca3aeddb1007eff6b5b289b95a9f562730199 /src/federation/party.rs | |
| parent | 011560a72ca895d8b516983485cfc45c9984cd45 (diff) | |
continuum-party status: a key, a node, a party a line, nodes by their names
`status` said each party's keys and nodes in one line, separated by
commas, nodes by their IDs alone. Now each goes on a line of its own,
indented beneath its heading (party_lines): the keys the version names,
which sign votes, proposals, the key set and node list; those of the key
set as it counts, which sign writes, or `the same`; `--key`'s marked, and
said where it is none of them; and the nodes, each with the name it gave
itself (`--alias`) where it did, as the dashboard names nodes. The store
and the version are a heading each too, the parties one a line.
The names come from GET /events/counts, which gives each party's
`names` now (by node ID, of the nodes that gave themselves one), so that
a party's session, which reads no /peers, has them. Bash completion
reads the parties from the new layout.
Diffstat (limited to 'src/federation/party.rs')
| -rw-r--r-- | src/federation/party.rs | 176 |
1 files changed, 120 insertions, 56 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs index 17769f3..19aadbd 100644 --- a/src/federation/party.rs +++ b/src/federation/party.rs @@ -1566,30 +1566,37 @@ async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<( _ => id.to_owned(), }; let text = |value: &JsonValue| value.as_str().unwrap_or_default().to_owned(); + let plural = + |n: usize, one: &str, many: &str| format!("{n} {}", if n == 1 { one } else { many }); let heads = summary["heads"].as_array().map_or(0, Vec::len); + println!("store {}", short(&text(&summary["store"]))); + println!(" checkpoint {}", short(&text(&summary["checkpoint"]))); println!( - "store {}: checkpoint {}, {heads} head{}, {} events taken after it", - short(&text(&summary["store"])), - short(&text(&summary["checkpoint"])), - if heads == 1 { "" } else { "s" }, - summary["taken"] + " {}, {} taken after the checkpoint", + plural(heads, "head", "heads"), + plural( + summary["taken"].as_u64().unwrap_or_default() as usize, + "event", + "events" + ) ); - let parties: Vec<&String> = current.parties.keys().collect(); - let needed = (2 * parties.len()).div_ceil(3); + let needed = (2 * current.parties.len()).div_ceil(3); println!( - "version {} ({}) of federation {}, {}: {} part{}, {needed} passing a change ({})", + "version {} ({})", current.number, - short(¤t.hash.to_string()), - counts["version"]["version"]["federation"], - current.revision, - parties.len(), - if parties.len() == 1 { "y" } else { "ies" }, - parties - .iter() - .map(|party| party.as_str()) - .collect::<Vec<_>>() - .join(", ") + short(¤t.hash.to_string()) ); + println!( + " federation {}, {}", + counts["version"]["version"]["federation"], current.revision + ); + println!( + " {}, {needed} passing a change:", + plural(current.parties.len(), "party", "parties") + ); + for party in current.parties.keys() { + println!(" {party}"); + } let record = options .record .as_ref() @@ -1601,46 +1608,14 @@ async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<( .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"); - let nodes = listed(&counts, party, "nodes"); - let named = match options.key.as_deref().map(given_key) { - Some(Ok(given)) => { - let line = match given { - Given::Private(key) => PublicKey(key.verifying_key().to_bytes()).line(), - Given::Public(key, _) => key.line(), - }; - let names = current - .parties - .get(party) - .is_some_and(|given| given.keys.contains(&line)); - if names { - "; the version names --key's" - } else { - "; the version doesn't name --key's: it signs none of its votes, proposals, \ - key set or node list" + println!("{party}"); + match current.parties.get(party) { + None => println!(" no party of version {}", current.number), + Some(given) => { + for line in party_lines(&counts, party, &given.keys, options.key.as_deref()) { + println!(" {line}"); } } - _ => "", - }; - let spelled = |items: &[String], spell: fn(&str) -> String| { - items - .iter() - .map(|item| spell(item)) - .collect::<Vec<_>>() - .join(", ") - }; - if current.parties.contains_key(party) { - println!( - "{party}: {} key{} ({}){named}; {} node{} ({})", - keys.len(), - if keys.len() == 1 { "" } else { "s" }, - spelled(&keys, client::fingerprint), - nodes.len(), - if nodes.len() == 1 { "" } else { "s" }, - spelled(&nodes, |node| node.to_owned()), - ); - } else { - println!("{party}: no party of version {}", current.number); } } let by_itself = if summary["votesByItself"].as_bool() == Some(true) { @@ -1707,6 +1682,63 @@ async fn status(node: &Node, options: &Options, party: Option<&str>) -> Result<( Ok(()) } +/// A party's keys and nodes, as `status` says them under its name, a line each, indented +/// beneath their heading: the keys the version names (`named`), which sign its votes, +/// proposals, key set and node list; those of its key set as it counts (`counts`), which +/// sign its writes; each by its fingerprint, `--key`'s (`given`) marked, and said where +/// it is neither; and its nodes as they count, by ID, each with the name it gave itself +/// where it did. +fn party_lines( + counts: &JsonValue, + party: &str, + named: &[String], + given: Option<&str>, +) -> Vec<String> { + let given = given.and_then(|given| match given_key(given).ok()? { + Given::Private(key) => Some(PublicKey(key.verifying_key().to_bytes()).line()), + Given::Public(key, _) => Some(key.line()), + }); + let key_line = |key: &String| { + let mark = if given.as_ref() == Some(key) { + " (--key)" + } else { + "" + }; + format!(" {}{mark}", client::fingerprint(key)) + }; + let set = listed(counts, party, "keys"); + let mut lines = + vec!["keys the version names (votes, proposals, key set, node list):".to_owned()]; + lines.extend(named.iter().map(key_line)); + if set == named { + lines.push("keys of its key set (writes): the same".to_owned()); + } else { + lines.push("keys of its key set (writes):".to_owned()); + lines.extend(set.iter().map(key_line)); + } + if let Some(given) = &given + && !named.contains(given) + && !set.contains(given) + { + lines.push(format!( + "--key, {}, is none of these: it signs nothing for {party}", + client::fingerprint(given) + )); + } + let nodes = listed(counts, party, "nodes"); + if nodes.is_empty() { + lines.push("nodes: none".to_owned()); + } else { + lines.push("nodes:".to_owned()); + } + let names = &counts["parties"][party]["names"]; + lines.extend(nodes.iter().map(|node| match names[node].as_str() { + Some(name) => format!(" {node} ({name})"), + None => format!(" {node}"), + })); + lines +} + /// The values that count, all or under the place `path` names (and it), each with who /// writes there, a line each: `PATH VALUE (WRITER)`, the value as JSON; or with `--json`, /// one JSON object of them, by place. @@ -2866,6 +2898,38 @@ mod tests { assert_eq!(working_as(&["status"], None, None).unwrap(), None); } + /// `status` says a party's keys and nodes a line each: the version's, its key set's + /// where they differ, `--key`'s marked, and each node with the name it gave itself. + #[test] + fn a_partys_keys_and_nodes_a_line_each() { + use crate::federation::client::fingerprint; + use crate::federation::harness::{key_line, node_id}; + let (named, laptop) = (key_line(1), key_line(2)); + let counts = serde_json::json!({"parties": {"tv": { + "keys": [laptop], + "nodes": [node_id(1), node_id(2)], + "names": {node_id(1): "alpha"}, + }}}); + let dir = crate::files::scratch_dir("party-lines"); + let given = dir.join("laptop.pub"); + std::fs::write(&given, format!("{laptop} tv@laptop\n")).unwrap(); + let lines = super::party_lines(&counts, "tv", std::slice::from_ref(&named), given.to_str()); + assert_eq!( + lines, + [ + "keys the version names (votes, proposals, key set, node list):".to_owned(), + format!(" {}", fingerprint(&named)), + "keys of its key set (writes):".to_owned(), + format!(" {} (--key)", fingerprint(&laptop)), + "nodes:".to_owned(), + format!(" {} (alpha)", node_id(1)), + format!(" {}", node_id(2)), + ] + ); + let lines = super::party_lines(&counts, "tv", std::slice::from_ref(&laptop), None); + assert_eq!(lines[2], "keys of its key set (writes): the same"); + } + /// `values` shows a place and those under it, not those beside it. #[test] fn places_under_a_path() { |
