File tree Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Expand file tree Collapse file tree 3 files changed +46
-3
lines changed Original file line number Diff line number Diff line change @@ -154,6 +154,10 @@ required-features = ["example-iroh"]
154
154
name = " custom-protocol"
155
155
required-features = [" example-iroh" ]
156
156
157
+ [[example ]]
158
+ name = " setup"
159
+ required-features = [" example-iroh" ]
160
+
157
161
[lints .rust ]
158
162
missing_debug_implementations = " warn"
159
163
Original file line number Diff line number Diff line change @@ -35,10 +35,10 @@ use iroh::{protocol::Router, Endpoint};
35
35
use iroh_blobs :: {net_protocol :: Blobs , util :: local_pool :: LocalPool };
36
36
37
37
#[tokio:: main]
38
- async fn main () -> Result <(), std :: fmt :: Error > {
38
+ async fn main () -> anyhow :: Result <()> {
39
39
// create an iroh endpoint that includes the standard discovery mechanisms
40
40
// we've built at number0
41
- let endpoint = Endpoint :: builder (). discovery_n0 (). bind (). await . unwrap () ;
41
+ let endpoint = Endpoint :: builder (). discovery_n0 (). bind (). await ? ;
42
42
43
43
// spawn a local pool with one thread per CPU
44
44
// for a single threaded pool use `LocalPool::single`
@@ -56,10 +56,14 @@ async fn main() -> Result<(), std::fmt::Error> {
56
56
// build the router
57
57
let router = Router :: builder (endpoint )
58
58
. accept (iroh_blobs :: ALPN , blobs . clone ())
59
- . spawn ();
59
+ . spawn ()
60
+ . await ? ;
60
61
61
62
// do fun stuff with the blobs protocol!
62
63
// make sure not to drop the local_pool before you are finished
64
+ router . shutdown (). await ? ;
65
+ drop (local_pool );
66
+ drop (tags_client );
63
67
Ok (())
64
68
}
65
69
```
Original file line number Diff line number Diff line change
1
+ use iroh:: { protocol:: Router , Endpoint } ;
2
+ use iroh_blobs:: { net_protocol:: Blobs , util:: local_pool:: LocalPool } ;
3
+
4
+ #[ tokio:: main]
5
+ async fn main ( ) -> anyhow:: Result < ( ) > {
6
+ // create an iroh endpoint that includes the standard discovery mechanisms
7
+ // we've built at number0
8
+ let endpoint = Endpoint :: builder ( ) . discovery_n0 ( ) . bind ( ) . await ?;
9
+
10
+ // spawn a local pool with one thread per CPU
11
+ // for a single threaded pool use `LocalPool::single`
12
+ let local_pool = LocalPool :: default ( ) ;
13
+
14
+ // create an in-memory blob store
15
+ // use `iroh_blobs::net_protocol::Blobs::persistent` to load or create a
16
+ // persistent blob store from a path
17
+ let blobs = Blobs :: memory ( ) . build ( local_pool. handle ( ) , & endpoint) ;
18
+
19
+ // turn on the "rpc" feature if you need to create blobs and tags clients
20
+ let blobs_client = blobs. client ( ) ;
21
+ let tags_client = blobs_client. tags ( ) ;
22
+
23
+ // build the router
24
+ let router = Router :: builder ( endpoint)
25
+ . accept ( iroh_blobs:: ALPN , blobs. clone ( ) )
26
+ . spawn ( )
27
+ . await ?;
28
+
29
+ // do fun stuff with the blobs protocol!
30
+ // make sure not to drop the local_pool before you are finished
31
+ router. shutdown ( ) . await ?;
32
+ drop ( local_pool) ;
33
+ drop ( tags_client) ;
34
+ Ok ( ( ) )
35
+ }
You can’t perform that action at this time.
0 commit comments