aboutsummaryrefslogtreecommitdiffstats
path: root/src/document
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-05 16:41:38 +0100
committertv <tv@krebsco.de>2026-11-05 16:41:38 +0100
commit565b27269b598de3e337d732525b2a171a30cb5e (patch)
tree7fa7ca968c8a23bb434684d9db6ce5adcd2351f3 /src/document
parentb3e102076666e515c77c50f0eb1150f44f0874e5 (diff)
answering behind counted
Diffstat (limited to 'src/document')
-rw-r--r--src/document/sync.rs17
1 files changed, 17 insertions, 0 deletions
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