diff options
Diffstat (limited to 'src/swarm')
| -rw-r--r-- | src/swarm/sync.rs | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/src/swarm/sync.rs b/src/swarm/sync.rs index 5819bb7..a4ad30c 100644 --- a/src/swarm/sync.rs +++ b/src/swarm/sync.rs @@ -722,14 +722,12 @@ fn fetch_delta(state: &AppState, peer: &str, epoch: transport::Epoch, spec: tran let state = state.clone(); let peer = peer.to_owned(); tokio::spawn(async move { + let done = DeltaDone { + state: state.clone(), + peer: peer.clone(), + }; let applied = download_and_apply_delta(&state, &peer, epoch, spec).await; - // Those that offered meanwhile send what is still missing: our next message - // says what we have now. - for other in state.blobs.end_delta(&peer) { - if other != peer { - state.request_sync(&other); - } - } + drop(done); match applied { Ok(changed) => { state.notify_store_changed(); @@ -746,6 +744,24 @@ fn fetch_delta(state: &AppState, peer: &str, epoch: transport::Epoch, spec: tran }); } +/// The delta download from `peer` ended, when dropped: however it ended, a panic +/// included, the next may start (`Blobs::end_delta`), and those that offered meanwhile +/// send what is still missing (our next message says what we have now). +struct DeltaDone { + state: AppState, + peer: String, +} + +impl Drop for DeltaDone { + fn drop(&mut self) { + for other in self.state.blobs.end_delta(&self.peer) { + if other != self.peer { + self.state.request_sync(&other); + } + } + } +} + /// Returns whether our heads changed. async fn download_and_apply_delta( state: &AppState, |
