@@ -22,6 +22,7 @@ This crate is used together with [iroh](https://crates.io/crates/iroh). Connecti
22
22
23
23
- ** Requester:** The side that asks for data. It is initiating requests to one or many providers.
24
24
25
+ A node can be a provider and a requester at the same time.
25
26
26
27
## Getting started
27
28
@@ -33,31 +34,31 @@ Here is a basic example of how to set up `iroh-blobs` with `iroh`:
33
34
34
35
``` rust
35
36
use iroh :: {protocol :: Router , Endpoint };
36
- use iroh_blobs :: {store :: Store , net_protocol :: Blobs };
37
+ use iroh_blobs :: {store :: mem :: MemStore , BlobsProtocol };
37
38
38
39
#[tokio:: main]
39
40
async fn main () -> anyhow :: Result <()> {
40
41
// create an iroh endpoint that includes the standard discovery mechanisms
41
42
// we've built at number0
42
43
let endpoint = Endpoint :: builder (). discovery_n0 (). bind (). await ? ;
43
44
44
- // create an in-memory blob store
45
- // use `iroh_blobs::net_protocol::Blobs::persistent` to load or create a
46
- // persistent blob store from a path
47
- let blobs = Blobs :: memory (). build (& endpoint );
48
-
49
- // turn on the "rpc" feature if you need to create blobs and tags clients
50
- let blobs_client = blobs . client ();
51
- let tags_client = blobs_client . tags ();
45
+ // create a protocol handler using an in-memory blob store.
46
+ let store = MemStore :: new ();
47
+ let blobs = BlobsProtocol :: new (& store , endpoint . clone (), None );
52
48
53
49
// build the router
54
50
let router = Router :: builder (endpoint )
55
51
. accept (iroh_blobs :: ALPN , blobs . clone ())
56
52
. spawn ();
57
53
58
- // do fun stuff with the blobs protocol!
54
+ let tag = blobs . add_slice (b " Hello world" ). await ? ;
55
+ println! (" We are now serving {}" , blobs . ticket (tag ). await ? );
56
+
57
+ // wait a second
58
+ tokio :: time :: sleep (std :: time :: Duration :: from_secs (1 )). await ;
59
+
60
+ // clean shutdown of router and store
59
61
router . shutdown (). await ? ;
60
- drop (tags_client );
61
62
Ok (())
62
63
}
63
64
```
@@ -81,4 +82,4 @@ at your option.
81
82
82
83
Unless you explicitly state otherwise, any contribution intentionally submitted
83
84
for inclusion in this project by you, as defined in the Apache-2.0 license,
84
- shall be dual licensed as above, without any additional terms or conditions.
85
+ shall be dual licensed as above, without any additional terms or conditions.
0 commit comments