From e9eb4d9e5c42948c7b3bc58c486fbadce6fffb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cramfox=E2=80=9D?= <“kasey@n0.computer”> Date: Mon, 17 Mar 2025 14:56:24 -0400 Subject: [PATCH 1/4] chore: update to latest iroh --- Cargo.lock | 37 ++-- Cargo.toml | 2 +- examples/custom-protocol.rs | 6 +- examples/discovery-local-network.rs | 266 ++++++++++++++++++++++++++++ examples/local-swarm-discovery.rs | 14 +- src/net_protocol.rs | 6 +- 6 files changed, 303 insertions(+), 28 deletions(-) create mode 100644 examples/discovery-local-network.rs diff --git a/Cargo.lock b/Cargo.lock index b599df9d1..331afee48 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -319,16 +319,14 @@ dependencies = [ ] [[package]] -name = "backoff" -version = "0.4.0" +name = "backon" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62ddb9cb1ec0a098ad4bbf9344d0713fa193ae1a80af55febcff2627b6a00c1" +checksum = "49fef586913a57ff189f25c9b3d034356a5bf6b3fa9a7f067588fe1698ba1f5d" dependencies = [ - "futures-core", - "getrandom 0.2.15", - "instant", - "pin-project-lite", - "rand 0.8.5", + "fastrand", + "gloo-timers", + "tokio", ] [[package]] @@ -843,6 +841,7 @@ checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", "der_derive", + "pem-rfc7468", "zeroize", ] @@ -1404,6 +1403,18 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "governor" version = "0.7.0" @@ -1985,13 +1996,13 @@ checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130" [[package]] name = "iroh" version = "0.33.0" -source = "git+https://github.com/n0-computer/iroh.git?branch=main#493083765083c77fd74c7575236d8b7696b61754" +source = "git+https://github.com/n0-computer/iroh.git?branch=main#ef3645e8b7d5700e309de3cd13b745bbf352f151" dependencies = [ "aead", "anyhow", "atomic-waker", "axum", - "backoff", + "backon", "bytes", "cfg_aliases", "concurrent-queue", @@ -2045,7 +2056,7 @@ dependencies = [ [[package]] name = "iroh-base" version = "0.33.0" -source = "git+https://github.com/n0-computer/iroh.git?branch=main#493083765083c77fd74c7575236d8b7696b61754" +source = "git+https://github.com/n0-computer/iroh.git?branch=main#ef3645e8b7d5700e309de3cd13b745bbf352f151" dependencies = [ "curve25519-dalek", "data-encoding", @@ -2188,7 +2199,7 @@ dependencies = [ [[package]] name = "iroh-net-report" version = "0.33.0" -source = "git+https://github.com/n0-computer/iroh.git?branch=main#493083765083c77fd74c7575236d8b7696b61754" +source = "git+https://github.com/n0-computer/iroh.git?branch=main#ef3645e8b7d5700e309de3cd13b745bbf352f151" dependencies = [ "anyhow", "bytes", @@ -2271,7 +2282,7 @@ dependencies = [ [[package]] name = "iroh-relay" version = "0.33.0" -source = "git+https://github.com/n0-computer/iroh.git?branch=main#493083765083c77fd74c7575236d8b7696b61754" +source = "git+https://github.com/n0-computer/iroh.git?branch=main#ef3645e8b7d5700e309de3cd13b745bbf352f151" dependencies = [ "anyhow", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 8b5e4475c..5be0e82e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,7 +149,7 @@ name = "hello-world-provide" required-features = ["example-iroh"] [[example]] -name = "local-swarm-discovery" +name = "discovery-local-network" required-features = ["example-iroh"] [[example]] diff --git a/examples/custom-protocol.rs b/examples/custom-protocol.rs index 5baef3c9c..2537562fe 100644 --- a/examples/custom-protocol.rs +++ b/examples/custom-protocol.rs @@ -44,7 +44,7 @@ use anyhow::Result; use clap::Parser; use futures_lite::future::Boxed as BoxedFuture; use iroh::{ - endpoint::Connecting, + endpoint::Connection, protocol::{ProtocolHandler, Router}, Endpoint, NodeId, }; @@ -142,12 +142,10 @@ impl ProtocolHandler for BlobSearch { /// /// The returned future runs on a newly spawned tokio task, so it can run as long as /// the connection lasts. - fn accept(&self, connecting: Connecting) -> BoxedFuture> { + fn accept(&self, connection: Connection) -> BoxedFuture> { let this = self.clone(); // We have to return a boxed future from the handler. Box::pin(async move { - // Wait for the connection to be fully established. - let connection = connecting.await?; // We can get the remote's node id from the connection. let node_id = connection.remote_node_id()?; println!("accepted connection from {node_id}"); diff --git a/examples/discovery-local-network.rs b/examples/discovery-local-network.rs new file mode 100644 index 000000000..44ef6e9b7 --- /dev/null +++ b/examples/discovery-local-network.rs @@ -0,0 +1,266 @@ +//! Example that runs and iroh node with local node discovery and no relay server +//! +//! Run the follow command to run the "accept" side, that hosts the content: +//! $ cargo run --example discovery_local_network --features="discovery-local-network" -- accept [FILE_PATH] +//! Wait for output that looks like the following: +//! $ cargo run --example discovery_local_network --features="discovery-local-network" -- connect [NODE_ID] [HASH] -o [FILE_PATH] +//! Run that command on another machine in the same local network, replacing [FILE_PATH] to the path on which you want to save the transferred content. +use std::path::PathBuf; + +use anyhow::ensure; +use clap::{Parser, Subcommand}; +use iroh::{ + discovery::mdns::MdnsDiscovery, protocol::Router, Endpoint, NodeAddr, PublicKey, RelayMode, + SecretKey, +}; +use iroh_blobs::{net_protocol::Blobs, rpc::client::blobs::WrapOption, Hash}; +use tracing_subscriber::{prelude::*, EnvFilter}; + +use self::progress::show_download_progress; + +// set the RUST_LOG env var to one of {debug,info,warn} to see logging info +pub fn setup_logging() { + tracing_subscriber::registry() + .with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr)) + .with(EnvFilter::from_default_env()) + .try_init() + .ok(); +} + +#[derive(Debug, Parser)] +#[command(version, about)] +pub struct Cli { + #[clap(subcommand)] + command: Commands, +} + +#[derive(Subcommand, Clone, Debug)] +pub enum Commands { + /// Launch an iroh node and provide the content at the given path + Accept { + /// path to the file you want to provide + path: PathBuf, + }, + /// Get the node_id and hash string from a node running accept in the local network + /// Download the content from that node. + Connect { + /// Node ID of a node on the local network + node_id: PublicKey, + /// Hash of content you want to download from the node + hash: Hash, + /// save the content to a file + #[clap(long, short)] + out: Option, + }, +} + +#[tokio::main] +async fn main() -> anyhow::Result<()> { + setup_logging(); + let cli = Cli::parse(); + + let key = SecretKey::generate(rand::rngs::OsRng); + let discovery = MdnsDiscovery::new(key.public())?; + + println!("Starting iroh node with mdns discovery..."); + // create a new node + let endpoint = Endpoint::builder() + .secret_key(key) + .discovery(Box::new(discovery)) + .relay_mode(RelayMode::Disabled) + .bind() + .await?; + let builder = Router::builder(endpoint); + let blobs = Blobs::memory().build(builder.endpoint()); + let builder = builder.accept(iroh_blobs::ALPN, blobs.clone()); + let node = builder.spawn().await?; + let blobs_client = blobs.client(); + + match &cli.command { + Commands::Accept { path } => { + if !path.is_file() { + println!("Content must be a file."); + node.shutdown().await?; + return Ok(()); + } + let absolute = path.canonicalize()?; + println!("Adding {} as {}...", path.display(), absolute.display()); + let stream = blobs_client + .add_from_path( + absolute, + true, + iroh_blobs::util::SetTagOption::Auto, + WrapOption::NoWrap, + ) + .await?; + let outcome = stream.finish().await?; + println!("To fetch the blob:\n\tcargo run --example discovery_local_network --features=\"discovery-local-network\" -- connect {} {} -o [FILE_PATH]", node.endpoint().node_id(), outcome.hash); + tokio::signal::ctrl_c().await?; + node.shutdown().await?; + std::process::exit(0); + } + Commands::Connect { node_id, hash, out } => { + println!("NodeID: {}", node.endpoint().node_id()); + let mut stream = blobs_client + .download(*hash, NodeAddr::new(*node_id)) + .await?; + show_download_progress(*hash, &mut stream).await?; + if let Some(path) = out { + let absolute = std::env::current_dir()?.join(path); + ensure!(!absolute.is_dir(), "output must not be a directory"); + tracing::info!( + "exporting {hash} to {} -> {}", + path.display(), + absolute.display() + ); + let stream = blobs_client + .export( + *hash, + absolute, + iroh_blobs::store::ExportFormat::Blob, + iroh_blobs::store::ExportMode::Copy, + ) + .await?; + stream.await?; + } + } + } + Ok(()) +} + +mod progress { + use anyhow::{bail, Result}; + use console::style; + use futures_lite::{Stream, StreamExt}; + use indicatif::{ + HumanBytes, HumanDuration, MultiProgress, ProgressBar, ProgressDrawTarget, ProgressState, + ProgressStyle, + }; + use iroh_blobs::{ + get::{db::DownloadProgress, progress::BlobProgress, Stats}, + Hash, + }; + + pub async fn show_download_progress( + hash: Hash, + mut stream: impl Stream> + Unpin, + ) -> Result<()> { + eprintln!("Fetching: {}", hash); + let mp = MultiProgress::new(); + mp.set_draw_target(ProgressDrawTarget::stderr()); + let op = mp.add(make_overall_progress()); + let ip = mp.add(make_individual_progress()); + op.set_message(format!("{} Connecting ...\n", style("[1/3]").bold().dim())); + let mut seq = false; + while let Some(x) = stream.next().await { + match x? { + DownloadProgress::InitialState(state) => { + if state.connected { + op.set_message(format!("{} Requesting ...\n", style("[2/3]").bold().dim())); + } + if let Some(count) = state.root.child_count { + op.set_message(format!( + "{} Downloading {} blob(s)\n", + style("[3/3]").bold().dim(), + count + 1, + )); + op.set_length(count + 1); + op.reset(); + op.set_position(state.current.map(u64::from).unwrap_or(0)); + seq = true; + } + if let Some(blob) = state.get_current() { + if let Some(size) = blob.size { + ip.set_length(size.value()); + ip.reset(); + match blob.progress { + BlobProgress::Pending => {} + BlobProgress::Progressing(offset) => ip.set_position(offset), + BlobProgress::Done => ip.finish_and_clear(), + } + if !seq { + op.finish_and_clear(); + } + } + } + } + DownloadProgress::FoundLocal { .. } => {} + DownloadProgress::Connected => { + op.set_message(format!("{} Requesting ...\n", style("[2/3]").bold().dim())); + } + DownloadProgress::FoundHashSeq { children, .. } => { + op.set_message(format!( + "{} Downloading {} blob(s)\n", + style("[3/3]").bold().dim(), + children + 1, + )); + op.set_length(children + 1); + op.reset(); + seq = true; + } + DownloadProgress::Found { size, child, .. } => { + if seq { + op.set_position(child.into()); + } else { + op.finish_and_clear(); + } + ip.set_length(size); + ip.reset(); + } + DownloadProgress::Progress { offset, .. } => { + ip.set_position(offset); + } + DownloadProgress::Done { .. } => { + ip.finish_and_clear(); + } + DownloadProgress::AllDone(Stats { + bytes_read, + elapsed, + .. + }) => { + op.finish_and_clear(); + eprintln!( + "Transferred {} in {}, {}/s", + HumanBytes(bytes_read), + HumanDuration(elapsed), + HumanBytes((bytes_read as f64 / elapsed.as_secs_f64()) as u64) + ); + break; + } + DownloadProgress::Abort(e) => { + bail!("download aborted: {}", e); + } + } + } + Ok(()) + } + fn make_overall_progress() -> ProgressBar { + let pb = ProgressBar::hidden(); + pb.enable_steady_tick(std::time::Duration::from_millis(100)); + pb.set_style( + ProgressStyle::with_template( + "{msg}{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len}", + ) + .unwrap() + .progress_chars("#>-"), + ); + pb + } + + fn make_individual_progress() -> ProgressBar { + let pb = ProgressBar::hidden(); + pb.enable_steady_tick(std::time::Duration::from_millis(100)); + pb.set_style( + ProgressStyle::with_template("{msg}{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})") + .unwrap() + .with_key( + "eta", + |state: &ProgressState, w: &mut dyn std::fmt::Write| { + write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap() + }, + ) + .progress_chars("#>-"), + ); + pb + } +} diff --git a/examples/local-swarm-discovery.rs b/examples/local-swarm-discovery.rs index f91e2f077..1276b7051 100644 --- a/examples/local-swarm-discovery.rs +++ b/examples/local-swarm-discovery.rs @@ -1,17 +1,17 @@ //! Example that runs and iroh node with local node discovery and no relay server //! //! Run the follow command to run the "accept" side, that hosts the content: -//! $ cargo run --example local_swarm_discovery --features="discovery-local-network" -- accept [FILE_PATH] +//! $ cargo run --example discovery-local-network --features="discovery-local-network" -- accept [FILE_PATH] //! Wait for output that looks like the following: -//! $ cargo run --example local_swarm_discovery --features="discovery-local-network" -- connect [NODE_ID] [HASH] -o [FILE_PATH] +//! $ cargo run --example discovery-local-network --features="discovery-local-network" -- connect [NODE_ID] [HASH] -o [FILE_PATH] //! Run that command on another machine in the same local network, replacing [FILE_PATH] to the path on which you want to save the transferred content. use std::path::PathBuf; use anyhow::ensure; use clap::{Parser, Subcommand}; use iroh::{ - discovery::local_swarm_discovery::LocalSwarmDiscovery, protocol::Router, Endpoint, NodeAddr, - PublicKey, RelayMode, SecretKey, + discovery::mdns::MdnsDiscovery, protocol::Router, Endpoint, NodeAddr, PublicKey, RelayMode, + SecretKey, }; use iroh_blobs::{net_protocol::Blobs, rpc::client::blobs::WrapOption, Hash}; use tracing_subscriber::{prelude::*, EnvFilter}; @@ -60,9 +60,9 @@ async fn main() -> anyhow::Result<()> { let cli = Cli::parse(); let key = SecretKey::generate(rand::rngs::OsRng); - let discovery = LocalSwarmDiscovery::new(key.public())?; + let discovery = MdnsDiscovery::new(key.public())?; - println!("Starting iroh node with local node discovery..."); + println!("Starting iroh node with mdns discovery..."); // create a new node let endpoint = Endpoint::builder() .secret_key(key) @@ -94,7 +94,7 @@ async fn main() -> anyhow::Result<()> { ) .await?; let outcome = stream.finish().await?; - println!("To fetch the blob:\n\tcargo run --example local_swarm_discovery --features=\"local-swarm-discovery\" -- connect {} {} -o [FILE_PATH]", node.endpoint().node_id(), outcome.hash); + println!("To fetch the blob:\n\tcargo run --example discovery-local-network --features=\"local-swarm-discovery\" -- connect {} {} -o [FILE_PATH]", node.endpoint().node_id(), outcome.hash); tokio::signal::ctrl_c().await?; node.shutdown().await?; std::process::exit(0); diff --git a/src/net_protocol.rs b/src/net_protocol.rs index c8b0d83b8..9fc8ba7ee 100644 --- a/src/net_protocol.rs +++ b/src/net_protocol.rs @@ -13,7 +13,7 @@ use std::{ use anyhow::{bail, Result}; use futures_lite::future::Boxed as BoxedFuture; use futures_util::future::BoxFuture; -use iroh::{endpoint::Connecting, protocol::ProtocolHandler, Endpoint, NodeAddr}; +use iroh::{endpoint::Connection, protocol::ProtocolHandler, Endpoint, NodeAddr}; use serde::{Deserialize, Serialize}; use tracing::debug; @@ -318,13 +318,13 @@ impl Blobs { } impl ProtocolHandler for Blobs { - fn accept(&self, conn: Connecting) -> BoxedFuture> { + fn accept(&self, conn: Connection) -> BoxedFuture> { let db = self.store().clone(); let events = self.events().clone(); let rt = self.rt().clone(); Box::pin(async move { - crate::provider::handle_connection(conn.await?, db, events, rt).await; + crate::provider::handle_connection(conn, db, events, rt).await; Ok(()) }) } From c4b202a8c193968fe5829ee0de43034c6726af42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cramfox=E2=80=9D?= <“kasey@n0.computer”> Date: Mon, 17 Mar 2025 17:02:27 -0400 Subject: [PATCH 2/4] chore: remove "backoff" deny --- deny.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/deny.toml b/deny.toml index 722e547ba..bfae3e459 100644 --- a/deny.toml +++ b/deny.toml @@ -34,7 +34,6 @@ ignore = [ "RUSTSEC-2024-0370", # unmaintained, no upgrade available "RUSTSEC-2024-0384", # unmaintained, no upgrade available "RUSTSEC-2024-0436", # unmaintained paste - "RUSTSEC-2025-0012", # unmaintained backoff ] [sources] From f82056e37c15fe4402e3537ec27325b3a5508cfa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cramfox=E2=80=9D?= <“kasey@n0.computer”> Date: Mon, 17 Mar 2025 17:05:47 -0400 Subject: [PATCH 3/4] chore: removed the renamed "local-swarm-discovery" example --- examples/local-swarm-discovery.rs | 266 ------------------------------ 1 file changed, 266 deletions(-) delete mode 100644 examples/local-swarm-discovery.rs diff --git a/examples/local-swarm-discovery.rs b/examples/local-swarm-discovery.rs deleted file mode 100644 index 1276b7051..000000000 --- a/examples/local-swarm-discovery.rs +++ /dev/null @@ -1,266 +0,0 @@ -//! Example that runs and iroh node with local node discovery and no relay server -//! -//! Run the follow command to run the "accept" side, that hosts the content: -//! $ cargo run --example discovery-local-network --features="discovery-local-network" -- accept [FILE_PATH] -//! Wait for output that looks like the following: -//! $ cargo run --example discovery-local-network --features="discovery-local-network" -- connect [NODE_ID] [HASH] -o [FILE_PATH] -//! Run that command on another machine in the same local network, replacing [FILE_PATH] to the path on which you want to save the transferred content. -use std::path::PathBuf; - -use anyhow::ensure; -use clap::{Parser, Subcommand}; -use iroh::{ - discovery::mdns::MdnsDiscovery, protocol::Router, Endpoint, NodeAddr, PublicKey, RelayMode, - SecretKey, -}; -use iroh_blobs::{net_protocol::Blobs, rpc::client::blobs::WrapOption, Hash}; -use tracing_subscriber::{prelude::*, EnvFilter}; - -use self::progress::show_download_progress; - -// set the RUST_LOG env var to one of {debug,info,warn} to see logging info -pub fn setup_logging() { - tracing_subscriber::registry() - .with(tracing_subscriber::fmt::layer().with_writer(std::io::stderr)) - .with(EnvFilter::from_default_env()) - .try_init() - .ok(); -} - -#[derive(Debug, Parser)] -#[command(version, about)] -pub struct Cli { - #[clap(subcommand)] - command: Commands, -} - -#[derive(Subcommand, Clone, Debug)] -pub enum Commands { - /// Launch an iroh node and provide the content at the given path - Accept { - /// path to the file you want to provide - path: PathBuf, - }, - /// Get the node_id and hash string from a node running accept in the local network - /// Download the content from that node. - Connect { - /// Node ID of a node on the local network - node_id: PublicKey, - /// Hash of content you want to download from the node - hash: Hash, - /// save the content to a file - #[clap(long, short)] - out: Option, - }, -} - -#[tokio::main] -async fn main() -> anyhow::Result<()> { - setup_logging(); - let cli = Cli::parse(); - - let key = SecretKey::generate(rand::rngs::OsRng); - let discovery = MdnsDiscovery::new(key.public())?; - - println!("Starting iroh node with mdns discovery..."); - // create a new node - let endpoint = Endpoint::builder() - .secret_key(key) - .discovery(Box::new(discovery)) - .relay_mode(RelayMode::Disabled) - .bind() - .await?; - let builder = Router::builder(endpoint); - let blobs = Blobs::memory().build(builder.endpoint()); - let builder = builder.accept(iroh_blobs::ALPN, blobs.clone()); - let node = builder.spawn().await?; - let blobs_client = blobs.client(); - - match &cli.command { - Commands::Accept { path } => { - if !path.is_file() { - println!("Content must be a file."); - node.shutdown().await?; - return Ok(()); - } - let absolute = path.canonicalize()?; - println!("Adding {} as {}...", path.display(), absolute.display()); - let stream = blobs_client - .add_from_path( - absolute, - true, - iroh_blobs::util::SetTagOption::Auto, - WrapOption::NoWrap, - ) - .await?; - let outcome = stream.finish().await?; - println!("To fetch the blob:\n\tcargo run --example discovery-local-network --features=\"local-swarm-discovery\" -- connect {} {} -o [FILE_PATH]", node.endpoint().node_id(), outcome.hash); - tokio::signal::ctrl_c().await?; - node.shutdown().await?; - std::process::exit(0); - } - Commands::Connect { node_id, hash, out } => { - println!("NodeID: {}", node.endpoint().node_id()); - let mut stream = blobs_client - .download(*hash, NodeAddr::new(*node_id)) - .await?; - show_download_progress(*hash, &mut stream).await?; - if let Some(path) = out { - let absolute = std::env::current_dir()?.join(path); - ensure!(!absolute.is_dir(), "output must not be a directory"); - tracing::info!( - "exporting {hash} to {} -> {}", - path.display(), - absolute.display() - ); - let stream = blobs_client - .export( - *hash, - absolute, - iroh_blobs::store::ExportFormat::Blob, - iroh_blobs::store::ExportMode::Copy, - ) - .await?; - stream.await?; - } - } - } - Ok(()) -} - -mod progress { - use anyhow::{bail, Result}; - use console::style; - use futures_lite::{Stream, StreamExt}; - use indicatif::{ - HumanBytes, HumanDuration, MultiProgress, ProgressBar, ProgressDrawTarget, ProgressState, - ProgressStyle, - }; - use iroh_blobs::{ - get::{db::DownloadProgress, progress::BlobProgress, Stats}, - Hash, - }; - - pub async fn show_download_progress( - hash: Hash, - mut stream: impl Stream> + Unpin, - ) -> Result<()> { - eprintln!("Fetching: {}", hash); - let mp = MultiProgress::new(); - mp.set_draw_target(ProgressDrawTarget::stderr()); - let op = mp.add(make_overall_progress()); - let ip = mp.add(make_individual_progress()); - op.set_message(format!("{} Connecting ...\n", style("[1/3]").bold().dim())); - let mut seq = false; - while let Some(x) = stream.next().await { - match x? { - DownloadProgress::InitialState(state) => { - if state.connected { - op.set_message(format!("{} Requesting ...\n", style("[2/3]").bold().dim())); - } - if let Some(count) = state.root.child_count { - op.set_message(format!( - "{} Downloading {} blob(s)\n", - style("[3/3]").bold().dim(), - count + 1, - )); - op.set_length(count + 1); - op.reset(); - op.set_position(state.current.map(u64::from).unwrap_or(0)); - seq = true; - } - if let Some(blob) = state.get_current() { - if let Some(size) = blob.size { - ip.set_length(size.value()); - ip.reset(); - match blob.progress { - BlobProgress::Pending => {} - BlobProgress::Progressing(offset) => ip.set_position(offset), - BlobProgress::Done => ip.finish_and_clear(), - } - if !seq { - op.finish_and_clear(); - } - } - } - } - DownloadProgress::FoundLocal { .. } => {} - DownloadProgress::Connected => { - op.set_message(format!("{} Requesting ...\n", style("[2/3]").bold().dim())); - } - DownloadProgress::FoundHashSeq { children, .. } => { - op.set_message(format!( - "{} Downloading {} blob(s)\n", - style("[3/3]").bold().dim(), - children + 1, - )); - op.set_length(children + 1); - op.reset(); - seq = true; - } - DownloadProgress::Found { size, child, .. } => { - if seq { - op.set_position(child.into()); - } else { - op.finish_and_clear(); - } - ip.set_length(size); - ip.reset(); - } - DownloadProgress::Progress { offset, .. } => { - ip.set_position(offset); - } - DownloadProgress::Done { .. } => { - ip.finish_and_clear(); - } - DownloadProgress::AllDone(Stats { - bytes_read, - elapsed, - .. - }) => { - op.finish_and_clear(); - eprintln!( - "Transferred {} in {}, {}/s", - HumanBytes(bytes_read), - HumanDuration(elapsed), - HumanBytes((bytes_read as f64 / elapsed.as_secs_f64()) as u64) - ); - break; - } - DownloadProgress::Abort(e) => { - bail!("download aborted: {}", e); - } - } - } - Ok(()) - } - fn make_overall_progress() -> ProgressBar { - let pb = ProgressBar::hidden(); - pb.enable_steady_tick(std::time::Duration::from_millis(100)); - pb.set_style( - ProgressStyle::with_template( - "{msg}{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len}", - ) - .unwrap() - .progress_chars("#>-"), - ); - pb - } - - fn make_individual_progress() -> ProgressBar { - let pb = ProgressBar::hidden(); - pb.enable_steady_tick(std::time::Duration::from_millis(100)); - pb.set_style( - ProgressStyle::with_template("{msg}{spinner:.green} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {bytes}/{total_bytes} ({eta})") - .unwrap() - .with_key( - "eta", - |state: &ProgressState, w: &mut dyn std::fmt::Write| { - write!(w, "{:.1}s", state.eta().as_secs_f64()).unwrap() - }, - ) - .progress_chars("#>-"), - ); - pb - } -} From bcdf4fc9fad603ee997db0fc4dc3e0787fce99b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cramfox=E2=80=9D?= <“kasey@n0.computer”> Date: Mon, 17 Mar 2025 19:46:49 -0400 Subject: [PATCH 4/4] chore: upgrade `iroh` and `quic-rpc remove git patches from cargo-deny allow list --- Cargo.toml | 17 ++++++----------- deny.toml | 5 +---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 5be0e82e0..537e3d271 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,10 +40,10 @@ genawaiter = { version = "0.99.1", features = ["futures03"] } hashlink = { version = "0.9.0", optional = true } hex = "0.4.3" indicatif = { version = "0.17.8", optional = true } -iroh-base = { version = "0.33" } +iroh-base = { version = "0.34" } iroh-io = { version = "0.6.0", features = ["stats"] } -iroh-metrics = { version = "0.31", default-features = false } -iroh = "0.33" +iroh-metrics = { version = "0.32", default-features = false } +iroh = "0.34" nested_enum_utils = { version = "0.1.0", optional = true } num_cpus = "1.15.0" oneshot = "0.1.8" @@ -54,8 +54,8 @@ postcard = { version = "1", default-features = false, features = [ "use-std", "experimental-derive", ] } -quic-rpc = { version = "0.18.3", optional = true } -quic-rpc-derive = { version = "0.18", optional = true } +quic-rpc = { version = "0.19", optional = true } +quic-rpc-derive = { version = "0.19", optional = true } rand = "0.8" range-collections = "0.4.0" redb = { version = "2.2.0", optional = true } @@ -80,7 +80,7 @@ tracing-test = "0.2.5" [dev-dependencies] http-body = "1.0" -iroh = { version = "0.33", features = ["test-utils"] } +iroh = { version = "0.34", features = ["test-utils"] } quinn = { package = "iroh-quinn", version = "0.13", features = ["ring"] } futures-buffered = "0.2.4" proptest = "1.0.0" @@ -184,8 +184,3 @@ debug-assertions = false opt-level = 3 panic = 'abort' incremental = false - -[patch.crates-io] -iroh = { git = "https://github.com/n0-computer/iroh.git", branch = "main" } -iroh-base = { git = "https://github.com/n0-computer/iroh.git", branch = "main" } -quic-rpc = { git = "https://github.com/n0-computer/quic-rpc", branch = "main" } diff --git a/deny.toml b/deny.toml index bfae3e459..fd814582d 100644 --- a/deny.toml +++ b/deny.toml @@ -37,7 +37,4 @@ ignore = [ ] [sources] -allow-git = [ - "https://github.com/n0-computer/iroh.git", - "https://github.com/n0-computer/quic-rpc.git" -] +allow-git = []