Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/docs/concepts/endpoint-addr/page.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Endpoint Addresses

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:
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:

```rust
pub struct Addr {
Expand All @@ -11,7 +11,7 @@ pub struct Addr {

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.

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.
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.

### Interaction with discovery
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:
Expand Down
2 changes: 1 addition & 1 deletion src/app/docs/concepts/relay/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ number 0 provides a set of public relays that are free to use, and are configure

## Local Discovery

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).
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).
12 changes: 7 additions & 5 deletions src/app/docs/concepts/router/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ We use the term _router_ because it mimics what an HTTP server would do with an
use anyhow::Result;
use iroh::protocol::Router;
use iroh::Endpoint;
use iroh_blobs::net_protocol::Blobs;
use iroh_blobs::util::local_pool::LocalPool;
use iroh_blobs::{store::mem::MemStore, BlobsProtocol};


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

// configure the blobs protocol to run in-memory
let blobs = Blobs::memory().build(&endpoint);
// We initialize an in-memory backing store for iroh-blobs
let store = MemStore::new();

// Then we initialize a struct that can accept blobs requests over iroh connections
let blobs = BlobsProtocol::new(&store, None);

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

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

// Wait for exit
tokio::signal::ctrl_c().await?;
Expand Down
40 changes: 19 additions & 21 deletions src/app/docs/examples/gossip-chat/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> Result<()> {
// identity for your endpoint. If you want to have
// the same identity each time you open the app,
// you would need to store and load it each time.
let secret_key = SecretKey::generate(rand::rngs::OsRng);
let secret_key = SecretKey::generate(&mut rand::rng());

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

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

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

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

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

...
Expand All @@ -283,7 +283,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
// iterate over all events
while let Some(event) = receiver.try_next().await? {
// if the Event is a `GossipEvent::Received`, let's deserialize the message:
if let Event::Gossip(GossipEvent::Received(msg)) = event {
if let Event::Received(msg) = event {
// deserialize the message and match on the
// message type:
match Message::from_bytes(&msg.content)?.body {
Expand All @@ -300,7 +300,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
// and print the message
let name = names
.get(&from)
.map_or_else(|| from.fmt_short(), String::to_string);
.map_or_else(|| from.fmt_short().to_string(), String::to_string);
println!("{}: {}", name, text);
}
}
Expand All @@ -325,7 +325,8 @@ use futures_lite::StreamExt;
use iroh::protocol::Router;
use iroh::{Endpoint, EndpointId};
use iroh_gossip::{
net::{Event, Gossip, GossipEvent, GossipReceiver},
api::{GossipReceiver, Event},
net::Gossip,
proto::TopicId,
};
use serde::{Deserialize, Serialize};
Expand All @@ -335,7 +336,7 @@ async fn main() -> Result<()> {
let endpoint = Endpoint::bind().await?;

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

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

let (sender, receiver) = gossip.subscribe(id, endpoint_ids)?.split();
let (sender, receiver) = gossip.subscribe(id, endpoint_ids).await?.split();

let message = Message::new(MessageBody::AboutMe {
from: endpoint.id(),
Expand Down Expand Up @@ -486,7 +487,7 @@ let ticket = {
// Get our address information, includes our
// `EndpointId`, our `RelayUrl`, and any direct
// addresses.
let me = endpoint.addr().await?;
let me = endpoint.addr();
let endpoints = vec![me];
Ticket { topic: id, endpoints }
};
Expand Down Expand Up @@ -535,7 +536,8 @@ use clap::Parser;
use futures_lite::StreamExt;
use iroh::{protocol::Router, Endpoint, EndpointAddr, EndpointId};
use iroh_gossip::{
net::{Event, Gossip, GossipEvent, GossipReceiver},
api::{GossipReceiver, Event},
net::Gossip,
proto::TopicId,
};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -591,7 +593,7 @@ async fn main() -> Result<()> {
let endpoint = Endpoint::bind().await?;

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

let router = Router::builder(endpoint.clone())
.accept(iroh_gossip::ALPN, gossip.clone())
Expand All @@ -603,7 +605,7 @@ async fn main() -> Result<()> {
// Get our address information, includes our
// `EndpointId`, our `RelayUrl`, and any direct
// addresses.
let me = endpoint.addr().await?;
let me = endpoint.addr();
let endpoints = vec![me];
Ticket { topic, endpoints }
};
Expand All @@ -615,10 +617,6 @@ async fn main() -> Result<()> {
println!("> waiting for endpoints to join us...");
} else {
println!("> trying to connect to {} endpoints...", endpoints.len());
// add the peer addrs from the ticket to our endpoint's addressbook so that they can be dialed
for endpoint_addr in endpoints.into_iter() {
endpoint.add_node_addr(endpoint_addr)?;
}
};
let (sender, receiver) = gossip.subscribe_and_join(topic, endpoint_ids).await?.split();
println!("> connected!");
Expand Down Expand Up @@ -696,7 +694,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
// iterate over all events
while let Some(event) = receiver.try_next().await? {
// if the Event is a `GossipEvent::Received`, let's deserialize the message:
if let Event::Gossip(GossipEvent::Received(msg)) = event {
if let Event::Received(msg) = event {
// deserialize the message and match on the
// message type:
match Message::from_bytes(&msg.content)?.body {
Expand All @@ -713,7 +711,7 @@ async fn subscribe_loop(mut receiver: GossipReceiver) -> Result<()> {
// and print the message
let name = names
.get(&from)
.map_or_else(|| from.fmt_short(), String::to_string);
.map_or_else(|| from.fmt_short().to_string(), String::to_string);
println!("{}: {}", name, text);
}
}
Expand All @@ -736,7 +734,7 @@ fn input_loop(line_tx: tokio::sync::mpsc::Sender<String>) -> Result<()> {
#[derive(Debug, Serialize, Deserialize)]
struct Ticket {
topic: TopicId,
endpoints: Vec<Addr>,
endpoints: Vec<EndpointAddr>,
}

impl Ticket {
Expand Down
Loading