From 43bc3f13066ba0ee436c55b744978059e8cc8bda Mon Sep 17 00:00:00 2001 From: tv Date: Thu, 5 Nov 2026 20:08:02 +0100 Subject: offerer asked first --- src/swarm/blob.rs | 6 ++++-- src/swarm/sync.rs | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/swarm/blob.rs b/src/swarm/blob.rs index f3494af..588868f 100644 --- a/src/swarm/blob.rs +++ b/src/swarm/blob.rs @@ -474,7 +474,9 @@ pub(crate) async fn fetch( } let _registration = Registration { state, id }; - // Closest first; peers without a round-trip time last. + // Closest first; peers without a round-trip time last. For a delta, the first is + // the one that offered it, which holds it: asked first however far. + let offerer = delta.and_then(|_| peers.first().cloned()); let now = Instant::now(); let mut peers: Vec<(String, Option)> = { let rtt = state.lock_rtt(); @@ -486,7 +488,7 @@ pub(crate) async fn fetch( }) .collect() }; - peers.sort_by_key(|(_, rtt)| rtt.unwrap_or(Duration::MAX)); + peers.sort_by_key(|(peer, rtt)| (offerer.as_ref() != Some(peer), rtt.unwrap_or(Duration::MAX))); let rtts: HashMap> = peers.iter().cloned().collect(); let mut candidates: VecDeque = peers.into_iter().map(|(peer, _)| peer).collect(); if candidates.is_empty() { diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 5100b98..62bb27e 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -752,6 +752,7 @@ async fn download_and_apply_delta( epoch: transport::Epoch, spec: transport::DeltaSpec, ) -> Result { + // The offerer first: it holds what it offers (`blob::fetch` asks it first). let mut peers = vec![peer.to_owned()]; peers.extend( state -- cgit v1.3.1