diff --git a/Cargo.lock b/Cargo.lock index 2ff1cd0..55c3cfe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1142,9 +1142,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "171fefbc92fe4a4de27e0698d6a5b392d6a0e333506bc49133760b3bcf948733" +checksum = "6cb093c84e8bd9b188d4c4a8cb6579fc016968d14c99882163cd3ff402a4f155" dependencies = [ "atomic-waker", "bytes", @@ -1529,9 +1529,9 @@ dependencies = [ [[package]] name = "igd-next" -version = "0.17.0" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bac9a3c8278f43b4cd8463380f4a25653ac843e5b177e1d3eaf849cc9ba10d4d" +checksum = "de7238d487a9aff61f81b5ab41c0a841532a115a398b5fa92a2fadd0885e2581" dependencies = [ "attohttpc", "bytes", @@ -1814,6 +1814,7 @@ dependencies = [ "opentelemetry", "opentelemetry-otlp", "opentelemetry_sdk", + "portable-atomic", "postcard", "rand 0.9.4", "serde", diff --git a/Cargo.toml b/Cargo.toml index 08934b5..a8d4918 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -120,7 +120,7 @@ tracing = { version = "0.1.41", default-features = false } n0-future = { version = "0.3", default-features = false } n0-error = { version = "1" } tracing-subscriber = { version = "0.3.23" } -iroh = { version = "1" } -iroh-base = { version = "1" } +iroh = { version = "1", default-features = false } +iroh-base = { version = "1", default-features = false } noq = { version = "1", default-features = false } futures-util = { version = "0.3", features = ["sink"] } diff --git a/irpc-iroh/Cargo.toml b/irpc-iroh/Cargo.toml index 10dd914..c1dc8f9 100644 --- a/irpc-iroh/Cargo.toml +++ b/irpc-iroh/Cargo.toml @@ -20,13 +20,16 @@ serde = { workspace = true } postcard = { workspace = true, features = ["alloc", "use-std"] } n0-error = { workspace = true } n0-future = { workspace = true } -irpc = { version = "0.17.0", path = ".." } +portable-atomic = "1" +irpc = { version = "0.17.0", path = "..", default-features = false, features = ["rpc", "spans", "stream", "derive"] } iroh-base.workspace = true [target.'cfg(all(target_family = "wasm", target_os = "unknown"))'.dependencies] getrandom = { version = "0.3", features = ["wasm_js"] } [dev-dependencies] +# Tests and examples need a crypto provider, which iroh's default features supply. +iroh = { workspace = true, default-features = true } n0-future = { workspace = true } tracing-subscriber = { workspace = true, features = ["fmt"] } irpc-derive = { version = "0.17.0", path = "../irpc-derive" } diff --git a/irpc-iroh/src/lib.rs b/irpc-iroh/src/lib.rs index 7307ab2..41d4520 100644 --- a/irpc-iroh/src/lib.rs +++ b/irpc-iroh/src/lib.rs @@ -1,9 +1,4 @@ -use std::{ - fmt, - future::Future, - io, - sync::{Arc, atomic::AtomicU64}, -}; +use std::{fmt, future::Future, io, sync::Arc}; use iroh::{ EndpointId, @@ -25,6 +20,9 @@ use irpc::{ }; use n0_error::{Result, e}; use n0_future::{TryFutureExt, future::Boxed as BoxFuture}; +// portable-atomic provides AtomicU64 on 32-bit targets (e.g. Xtensa ESP32) that +// lack native 64-bit atomics, same as iroh itself. +use portable_atomic::{AtomicU64, Ordering}; use tracing::{Instrument, debug, error_span, trace, trace_span, warn}; /// Returns a client that connects to a irpc service using an [`iroh::Endpoint`]. @@ -219,9 +217,7 @@ impl IrohProtocol { impl ProtocolHandler for IrohProtocol { async fn accept(&self, connection: Connection) -> Result<(), AcceptError> { let handler = self.handler.clone(); - let request_id = self - .request_id - .fetch_add(1, std::sync::atomic::Ordering::AcqRel); + let request_id = self.request_id.fetch_add(1, Ordering::AcqRel); let fut = handle_connection::(&connection, handler).map_err(AcceptError::from_err); let span = trace_span!("rpc", id = request_id); fut.instrument(span).await @@ -267,9 +263,7 @@ impl ProtocolHandler for Iroh0RttProtocol { async fn on_accepting(&self, accepting: Accepting) -> Result { let zrtt_conn = accepting.into_0rtt(); let handler = self.handler.clone(); - let request_id = self - .request_id - .fetch_add(1, std::sync::atomic::Ordering::AcqRel); + let request_id = self.request_id.fetch_add(1, Ordering::AcqRel); handle_connection::(&zrtt_conn, handler) .map_err(AcceptError::from_err) .instrument(trace_span!("rpc", id = request_id))