From b67ee4d3d59434f5a911b4eb0ee815ac9bcad3fe Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 01:27:07 +0100 Subject: predecessors go along --- src/swarm/tree.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/swarm') diff --git a/src/swarm/tree.rs b/src/swarm/tree.rs index 20df2ec..ffdf80e 100644 --- a/src/swarm/tree.rs +++ b/src/swarm/tree.rs @@ -361,7 +361,9 @@ pub(crate) async fn plan(state: &AppState, writer: u64) -> Option { /// them (`SyncSession::known_to_peer`): else, with writers in turn, each change coming /// along another tree, the next message we pass on to one would carry all we got since /// our last to it, mostly what its other parents brought it. Should one lack them after -/// all, it asks, and gets them (`resend_if_needed`). +/// all, it asks, and gets them (`resend_if_needed`). But to our children, those of +/// them that `changes` build on go along, if they were counted so lately +/// (`SyncSession::with_predecessors`). pub(crate) async fn forward( state: &AppState, writer: u64, @@ -372,15 +374,28 @@ pub(crate) async fn forward( if !changes.is_empty() { for neighbour in &plan.covered { if let Some(peer_state) = state.get_peer_state(neighbour).await { - peer_state.lock().await.sync.known_to_peer(changes); + peer_state + .lock() + .await + .sync + .known_to_peer(changes, tokio::time::Instant::now()); } } } plan.children.retain(|child| child != from); let children = &plan.children; + let replica = if changes.is_empty() { + None + } else { + Some(state.doc.read().await) + }; for child in children { if let Some(peer_state) = state.get_peer_state(child).await { - peer_state.lock().await.tree_writer = Some(writer); + let mut peer_state = peer_state.lock().await; + peer_state.tree_writer = Some(writer); + if let Some(replica) = &replica { + peer_state.sync.with_predecessors(&replica.doc, changes); + } } state.stats.tree_forward(); state.request_sync(child); -- cgit v1.3.1