diff options
Diffstat (limited to 'src/swarm/peer/keepalive.rs')
| -rw-r--r-- | src/swarm/peer/keepalive.rs | 28 |
1 files changed, 28 insertions, 0 deletions
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 { |
