From 7e6c79b2ca23edcbd0400c0d522420db09861c9d Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 16 Nov 2026 20:37:13 +0000 Subject: node: the party a node of a swarm holding a store is of A node's group is its operator's, in its configuration (`docs/store.md`, Members): `--store-party NAME`, which `--store-root` and `--store-id` need, a party's name as the federation spells one. The node keeps it with its store (`Holding::party`), to name it in its entry and its handshakes. The options of a node of a swarm holding a store (`--store-file`, `--store-checkpoint`, `--store-party`) set without either are refused together. --- src/federation/held.rs | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'src/federation') diff --git a/src/federation/held.rs b/src/federation/held.rs index 8f48c65..f8825e5 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -77,12 +77,13 @@ impl Kept { } } -/// The store a node holds, if its swarm holds one, the file it keeps its own in, and the -/// checkpoint its operator pins. +/// The store a node holds, if its swarm holds one, the file it keeps its own in, the +/// checkpoint its operator pins, and the party its operator says it is of. #[derive(Default)] pub(crate) struct Holding { file: Option<(PathBuf, Arc)>, pin: Option, + party: Option, // A std mutex: never held while waiting for the document. inner: Mutex, } @@ -115,11 +116,18 @@ pub(crate) struct Unread { impl Holding { /// Keeping the node's own in the file at `path`, if any, which holds what it kept /// before: a missing file nothing. One that doesn't read is an error: the node would - /// take what it refused. Its store starts from the checkpoint `pin`, if any. - pub(crate) fn open(path: Option, files: Arc, pin: Option) -> Result { + /// take what it refused. Its store starts from the checkpoint `pin`, if any; the node + /// is of `party`. + pub(crate) fn open( + path: Option, + files: Arc, + pin: Option, + party: Option, + ) -> Result { let Some(path) = path else { return Ok(Holding { pin, + party, ..Holding::default() }); }; @@ -139,6 +147,7 @@ impl Holding { Ok(Holding { file: Some((path, files)), pin, + party, inner: Mutex::new(Inner { kept, ..Inner::default() @@ -307,6 +316,11 @@ impl Holding { .unwrap_or_default() } + /// The party its operator says the node is of (`--store-party`). + pub(crate) fn party(&self) -> Option<&str> { + self.party.as_deref() + } + /// `f` of the store, where the node holds one. pub(crate) fn with(&self, f: impl FnOnce(&Store) -> T) -> Option { self.inner.lock_or_recover().store.as_ref().map(f) @@ -521,7 +535,7 @@ mod tests { assert_ne!(pin, Id::of(&root)); let files = Arc::new(Files::default()); - let pinned = Holding::open(None, Arc::clone(&files), Some(pin)).unwrap(); + let pinned = Holding::open(None, Arc::clone(&files), Some(pin), None).unwrap(); read(&pinned, &doc, 0); assert_eq!(pinned.with(|store| Id::of(store.checkpoint())), Some(pin)); let taken = |holding: &Holding| { @@ -534,7 +548,7 @@ mod tests { pinned.with(|store| store.holds(&Id::of(&beside))), Some(false) ); - let elsewhere = Holding::open(None, files, Some(Id::of(b"elsewhere"))).unwrap(); + let elsewhere = Holding::open(None, files, Some(Id::of(b"elsewhere")), None).unwrap(); read(&elsewhere, &doc, 0); assert!(elsewhere.with(|_| ()).is_none()); } @@ -638,7 +652,7 @@ mod tests { let dir = crate::files::scratch_dir("held"); let path = dir.join("store.json"); let files = Arc::new(Files::default()); - let holding = Holding::open(Some(path.clone()), Arc::clone(&files), None).unwrap(); + let holding = Holding::open(Some(path.clone()), Arc::clone(&files), None, None).unwrap(); let mut doc = events::started(Federation::NAME, &root).unwrap(); for event in before.iter().copied().chain([&first_taken]) { put(&mut doc, event); @@ -650,12 +664,12 @@ mod tests { assert!(!taken(&holding).contains(&Id::of(&later))); // Restarted: the store read anew, all at once, refuses the later as before. - let anew = Holding::open(Some(path.clone()), Arc::clone(&files), None).unwrap(); + let anew = Holding::open(Some(path.clone()), Arc::clone(&files), None, None).unwrap(); read(&anew, &all, 0); assert!(taken(&anew).contains(&Id::of(&first_taken))); assert!(!taken(&anew).contains(&Id::of(&later))); std::fs::write(&path, b"{\"refused\": [\"not an ID\"]}").unwrap(); - assert!(Holding::open(Some(path), files, None).is_err()); + assert!(Holding::open(Some(path), files, None, None).is_err()); } } -- cgit v1.3.1