@@ -47,14 +47,14 @@ impl Default for GcState {
47
47
}
48
48
}
49
49
50
- #[ derive( Debug ) ]
50
+ #[ derive( Debug , Clone ) ]
51
51
pub struct Blobs < S > {
52
52
rt : LocalPoolHandle ,
53
53
pub ( crate ) store : S ,
54
54
events : EventSender ,
55
55
downloader : Downloader ,
56
56
#[ cfg( feature = "rpc" ) ]
57
- batches : tokio:: sync:: Mutex < BlobBatches > ,
57
+ batches : Arc < tokio:: sync:: Mutex < BlobBatches > > ,
58
58
endpoint : Endpoint ,
59
59
gc_state : Arc < std:: sync:: Mutex < GcState > > ,
60
60
#[ cfg( feature = "rpc" ) ]
@@ -131,15 +131,15 @@ impl<S: crate::store::Store> Builder<S> {
131
131
132
132
/// Build the Blobs protocol handler.
133
133
/// You need to provide a local pool handle and an endpoint.
134
- pub fn build ( self , rt : & LocalPoolHandle , endpoint : & Endpoint ) -> Arc < Blobs < S > > {
134
+ pub fn build ( self , rt : & LocalPoolHandle , endpoint : & Endpoint ) -> Blobs < S > {
135
135
let downloader = Downloader :: new ( self . store . clone ( ) , endpoint. clone ( ) , rt. clone ( ) ) ;
136
- Arc :: new ( Blobs :: new (
136
+ Blobs :: new (
137
137
self . store ,
138
138
rt. clone ( ) ,
139
139
self . events . unwrap_or_default ( ) ,
140
140
downloader,
141
141
endpoint. clone ( ) ,
142
- ) )
142
+ )
143
143
}
144
144
}
145
145
@@ -391,82 +391,22 @@ impl<S: crate::store::Store> Blobs<S> {
391
391
}
392
392
}
393
393
394
- // trait BlobsInner: Debug + Send + Sync + 'static {
395
- // fn shutdown(self: Arc<Self>) -> BoxedFuture<()>;
396
- // fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>>;
397
- // fn client(self: Arc<Self>) -> MemClient;
398
- // fn local_pool_handle(&self) -> &LocalPoolHandle;
399
- // fn downloader(&self) -> &Downloader;
400
- // }
401
-
402
- // #[derive(Debug)]
403
- // struct Blobs2 {
404
- // inner: Arc<dyn BlobsInner>,
405
- // }
406
-
407
- // impl Blobs2 {
408
- // fn client(&self) -> MemClient {
409
- // self.inner.clone().client()
410
- // }
411
-
412
- // fn local_pool_handle(&self) -> &LocalPoolHandle {
413
- // self.inner.local_pool_handle()
414
- // }
415
-
416
- // fn downloader(&self) -> &Downloader {
417
- // self.inner.downloader()
418
- // }
419
- // }
420
-
421
- // impl<S: crate::store::Store> BlobsInner for Blobs<S> {
422
- // fn shutdown(self: Arc<Self>) -> BoxedFuture<()> {
423
- // ProtocolHandler::shutdown(self)
424
- // }
425
-
426
- // fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
427
- // ProtocolHandler::accept(self, conn)
428
- // }
429
-
430
- // fn client(self: Arc<Self>) -> MemClient {
431
- // Blobs::client(self)
432
- // }
433
-
434
- // fn local_pool_handle(&self) -> &LocalPoolHandle {
435
- // self.rt()
436
- // }
437
-
438
- // fn downloader(&self) -> &Downloader {
439
- // self.downloader()
440
- // }
441
- // }
442
-
443
- // impl ProtocolHandler for Blobs2 {
444
- // fn accept(self: Arc<Self>, conn: Connecting) -> BoxedFuture<Result<()>> {
445
- // self.inner.clone().accept(conn)
446
- // }
447
-
448
- // fn shutdown(self: Arc<Self>) -> BoxedFuture<()> {
449
- // self.inner.clone().shutdown()
450
- // }
451
- // }
452
-
453
394
impl < S : crate :: store:: Store > ProtocolHandler for Blobs < S > {
454
- fn accept ( self : Arc < Self > , conn : Connecting ) -> BoxedFuture < Result < ( ) > > {
395
+ fn accept ( & self , conn : Connecting ) -> BoxedFuture < Result < ( ) > > {
396
+ let db = self . store . clone ( ) ;
397
+ let events = self . events . clone ( ) ;
398
+ let rt = self . rt . clone ( ) ;
399
+
455
400
Box :: pin ( async move {
456
- crate :: provider:: handle_connection (
457
- conn. await ?,
458
- self . store . clone ( ) ,
459
- self . events . clone ( ) ,
460
- self . rt . clone ( ) ,
461
- )
462
- . await ;
401
+ crate :: provider:: handle_connection ( conn. await ?, db, events, rt) . await ;
463
402
Ok ( ( ) )
464
403
} )
465
404
}
466
405
467
- fn shutdown ( self : Arc < Self > ) -> BoxedFuture < ( ) > {
406
+ fn shutdown ( & self ) -> BoxedFuture < ( ) > {
407
+ let store = self . store . clone ( ) ;
468
408
Box :: pin ( async move {
469
- self . store . shutdown ( ) . await ;
409
+ store. shutdown ( ) . await ;
470
410
} )
471
411
}
472
412
}
0 commit comments