Skip to content

Commit

Permalink
fix: do not queue downloads with no providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Frando committed Mar 27, 2024
1 parent 4aaf7b4 commit 7b8b587
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions iroh-bytes/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,26 @@ impl<DB: Store, G: Getter<Connection = D::Connection>, D: Dialer> Service<G, D,
progress,
} = request;
debug!(kind=%kind.fmt_short(), nodes=?nodes.iter().map(|n| n.node_id.fmt_short()).collect::<Vec<_>>(), "queue intent");
self.providers
.add_hash_with_nodes(kind.hash(), nodes.iter().map(|n| n.node_id));

// store the download intent
let intent_callbacks = IntentCallbacks {
on_finish,
on_progress: progress,
};
self.intents.insert(intent_id, intent_callbacks);
let intent_callbacks = self.intents.get(&intent_id).expect("just inserted");

// early exit if no providers.
if nodes.is_empty() && self.providers.get_candidates(&kind.hash()).next().is_none() {
self.finalize_download(kind, [intent_id].into(), Err(DownloadError::NoProviders));
return;
}

// add the nodes to the provider map
self.providers
.add_hash_with_nodes(kind.hash(), nodes.iter().map(|n| n.node_id));

// store or modify the request info
self.requests
.entry(kind)
.and_modify(|info| {
Expand All @@ -642,6 +656,7 @@ impl<DB: Store, G: Getter<Connection = D::Connection>, D: Dialer> Service<G, D,
})
.or_insert_with(|| RequestInfo::new(intent_id, tag));

// queue the transfer (if not running) or attach to transfer progress (if already running)
if self.active_requests.contains_key(&kind) {
// the transfer is already running, so attach the progress sender
if let Some(on_progress) = &intent_callbacks.on_progress {
Expand All @@ -659,8 +674,6 @@ impl<DB: Store, G: Getter<Connection = D::Connection>, D: Dialer> Service<G, D,
// this is a noop if the transfer is already queued.
self.queue.insert(kind);
}
// store the download intent
self.intents.insert(intent_id, intent_callbacks);
}

/// Cancels the download request.
Expand Down

0 comments on commit 7b8b587

Please sign in to comment.