From af9de78d7de36848f6ff115c9710fb90d2468af2 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 13:58:03 +0000 Subject: swarm: a node says the kind of the document it holds In its handshakes, and checks a peer's against it (AppState::kind): a set of events where one carries its store (Holding::of_a_set), else Automerge's, as it was for every node. --- src/federation/held.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/federation/held.rs') diff --git a/src/federation/held.rs b/src/federation/held.rs index dc0db6f..fec21ab 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -111,6 +111,8 @@ pub(crate) struct Holding { members: RwLock>>, /// What it votes for its party with, if it votes by itself. voter: Option, + /// Whether a set of events carries the store (`carrying`), from the node's start on. + of_a_set: bool, // A std mutex: never held while waiting for the document. inner: Mutex, } @@ -261,6 +263,7 @@ impl Holding { near: Vec::new(), members: RwLock::default(), voter: None, + of_a_set: false, inner: Mutex::new(Inner { kept, ..Inner::default() @@ -1017,7 +1020,8 @@ impl Holding { /// Itself, its store carried by `set`: the store's own document, read from no /// other (`store::set`). - pub(crate) fn carrying(self, set: Set) -> Self { + pub(crate) fn carrying(mut self, set: Set) -> Self { + self.of_a_set = true; { let mut inner = self.inner.lock_or_recover(); inner.store = Some(Carried::Set(Box::new(set))); @@ -1029,12 +1033,18 @@ impl Holding { /// The kind of the document that carries the store: a set of events, or the /// document the node holds, which the store is read from. pub(crate) fn kind(&self) -> &'static str { - match self.inner.lock_or_recover().store { - Some(Carried::Set(_)) => super::store::set::KIND, - _ => crate::document::KIND, + if self.of_a_set { + super::store::set::KIND + } else { + crate::document::KIND } } + /// Whether a set of events carries the store. + pub(crate) fn of_a_set(&self) -> bool { + self.of_a_set + } + /// What `f` makes of the set of events carrying the store, where one does. pub(crate) fn with_set(&self, f: impl FnOnce(&Set) -> T) -> Option { match &self.inner.lock_or_recover().store { -- cgit v1.3.1