diff options
| author | tv <tv@krebsco.de> | 2026-11-30 13:58:03 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-30 13:58:03 +0000 |
| commit | af9de78d7de36848f6ff115c9710fb90d2468af2 (patch) | |
| tree | 57013cd112c7928d72e2a6e2c0c7fb4a55edc92b /src/federation | |
| parent | 27b0fb294c47fea75359c3abadab56cd74c93b33 (diff) | |
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.
Diffstat (limited to 'src/federation')
| -rw-r--r-- | src/federation/held.rs | 18 |
1 files changed, 14 insertions, 4 deletions
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<Option<BTreeSet<(String, String)>>>, /// What it votes for its party with, if it votes by itself. voter: Option<Voter>, + /// 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<Inner>, } @@ -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<Federation>) -> Self { + pub(crate) fn carrying(mut self, set: Set<Federation>) -> 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<T>(&self, f: impl FnOnce(&Set<Federation>) -> T) -> Option<T> { match &self.inner.lock_or_recover().store { |
