@@ -23,9 +23,7 @@ use tracing::instrument::Instrument;
23
23
24
24
use super :: { Store , remote:: GetConnection } ;
25
25
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
29
27
} ;
30
28
31
29
#[ derive( Debug , Clone ) ]
@@ -45,7 +43,7 @@ enum SwarmProtocol {
45
43
Download ( DownloadRequest ) ,
46
44
}
47
45
48
- struct SwarmActor {
46
+ struct DownloaderActor {
49
47
store : Store ,
50
48
pool : ConnectionPool ,
51
49
tasks : JoinSet < ( ) > ,
@@ -71,7 +69,7 @@ pub enum DownloadProgessItem {
71
69
DownloadError ,
72
70
}
73
71
74
- impl SwarmActor {
72
+ impl DownloaderActor {
75
73
fn new ( store : Store , endpoint : Endpoint ) -> Self {
76
74
Self {
77
75
store,
@@ -226,13 +224,28 @@ impl<I: Into<Hash>, T: IntoIterator<Item = I>> SupportedRequest for T {
226
224
227
225
impl SupportedRequest for GetRequest {
228
226
fn into_request ( self ) -> FiniteRequest {
229
- FiniteRequest :: Get ( self )
227
+ self . into ( )
230
228
}
231
229
}
232
230
233
231
impl SupportedRequest for GetManyRequest {
234
232
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 ( )
236
249
}
237
250
}
238
251
@@ -339,7 +352,7 @@ impl IntoFuture for DownloadProgress {
339
352
impl Downloader {
340
353
pub fn new ( store : & Store , endpoint : & Endpoint ) -> Self {
341
354
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 ( ) ) ;
343
356
tokio:: spawn ( actor. run ( rx) ) ;
344
357
Self { client : tx. into ( ) }
345
358
}
0 commit comments