From 9cf079423c60c15f660a14f07eb9fdcde6c9cb40 Mon Sep 17 00:00:00 2001 From: tv Date: Fri, 6 Nov 2026 04:57:09 +0100 Subject: heads heard forget sent --- src/swarm/peer/keepalive.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/swarm/peer/keepalive.rs') diff --git a/src/swarm/peer/keepalive.rs b/src/swarm/peer/keepalive.rs index d698585..693a370 100644 --- a/src/swarm/peer/keepalive.rs +++ b/src/swarm/peer/keepalive.rs @@ -218,6 +218,34 @@ pub(super) async fn status_received(state: &AppState, peer: &str) { } } +/// A keepalive STATUS said the peer's heads: what it has counts as sent to it no more +/// (`SyncSession::heard_heads`). Off the consumer: it takes the document's lock. +pub(super) fn heard_heads(state: &AppState, peer: &str, remote: &transport::Status) { + let Some(heads) = remote.heads.heads() else { + return; + }; + if heads.is_empty() || remote.epoch != state.local_epoch() { + return; + } + let (state, peer, heads, epoch) = + (state.clone(), peer.to_owned(), heads.to_vec(), remote.epoch); + tokio::spawn(async move { + let Some(peer_state) = state.get_peer_state(&peer).await else { + return; + }; + let replica = state.doc.read().await; + // The same epoch still: a switch meanwhile makes the heads another document's. + if replica.epoch != epoch { + return; + } + peer_state + .lock() + .await + .sync + .heard_heads(&replica.doc, &heads); + }); +} + /// What a peer's status says about it. pub(super) async fn note_status(state: &AppState, peer: &str, remote: &transport::Status) { if let Some(peer_state) = state.get_peer_state(peer).await { -- cgit v1.3.1