aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/tree.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/tree.rs')
-rw-r--r--src/swarm/tree.rs21
1 files changed, 18 insertions, 3 deletions
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<Plan> {
/// 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);