1
1
#![ cfg( feature = "rpc" ) ]
2
2
use std:: {
3
3
io:: { Cursor , Write } ,
4
+ path:: PathBuf ,
4
5
time:: Duration ,
5
6
} ;
6
7
@@ -14,7 +15,7 @@ use iroh_blobs::{
14
15
BlobFormat , HashAndFormat , IROH_BLOCK_SIZE ,
15
16
} ;
16
17
use rand:: RngCore ;
17
- use util:: { Builder , Node } ;
18
+ use util:: Node ;
18
19
19
20
mod util;
20
21
@@ -39,15 +40,34 @@ pub fn simulate_remote(data: &[u8]) -> (blake3::Hash, Cursor<Bytes>) {
39
40
}
40
41
41
42
/// Wrap a bao store in a node that has gc enabled.
42
- async fn wrap_in_node < S > (
43
- bao_store : S ,
43
+ async fn mem_node (
44
44
gc_period : Duration ,
45
- ) -> ( Node < S > , async_channel :: Receiver < ( ) > )
46
- where
47
- S : iroh_blobs :: store :: Store ,
48
- {
45
+ ) -> (
46
+ Node < iroh_blobs :: store :: mem :: Store > ,
47
+ async_channel :: Receiver < ( ) > ,
48
+ ) {
49
49
let ( gc_send, gc_recv) = async_channel:: unbounded ( ) ;
50
- let node = Builder :: new ( bao_store)
50
+ let node = Node :: memory ( )
51
+ . gc_interval ( Some ( gc_period) )
52
+ . register_gc_done_cb ( Box :: new ( move || {
53
+ gc_send. send_blocking ( ( ) ) . ok ( ) ;
54
+ } ) )
55
+ . spawn ( )
56
+ . await
57
+ . unwrap ( ) ;
58
+ ( node, gc_recv)
59
+ }
60
+
61
+ /// Wrap a bao store in a node that has gc enabled.
62
+ async fn persistent_node (
63
+ path : PathBuf ,
64
+ gc_period : Duration ,
65
+ ) -> (
66
+ Node < iroh_blobs:: store:: fs:: Store > ,
67
+ async_channel:: Receiver < ( ) > ,
68
+ ) {
69
+ let ( gc_send, gc_recv) = async_channel:: unbounded ( ) ;
70
+ let node = Node :: persistent ( path)
51
71
. gc_interval ( Some ( gc_period) )
52
72
. register_gc_done_cb ( Box :: new ( move || {
53
73
gc_send. send_blocking ( ( ) ) . ok ( ) ;
@@ -63,9 +83,9 @@ async fn gc_test_node() -> (
63
83
iroh_blobs:: store:: mem:: Store ,
64
84
async_channel:: Receiver < ( ) > ,
65
85
) {
66
- let bao_store = iroh_blobs :: store :: mem :: Store :: new ( ) ;
67
- let ( node , gc_recv ) = wrap_in_node ( bao_store . clone ( ) , Duration :: from_millis ( 500 ) ) . await ;
68
- ( node, bao_store , gc_recv)
86
+ let ( node , gc_recv ) = mem_node ( Duration :: from_millis ( 500 ) ) . await ;
87
+ let store = node . blob_store ( ) . clone ( ) ;
88
+ ( node, store , gc_recv)
69
89
}
70
90
71
91
async fn step ( evs : & async_channel:: Receiver < ( ) > ) {
@@ -230,8 +250,8 @@ mod file {
230
250
async fn redb_doc_import_stress ( ) -> Result < ( ) > {
231
251
let _ = tracing_subscriber:: fmt:: try_init ( ) ;
232
252
let dir = testdir ! ( ) ;
233
- let bao_store = iroh_blobs :: store :: fs :: Store :: load ( dir. join ( "store" ) ) . await ? ;
234
- let ( node , _ ) = wrap_in_node ( bao_store . clone ( ) , Duration :: from_secs ( 10 ) ) . await ;
253
+ let ( node , _ ) = persistent_node ( dir. join ( "store" ) , Duration :: from_secs ( 10 ) ) . await ;
254
+ let bao_store = node . blob_store ( ) . clone ( ) ;
235
255
let client = node. client ( ) ;
236
256
let doc = client. docs ( ) . create ( ) . await ?;
237
257
let author = client. docs ( ) . author_create ( ) . await ?;
@@ -272,9 +292,8 @@ mod file {
272
292
let dir = testdir ! ( ) ;
273
293
let path = data_path ( dir. clone ( ) ) ;
274
294
let outboard_path = outboard_path ( dir. clone ( ) ) ;
275
-
276
- let bao_store = iroh_blobs:: store:: fs:: Store :: load ( dir. clone ( ) ) . await ?;
277
- let ( node, evs) = wrap_in_node ( bao_store. clone ( ) , Duration :: from_millis ( 100 ) ) . await ;
295
+ let ( node, evs) = persistent_node ( dir. clone ( ) , Duration :: from_millis ( 100 ) ) . await ;
296
+ let bao_store = node. blob_store ( ) . clone ( ) ;
278
297
let data1 = create_test_data ( 10000000 ) ;
279
298
let tt1 = bao_store
280
299
. import_bytes ( data1. clone ( ) , BlobFormat :: Raw )
@@ -434,8 +453,8 @@ mod file {
434
453
let path = data_path ( dir. clone ( ) ) ;
435
454
let outboard_path = outboard_path ( dir. clone ( ) ) ;
436
455
437
- let bao_store = iroh_blobs :: store :: fs :: Store :: load ( dir. clone ( ) ) . await ? ;
438
- let ( node , evs ) = wrap_in_node ( bao_store . clone ( ) , Duration :: from_millis ( 10 ) ) . await ;
456
+ let ( node , evs ) = persistent_node ( dir. clone ( ) , Duration :: from_millis ( 10 ) ) . await ;
457
+ let bao_store = node . blob_store ( ) . clone ( ) ;
439
458
440
459
let data1: Bytes = create_test_data ( 10000000 ) ;
441
460
let ( _entry, tt1) = simulate_download_partial ( & bao_store, data1. clone ( ) ) . await ?;
@@ -465,8 +484,8 @@ mod file {
465
484
let _ = tracing_subscriber:: fmt:: try_init ( ) ;
466
485
let dir = testdir ! ( ) ;
467
486
468
- let bao_store = iroh_blobs :: store :: fs :: Store :: load ( dir. clone ( ) ) . await ? ;
469
- let ( node , evs ) = wrap_in_node ( bao_store . clone ( ) , Duration :: from_secs ( 1 ) ) . await ;
487
+ let ( node , evs ) = persistent_node ( dir. clone ( ) , Duration :: from_secs ( 1 ) ) . await ;
488
+ let bao_store = node . blob_store ( ) . clone ( ) ;
470
489
471
490
let mut deleted = Vec :: new ( ) ;
472
491
let mut live = Vec :: new ( ) ;
0 commit comments