aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-30 17:39:23 +0000
committertv <tv@krebsco.de>2026-11-30 17:39:23 +0000
commit93defc68f9b99da921f4746e91e5cee9e6e3f1b9 (patch)
treeb38f06c630c044f2c608ca321b1b73517bae5ea6 /src/federation
parent6ca6a97f5f9864c971c979c2c1758071a88635d0 (diff)
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.
Diffstat (limited to 'src/federation')
-rw-r--r--src/federation/held.rs33
1 files changed, 27 insertions, 6 deletions
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<Option<super::store::passing::Stamp>>,
/// 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<Inner>,
}
@@ -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<T>(&self, f: impl FnOnce(&Set<Federation>) -> T) -> Option<T> {
match &self.inner.lock_or_recover().store {