aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/set.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/set.rs')
-rw-r--r--src/swarm/set.rs50
1 files changed, 48 insertions, 2 deletions
diff --git a/src/swarm/set.rs b/src/swarm/set.rs
index 54a48fe..82158be 100644
--- a/src/swarm/set.rs
+++ b/src/swarm/set.rs
@@ -22,13 +22,59 @@ use crate::state::AppState;
use crate::swarm::topology;
use crate::transport::{self, HeadsSummary, ParsedMessage, SyncBody};
-/// Whether `peer` holds a set of events, as its handshakes said: what a node of both
+/// Whether `peer` holds a set of events and nothing else, as its handshakes said: with
+/// such a peer, a node of both kinds syncs no Automerge document.
+pub(crate) async fn holds_a_set_alone(state: &AppState, peer: &str) -> bool {
+ match state.get_peer_state(peer).await {
+ Some(peer_state) => {
+ peer_state.lock().await.kind == Some(crate::federation::store::set::KIND)
+ }
+ None => false,
+ }
+}
+
+/// Notes that `peer`, whose handshakes say an Automerge document, holds a set of
+/// events beside it: it sent what a set says.
+pub(crate) async fn holds_one_beside(state: &AppState, peer: &str) {
+ if let Some(peer_state) = state.get_peer_state(peer).await {
+ let mut peer_state = peer_state.lock().await;
+ if peer_state.kind == Some(crate::document::KIND) {
+ peer_state.set_beside = true;
+ }
+ }
+}
+
+/// On a node of both kinds, says to `peer`, whose handshakes say an Automerge
+/// document, where this node's set stands, beside the STATUS that says where its
+/// document does: a node of both kinds takes it, answers what its own set lacks or
+/// has more of, and passes its set on to this node from then on; a node on the
+/// document alone drops it. So what sets alone hold, the members' entries, crosses
+/// between nodes of both kinds too.
+pub(crate) async fn say_beside(state: &AppState, peer: &str) {
+ if !state.holding.has_a_set() || state.holding.of_a_set() {
+ return;
+ }
+ let of_a_document = match state.get_peer_state(peer).await {
+ Some(peer_state) => peer_state.lock().await.kind == Some(crate::document::KIND),
+ None => false,
+ };
+ if !of_a_document {
+ return;
+ }
+ if let Some(stamp) = state.holding.with_set(passing::stamp) {
+ send(state, peer, &Message::Stamp(stamp)).await;
+ }
+}
+
+/// Whether `peer` holds a set of events, as its handshakes said, or, beside an
+/// Automerge document, as what it sent did: what a node of both
/// kinds passes its set on to. A node that holds a set alone takes handshakes of no
/// other.
pub(crate) async fn holds_a_set(state: &AppState, peer: &str) -> bool {
match state.get_peer_state(peer).await {
Some(peer_state) => {
- peer_state.lock().await.kind == Some(crate::federation::store::set::KIND)
+ let peer_state = peer_state.lock().await;
+ peer_state.kind == Some(crate::federation::store::set::KIND) || peer_state.set_beside
}
None => false,
}