2
2
3
3
use std:: {
4
4
io,
5
+ ops:: Deref ,
5
6
sync:: { Arc , Mutex } ,
6
7
} ;
7
8
@@ -81,15 +82,33 @@ impl<D: crate::store::Store> Blobs<D> {
81
82
C : ChannelTypes < RpcService > ,
82
83
{
83
84
use Request :: * ;
85
+ let handler = Handler ( self ) ;
84
86
match msg {
85
- Blobs ( msg) => self . handle_blobs_request ( msg, chan) . await ,
86
- Tags ( msg) => self . handle_tags_request ( msg, chan) . await ,
87
+ Blobs ( msg) => handler . handle_blobs_request ( msg, chan) . await ,
88
+ Tags ( msg) => handler . handle_tags_request ( msg, chan) . await ,
87
89
}
88
90
}
91
+ }
92
+
93
+ #[ derive( Clone ) ]
94
+ struct Handler < S > ( Arc < Blobs < S > > ) ;
95
+
96
+ impl < S > Deref for Handler < S > {
97
+ type Target = Blobs < S > ;
98
+
99
+ fn deref ( & self ) -> & Self :: Target {
100
+ & self . 0
101
+ }
102
+ }
103
+
104
+ impl < D : crate :: store:: Store > Handler < D > {
105
+ fn store ( & self ) -> & D {
106
+ & self . 0 . store
107
+ }
89
108
90
109
/// Handle a tags request
91
- async fn handle_tags_request < C > (
92
- self : Arc < Self > ,
110
+ pub async fn handle_tags_request < C > (
111
+ self ,
93
112
msg : proto:: tags:: Request ,
94
113
chan : RpcChannel < proto:: RpcService , C > ,
95
114
) -> std:: result:: Result < ( ) , RpcServerError < C > >
@@ -106,8 +125,8 @@ impl<D: crate::store::Store> Blobs<D> {
106
125
}
107
126
108
127
/// Handle a blobs request
109
- async fn handle_blobs_request < C > (
110
- self : Arc < Self > ,
128
+ pub async fn handle_blobs_request < C > (
129
+ self ,
111
130
msg : proto:: blobs:: Request ,
112
131
chan : RpcChannel < proto:: RpcService , C > ,
113
132
) -> std:: result:: Result < ( ) , RpcServerError < C > >
@@ -150,7 +169,7 @@ impl<D: crate::store::Store> Blobs<D> {
150
169
}
151
170
}
152
171
153
- async fn blob_status ( self : Arc < Self > , msg : BlobStatusRequest ) -> RpcResult < BlobStatusResponse > {
172
+ async fn blob_status ( self , msg : BlobStatusRequest ) -> RpcResult < BlobStatusResponse > {
154
173
let blobs = self ;
155
174
let entry = blobs
156
175
. store ( )
@@ -171,7 +190,7 @@ impl<D: crate::store::Store> Blobs<D> {
171
190
} ) )
172
191
}
173
192
174
- async fn blob_list_impl ( self : Arc < Self > , co : & Co < RpcResult < BlobInfo > > ) -> io:: Result < ( ) > {
193
+ async fn blob_list_impl ( self , co : & Co < RpcResult < BlobInfo > > ) -> io:: Result < ( ) > {
175
194
use bao_tree:: io:: fsm:: Outboard ;
176
195
177
196
let blobs = self ;
@@ -190,7 +209,7 @@ impl<D: crate::store::Store> Blobs<D> {
190
209
}
191
210
192
211
async fn blob_list_incomplete_impl (
193
- self : Arc < Self > ,
212
+ self ,
194
213
co : & Co < RpcResult < IncompleteBlobInfo > > ,
195
214
) -> io:: Result < ( ) > {
196
215
let blobs = self ;
@@ -216,7 +235,7 @@ impl<D: crate::store::Store> Blobs<D> {
216
235
}
217
236
218
237
fn blob_list (
219
- self : Arc < Self > ,
238
+ self ,
220
239
_msg : ListRequest ,
221
240
) -> impl Stream < Item = RpcResult < BlobInfo > > + Send + ' static {
222
241
Gen :: new ( |co| async move {
@@ -227,7 +246,7 @@ impl<D: crate::store::Store> Blobs<D> {
227
246
}
228
247
229
248
fn blob_list_incomplete (
230
- self : Arc < Self > ,
249
+ self ,
231
250
_msg : ListIncompleteRequest ,
232
251
) -> impl Stream < Item = RpcResult < IncompleteBlobInfo > > + Send + ' static {
233
252
Gen :: new ( move |co| async move {
@@ -237,26 +256,23 @@ impl<D: crate::store::Store> Blobs<D> {
237
256
} )
238
257
}
239
258
240
- async fn blob_delete_tag ( self : Arc < Self > , msg : TagDeleteRequest ) -> RpcResult < ( ) > {
259
+ async fn blob_delete_tag ( self , msg : TagDeleteRequest ) -> RpcResult < ( ) > {
241
260
self . store ( )
242
261
. set_tag ( msg. name , None )
243
262
. await
244
263
. map_err ( |e| RpcError :: new ( & e) ) ?;
245
264
Ok ( ( ) )
246
265
}
247
266
248
- async fn blob_delete_blob ( self : Arc < Self > , msg : DeleteRequest ) -> RpcResult < ( ) > {
267
+ async fn blob_delete_blob ( self , msg : DeleteRequest ) -> RpcResult < ( ) > {
249
268
self . store ( )
250
269
. delete ( vec ! [ msg. hash] )
251
270
. await
252
271
. map_err ( |e| RpcError :: new ( & e) ) ?;
253
272
Ok ( ( ) )
254
273
}
255
274
256
- fn blob_list_tags (
257
- self : Arc < Self > ,
258
- msg : TagListRequest ,
259
- ) -> impl Stream < Item = TagInfo > + Send + ' static {
275
+ fn blob_list_tags ( self , msg : TagListRequest ) -> impl Stream < Item = TagInfo > + Send + ' static {
260
276
tracing:: info!( "blob_list_tags" ) ;
261
277
let blobs = self ;
262
278
Gen :: new ( |co| async move {
@@ -274,7 +290,7 @@ impl<D: crate::store::Store> Blobs<D> {
274
290
275
291
/// Invoke validate on the database and stream out the result
276
292
fn blob_validate (
277
- self : Arc < Self > ,
293
+ self ,
278
294
msg : ValidateRequest ,
279
295
) -> impl Stream < Item = ValidateProgress > + Send + ' static {
280
296
let ( tx, rx) = async_channel:: bounded ( 1 ) ;
@@ -296,7 +312,7 @@ impl<D: crate::store::Store> Blobs<D> {
296
312
297
313
/// Invoke validate on the database and stream out the result
298
314
fn blob_consistency_check (
299
- self : Arc < Self > ,
315
+ self ,
300
316
msg : ConsistencyCheckRequest ,
301
317
) -> impl Stream < Item = ConsistencyCheckProgress > + Send + ' static {
302
318
let ( tx, rx) = async_channel:: bounded ( 1 ) ;
@@ -316,10 +332,7 @@ impl<D: crate::store::Store> Blobs<D> {
316
332
rx
317
333
}
318
334
319
- fn blob_add_from_path (
320
- self : Arc < Self > ,
321
- msg : AddPathRequest ,
322
- ) -> impl Stream < Item = AddPathResponse > {
335
+ fn blob_add_from_path ( self , msg : AddPathRequest ) -> impl Stream < Item = AddPathResponse > {
323
336
// provide a little buffer so that we don't slow down the sender
324
337
let ( tx, rx) = async_channel:: bounded ( 32 ) ;
325
338
let tx2 = tx. clone ( ) ;
@@ -332,7 +345,7 @@ impl<D: crate::store::Store> Blobs<D> {
332
345
rx. map ( AddPathResponse )
333
346
}
334
347
335
- async fn tags_set ( self : Arc < Self > , msg : TagsSetRequest ) -> RpcResult < ( ) > {
348
+ async fn tags_set ( self , msg : TagsSetRequest ) -> RpcResult < ( ) > {
336
349
let blobs = self ;
337
350
blobs
338
351
. store ( )
@@ -354,7 +367,7 @@ impl<D: crate::store::Store> Blobs<D> {
354
367
Ok ( ( ) )
355
368
}
356
369
357
- async fn tags_create ( self : Arc < Self > , msg : TagsCreateRequest ) -> RpcResult < Tag > {
370
+ async fn tags_create ( self , msg : TagsCreateRequest ) -> RpcResult < Tag > {
358
371
let blobs = self ;
359
372
let tag = blobs
360
373
. store ( )
@@ -374,10 +387,7 @@ impl<D: crate::store::Store> Blobs<D> {
374
387
Ok ( tag)
375
388
}
376
389
377
- fn blob_download (
378
- self : Arc < Self > ,
379
- msg : BlobDownloadRequest ,
380
- ) -> impl Stream < Item = DownloadResponse > {
390
+ fn blob_download ( self , msg : BlobDownloadRequest ) -> impl Stream < Item = DownloadResponse > {
381
391
let ( sender, receiver) = async_channel:: bounded ( 1024 ) ;
382
392
let endpoint = self . endpoint ( ) . clone ( ) ;
383
393
let progress = AsyncChannelProgressSender :: new ( sender) ;
@@ -399,7 +409,7 @@ impl<D: crate::store::Store> Blobs<D> {
399
409
receiver. map ( DownloadResponse )
400
410
}
401
411
402
- fn blob_export ( self : Arc < Self > , msg : ExportRequest ) -> impl Stream < Item = ExportResponse > {
412
+ fn blob_export ( self , msg : ExportRequest ) -> impl Stream < Item = ExportResponse > {
403
413
let ( tx, rx) = async_channel:: bounded ( 1024 ) ;
404
414
let progress = AsyncChannelProgressSender :: new ( tx) ;
405
415
let rt = self . rt ( ) . clone ( ) ;
@@ -425,7 +435,7 @@ impl<D: crate::store::Store> Blobs<D> {
425
435
}
426
436
427
437
async fn blob_add_from_path0 (
428
- self : Arc < Self > ,
438
+ self ,
429
439
msg : AddPathRequest ,
430
440
progress : async_channel:: Sender < AddProgress > ,
431
441
) -> anyhow:: Result < ( ) > {
@@ -543,18 +553,15 @@ impl<D: crate::store::Store> Blobs<D> {
543
553
Ok ( ( ) )
544
554
}
545
555
546
- async fn batch_create_temp_tag (
547
- self : Arc < Self > ,
548
- msg : BatchCreateTempTagRequest ,
549
- ) -> RpcResult < ( ) > {
556
+ async fn batch_create_temp_tag ( self , msg : BatchCreateTempTagRequest ) -> RpcResult < ( ) > {
550
557
let blobs = self ;
551
558
let tag = blobs. store ( ) . temp_tag ( msg. content ) ;
552
559
blobs. batches ( ) . await . store ( msg. batch , tag) ;
553
560
Ok ( ( ) )
554
561
}
555
562
556
563
fn batch_add_stream (
557
- self : Arc < Self > ,
564
+ self ,
558
565
msg : BatchAddStreamRequest ,
559
566
stream : impl Stream < Item = BatchAddStreamUpdate > + Send + Unpin + ' static ,
560
567
) -> impl Stream < Item = BatchAddStreamResponse > {
@@ -572,7 +579,7 @@ impl<D: crate::store::Store> Blobs<D> {
572
579
}
573
580
574
581
fn batch_add_from_path (
575
- self : Arc < Self > ,
582
+ self ,
576
583
msg : BatchAddPathRequest ,
577
584
) -> impl Stream < Item = BatchAddPathResponse > {
578
585
// provide a little buffer so that we don't slow down the sender
@@ -590,7 +597,7 @@ impl<D: crate::store::Store> Blobs<D> {
590
597
}
591
598
592
599
async fn batch_add_stream0 (
593
- self : Arc < Self > ,
600
+ self ,
594
601
msg : BatchAddStreamRequest ,
595
602
stream : impl Stream < Item = BatchAddStreamUpdate > + Send + Unpin + ' static ,
596
603
progress : async_channel:: Sender < BatchAddStreamResponse > ,
@@ -624,7 +631,7 @@ impl<D: crate::store::Store> Blobs<D> {
624
631
}
625
632
626
633
async fn batch_add_from_path0 (
627
- self : Arc < Self > ,
634
+ self ,
628
635
msg : BatchAddPathRequest ,
629
636
progress : async_channel:: Sender < BatchAddPathProgress > ,
630
637
) -> anyhow:: Result < ( ) > {
@@ -664,7 +671,7 @@ impl<D: crate::store::Store> Blobs<D> {
664
671
}
665
672
666
673
fn blob_add_stream (
667
- self : Arc < Self > ,
674
+ self ,
668
675
msg : AddStreamRequest ,
669
676
stream : impl Stream < Item = AddStreamUpdate > + Send + Unpin + ' static ,
670
677
) -> impl Stream < Item = AddStreamResponse > {
@@ -681,7 +688,7 @@ impl<D: crate::store::Store> Blobs<D> {
681
688
}
682
689
683
690
async fn blob_add_stream0 (
684
- self : Arc < Self > ,
691
+ self ,
685
692
msg : AddStreamRequest ,
686
693
stream : impl Stream < Item = AddStreamUpdate > + Send + Unpin + ' static ,
687
694
progress : async_channel:: Sender < AddProgress > ,
@@ -735,7 +742,7 @@ impl<D: crate::store::Store> Blobs<D> {
735
742
}
736
743
737
744
fn blob_read_at (
738
- self : Arc < Self > ,
745
+ self ,
739
746
req : ReadAtRequest ,
740
747
) -> impl Stream < Item = RpcResult < ReadAtResponse > > + Send + ' static {
741
748
let ( tx, rx) = async_channel:: bounded ( RPC_BLOB_GET_CHANNEL_CAP ) ;
@@ -816,7 +823,7 @@ impl<D: crate::store::Store> Blobs<D> {
816
823
}
817
824
818
825
fn batch_create (
819
- self : Arc < Self > ,
826
+ self ,
820
827
_: BatchCreateRequest ,
821
828
mut updates : impl Stream < Item = BatchUpdate > + Send + Unpin + ' static ,
822
829
) -> impl Stream < Item = BatchCreateResponse > {
@@ -842,7 +849,7 @@ impl<D: crate::store::Store> Blobs<D> {
842
849
}
843
850
844
851
async fn create_collection (
845
- self : Arc < Self > ,
852
+ self ,
846
853
req : CreateCollectionRequest ,
847
854
) -> RpcResult < CreateCollectionResponse > {
848
855
let CreateCollectionRequest {
0 commit comments