38
38
use std:: {
39
39
collections:: BTreeSet ,
40
40
fmt:: Debug ,
41
- marker:: PhantomData ,
42
41
net:: SocketAddr ,
43
42
path:: { Path , PathBuf } ,
44
43
sync:: Arc ,
@@ -49,11 +48,6 @@ use anyhow::{anyhow, Result};
49
48
use futures_lite:: StreamExt ;
50
49
use futures_util:: future:: { MapErr , Shared } ;
51
50
use 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
- } ;
57
51
use iroh_net:: {
58
52
endpoint:: { DirectAddrsStream , RemoteInfo } ,
59
53
AddrInfo , Endpoint , NodeAddr ,
@@ -73,9 +67,7 @@ mod rpc_status;
73
67
74
68
pub ( crate ) use self :: rpc:: RpcResult ;
75
69
pub use self :: {
76
- builder:: {
77
- Builder , DiscoveryConfig , GcPolicy , ProtocolBuilder , StorageConfig , DEFAULT_RPC_ADDR ,
78
- } ,
70
+ builder:: { Builder , DiscoveryConfig , ProtocolBuilder , StorageConfig , DEFAULT_RPC_ADDR } ,
79
71
rpc_status:: RpcStatus ,
80
72
} ;
81
73
@@ -101,8 +93,8 @@ pub type IrohServerEndpoint = quic_rpc::transport::boxed::BoxedListener<
101
93
/// await the [`Node`] struct directly, it will complete when the task completes. If
102
94
/// this is dropped the node task is not stopped but keeps running.
103
95
#[ derive( Debug , Clone ) ]
104
- pub struct Node < D > {
105
- inner : Arc < NodeInner < D > > ,
96
+ pub struct Node {
97
+ inner : Arc < NodeInner > ,
106
98
// `Node` needs to be `Clone + Send`, and we need to `task.await` in its `shutdown()` impl.
107
99
// So we need
108
100
// - `Shared` so we can `task.await` from all `Node` clones
@@ -116,43 +108,37 @@ pub struct Node<D> {
116
108
pub ( crate ) type JoinErrToStr = Box < dyn Fn ( JoinError ) -> String + Send + Sync + ' static > ;
117
109
118
110
#[ derive( derive_more:: Debug ) ]
119
- struct NodeInner < D > {
120
- db : PhantomData < D > ,
111
+ struct NodeInner {
121
112
rpc_addr : Option < SocketAddr > ,
122
113
endpoint : Endpoint ,
123
114
cancel_token : CancellationToken ,
124
115
client : crate :: client:: Iroh ,
125
- local_pool_handle : LocalPoolHandle ,
126
116
}
127
117
128
118
/// In memory node.
129
- pub type MemNode = Node < iroh_blobs:: store:: mem:: Store > ;
119
+ #[ deprecated]
120
+ pub type MemNode = Node ;
130
121
131
122
/// Persistent node.
132
- pub type FsNode = Node < iroh_blobs:: store:: fs:: Store > ;
123
+ #[ deprecated]
124
+ pub type FsNode = Node ;
133
125
134
- impl MemNode {
126
+ impl Node {
135
127
/// Returns a new builder for the [`Node`], by default configured to run in memory.
136
128
///
137
129
/// 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 ( )
140
132
}
141
- }
142
133
143
- impl FsNode {
144
134
/// Returns a new builder for the [`Node`], configured to persist all data
145
135
/// from the given path.
146
136
///
147
137
/// 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
152
140
}
153
- }
154
141
155
- impl < D : BaoStore > Node < D > {
156
142
/// Returns the [`Endpoint`] of the node.
157
143
///
158
144
/// This can be used to establish connections to other nodes under any
@@ -196,11 +182,6 @@ impl<D: BaoStore> Node<D> {
196
182
& self . inner . client
197
183
}
198
184
199
- /// Returns a reference to the used `LocalPoolHandle`.
200
- pub fn local_pool_handle ( & self ) -> & LocalPoolHandle {
201
- & self . inner . local_pool_handle
202
- }
203
-
204
185
/// Get the relay server we are connected to.
205
186
pub fn home_relay ( & self ) -> Option < iroh_net:: RelayUrl > {
206
187
self . inner . endpoint . home_relay ( )
@@ -243,15 +224,15 @@ impl<D: BaoStore> Node<D> {
243
224
}
244
225
}
245
226
246
- impl < D > std:: ops:: Deref for Node < D > {
227
+ impl std:: ops:: Deref for Node {
247
228
type Target = crate :: client:: Iroh ;
248
229
249
230
fn deref ( & self ) -> & Self :: Target {
250
231
& self . inner . client
251
232
}
252
233
}
253
234
254
- impl < D : iroh_blobs :: store :: Store > NodeInner < D > {
235
+ impl NodeInner {
255
236
async fn local_endpoint_addresses ( & self ) -> Result < Vec < SocketAddr > > {
256
237
let endpoints = self
257
238
. endpoint
@@ -268,10 +249,7 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
268
249
external_rpc : IrohServerEndpoint ,
269
250
internal_rpc : IrohServerEndpoint ,
270
251
router : Router ,
271
- gc_policy : GcPolicy ,
272
- gc_done_callback : Option < Box < dyn Fn ( ) + Send > > ,
273
252
nodes_data_path : Option < PathBuf > ,
274
- local_pool : LocalPool ,
275
253
) {
276
254
let ( ipv4, ipv6) = self . endpoint . bound_sockets ( ) ;
277
255
debug ! (
@@ -287,37 +265,6 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
287
265
let external_rpc = RpcServer :: new ( external_rpc) ;
288
266
let internal_rpc = RpcServer :: new ( internal_rpc) ;
289
267
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
-
321
268
if let Some ( nodes_data_path) = nodes_data_path {
322
269
let ep = self . endpoint . clone ( ) ;
323
270
let token = self . cancel_token . clone ( ) ;
@@ -419,7 +366,6 @@ impl<D: iroh_blobs::store::Store> NodeInner<D> {
419
366
420
367
// Abort remaining local tasks.
421
368
tracing:: info!( "Shutting down local pool" ) ;
422
- local_pool. shutdown ( ) . await ;
423
369
}
424
370
}
425
371
0 commit comments