3838use std:: {
3939 collections:: BTreeSet ,
4040 fmt:: Debug ,
41- marker:: PhantomData ,
4241 net:: SocketAddr ,
4342 path:: { Path , PathBuf } ,
4443 sync:: Arc ,
@@ -49,11 +48,6 @@ use anyhow::{anyhow, Result};
4948use futures_lite:: StreamExt ;
5049use futures_util:: future:: { MapErr , Shared } ;
5150use iroh_base:: key:: PublicKey ;
52- use iroh_blobs:: {
53- net_protocol:: Blobs as BlobsProtocol ,
54- store:: Store as BaoStore ,
55- util:: local_pool:: { LocalPool , LocalPoolHandle } ,
56- } ;
5751use iroh_net:: {
5852 endpoint:: { DirectAddrsStream , RemoteInfo } ,
5953 AddrInfo , Endpoint , NodeAddr ,
@@ -73,9 +67,7 @@ mod rpc_status;
7367
7468pub ( crate ) use self :: rpc:: RpcResult ;
7569pub use self :: {
76- builder:: {
77- Builder , DiscoveryConfig , GcPolicy , ProtocolBuilder , StorageConfig , DEFAULT_RPC_ADDR ,
78- } ,
70+ builder:: { Builder , DiscoveryConfig , ProtocolBuilder , StorageConfig , DEFAULT_RPC_ADDR } ,
7971 rpc_status:: RpcStatus ,
8072} ;
8173
@@ -101,8 +93,8 @@ pub type IrohServerEndpoint = quic_rpc::transport::boxed::BoxedListener<
10193/// await the [`Node`] struct directly, it will complete when the task completes. If
10294/// this is dropped the node task is not stopped but keeps running.
10395#[ derive( Debug , Clone ) ]
104- pub struct Node < D > {
105- inner : Arc < NodeInner < D > > ,
96+ pub struct Node {
97+ inner : Arc < NodeInner > ,
10698 // `Node` needs to be `Clone + Send`, and we need to `task.await` in its `shutdown()` impl.
10799 // So we need
108100 // - `Shared` so we can `task.await` from all `Node` clones
@@ -116,43 +108,37 @@ pub struct Node<D> {
116108pub ( crate ) type JoinErrToStr = Box < dyn Fn ( JoinError ) -> String + Send + Sync + ' static > ;
117109
118110#[ derive( derive_more:: Debug ) ]
119- struct NodeInner < D > {
120- db : PhantomData < D > ,
111+ struct NodeInner {
121112 rpc_addr : Option < SocketAddr > ,
122113 endpoint : Endpoint ,
123114 cancel_token : CancellationToken ,
124115 client : crate :: client:: Iroh ,
125- local_pool_handle : LocalPoolHandle ,
126116}
127117
128118/// In memory node.
129- pub type MemNode = Node < iroh_blobs:: store:: mem:: Store > ;
119+ #[ deprecated]
120+ pub type MemNode = Node ;
130121
131122/// Persistent node.
132- pub type FsNode = Node < iroh_blobs:: store:: fs:: Store > ;
123+ #[ deprecated]
124+ pub type FsNode = Node ;
133125
134- impl MemNode {
126+ impl Node {
135127 /// Returns a new builder for the [`Node`], by default configured to run in memory.
136128 ///
137129 /// Once done with the builder call [`Builder::spawn`] to create the node.
138- pub fn memory ( ) -> Builder < iroh_blobs :: store :: mem :: Store > {
139- Builder :: default ( )
130+ pub fn memory ( ) -> Builder {
131+ Builder :: memory ( )
140132 }
141- }
142133
143- impl FsNode {
144134 /// Returns a new builder for the [`Node`], configured to persist all data
145135 /// from the given path.
146136 ///
147137 /// Once done with the builder call [`Builder::spawn`] to create the node.
148- pub async fn persistent (
149- root : impl AsRef < Path > ,
150- ) -> Result < Builder < iroh_blobs:: store:: fs:: Store > > {
151- Builder :: default ( ) . persist ( root) . await
138+ pub async fn persistent ( root : impl AsRef < Path > ) -> Result < Builder > {
139+ Builder :: memory ( ) . persist ( root) . await
152140 }
153- }
154141
155- impl < D : BaoStore > Node < D > {
156142 /// Returns the [`Endpoint`] of the node.
157143 ///
158144 /// This can be used to establish connections to other nodes under any
@@ -196,11 +182,6 @@ impl<D: BaoStore> Node<D> {
196182 & self . inner . client
197183 }
198184
199- /// Returns a reference to the used `LocalPoolHandle`.
200- pub fn local_pool_handle ( & self ) -> & LocalPoolHandle {
201- & self . inner . local_pool_handle
202- }
203-
204185 /// Get the relay server we are connected to.
205186 pub fn home_relay ( & self ) -> Option < iroh_net:: RelayUrl > {
206187 self . inner . endpoint . home_relay ( )
@@ -243,15 +224,15 @@ impl<D: BaoStore> Node<D> {
243224 }
244225}
245226
246- impl < D > std:: ops:: Deref for Node < D > {
227+ impl std:: ops:: Deref for Node {
247228 type Target = crate :: client:: Iroh ;
248229
249230 fn deref ( & self ) -> & Self :: Target {
250231 & self . inner . client
251232 }
252233}
253234
254- impl < D : iroh_blobs :: store :: Store > NodeInner < D > {
235+ impl NodeInner {
255236 async fn local_endpoint_addresses ( & self ) -> Result < Vec < SocketAddr > > {
256237 let endpoints = self
257238 . endpoint
@@ -268,10 +249,7 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
268249 external_rpc : IrohServerEndpoint ,
269250 internal_rpc : IrohServerEndpoint ,
270251 router : Router ,
271- gc_policy : GcPolicy ,
272- gc_done_callback : Option < Box < dyn Fn ( ) + Send > > ,
273252 nodes_data_path : Option < PathBuf > ,
274- local_pool : LocalPool ,
275253 ) {
276254 let ( ipv4, ipv6) = self . endpoint . bound_sockets ( ) ;
277255 debug ! (
@@ -287,37 +265,6 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
287265 let external_rpc = RpcServer :: new ( external_rpc) ;
288266 let internal_rpc = RpcServer :: new ( internal_rpc) ;
289267
290- // Spawn a task for the garbage collection.
291- if let GcPolicy :: Interval ( gc_period) = gc_policy {
292- let router = router. clone ( ) ;
293- let handle = local_pool. spawn ( move || async move {
294- let blobs = router
295- . get_protocol :: < BlobsProtocol < D > > ( iroh_blobs:: protocol:: ALPN )
296- . expect ( "missing blobs" ) ;
297-
298- blobs
299- . store ( )
300- . gc_run (
301- iroh_blobs:: store:: GcConfig {
302- period : gc_period,
303- done_callback : gc_done_callback,
304- } ,
305- || async move { BTreeSet :: default ( ) } ,
306- )
307- . await ;
308- } ) ;
309- // We cannot spawn tasks that run on the local pool directly into the join set,
310- // so instead we create a new task that supervises the local task.
311- join_set. spawn ( {
312- async move {
313- if let Err ( err) = handle. await {
314- return Err ( anyhow:: Error :: from ( err) ) ;
315- }
316- Ok ( ( ) )
317- }
318- } ) ;
319- }
320-
321268 if let Some ( nodes_data_path) = nodes_data_path {
322269 let ep = self . endpoint . clone ( ) ;
323270 let token = self . cancel_token . clone ( ) ;
@@ -419,7 +366,6 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
419366
420367 // Abort remaining local tasks.
421368 tracing:: info!( "Shutting down local pool" ) ;
422- local_pool. shutdown ( ) . await ;
423369 }
424370}
425371
0 commit comments