From baf9498c69340da18001c7ca2c223ed45fddc249 Mon Sep 17 00:00:00 2001 From: tv Date: Sat, 31 Oct 2026 13:25:11 +0100 Subject: rename AutoMerge to Document --- src/state/session.rs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src/state/session.rs') diff --git a/src/state/session.rs b/src/state/session.rs index 8885699..98b4dc3 100644 --- a/src/state/session.rs +++ b/src/state/session.rs @@ -9,12 +9,13 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::time::Duration; +use automerge::AutomergeError; use automerge::sync::{self, SyncDoc}; -use automerge::{AutoCommit, AutomergeError}; use tokio::time::Instant; use tracing::debug; use crate::backoff::Backoff; +use crate::document::Document; use crate::swarm::throughput::SyncBytes; /// A sync message being handed to our transport (for Mycelium: the HTTP request is in @@ -22,7 +23,7 @@ use crate::swarm::throughput::SyncBytes; #[derive(Clone)] pub(crate) struct Sending { /// Changes it carries for the first time; taken back if the send fails. - pub(crate) sent: Vec, + pub(crate) sent: Vec, /// A sync pass was requested meanwhile. Once this one is handed over, the peer must /// be enqueued again so the deferred changes go out. pub(crate) regenerate: bool, @@ -63,7 +64,7 @@ pub(crate) struct SyncSession { /// once the peer has the delta and says its heads are ours, never answers it, so the /// peer never learns our heads (a joining node then never finishes its initial /// sync). - before_generate: (Vec, bool), + before_generate: (Vec, bool), /// The answer we expect to our last sync message(s), if any. pub(crate) reply: Option, @@ -81,7 +82,7 @@ pub(crate) struct SyncReplyWait { /// exchanged with the peer by then (`swarm::throughput`). pub(crate) started: (Instant, SyncBytes), /// Changes first sent in the unanswered messages. - pub(crate) sent: Vec, + pub(crate) sent: Vec, } impl SyncSession { @@ -113,7 +114,7 @@ impl SyncSession { /// peer so far (`swarm::throughput`). pub(crate) fn generate( &mut self, - doc: &mut AutoCommit, + doc: &mut Document, now: Instant, bytes: SyncBytes, ) -> Option { @@ -150,7 +151,7 @@ impl SyncSession { /// answer: the caller measures the exchange first (`reply`). pub(crate) fn receive( &mut self, - doc: &mut AutoCommit, + doc: &mut Document, message: sync::Message, ) -> Result<(), AutomergeError> { self.delta_offered = false; @@ -162,7 +163,7 @@ impl SyncSession { /// message being handed over becomes the offer (it carries nothing); the answer is /// still awaited, and if it doesn't come, the offer is made again. Returns the /// peer's heads as far as we know them: where the delta starts. - pub(crate) fn withdraw_for_delta(&mut self) -> Vec { + pub(crate) fn withdraw_for_delta(&mut self) -> Vec { if let Some(sending) = &mut self.sending { let sent = std::mem::take(&mut sending.sent); for hash in &sent { @@ -181,7 +182,7 @@ impl SyncSession { /// Whether `doc` holds everything the peer had when it last told us its heads: they /// are known, not empty (empty heads are "contained" in every document, so they /// prove nothing), and all in `doc`. - pub(crate) fn have_all_theirs(&self, doc: &mut AutoCommit) -> bool { + pub(crate) fn have_all_theirs(&self, doc: &mut Document) -> bool { self.state.their_heads.as_ref().is_some_and(|heads| { !heads.is_empty() && heads @@ -192,7 +193,7 @@ impl SyncSession { /// The peer has heads we lack (its keepalive said so): ask for what they need, /// even though Automerge thinks a message is still in flight. - pub(crate) fn pull_from(&mut self, heads: Vec) { + pub(crate) fn pull_from(&mut self, heads: Vec) { self.state.their_heads = Some(heads); self.state.in_flight = false; } @@ -232,7 +233,7 @@ impl SyncSession { /// For the simulator's dump: the peer's heads as Automerge knows them, and whether /// it thinks a message is in flight. #[cfg(test)] - pub(crate) fn automerge_view(&self) -> (Option<&[automerge::ChangeHash]>, bool) { + pub(crate) fn automerge_view(&self) -> (Option<&[crate::document::ChangeHash]>, bool) { (self.state.their_heads.as_deref(), self.state.in_flight) } @@ -294,7 +295,7 @@ impl SyncSession { /// `bytes` are the sync bytes exchanged with the peer before it. pub(crate) fn expect_reply( &mut self, - sent: Vec, + sent: Vec, now: Instant, bytes: SyncBytes, ) { @@ -372,8 +373,8 @@ mod tests { #[test] fn missing_predecessors_go_at_once() { use automerge::transaction::Transactable; - let mut a = AutoCommit::new(); - let mut b = AutoCommit::new(); + let mut a = Document::new(); + let mut b = Document::new(); let (mut at_a, mut at_b) = (sync::State::new(), sync::State::new()); a.put(automerge::ROOT, "early", 1).unwrap(); // Until in step. @@ -462,10 +463,10 @@ mod tests { let big: String = (0..1024) .map(|_| format!("{:016x}", rng.next_u64())) .collect(); - let mut ours = AutoCommit::new(); + let mut ours = Document::new(); ours.put(ROOT, "big", big).unwrap(); ours.commit(); - let mut theirs = AutoCommit::new(); + let mut theirs = Document::new(); let (mut a, mut b) = (session(), session()); let now = Instant::now(); let bytes = SyncBytes::default(); @@ -508,10 +509,10 @@ mod tests { let big: String = (0..1024) .map(|_| format!("{:016x}", rng.next_u64())) .collect(); - let mut ours = AutoCommit::new(); + let mut ours = Document::new(); ours.put(ROOT, "big", big).unwrap(); ours.commit(); - let mut theirs = AutoCommit::new(); + let mut theirs = Document::new(); let (mut a, mut b) = (session(), session()); let now = Instant::now(); let bytes = SyncBytes::default(); -- cgit v1.3.1