diff --git a/src/app/docs/concepts/endpoint-addr/page.mdx b/src/app/docs/concepts/endpoint-addr/page.mdx index 91d4f4eb..602b7489 100644 --- a/src/app/docs/concepts/endpoint-addr/page.mdx +++ b/src/app/docs/concepts/endpoint-addr/page.mdx @@ -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 { @@ -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: diff --git a/src/app/docs/concepts/relay/page.mdx b/src/app/docs/concepts/relay/page.mdx index ead07726..ae1b62ef 100644 --- a/src/app/docs/concepts/relay/page.mdx +++ b/src/app/docs/concepts/relay/page.mdx @@ -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). diff --git a/src/app/docs/concepts/router/page.mdx b/src/app/docs/concepts/router/page.mdx index 5b4ba9cb..b14d7aaf 100644 --- a/src/app/docs/concepts/router/page.mdx +++ b/src/app/docs/concepts/router/page.mdx @@ -10,8 +10,7 @@ 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] @@ -19,8 +18,11 @@ 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. @@ -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?; diff --git a/src/app/docs/examples/gossip-chat/page.mdx b/src/app/docs/examples/gossip-chat/page.mdx index 756ee453..4e70afc1 100644 --- a/src/app/docs/examples/gossip-chat/page.mdx +++ b/src/app/docs/examples/gossip-chat/page.mdx @@ -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. @@ -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 @@ -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()) @@ -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 @@ -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; ... @@ -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 { @@ -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); } } @@ -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}; @@ -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()) @@ -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(), @@ -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 } }; @@ -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}; @@ -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()) @@ -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 } }; @@ -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!"); @@ -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 { @@ -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); } } @@ -736,7 +734,7 @@ fn input_loop(line_tx: tokio::sync::mpsc::Sender) -> Result<()> { #[derive(Debug, Serialize, Deserialize)] struct Ticket { topic: TopicId, - endpoints: Vec, + endpoints: Vec, } impl Ticket {