aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/peer')
-rw-r--r--src/swarm/peer/inbound.rs11
-rw-r--r--src/swarm/peer/keepalive.rs18
2 files changed, 20 insertions, 9 deletions
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs
index 35d67c8..b6c486d 100644
--- a/src/swarm/peer/inbound.rs
+++ b/src/swarm/peer/inbound.rs
@@ -228,11 +228,14 @@ pub(crate) async fn handle_message(
.map_err(|error| anyhow!("Failed to notify sync worker: {error}"))?;
}
transport::ParsedMessage::Sync(envelope) => {
- // Of a set of events, where one carries this node's store: its own to
- // take (`swarm::set`), and nothing of an Automerge document's.
+ // Of a set of events: this node's set's to take, where it holds one
+ // (`swarm::set`); and of an Automerge document nothing, where it holds a set
+ // alone.
#[cfg(feature = "federation")]
- if state.of_a_set() {
- if let transport::SyncBody::Kind(body) = envelope.body {
+ if state.of_a_set() || matches!(envelope.body, transport::SyncBody::Kind(_)) {
+ if let transport::SyncBody::Kind(body) = envelope.body
+ && state.holding.has_a_set()
+ {
crate::swarm::set::received(state, &peer, body).await;
}
return Ok(());
diff --git a/src/swarm/peer/keepalive.rs b/src/swarm/peer/keepalive.rs
index 6ab49d8..bbcc6e3 100644
--- a/src/swarm/peer/keepalive.rs
+++ b/src/swarm/peer/keepalive.rs
@@ -182,13 +182,21 @@ pub(crate) async fn local_status(state: &AppState, peer: &str) -> transport::Sta
let stamp = state.stamp.borrow();
(stamp.summary(), stamp.epoch, stamp.epoch_seq)
};
- let syncs_with_you = match state.get_peer_state(peer).await {
- Some(peer_state) => peer_state.lock().await.syncs_on(epoch),
- None => false,
+ let (syncs_with_you, _of_a_set) = match state.get_peer_state(peer).await {
+ Some(peer_state) => {
+ let peer_state = peer_state.lock().await;
+ (
+ peer_state.syncs_on(epoch),
+ peer_state
+ .kind
+ .is_some_and(|kind| kind != crate::document::KIND),
+ )
+ }
+ None => (false, false),
};
- // Where a set of events carries the store, where that stands (`swarm::set`).
+ // To a peer that holds a set of events, where this node's stands (`swarm::set`).
#[cfg(feature = "federation")]
- let heads = crate::swarm::set::stamp(state).unwrap_or(heads);
+ let heads = crate::swarm::set::stamp(state, _of_a_set).unwrap_or(heads);
let (reaches, round_trips) = crate::swarm::reach::published_with_round_trips(state);
transport::Status {
heads,