diff options
Diffstat (limited to 'src/document/sync.rs')
| -rw-r--r-- | src/document/sync.rs | 17 |
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 |
