Skip to content

Commit 9d0fccd

Browse files
committed
impl SupportedRequest for Hash and HashAndFormat
1 parent 59b8da8 commit 9d0fccd

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

src/api/downloader.rs

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ use tracing::instrument::Instrument;
2323

2424
use super::{Store, remote::GetConnection};
2525
use crate::{
26-
Hash, HashAndFormat,
27-
protocol::{GetManyRequest, GetRequest},
28-
util::sink::{Drain, IrpcSenderRefSink, Sink, TokioMpscSenderSink},
26+
protocol::{GetManyRequest, GetRequest}, util::sink::{Drain, IrpcSenderRefSink, Sink, TokioMpscSenderSink}, BlobFormat, Hash, HashAndFormat
2927
};
3028

3129
#[derive(Debug, Clone)]
@@ -45,7 +43,7 @@ enum SwarmProtocol {
4543
Download(DownloadRequest),
4644
}
4745

48-
struct SwarmActor {
46+
struct DownloaderActor {
4947
store: Store,
5048
pool: ConnectionPool,
5149
tasks: JoinSet<()>,
@@ -71,7 +69,7 @@ pub enum DownloadProgessItem {
7169
DownloadError,
7270
}
7371

74-
impl SwarmActor {
72+
impl DownloaderActor {
7573
fn new(store: Store, endpoint: Endpoint) -> Self {
7674
Self {
7775
store,
@@ -226,13 +224,28 @@ impl<I: Into<Hash>, T: IntoIterator<Item = I>> SupportedRequest for T {
226224

227225
impl SupportedRequest for GetRequest {
228226
fn into_request(self) -> FiniteRequest {
229-
FiniteRequest::Get(self)
227+
self.into()
230228
}
231229
}
232230

233231
impl SupportedRequest for GetManyRequest {
234232
fn into_request(self) -> FiniteRequest {
235-
FiniteRequest::GetMany(self)
233+
self.into()
234+
}
235+
}
236+
237+
impl SupportedRequest for Hash {
238+
fn into_request(self) -> FiniteRequest {
239+
GetRequest::blob(self).into()
240+
}
241+
}
242+
243+
impl SupportedRequest for HashAndFormat {
244+
fn into_request(self) -> FiniteRequest {
245+
(match self.format {
246+
BlobFormat::Raw => GetRequest::blob(self.hash),
247+
BlobFormat::HashSeq => GetRequest::all(self.hash),
248+
}).into()
236249
}
237250
}
238251

@@ -339,7 +352,7 @@ impl IntoFuture for DownloadProgress {
339352
impl Downloader {
340353
pub fn new(store: &Store, endpoint: &Endpoint) -> Self {
341354
let (tx, rx) = mpsc::channel::<SwarmMsg>(32);
342-
let actor = SwarmActor::new(store.clone(), endpoint.clone());
355+
let actor = DownloaderActor::new(store.clone(), endpoint.clone());
343356
tokio::spawn(actor.run(rx));
344357
Self { client: tx.into() }
345358
}

0 commit comments

Comments
 (0)