aboutsummaryrefslogtreecommitdiffstats
path: root/src/swarm/sync.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/swarm/sync.rs')
-rw-r--r--src/swarm/sync.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index 8059fe2..aa6a8f9 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -620,6 +620,25 @@ async fn download_and_apply_delta(
.into_iter()
.filter(|other| other != peer),
);
+ if let Some(peer_state) = state.get_peer_state(peer).await {
+ let doc = Arc::clone(&state.doc);
+ let from = spec.from.clone();
+ let known = tokio::task::spawn_blocking(move || {
+ let replica = doc.blocking_read();
+ peer_state
+ .blocking_lock()
+ .sync
+ .known_beyond(&replica.doc, &from)
+ })
+ .await
+ .context("Delta check task panicked")?;
+ if known > 0 {
+ // Offered before it heard what we have: it would bring those again. Our
+ // next message tells it (`fetch_delta`); it offers afresh if still needed.
+ info!(peer = %peer, known, "Offered changes partly here already; not fetched");
+ return Ok(false);
+ }
+ }
info!(peer = %peer, to = spec.to.len(), "Fetching changes offered as a blob");
let started = Instant::now();
let bytes = crate::swarm::blob::fetch_delta(state, &spec, peers).await?;