aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/inbound.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/peer/inbound.rs')
-rw-r--r--src/swarm/peer/inbound.rs41
1 files changed, 35 insertions, 6 deletions
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs
index a558ded..e16eb3f 100644
--- a/src/swarm/peer/inbound.rs
+++ b/src/swarm/peer/inbound.rs
@@ -114,12 +114,24 @@ pub(crate) async fn handle_message(
ParsedMessage::HelloReply(reply) => Some(&reply.kind),
_ => None,
};
- if let Some(theirs) = kind.filter(|kind| *kind != crate::document::KIND) {
- anyhow::bail!(
- "{peer} holds a document of another kind ({theirs}; this node's is {}): they sync \
- nothing; a release that knows the kind does",
- crate::document::KIND
- );
+ if let Some(theirs) = kind {
+ let Some(held) = state.kinds().iter().find(|held| *held == theirs) else {
+ anyhow::bail!(
+ "{peer} holds a document of another kind ({theirs}; this node's is {}): they \
+ sync nothing; a release that knows the kind does",
+ state.kinds().join(" and ")
+ );
+ };
+ // Of the kinds this node holds, the one the peer holds: what it is told in
+ // turn, and passed on.
+ let peer_state = state.get_or_create_peer_state(&peer).await;
+ let mut peer_state = peer_state.lock().await;
+ // A handshake of another kind than before: of a node started anew.
+ #[cfg(feature = "federation")]
+ if peer_state.kind != Some(held) {
+ peer_state.set_beside = false;
+ }
+ peer_state.kind = Some(held);
}
// The root its document starts from: another than ours, of our epoch, is another
@@ -218,6 +230,19 @@ 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: 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() || matches!(envelope.body, transport::SyncBody::Kind(_)) {
+ if let transport::SyncBody::Kind(body) = envelope.body
+ && state.holding.has_a_set()
+ {
+ crate::swarm::set::holds_one_beside(state, &peer).await;
+ crate::swarm::set::received(state, &peer, body).await;
+ }
+ return Ok(());
+ }
if reactivated {
ensure_handshake(state, &peer).await;
}
@@ -251,6 +276,8 @@ pub(crate) async fn handle_message(
crate::swarm::blob::handle(state, &peer, blob).await;
}
transport::ParsedMessage::Status(remote) => {
+ #[cfg(feature = "federation")]
+ let remote = crate::swarm::set::heard_status(state, &peer, remote);
// An announcement is no keepalive; it is answered only if we lack some of the
// heads it announced (`relay::lacks`), so the announcer learns what we have
// that it lacks while we pull. Having all of them, we are as far or further,
@@ -290,6 +317,8 @@ pub(crate) async fn handle_message(
}
}
transport::ParsedMessage::StatusReply(remote) => {
+ #[cfg(feature = "federation")]
+ let remote = crate::swarm::set::heard_status(state, &peer, remote);
// An answer to our slow round's announcement: a tree missed.
let announced = peer_state.lock().await.slow_announced_at.take();
if let Some(at) = announced {