aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/peer
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-12-01 02:08:53 +0000
committertv <tv@krebsco.de>2026-12-01 02:08:53 +0000
commit22f9ac13bd0089f89cd2dd74932b522ab0c285c0 (patch)
tree5b5f9c09755f385743c9537672542456b79a6a2e /src/swarm/peer
parenteadf0952260ba4b21e791226cf5ad39e8f079c86 (diff)
federation: nodes of both kinds pass their sets on to each other, too
Two nodes of both kinds say an Automerge document in their handshakes, and synced that alone: what only sets hold, the entries of the nodes on sets, stopped at the first node of both it reached, so that in a swarm larger than its neighbour count the nodes on sets never came to read each other's entries. A node of both now says where its set stands beside each STATUS to a peer on a document; one of both that hears it passes its set on in turn, one on the document alone drops it. A simulation of nine nodes, three of each kind, two neighbours each.
Diffstat (limited to 'src/swarm/peer')
-rw-r--r--src/swarm/peer/inbound.rs15
-rw-r--r--src/swarm/peer/keepalive.rs3
2 files changed, 12 insertions, 6 deletions
diff --git a/src/swarm/peer/inbound.rs b/src/swarm/peer/inbound.rs
index b6c486d..e16eb3f 100644
--- a/src/swarm/peer/inbound.rs
+++ b/src/swarm/peer/inbound.rs
@@ -124,12 +124,14 @@ pub(crate) async fn handle_message(
};
// 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);
+ 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
@@ -236,6 +238,7 @@ pub(crate) async fn handle_message(
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(());
diff --git a/src/swarm/peer/keepalive.rs b/src/swarm/peer/keepalive.rs
index bbcc6e3..5072f01 100644
--- a/src/swarm/peer/keepalive.rs
+++ b/src/swarm/peer/keepalive.rs
@@ -22,6 +22,9 @@ use crate::transport::{self, ParsedMessage};
/// Sends `peer` a STATUS with our status.
pub(crate) async fn send_status(state: &AppState, peer: &str) -> Result<()> {
+ // A node of both kinds: where its set stands, beside (`swarm::set`).
+ #[cfg(feature = "federation")]
+ crate::swarm::set::say_beside(state, peer).await;
let status = local_status(state, peer).await;
if let Some(peer_state) = state.get_peer_state(peer).await {
peer_state.lock().await.last_status_at = Some(Instant::now());