diff --git a/iroh/examples/collection-provide.rs b/iroh/examples/collection-provide.rs index 867b2ac5e3..429288a2f2 100644 --- a/iroh/examples/collection-provide.rs +++ b/iroh/examples/collection-provide.rs @@ -7,6 +7,7 @@ //! run this example from the project root: //! $ cargo run --example collection-provide use iroh::blobs::{format::collection::Collection, util::SetTagOption, BlobFormat}; +use iroh_base::node_addr::AddrInfoOptions; use tracing_subscriber::{prelude::*, EnvFilter}; // set the RUST_LOG env var to one of {debug,info,warn} to see logging info @@ -45,7 +46,11 @@ async fn main() -> anyhow::Result<()> { // tickets wrap all details needed to get a collection let ticket = node .blobs() - .share(hash, BlobFormat::HashSeq, Default::default()) + .share( + hash, + BlobFormat::HashSeq, + AddrInfoOptions::RelayAndAddresses, + ) .await?; // print some info about the node @@ -66,8 +71,8 @@ async fn main() -> anyhow::Result<()> { // print the ticket, containing all the above information println!("\nin another terminal, run:"); println!("\tcargo run --example collection-fetch {}", ticket); - // wait for the node to finish, this will block indefinitely - // stop with SIGINT (ctrl+c) + // block until SIGINT is received (ctrl+c) + tokio::signal::ctrl_c().await?; node.shutdown().await?; Ok(()) } diff --git a/iroh/examples/hello-world-provide.rs b/iroh/examples/hello-world-provide.rs index 8fe0e9c12a..15c21801de 100644 --- a/iroh/examples/hello-world-provide.rs +++ b/iroh/examples/hello-world-provide.rs @@ -3,6 +3,7 @@ //! This is using an in memory database and a random node id. //! run this example from the project root: //! $ cargo run --example hello-world-provide +use iroh_base::node_addr::AddrInfoOptions; use tracing_subscriber::{prelude::*, EnvFilter}; // set the RUST_LOG env var to one of {debug,info,warn} to see logging info @@ -28,7 +29,7 @@ async fn main() -> anyhow::Result<()> { // create a ticket let ticket = node .blobs() - .share(res.hash, res.format, Default::default()) + .share(res.hash, res.format, AddrInfoOptions::RelayAndAddresses) .await?; // print some info about the node @@ -49,8 +50,8 @@ async fn main() -> anyhow::Result<()> { // print the ticket, containing all the above information println!("\nin another terminal, run:"); println!("\t cargo run --example hello-world-fetch {}", ticket); - // wait for the node to finish, this will block indefinitely - // stop with SIGINT (ctrl+c) + // block until SIGINT is received (ctrl+c) + tokio::signal::ctrl_c().await?; node.shutdown().await?; Ok(()) } diff --git a/iroh/examples/rpc.rs b/iroh/examples/rpc.rs index 29e5a4773d..e331cf7d67 100644 --- a/iroh/examples/rpc.rs +++ b/iroh/examples/rpc.rs @@ -2,10 +2,11 @@ //! //! Run this example with //! $ cargo run --features=examples --example rpc -//! Then in another terminal, run any of the normal iroh CLI commands, which you can run from -//! cargo as well: -//! $ cargo run net stats -//! The `net stats` command will reach out over RPC to the node constructed in the example +//! This will print the rpc address of the node. Copy it to use it to connect from the CLI. +//! Then in another terminal, run any of the normal iroh CLI commands supplying the rpc address, +//! which you can run from cargo as well, +//! $ cargo run -- --rpc-addr net node-addr +//! The `net node-addr` command will reach out over RPC to the node constructed in the example. use clap::Parser; use iroh_blobs::store::Store; @@ -38,8 +39,11 @@ where for addr in addrs { println!(" {}", addr); } + let rpc_addr = node.my_rpc_addr().expect("rpc enabled"); + println!("Started node with RPC enabled ({rpc_addr}). Exit with Ctrl+C"); // wait for the node to finish, this will block indefinitely // stop with SIGINT (ctrl+c) + tokio::signal::ctrl_c().await?; node.shutdown().await?; Ok(())