aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation/version.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-20 01:28:41 +0000
committertv <tv@krebsco.de>2026-11-20 02:38:56 +0100
commit96a733e1ccbf6dab2d69f263d655e487ac54c20d (patch)
treeabfa6c292134a224b53e4a70c60a31721577a7bc /src/federation/version.rs
parent7a178877d3b979ae6bd0e48ddb06363a0d50affc (diff)
federation: revision 2, the federation's name
A version may give its federation a name (`name`, spelled as a party's), under a revision that has names: `federation-name`, revision 2. The first version's is in the root, so a rehearsal named otherwise is another federation, though its parties, keys, nodes and rules are the same; a later version changes the name as anything else, which changes what the federation is called, not which it is. A version giving a name under an earlier revision is none. What a version does says so, in words: it names the federation, renames it, or drops its name. Half the generated histories begin at the newest revision now, their versions naming the federation anew now and then; those of the revisions before are generated as they were.
Diffstat (limited to 'src/federation/version.rs')
-rw-r--r--src/federation/version.rs57
1 files changed, 55 insertions, 2 deletions
diff --git a/src/federation/version.rs b/src/federation/version.rs
index fa534b3..cebb83a 100644
--- a/src/federation/version.rs
+++ b/src/federation/version.rs
@@ -5,7 +5,7 @@ use std::collections::{BTreeMap, BTreeSet};
use super::jcs::Json;
use super::keys;
-use super::revision::Revision;
+use super::revision::{Feature, Revision};
use super::store::Id;
/// The federation this is: a version naming another is none here.
@@ -34,6 +34,10 @@ pub(crate) struct Version {
pub(crate) json: Json,
/// The revision of the federation it follows: the base revision where it names none.
pub(crate) revision: Revision,
+ /// The federation's name, where it gives one (`Feature::FederationName`): spelled as a
+ /// party's name. The first version's, in the root, parts the federation from one of a
+ /// first version alike otherwise; a later version's changes only what it is called.
+ pub(crate) name: Option<String>,
pub(crate) number: u64,
/// The version it changes; none for the first.
pub(crate) changes: Option<Id>,
@@ -157,7 +161,7 @@ impl Version {
json,
"a version",
&["federation", "number", "changes", "keys", "nodes", "rules"],
- &["checkpoint", "revision"],
+ &["checkpoint", "revision", "name"],
)?;
match json.get("federation").and_then(Json::as_int) {
Some(FEDERATION) => {}
@@ -192,6 +196,22 @@ impl Version {
}
}
};
+ let name = match json.get("name") {
+ None => None,
+ Some(_) if !revision.has(Feature::FederationName) => {
+ return Err(format!(
+ "a `name`, which {revision} doesn't give a version: {} does",
+ Feature::FederationName.revision()
+ ));
+ }
+ Some(Json::Str(name)) if is_party(name) => Some(name.clone()),
+ Some(_) => {
+ return Err(
+ "a `name` that is no name: 1 to 64 of A-Z a-z 0-9 . _ @ -, as a party's"
+ .to_owned(),
+ );
+ }
+ };
let number = json
.get("number")
.and_then(Json::as_int)
@@ -226,6 +246,7 @@ impl Version {
hash: Id::of(&json.bytes()),
json: json.clone(),
revision,
+ name,
number,
changes,
parties,
@@ -624,6 +645,38 @@ mod tests {
}
}
+ /// A version gives its federation a name only under a revision that has names, spelled
+ /// as a party's name; one without gives none.
+ #[test]
+ fn a_version_names_its_federation_under_a_revision_with_names() {
+ let named = Feature::FederationName.revision();
+ let with = |revision: Revision, name: &str| {
+ let text = String::from_utf8(first().bytes()).expect("UTF-8");
+ let text = text.replacen(r#""nodes":"#, &format!(r#""name":{name},"nodes":"#), 1);
+ let text = text.replacen(
+ r#""rules":"#,
+ &format!(r#""revision":"{}","rules":"#, revision.id()),
+ 1,
+ );
+ Version::read(&jcs::read(text.as_bytes()).expect("JCS"))
+ };
+ assert_eq!(
+ with(named, r#""krebs""#)
+ .expect("a version")
+ .name
+ .as_deref(),
+ Some("krebs")
+ );
+ let why = with(Revision(named.0 - 1), r#""krebs""#).unwrap_err();
+ assert!(why.starts_with("a `name`, which revision 1"), "{why}");
+ let long = format!(r#""{}""#, "x".repeat(65));
+ for none in [r#""""#, r#""a/b""#, "1", long.as_str()] {
+ let why = with(named, none).unwrap_err();
+ assert!(why.contains("no name"), "{none}: {why}");
+ }
+ assert_eq!(Version::read(&first()).expect("a version").name, None);
+ }
+
#[test]
fn a_version_changes_another_by_its_number_hash_and_sinces() {
let first = Version::read(&first()).expect("a version");