Skip to content

Commit 377d3e9

Browse files
committed
make readme example work
1 parent 8774252 commit 377d3e9

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Here is a basic example of how to set up `iroh-docs` with `iroh`:
4343

4444
```rust
4545
use iroh::{protocol::Router, Endpoint};
46-
use iroh_blobs::{net_protocol::Blobs, util::local_pool::LocalPool, ALPN as BLOBS_ALPN};
46+
use iroh_blobs::{net_protocol::Blobs, store::mem::MemStore, ALPN as BLOBS_ALPN};
4747
use iroh_docs::{protocol::Docs, ALPN as DOCS_ALPN};
4848
use iroh_gossip::{net::Gossip, ALPN as GOSSIP_ALPN};
4949

@@ -53,23 +53,25 @@ async fn main() -> anyhow::Result<()> {
5353
// we've built at number0
5454
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
5555

56-
// create a router builder, we will add the
57-
// protocols to this builder and then spawn
58-
// the router
59-
let builder = Router::builder(endpoint);
60-
6156
// build the blobs protocol
62-
let blobs = Blobs::memory().build(builder.endpoint());
57+
let blobs = MemStore::default();
6358

6459
// build the gossip protocol
65-
let gossip = Gossip::builder().spawn(builder.endpoint().clone()).await?;
60+
let gossip = Gossip::builder().spawn(endpoint.clone());
6661

6762
// build the docs protocol
68-
let docs = Docs::memory().spawn(&blobs, &gossip).await?;
63+
let docs = Docs::memory()
64+
.spawn(endpoint.clone(), (*blobs).clone(), gossip.clone())
65+
.await?;
66+
67+
// create a router builder, we will add the
68+
// protocols to this builder and then spawn
69+
// the router
70+
let builder = Router::builder(endpoint.clone());
6971

7072
// setup router
71-
let router = builder
72-
.accept(BLOBS_ALPN, blobs)
73+
let _router = builder
74+
.accept(BLOBS_ALPN, Blobs::new(&blobs, endpoint.clone(), None))
7375
.accept(GOSSIP_ALPN, gossip)
7476
.accept(DOCS_ALPN, docs)
7577
.spawn();

examples/setup.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use iroh::{protocol::Router, Endpoint};
2+
use iroh_blobs::{net_protocol::Blobs, store::mem::MemStore, ALPN as BLOBS_ALPN};
3+
use iroh_docs::{protocol::Docs, ALPN as DOCS_ALPN};
4+
use iroh_gossip::{net::Gossip, ALPN as GOSSIP_ALPN};
5+
6+
#[tokio::main]
7+
async fn main() -> anyhow::Result<()> {
8+
// create an iroh endpoint that includes the standard discovery mechanisms
9+
// we've built at number0
10+
let endpoint = Endpoint::builder().discovery_n0().bind().await?;
11+
12+
// build the blobs protocol
13+
let blobs = MemStore::default();
14+
15+
// build the gossip protocol
16+
let gossip = Gossip::builder().spawn(endpoint.clone());
17+
18+
// build the docs protocol
19+
let docs = Docs::memory()
20+
.spawn(endpoint.clone(), (*blobs).clone(), gossip.clone())
21+
.await?;
22+
23+
// create a router builder, we will add the
24+
// protocols to this builder and then spawn
25+
// the router
26+
let builder = Router::builder(endpoint.clone());
27+
28+
// setup router
29+
let _router = builder
30+
.accept(BLOBS_ALPN, Blobs::new(&blobs, endpoint.clone(), None))
31+
.accept(GOSSIP_ALPN, gossip)
32+
.accept(DOCS_ALPN, docs)
33+
.spawn();
34+
35+
// do fun stuff with docs!
36+
Ok(())
37+
}

0 commit comments

Comments
 (0)