@@ -47,14 +47,14 @@ impl Default for GcState {
4747 }
4848}
4949
50- #[ derive( Debug ) ]
50+ #[ derive( Debug , Clone ) ]
5151pub struct Blobs < S > {
5252 rt : LocalPoolHandle ,
5353 pub ( crate ) store : S ,
5454 events : EventSender ,
5555 downloader : Downloader ,
5656 #[ cfg( feature = "rpc" ) ]
57- batches : tokio:: sync:: Mutex < BlobBatches > ,
57+ batches : Arc < tokio:: sync:: Mutex < BlobBatches > > ,
5858 endpoint : Endpoint ,
5959 gc_state : Arc < std:: sync:: Mutex < GcState > > ,
6060 #[ cfg( feature = "rpc" ) ]
@@ -131,15 +131,15 @@ impl<S: crate::store::Store> Builder<S> {
131131
132132 /// Build the Blobs protocol handler.
133133 /// 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 > {
135135 let downloader = Downloader :: new ( self . store . clone ( ) , endpoint. clone ( ) , rt. clone ( ) ) ;
136- Arc :: new ( Blobs :: new (
136+ Blobs :: new (
137137 self . store ,
138138 rt. clone ( ) ,
139139 self . events . unwrap_or_default ( ) ,
140140 downloader,
141141 endpoint. clone ( ) ,
142- ) )
142+ )
143143 }
144144}
145145
@@ -391,82 +391,22 @@ impl<S: crate::store::Store> Blobs<S> {
391391 }
392392}
393393
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-
453394impl < 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+
455400 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 ;
463402 Ok ( ( ) )
464403 } )
465404 }
466405
467- fn shutdown ( self : Arc < Self > ) -> BoxedFuture < ( ) > {
406+ fn shutdown ( & self ) -> BoxedFuture < ( ) > {
407+ let store = self . store . clone ( ) ;
468408 Box :: pin ( async move {
469- self . store . shutdown ( ) . await ;
409+ store. shutdown ( ) . await ;
470410 } )
471411 }
472412}
0 commit comments