From 565b27269b598de3e337d732525b2a171a30cb5e Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 16:41:38 +0100 Subject: answering behind counted --- src/document/sync.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/document') diff --git a/src/document/sync.rs b/src/document/sync.rs index f9f0295..179df78 100644 --- a/src/document/sync.rs +++ b/src/document/sync.rs @@ -700,6 +700,23 @@ impl SyncSession { } } + /// Whether the peer, as the message just applied says, is behind us: all its heads + /// in our history, and not all of ours. Asked before `answered_as_delivered`: a + /// message taken as delivered from a peer behind us is answered with what it lacks + /// (a node that got its writer's changes before its parent did, by another way). + pub(crate) fn peer_behind( + &self, + doc: &Document, + heads: &[crate::document::ChangeHash], + ) -> bool { + self.state.their_heads.as_ref().is_some_and(|theirs| { + theirs + .iter() + .all(|hash| doc.get_change_by_hash(hash).is_some()) + && heads.iter().any(|hash| !theirs.contains(hash)) + }) + } + /// We applied a message its sender took as delivered (`assume_delivered`, /// `SyncEnvelope::delivered`) to `doc`: if we hold exactly its sender's heads now, /// Automerge's answer, our heads, would tell it nothing. So none goes: we count as -- cgit v1.3.1