From 93defc68f9b99da921f4746e91e5cee9e6e3f1b9 Mon Sep 17 00:00:00 2001 From: tv Date: Mon, 30 Nov 2026 17:39:23 +0000 Subject: swarm: a node says to each peer the kind that peer holds, of those it holds A node holds one kind of document, or, to come, its store in both (Holding::kinds, of_both). The kind a peer's handshakes say is kept with the peer, where the node holds it too, and is what the node says to it in turn; to a peer that said none yet, a node of more than one kind says each in turn, HELLO by HELLO, until one is answered. A node of one kind says and takes that one, as before. --- src/federation/held.rs | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/federation/held.rs') diff --git a/src/federation/held.rs b/src/federation/held.rs index 51d8ef0..154544f 100644 --- a/src/federation/held.rs +++ b/src/federation/held.rs @@ -117,6 +117,9 @@ pub(crate) struct Holding { written: Mutex>, /// Whether a set of events carries the store (`carrying`), from the node's start on. of_a_set: bool, + /// Whether the node holds the store in the document a swarm syncs otherwise too + /// (`of_both`): a node of both kinds, by which a running swarm moves to sets. + both: bool, // A std mutex: never held while waiting for the document. inner: Mutex, } @@ -278,6 +281,7 @@ impl Holding { members: RwLock::default(), voter: None, of_a_set: false, + both: false, document: None, written: Mutex::default(), inner: Mutex::new(Inner { @@ -1145,18 +1149,35 @@ 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 { - if self.of_a_set { - super::store::set::KIND - } else { - crate::document::KIND - } + self.kinds()[0] } - /// Whether a set of events carries the store. + /// Whether a set of events carries the store, and nothing else does. pub(crate) fn of_a_set(&self) -> bool { + self.of_a_set && !self.both + } + + /// Whether the node holds a set of events, alone or beside the Automerge document. + pub(crate) fn has_a_set(&self) -> bool { self.of_a_set } + /// Itself, holding its store in the Automerge document too, beside the set. + pub(crate) fn of_both(mut self) -> Self { + self.both = true; + self + } + + /// The kinds of document the node holds its store in, which it says in + /// handshakes: the one it says first, first. + pub(crate) fn kinds(&self) -> &'static [&'static str] { + match (self.of_a_set, self.both) { + (true, true) => &[crate::document::KIND, super::store::set::KIND], + (true, false) => &[super::store::set::KIND], + (false, _) => &[crate::document::KIND], + } + } + /// 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