aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 01:42:08 +0000
committertv <tv@krebsco.de>2026-11-20 02:46:18 +0100
commit43259e8bc812db6d8f6e767a22d48d0b28f5dccf (patch)
treee8a6320962600fef34e448b36a3c6db5da4e6448 /src
parent7f5abd6c7a16e7824c5e88cd392ef4b3f8507f07 (diff)
continuum-party found: a random name at revision 2 where none is given
At a revision that gives a name, `found` without `--name` names the federation at random, 16 hex digits, and says so on standard error: so every first version it writes at revision 2 or later has a name in its root, and a rehearsal is another federation even where nobody named it. `found` then writes another federation each run, and its founders share the file it wrote, as they do. Without `--name` and `--revision`, the base revision and no name, as before.
Diffstat (limited to 'src')
-rw-r--r--src/federation/party.rs50
1 files changed, 43 insertions, 7 deletions
diff --git a/src/federation/party.rs b/src/federation/party.rs
index 9e9591b..ff66de3 100644
--- a/src/federation/party.rs
+++ b/src/federation/party.rs
@@ -220,8 +220,9 @@ fn command() -> Command {
.help(
"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",
+ a-z 0-9 . _ @ -. Without it, at revision 2 or later a random one; \
+ before, none, two federations differing by their parties, keys, \
+ nodes and rules alone",
),
)
.arg(
@@ -2313,8 +2314,8 @@ fn adding(name: &str) -> Result<Revision> {
/// 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`), where none is given
-/// the one that gives a name with a name, else the base revision. Checked as a first
-/// version.
+/// the one that gives a name with a name, else the base revision. At a revision that gives
+/// a name, it has one: given, else at random (`random_name`). 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") {
@@ -2380,13 +2381,25 @@ fn founded(sub: &ArgMatches) -> Result<JsonValue> {
"nodes": given(&nodes, "nodes"),
"rules": rules,
});
- let name = sub.get_one::<String>("name");
+ let given = sub.get_one::<String>("name");
let revision = match sub.get_one::<String>("revision") {
Some(feature) => adding(feature)?,
- None if name.is_some() => Feature::FederationName.revision(),
+ None if given.is_some() => Feature::FederationName.revision(),
None => Revision::default(),
};
- if let Some(name) = name {
+ let name = match given {
+ Some(name) => Some(name.clone()),
+ None if revision.has(Feature::FederationName) => {
+ let name = random_name()?;
+ eprintln!(
+ "named {name} at random, as no --name was given: so it is another federation \
+ than any of a first version alike otherwise"
+ );
+ Some(name)
+ }
+ None => None,
+ };
+ if let Some(name) = &name {
if !revision.has(Feature::FederationName) {
bail!(
"{revision} gives a version no name: {} does, and those after it",
@@ -2408,6 +2421,13 @@ fn founded(sub: &ArgMatches) -> Result<JsonValue> {
Ok(version)
}
+/// A federation's name at random: 16 hex digits.
+fn random_name() -> Result<String> {
+ let mut bytes = [0u8; 8];
+ getrandom::fill(&mut bytes).map_err(|why| anyhow!("no random name: {why}"))?;
+ Ok(bytes.iter().map(|byte| format!("{byte:02x}")).collect())
+}
+
/// The current version, as `counts` names it, checked: its hash its own.
fn current(counts: &JsonValue) -> Result<Version> {
let json = client::json(&counts["version"]["version"]).map_err(|why| anyhow!(why))?;
@@ -3114,6 +3134,22 @@ mod tests {
])
.unwrap();
assert!(merging.get("name").is_none() && merging.get("revision").is_some());
+ // At a revision that gives a name, a random one where none is given, each its own.
+ let random = || {
+ nameless(&[
+ tv_key.clone(),
+ "--revision".to_owned(),
+ "federation-name".to_owned(),
+ ])
+ .unwrap()["name"]
+ .as_str()
+ .unwrap()
+ .to_owned()
+ };
+ let (one, other) = (random(), random());
+ assert_eq!(one.len(), 16);
+ assert!(one.bytes().all(|byte| byte.is_ascii_hexdigit()), "{one}");
+ assert_ne!(one, other);
assert!(founded(&[tv_key.clone(), tv_key.clone()]).is_err());
assert!(
founded(&[