aboutsummaryrefslogtreecommitdiffstats
path: root/src/federation
diff options
context:
space:
mode:
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 {