aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer/inbound.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 02:45:46 +0100
committertv <tv@krebsco.de>2026-12-01 02:45:46 +0100
commit34bfcb661ed74bf40809576bbb388362cb7ffaa1 (patch)
tree8422db7db396dd4ae83403837cd954a94f882a7a /src/swarm/peer/inbound.rs
parent34434f7fd5a6bab1884a63c96679f48045f4bffd (diff)
parent6a06bc4a955cdf2b5a183c9ff21e25c79a4e5d9f (diff)
Merge remote-tracking branch 'events'HEADmaster
Diffstat (limited to 'src/swarm/peer/inbound.rs')
-rw-r--r--src/swarm/peer/inbound.rs38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs
index a558ded..b6c486d 100644
--- a/src/swarm/peer/inbound.rs
+++ b/src/swarm/peer/inbound.rs
@@ -114,12 +114,22 @@ 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.
+ state
+ .get_or_create_peer_state(&peer)
+ .await
+ .lock()
+ .await
+ .kind = Some(held);
}
// The root its document starts from: another than ours, of our epoch, is another
@@ -218,6 +228,18 @@ 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::received(state, &peer, body).await;
+ }
+ return Ok(());
+ }
if reactivated {
ensure_handshake(state, &peer).await;
}
@@ -251,6 +273,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 +314,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 {