aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--docs/guides/federation/getting-started.md10
-rw-r--r--src/federation/party.rs50
3 files changed, 51 insertions, 12 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c37eb52..f430775 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,7 +8,8 @@ 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
- (without it, nameless, at the base revision or the one `--revision` names);
+ (without it, at the base revision without a name, or at a later one `--revision` names,
+ with a random name where it gives one);
`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),
diff --git a/docs/guides/federation/getting-started.md b/docs/guides/federation/getting-started.md
index aae3f06..33f9181 100644
--- a/docs/guides/federation/getting-started.md
+++ b/docs/guides/federation/getting-started.md
@@ -74,10 +74,12 @@ name is in the root, so a rehearsal named otherwise (`krebs-test`) is another fe
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)). Without `--name`, the federation has none, and follows
-the base revision unless `--revision` says otherwise: it differs from another by its
-parties, keys, nodes and rules alone, as two of one name do, and a name a later version
-gives it changes that no more.
+([`upgrades.md`](upgrades.md)). Without `--name`, at a revision `--revision` names, 2 or
+later, it gets a random one, said on standard error: so `found` writes another
+federation each time, and the founders share the file it wrote. Without either, it follows
+the base revision and has no name: it differs from another by its parties, keys, nodes
+and rules alone, as two of one name do, and a name a later version gives it changes that
+no more.
## The root
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(&[