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.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs
index de2d86d..10ebf9f 100644
--- a/src/swarm/sync.rs
+++ b/src/swarm/sync.rs
@@ -162,22 +162,32 @@ async fn deliver_sync_to_peer(state: &AppState, peer: &str) -> Result<()> {
peer_state
.sync
.generate(&replica.doc, Instant::now(), bytes_before);
- let body = message.map(|payload| {
+ let body = message.and_then(|payload| {
if payload.0.len() <= delta_threshold {
- return transport::SyncBody::Message(payload);
+ return Some(transport::SyncBody::Message(payload));
}
// Too large for one message: all or nothing, and on a slow link
// within the transport's delivery limit. The peer fetches it in
// chunks.
- let from = peer_state.sync.withdraw_for_delta();
+ let from = peer_state.sync.withdraw_for_delta(Instant::now());
let spec = transport::DeltaSpec::new(from, replica.heads().to_vec());
+ if spec.to.iter().all(|head| spec.from.contains(head)) {
+ // It has our heads: nothing to offer (Automerge thought it
+ // lacked what it has, as from a view of it that was old).
+ debug!(
+ message_bytes = payload.0.len(),
+ "Sync message too large, but the peer has our heads; not sent"
+ );
+ peer_state.sync.nothing_to_send();
+ return None;
+ }
info!(
message_bytes = payload.0.len(),
from = spec.from.len(),
to = spec.to.len(),
"Sync message too large; offering the changes as a blob"
);
- transport::SyncBody::Delta(spec)
+ Some(transport::SyncBody::Delta(spec))
});
let delivered = level && matches!(body, Some(transport::SyncBody::Message(_)));
if delivered {