Skip to content

Commit 0c1bc97

Browse files
Fix docs,links and update code (#412)
* fix example code * fix links * Update src/app/docs/concepts/router/page.mdx Co-authored-by: Philipp Krüger <[email protected]> * fix space * update gossip chat code * fix spaces --------- Co-authored-by: Philipp Krüger <[email protected]>
1 parent fbd7e12 commit 0c1bc97

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

src/app/docs/concepts/endpoint-addr/page.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Endpoint Addresses
22

3-
Endpoint Addresses or [`EndpointAddrs`](https://docs.rs/iroh/latest/iroh/struct.EndpointAddr.htm) are a common struct you'll interact when working with iroh to tell iroh what & where to dial. In rust they look like this:
3+
Endpoint Addresses or [`EndpointAddrs`](https://docs.rs/iroh/latest/iroh/struct.EndpointAddr.html) are a common struct you'll interact when working with iroh to tell iroh what & where to dial. In rust they look like this:
44

55
```rust
66
pub struct Addr {
@@ -11,7 +11,7 @@ pub struct Addr {
1111

1212
You'll interact with `EndpointAddr`s a fair amount when working with iroh. It's also quite normal to construct addresses manually from, say, endpoint identifiers stored in your application database.
1313

14-
When we call [`connect`](https://docs.rs/iroh/latest/iroh/endpoint/struct.Endpoint.html#method.connect) on an [Endpoint](http://localhost:3000/docs/concepts/endpoint), we need to pass either a `EndpointAddr`, or something that can turn into a `EndpointAddr`. In iroh `Endpoint`s will have different fields populated depending on where they came from, and the discovery services you've configured your endpoint with.
14+
When we call [`connect`](https://docs.rs/iroh/latest/iroh/endpoint/struct.Endpoint.html#method.connect) on an [Endpoint](https://www.iroh.computer/docs/concepts/endpoint), we need to pass either a `EndpointAddr`, or something that can turn into a `EndpointAddr`. In iroh `Endpoint`s will have different fields populated depending on where they came from, and the discovery services you've configured your endpoint with.
1515

1616
### Interaction with discovery
1717
From the above struct, the only _required_ field is the `id`. And because of this, there's an implementation of `From` that can turn `EndpointIDs` directly into EndpointAddrs. _but this will only work if you have a discovery service that can resolve EndpointIDs enabled_. Thankfully, we enable discovery by default:

src/app/docs/concepts/relay/page.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,4 @@ number 0 provides a set of public relays that are free to use, and are configure
106106

107107
## Local Discovery
108108

109-
Relays aren't the only way to find other iroh endpoint. Iroh also supports local [discovery](/docs/concepts/discovery), where endpoints on the same local network can find each other & exchange dialing information without a relay using mDNS. This is useful for local networks, or for bootstrapping a network before a relay is available. For more info on configuring local discovery, see the [local discovery docs](https://docs.rs/iroh/latest/iroh/discovery/local_swarm_discovery/index.html).
109+
Relays aren't the only way to find other iroh endpoint. Iroh also supports local [discovery](/docs/concepts/discovery), where endpoints on the same local network can find each other & exchange dialing information without a relay using mDNS. This is useful for local networks, or for bootstrapping a network before a relay is available. For more info on configuring local discovery, see the [local discovery docs](https://docs.rs/iroh/latest/iroh/discovery/mdns/index.html).

src/app/docs/concepts/router/page.mdx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ We use the term _router_ because it mimics what an HTTP server would do with an
1010
use anyhow::Result;
1111
use iroh::protocol::Router;
1212
use iroh::Endpoint;
13-
use iroh_blobs::net_protocol::Blobs;
14-
use iroh_blobs::util::local_pool::LocalPool;
13+
use iroh_blobs::{store::mem::MemStore, BlobsProtocol};
1514

1615

1716
#[tokio::main]
1817
async fn main() -> Result<()> {
1918
// Build an endpoint, defaulting to the public n0 relay network
2019
let endpoint = Endpoint::bind().await?;
2120

22-
// configure the blobs protocol to run in-memory
23-
let blobs = Blobs::memory().build(&endpoint);
21+
// We initialize an in-memory backing store for iroh-blobs
22+
let store = MemStore::new();
23+
24+
// Then we initialize a struct that can accept blobs requests over iroh connections
25+
let blobs = BlobsProtocol::new(&store, None);
2426

2527
// Build our router and add the blobs protocol,
2628
// identified by its ALPN. Spawn the router to start listening.
@@ -30,7 +32,7 @@ async fn main() -> Result<()> {
3032

3133
// get our own address. At this point we have a running router
3234
// that's ready to accept connections.
33-
let addr = router.endpoint().addr().await?;
35+
let addr = router.endpoint().addr();
3436

3537
// Wait for exit
3638
tokio::signal::ctrl_c().await?;

src/app/docs/examples/gossip-chat/page.mdx

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ async fn main() -> Result<()> {
5454
// identity for your endpoint. If you want to have
5555
// the same identity each time you open the app,
5656
// you would need to store and load it each time.
57-
let secret_key = SecretKey::generate(rand::rngs::OsRng);
57+
let secret_key = SecretKey::generate(&mut rand::rng());
5858

5959
// Create an endpoint.
6060
// By default we turn on our n0 discovery services.
@@ -109,7 +109,7 @@ async fn main() -> Result<()> {
109109
// and add a clone of the endpoint we have built.
110110
// The gossip protocol will use the endpoint to
111111
// make connections.
112-
let gossip = Gossip::builder().spawn(endpoint.clone()).await?;
112+
let gossip = Gossip::builder().spawn(endpoint.clone());
113113

114114
// The Router is how we manage protocols on top
115115
// of the iroh endpoint. It handles all incoming
@@ -141,7 +141,7 @@ async fn main() -> Result<()> {
141141
let endpoint = Endpoint::bind().await?;
142142

143143
println!("> our endpoint id: {}", endpoint.id());
144-
let gossip = Gossip::builder().spawn(endpoint.clone()).await?;
144+
let gossip = Gossip::builder().spawn(endpoint.clone());
145145

146146
let router = Router::builder(endpoint.clone())
147147
.accept(iroh_gossip::ALPN, gossip.clone())
@@ -155,7 +155,7 @@ async fn main() -> Result<()> {
155155
// Since the `endpoint_ids` list is empty, we will
156156
// subscribe to the topic, but not attempt to
157157
// connect to any other endpoint.
158-
let topic = gossip.subscribe(id, endpoint_ids)?;
158+
let topic = gossip.subscribe(id, endpoint_ids).await?;
159159

160160
// `split` splits the topic into the `GossipSender`
161161
// and `GossipReceiver` portions
@@ -270,7 +270,7 @@ Then implement message reception. We are going to use a separate `subscribe_loop
270270
```rust
271271
// at the top of the file add these imports:
272272
use std::collections::HashMap;
273-
use iroh_gossip::net::{Event, GossipEvent, GossipReceiver};
273+
use iroh_gossip::api::{GossipReceiver, Event};
274274
use futures_lite::StreamExt;
275275

276276
...
@@ -283,7 +283,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
283283
// iterate over all events
284284
while let Some(event) = receiver.try_next().await? {
285285
// if the Event is a `GossipEvent::Received`, let's deserialize the message:
286-
if let Event::Gossip(GossipEvent::Received(msg)) = event {
286+
if let Event::Received(msg) = event {
287287
// deserialize the message and match on the
288288
// message type:
289289
match Message::from_bytes(&msg.content)?.body {
@@ -300,7 +300,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
300300
// and print the message
301301
let name = names
302302
.get(&from)
303-
.map_or_else(|| from.fmt_short(), String::to_string);
303+
.map_or_else(|| from.fmt_short().to_string(), String::to_string);
304304
println!("{}: {}", name, text);
305305
}
306306
}
@@ -325,7 +325,8 @@ use futures_lite::StreamExt;
325325
use iroh::protocol::Router;
326326
use iroh::{Endpoint, EndpointId};
327327
use iroh_gossip::{
328-
net::{Event, Gossip, GossipEvent, GossipReceiver},
328+
api::{GossipReceiver, Event},
329+
net::Gossip,
329330
proto::TopicId,
330331
};
331332
use serde::{Deserialize, Serialize};
@@ -335,7 +336,7 @@ async fn main() -> Result<()> {
335336
let endpoint = Endpoint::bind().await?;
336337

337338
println!("> our endpoint id: {}", endpoint.id());
338-
let gossip = Gossip::builder().spawn(endpoint.clone()).await?;
339+
let gossip = Gossip::builder().spawn(endpoint.clone());
339340

340341
let router = Router::builder(endpoint.clone())
341342
.accept(iroh_gossip::ALPN, gossip.clone())
@@ -344,7 +345,7 @@ async fn main() -> Result<()> {
344345
let id = TopicId::from_bytes(rand::random());
345346
let endpoint_ids = vec![];
346347

347-
let (sender, receiver) = gossip.subscribe(id, endpoint_ids)?.split();
348+
let (sender, receiver) = gossip.subscribe(id, endpoint_ids).await?.split();
348349

349350
let message = Message::new(MessageBody::AboutMe {
350351
from: endpoint.id(),
@@ -486,7 +487,7 @@ let ticket = {
486487
// Get our address information, includes our
487488
// `EndpointId`, our `RelayUrl`, and any direct
488489
// addresses.
489-
let me = endpoint.addr().await?;
490+
let me = endpoint.addr();
490491
let endpoints = vec![me];
491492
Ticket { topic: id, endpoints }
492493
};
@@ -535,7 +536,8 @@ use clap::Parser;
535536
use futures_lite::StreamExt;
536537
use iroh::{protocol::Router, Endpoint, EndpointAddr, EndpointId};
537538
use iroh_gossip::{
538-
net::{Event, Gossip, GossipEvent, GossipReceiver},
539+
api::{GossipReceiver, Event},
540+
net::Gossip,
539541
proto::TopicId,
540542
};
541543
use serde::{Deserialize, Serialize};
@@ -591,7 +593,7 @@ async fn main() -> Result<()> {
591593
let endpoint = Endpoint::bind().await?;
592594

593595
println!("> our endpoint id: {}", endpoint.id());
594-
let gossip = Gossip::builder().spawn(endpoint.clone()).await?;
596+
let gossip = Gossip::builder().spawn(endpoint.clone());
595597

596598
let router = Router::builder(endpoint.clone())
597599
.accept(iroh_gossip::ALPN, gossip.clone())
@@ -603,7 +605,7 @@ async fn main() -> Result<()> {
603605
// Get our address information, includes our
604606
// `EndpointId`, our `RelayUrl`, and any direct
605607
// addresses.
606-
let me = endpoint.addr().await?;
608+
let me = endpoint.addr();
607609
let endpoints = vec![me];
608610
Ticket { topic, endpoints }
609611
};
@@ -615,10 +617,6 @@ async fn main() -> Result<()> {
615617
println!("> waiting for endpoints to join us...");
616618
} else {
617619
println!("> trying to connect to {} endpoints...", endpoints.len());
618-
// add the peer addrs from the ticket to our endpoint's addressbook so that they can be dialed
619-
for endpoint_addr in endpoints.into_iter() {
620-
endpoint.add_node_addr(endpoint_addr)?;
621-
}
622620
};
623621
let (sender, receiver) = gossip.subscribe_and_join(topic, endpoint_ids).await?.split();
624622
println!("> connected!");
@@ -696,7 +694,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
696694
// iterate over all events
697695
while let Some(event) = receiver.try_next().await? {
698696
// if the Event is a `GossipEvent::Received`, let's deserialize the message:
699-
if let Event::Gossip(GossipEvent::Received(msg)) = event {
697+
if let Event::Received(msg) = event {
700698
// deserialize the message and match on the
701699
// message type:
702700
match Message::from_bytes(&msg.content)?.body {
@@ -713,7 +711,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
713711
// and print the message
714712
let name = names
715713
.get(&from)
716-
.map_or_else(|| from.fmt_short(), String::to_string);
714+
.map_or_else(|| from.fmt_short().to_string(), String::to_string);
717715
println!("{}: {}", name, text);
718716
}
719717
}
@@ -736,7 +734,7 @@ fn input_loop(line_tx: tokio::sync::mpsc::Sender<String>) -> Result<()> {
736734
#[derive(Debug, Serialize, Deserialize)]
737735
struct Ticket {
738736
topic: TopicId,
739-
endpoints: Vec<Addr>,
737+
endpoints: Vec<EndpointAddr>,
740738
}
741739

742740
impl Ticket {

0 commit comments

Comments
 (0)