From c6cf7fec6913aa590622aeea16709fce6e9c99a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Tue, 24 Sep 2024 16:00:02 +0100 Subject: [PATCH 1/8] fix(ci): address cargo-deny advisories (#5596) ## Description by updating: - `bytes` to 1.7.1, `1.6.0` was [yanked](https://crates.io/crates/bytes/1.6.0) - `quinn-proto` to 0.11.8 to address [RUSTSEC-2024-0373](https://rustsec.org/advisories/RUSTSEC-2024-0373.html) - thirtyfour-macros to 0.1.11 to remove `proc-macro-error` dependency and address [RUSTSEC-2024-0370](https://rustsec.org/advisories/RUSTSEC-2024-0370.html) --- Cargo.lock | 73 ++++++++++++------------------- examples/autonatv2/Dockerfile | 2 +- hole-punching-tests/Dockerfile | 2 +- interop-tests/Dockerfile.chromium | 2 +- interop-tests/Dockerfile.native | 2 +- misc/server/Dockerfile | 2 +- protocols/perf/Dockerfile | 2 +- 7 files changed, 33 insertions(+), 52 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b3d1cd0d76d..4c3498a0635 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -833,9 +833,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" +checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" dependencies = [ "serde", ] @@ -4584,30 +4584,6 @@ dependencies = [ "elliptic-curve", ] -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn 1.0.109", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - [[package]] name = "proc-macro2" version = "1.0.85" @@ -4724,7 +4700,7 @@ dependencies = [ "pin-project-lite", "quinn-proto", "quinn-udp", - "rustc-hash", + "rustc-hash 1.1.0", "rustls 0.23.11", "thiserror", "tokio", @@ -4733,14 +4709,14 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.2" +version = "0.11.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e974563a4b1c2206bbc61191ca4da9c22e4308b4c455e8906751cc7828393f08" +checksum = "fadfaed2cd7f389d0161bb73eeb07b7b78f8691047a6f3e73caaeae55310a4a6" dependencies = [ "bytes", "rand 0.8.5", "ring 0.17.8", - "rustc-hash", + "rustc-hash 2.0.0", "rustls 0.23.11", "slab", "thiserror", @@ -5206,6 +5182,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.4.0" @@ -5471,18 +5453,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.203" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -5513,9 +5495,9 @@ dependencies = [ [[package]] name = "serde_repr" -version = "0.1.18" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b2e6b945e9d3df726b65d6ee24060aff8e3533d431f677a9695db04eff9dfdb" +checksum = "6c64451ba24fc7a6a2d60fc75dd9c83c90903b19028d4eff35e88fc1e86564e9" dependencies = [ "proc-macro2", "quote", @@ -6002,30 +5984,29 @@ dependencies = [ [[package]] name = "thirtyfour-macros" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cae91d1c7c61ec65817f1064954640ee350a50ae6548ff9a1bdd2489d6ffbb0" +checksum = "b72d056365e368fc57a56d0cec9e41b02fb4a3474a61c8735262b1cfebe67425" dependencies = [ - "proc-macro-error", "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.66", ] [[package]] name = "thiserror" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" +checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.61" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" +checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", @@ -6576,9 +6557,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.0" +version = "2.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" dependencies = [ "form_urlencoded", "idna 0.5.0", diff --git a/examples/autonatv2/Dockerfile b/examples/autonatv2/Dockerfile index 5a523649d80..6bc92e4d11b 100644 --- a/examples/autonatv2/Dockerfile +++ b/examples/autonatv2/Dockerfile @@ -1,4 +1,4 @@ -FROM rust:1.75-alpine as builder +FROM rust:1.81-alpine as builder RUN apk add musl-dev diff --git a/hole-punching-tests/Dockerfile b/hole-punching-tests/Dockerfile index af00ef2272f..403cc301fc6 100644 --- a/hole-punching-tests/Dockerfile +++ b/hole-punching-tests/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.75.0 as builder +FROM rust:1.81.0 as builder # Run with access to the target cache to speed up builds WORKDIR /workspace diff --git a/interop-tests/Dockerfile.chromium b/interop-tests/Dockerfile.chromium index a6b0fc89e82..86edbc5b9d2 100644 --- a/interop-tests/Dockerfile.chromium +++ b/interop-tests/Dockerfile.chromium @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.75.0 as chef +FROM rust:1.81 as chef RUN rustup target add wasm32-unknown-unknown RUN wget -q -O- https://github.com/rustwasm/wasm-pack/releases/download/v0.12.1/wasm-pack-v0.12.1-x86_64-unknown-linux-musl.tar.gz | tar -zx -C /usr/local/bin --strip-components 1 --wildcards "wasm-pack-*/wasm-pack" RUN wget -q -O- https://github.com/WebAssembly/binaryen/releases/download/version_115/binaryen-version_115-x86_64-linux.tar.gz | tar -zx -C /usr/local/bin --strip-components 2 --wildcards "binaryen-version_*/bin/wasm-opt" diff --git a/interop-tests/Dockerfile.native b/interop-tests/Dockerfile.native index b122ac72991..499c73437fc 100644 --- a/interop-tests/Dockerfile.native +++ b/interop-tests/Dockerfile.native @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM lukemathwalker/cargo-chef:0.1.62-rust-1.75.0 as chef +FROM lukemathwalker/cargo-chef:0.1.67-rust-bullseye as chef WORKDIR /app FROM chef AS planner diff --git a/misc/server/Dockerfile b/misc/server/Dockerfile index 1583fba6bef..24ae2b9fd99 100644 --- a/misc/server/Dockerfile +++ b/misc/server/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.75.0 as chef +FROM rust:1.81.0 as chef RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin RUN cargo install --locked --root /usr/local libp2p-lookup --version 0.6.4 WORKDIR /app diff --git a/protocols/perf/Dockerfile b/protocols/perf/Dockerfile index 1bd846cc228..f68ea6ef211 100644 --- a/protocols/perf/Dockerfile +++ b/protocols/perf/Dockerfile @@ -1,5 +1,5 @@ # syntax=docker/dockerfile:1.5-labs -FROM rust:1.75.0 as builder +FROM rust:1.81.0 as builder # Run with access to the target cache to speed up builds WORKDIR /workspace From f3e0e554821ca9233f202e80d1bae9e27cfb3ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Wed, 25 Sep 2024 10:36:01 +0100 Subject: [PATCH 2/8] chore(ci): address beta clippy lints (#5606) Co-authored-by: Darius Clark --- misc/allow-block-list/src/lib.rs | 2 ++ misc/connection-limits/src/lib.rs | 4 ++++ misc/memory-connection-limits/src/lib.rs | 2 ++ misc/memory-connection-limits/tests/util/mod.rs | 2 ++ misc/quick-protobuf-codec/src/lib.rs | 1 + .../autonat/src/v2/client/handler/dial_back.rs | 2 ++ .../autonat/src/v2/client/handler/dial_request.rs | 2 ++ protocols/autonat/src/v2/server/behaviour.rs | 2 ++ .../autonat/src/v2/server/handler/dial_request.rs | 2 ++ protocols/dcutr/src/behaviour.rs | 2 ++ protocols/dcutr/src/handler/relayed.rs | 8 ++++++++ protocols/gossipsub/src/handler.rs | 4 ++++ protocols/gossipsub/src/transform.rs | 1 + protocols/kad/src/handler.rs | 2 ++ protocols/perf/src/client/handler.rs | 4 ++++ protocols/perf/src/server/handler.rs | 8 ++++++++ protocols/ping/src/handler.rs | 2 ++ protocols/relay/src/behaviour.rs | 2 ++ protocols/relay/src/behaviour/handler.rs | 2 ++ protocols/relay/src/priv_client.rs | 2 ++ protocols/relay/src/priv_client/handler.rs | 6 ++++++ protocols/request-response/src/cbor.rs | 2 ++ protocols/request-response/src/handler.rs | 6 ++++++ protocols/stream/src/handler.rs | 4 ++++ swarm/src/behaviour/toggle.rs | 4 ++++ swarm/src/connection.rs | 10 ++++++++++ swarm/src/connection/pool/task.rs | 4 ++++ swarm/src/dummy.rs | 14 ++++++++++++++ swarm/src/handler/pending.rs | 8 ++++++++ swarm/src/upgrade.rs | 1 + swarm/tests/swarm_derive.rs | 2 ++ transports/quic/src/hole_punching.rs | 2 ++ 32 files changed, 119 insertions(+) diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index 7646638a651..56de29d1985 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -271,6 +271,8 @@ where _: ConnectionId, event: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index b02e52f25a1..05a9b639f26 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -355,6 +355,8 @@ impl NetworkBehaviour for Behaviour { _: ConnectionId, event: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } @@ -586,6 +588,8 @@ mod tests { _connection_id: ConnectionId, event: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } diff --git a/misc/memory-connection-limits/src/lib.rs b/misc/memory-connection-limits/src/lib.rs index 7b5803a61aa..757ff770487 100644 --- a/misc/memory-connection-limits/src/lib.rs +++ b/misc/memory-connection-limits/src/lib.rs @@ -190,6 +190,8 @@ impl NetworkBehaviour for Behaviour { _: ConnectionId, event: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } diff --git a/misc/memory-connection-limits/tests/util/mod.rs b/misc/memory-connection-limits/tests/util/mod.rs index d18aa78fd22..01e8cd9f655 100644 --- a/misc/memory-connection-limits/tests/util/mod.rs +++ b/misc/memory-connection-limits/tests/util/mod.rs @@ -116,6 +116,8 @@ impl NetworkBehaviour _: ConnectionId, event: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } diff --git a/misc/quick-protobuf-codec/src/lib.rs b/misc/quick-protobuf-codec/src/lib.rs index 166ee82ff08..32cee8eccac 100644 --- a/misc/quick-protobuf-codec/src/lib.rs +++ b/misc/quick-protobuf-codec/src/lib.rs @@ -12,6 +12,7 @@ mod generated; pub use generated::test as proto; /// [`Codec`] implements [`Encoder`] and [`Decoder`], uses [`unsigned_varint`] +/// /// to prefix messages with their length and uses [`quick_protobuf`] and a provided /// `struct` implementing [`MessageRead`] and [`MessageWrite`] to do the encoding. pub struct Codec { diff --git a/protocols/autonat/src/v2/client/handler/dial_back.rs b/protocols/autonat/src/v2/client/handler/dial_back.rs index b94580e69ba..98a41a82504 100644 --- a/protocols/autonat/src/v2/client/handler/dial_back.rs +++ b/protocols/autonat/src/v2/client/handler/dial_back.rs @@ -83,6 +83,8 @@ impl ConnectionHandler for Handler { tracing::warn!("Dial back request dropped, too many requests in flight"); } } + // TODO: remove when Rust 1.82 is MSRVprotocols/autonat/src/v2/client/handler/dial_back.rs + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(ListenUpgradeError { error, .. }) => { void::unreachable(error); } diff --git a/protocols/autonat/src/v2/client/handler/dial_request.rs b/protocols/autonat/src/v2/client/handler/dial_request.rs index 9d2df8ee6b4..85ad176ec30 100644 --- a/protocols/autonat/src/v2/client/handler/dial_request.rs +++ b/protocols/autonat/src/v2/client/handler/dial_request.rs @@ -216,6 +216,8 @@ async fn start_stream_handle( .map_err(|e| match e { StreamUpgradeError::NegotiationFailed => Error::UnsupportedProtocol, StreamUpgradeError::Timeout => Error::Io(io::ErrorKind::TimedOut.into()), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(v) => void::unreachable(v), StreamUpgradeError::Io(e) => Error::Io(e), })?; diff --git a/protocols/autonat/src/v2/server/behaviour.rs b/protocols/autonat/src/v2/server/behaviour.rs index 5f7b21d165b..9264c728fe4 100644 --- a/protocols/autonat/src/v2/server/behaviour.rs +++ b/protocols/autonat/src/v2/server/behaviour.rs @@ -112,6 +112,8 @@ where Either::Left(Either::Left(Err(e))) => { tracing::debug!("dial back error: {e:?}"); } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Left(Either::Right(v)) => void::unreachable(v), Either::Right(Either::Left(cmd)) => { let addr = cmd.addr.clone(); diff --git a/protocols/autonat/src/v2/server/handler/dial_request.rs b/protocols/autonat/src/v2/server/handler/dial_request.rs index 9a3729d4ccf..14ddb153416 100644 --- a/protocols/autonat/src/v2/server/handler/dial_request.rs +++ b/protocols/autonat/src/v2/server/handler/dial_request.rs @@ -143,6 +143,8 @@ where ); } } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(ListenUpgradeError { error, .. }) => { tracing::debug!("inbound request failed: {:?}", error); } diff --git a/protocols/dcutr/src/behaviour.rs b/protocols/dcutr/src/behaviour.rs index 574c96205fa..babd56bd28e 100644 --- a/protocols/dcutr/src/behaviour.rs +++ b/protocols/dcutr/src/behaviour.rs @@ -314,6 +314,8 @@ impl NetworkBehaviour for Behaviour { .or_default() += 1; self.queued_events.push_back(ToSwarm::Dial { opts }); } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Right(never) => void::unreachable(never), }; } diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index eba58f89313..72af9fec264 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -115,6 +115,8 @@ impl Handler { self.attempts += 1; } // A connection listener denies all incoming substreams, thus none can ever be fully negotiated. + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] future::Either::Right(output) => void::unreachable(output), } } @@ -153,6 +155,8 @@ impl Handler { ::InboundProtocol, >, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(error.into_inner()); } @@ -164,6 +168,8 @@ impl Handler { >, ) { let error = match error { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(v) => void::unreachable(v), StreamUpgradeError::NegotiationFailed => outbound::Error::Unsupported, StreamUpgradeError::Io(e) => outbound::Error::Io(e), @@ -298,6 +304,8 @@ impl ConnectionHandler for Handler { ConnectionEvent::FullyNegotiatedOutbound(fully_negotiated_outbound) => { self.on_fully_negotiated_outbound(fully_negotiated_outbound) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => { self.on_listen_upgrade_error(listen_upgrade_error) } diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 88def13a521..8e3b3a8b022 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -493,6 +493,8 @@ impl ConnectionHandler for Handler { .. }) => match protocol { Either::Left(protocol) => handler.on_fully_negotiated_inbound(protocol), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Right(v) => void::unreachable(v), }, ConnectionEvent::FullyNegotiatedOutbound(fully_negotiated_outbound) => { @@ -504,6 +506,8 @@ impl ConnectionHandler for Handler { }) => { tracing::debug!("Dial upgrade error: Protocol negotiation timeout"); } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::DialUpgradeError(DialUpgradeError { error: StreamUpgradeError::Apply(e), .. diff --git a/protocols/gossipsub/src/transform.rs b/protocols/gossipsub/src/transform.rs index 6f57d9fc46b..4831f9781b0 100644 --- a/protocols/gossipsub/src/transform.rs +++ b/protocols/gossipsub/src/transform.rs @@ -28,6 +28,7 @@ use crate::{Message, RawMessage, TopicHash}; /// A general trait of transforming a [`RawMessage`] into a [`Message`]. The +/// /// [`RawMessage`] is obtained from the wire and the [`Message`] is used to /// calculate the [`crate::MessageId`] of the message and is what is sent to the application. /// diff --git a/protocols/kad/src/handler.rs b/protocols/kad/src/handler.rs index 5e7c2e21b8b..17c483da709 100644 --- a/protocols/kad/src/handler.rs +++ b/protocols/kad/src/handler.rs @@ -501,6 +501,8 @@ impl Handler { // is a `Void`. let protocol = match protocol { future::Either::Left(p) => p, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] future::Either::Right(p) => void::unreachable(p), }; diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index 2a2c5499fc2..55fafad7fcc 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -112,6 +112,8 @@ impl ConnectionHandler for Handler { >, ) { match event { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { protocol, .. }) => void::unreachable(protocol), @@ -144,6 +146,8 @@ impl ConnectionHandler for Handler { result: Err(error.into()), })); } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { void::unreachable(error) } diff --git a/protocols/perf/src/server/handler.rs b/protocols/perf/src/server/handler.rs index ddfe8f881e5..4cb535a452c 100644 --- a/protocols/perf/src/server/handler.rs +++ b/protocols/perf/src/server/handler.rs @@ -73,6 +73,8 @@ impl ConnectionHandler for Handler { } fn on_behaviour_event(&mut self, v: Self::FromBehaviour) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(v) } @@ -98,16 +100,22 @@ impl ConnectionHandler for Handler { tracing::warn!("Dropping inbound stream because we are at capacity"); } } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { info, .. }) => { void::unreachable(info) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::DialUpgradeError(DialUpgradeError { info, .. }) => { void::unreachable(info) } ConnectionEvent::AddressChange(_) | ConnectionEvent::LocalProtocolsChange(_) | ConnectionEvent::RemoteProtocolsChange(_) => {} + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { void::unreachable(error) } diff --git a/protocols/ping/src/handler.rs b/protocols/ping/src/handler.rs index 2816cdc4048..7b36b2d4b3d 100644 --- a/protocols/ping/src/handler.rs +++ b/protocols/ping/src/handler.rs @@ -210,6 +210,8 @@ impl Handler { "ping protocol negotiation timed out", )), }, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(e) => void::unreachable(e), StreamUpgradeError::Io(e) => Failure::Other { error: Box::new(e) }, }; diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index 463febf9f2f..46419ae64e3 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -366,6 +366,8 @@ impl NetworkBehaviour for Behaviour { ) { let event = match event { Either::Left(e) => e, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Right(v) => void::unreachable(v), }; diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 92557287099..23e90f4b3f8 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -449,6 +449,8 @@ impl Handler { StreamUpgradeError::Timeout => outbound_stop::Error::Io(io::ErrorKind::TimedOut.into()), StreamUpgradeError::NegotiationFailed => outbound_stop::Error::Unsupported, StreamUpgradeError::Io(e) => outbound_stop::Error::Io(e), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(v) => void::unreachable(v), }; diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index f8d1d9c9eb2..8bbc813ec4c 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -236,6 +236,8 @@ impl NetworkBehaviour for Behaviour { ) { let handler_event = match handler_event { Either::Left(e) => e, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Right(v) => void::unreachable(v), }; diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 662d63cc742..05fdd5673ae 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -445,6 +445,8 @@ impl ConnectionHandler for Handler { let _ = next.send(Ok(ev.protocol)); } } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(ev) => void::unreachable(ev.error), ConnectionEvent::DialUpgradeError(ev) => { if let Some(next) = self.pending_streams.pop_front() { @@ -583,6 +585,8 @@ fn into_reserve_error(e: StreamUpgradeError) -> outbound_hop::ReserveError StreamUpgradeError::Timeout => { outbound_hop::ReserveError::Io(io::ErrorKind::TimedOut.into()) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(never) => void::unreachable(never), StreamUpgradeError::NegotiationFailed => outbound_hop::ReserveError::Unsupported, StreamUpgradeError::Io(e) => outbound_hop::ReserveError::Io(e), @@ -594,6 +598,8 @@ fn into_connect_error(e: StreamUpgradeError) -> outbound_hop::ConnectError StreamUpgradeError::Timeout => { outbound_hop::ConnectError::Io(io::ErrorKind::TimedOut.into()) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(never) => void::unreachable(never), StreamUpgradeError::NegotiationFailed => outbound_hop::ConnectError::Unsupported, StreamUpgradeError::Io(e) => outbound_hop::ConnectError::Io(e), diff --git a/protocols/request-response/src/cbor.rs b/protocols/request-response/src/cbor.rs index 44d82be2630..a27d069e758 100644 --- a/protocols/request-response/src/cbor.rs +++ b/protocols/request-response/src/cbor.rs @@ -143,6 +143,8 @@ mod codec { fn decode_into_io_error(err: cbor4ii::serde::DecodeError) -> io::Error { match err { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] cbor4ii::serde::DecodeError::Core(DecodeError::Read(e)) => { io::Error::new(io::ErrorKind::Other, e) } diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler.rs index f0467593f85..0591b37dc30 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler.rs @@ -240,6 +240,8 @@ where self.pending_events .push_back(Event::OutboundUnsupportedProtocols(message.request_id)); } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Apply(e) => void::unreachable(e), StreamUpgradeError::Io(e) => { self.pending_events.push_back(Event::OutboundStreamFailed { @@ -256,6 +258,8 @@ where ::InboundProtocol, >, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(error) } } @@ -484,6 +488,8 @@ where ConnectionEvent::DialUpgradeError(dial_upgrade_error) => { self.on_dial_upgrade_error(dial_upgrade_error) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::ListenUpgradeError(listen_upgrade_error) => { self.on_listen_upgrade_error(listen_upgrade_error) } diff --git a/protocols/stream/src/handler.rs b/protocols/stream/src/handler.rs index f63b93c1761..bf80e30c3c6 100644 --- a/protocols/stream/src/handler.rs +++ b/protocols/stream/src/handler.rs @@ -96,6 +96,8 @@ impl ConnectionHandler for Handler { } fn on_behaviour_event(&mut self, event: Self::FromBehaviour) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } @@ -143,6 +145,8 @@ impl ConnectionHandler for Handler { swarm::StreamUpgradeError::Timeout => { OpenStreamError::Io(io::Error::from(io::ErrorKind::TimedOut)) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] swarm::StreamUpgradeError::Apply(v) => void::unreachable(v), swarm::StreamUpgradeError::NegotiationFailed => { OpenStreamError::UnsupportedProtocol(p) diff --git a/swarm/src/behaviour/toggle.rs b/swarm/src/behaviour/toggle.rs index 398c919ae86..5d72534c91e 100644 --- a/swarm/src/behaviour/toggle.rs +++ b/swarm/src/behaviour/toggle.rs @@ -210,6 +210,8 @@ where ) { let out = match out { future::Either::Left(out) => out, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] future::Either::Right(v) => void::unreachable(v), }; @@ -251,6 +253,8 @@ where let err = match err { Either::Left(e) => e, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Right(v) => void::unreachable(v), }; diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index 603a5b0d7c4..2f9afc38418 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -1189,10 +1189,14 @@ mod tests { >, ) { match event { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { protocol, .. }) => void::unreachable(protocol), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { protocol, .. @@ -1200,6 +1204,8 @@ mod tests { ConnectionEvent::DialUpgradeError(DialUpgradeError { error, .. }) => { self.error = Some(error) } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::AddressChange(_) | ConnectionEvent::ListenUpgradeError(_) | ConnectionEvent::LocalProtocolsChange(_) @@ -1208,6 +1214,8 @@ mod tests { } fn on_behaviour_event(&mut self, event: Self::FromBehaviour) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } @@ -1283,6 +1291,8 @@ mod tests { } fn on_behaviour_event(&mut self, event: Self::FromBehaviour) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } diff --git a/swarm/src/connection/pool/task.rs b/swarm/src/connection/pool/task.rs index 08674fd2ee5..13977a17b85 100644 --- a/swarm/src/connection/pool/task.rs +++ b/swarm/src/connection/pool/task.rs @@ -105,6 +105,8 @@ pub(crate) async fn new_for_pending_outgoing_connection( }) .await; } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Left((Ok(v), _)) => void::unreachable(v), Either::Right((Ok((address, output, errors)), _)) => { let _ = events @@ -143,6 +145,8 @@ pub(crate) async fn new_for_pending_incoming_connection( }) .await; } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Left((Ok(v), _)) => void::unreachable(v), Either::Right((Ok(output), _)) => { let _ = events diff --git a/swarm/src/dummy.rs b/swarm/src/dummy.rs index 6e1b4d56eb9..0bd8c06862d 100644 --- a/swarm/src/dummy.rs +++ b/swarm/src/dummy.rs @@ -49,6 +49,8 @@ impl NetworkBehaviour for Behaviour { _: ConnectionId, event: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } @@ -76,6 +78,8 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { } fn on_behaviour_event(&mut self, event: Self::FromBehaviour) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(event) } @@ -98,19 +102,29 @@ impl crate::handler::ConnectionHandler for ConnectionHandler { >, ) { match event { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { protocol, .. }) => void::unreachable(protocol), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { protocol, .. }) => void::unreachable(protocol), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::DialUpgradeError(DialUpgradeError { info: _, error }) => match error { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] StreamUpgradeError::Timeout => unreachable!(), StreamUpgradeError::Apply(e) => void::unreachable(e), StreamUpgradeError::NegotiationFailed | StreamUpgradeError::Io(_) => { unreachable!("Denied upgrade does not support any protocols") } }, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::AddressChange(_) | ConnectionEvent::ListenUpgradeError(_) | ConnectionEvent::LocalProtocolsChange(_) diff --git a/swarm/src/handler/pending.rs b/swarm/src/handler/pending.rs index 23b9adcfd90..9601f5cf78b 100644 --- a/swarm/src/handler/pending.rs +++ b/swarm/src/handler/pending.rs @@ -52,6 +52,8 @@ impl ConnectionHandler for PendingConnectionHandler { } fn on_behaviour_event(&mut self, v: Self::FromBehaviour) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(v) } @@ -74,9 +76,13 @@ impl ConnectionHandler for PendingConnectionHandler { >, ) { match event { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedInbound(FullyNegotiatedInbound { protocol, .. }) => void::unreachable(protocol), + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { protocol, info: _info, @@ -87,6 +93,8 @@ impl ConnectionHandler for PendingConnectionHandler { void::unreachable(_info); } } + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] ConnectionEvent::AddressChange(_) | ConnectionEvent::DialUpgradeError(_) | ConnectionEvent::ListenUpgradeError(_) diff --git a/swarm/src/upgrade.rs b/swarm/src/upgrade.rs index 53b627458c9..f6c6648a373 100644 --- a/swarm/src/upgrade.rs +++ b/swarm/src/upgrade.rs @@ -121,6 +121,7 @@ where } /// Wraps around a type that implements [`OutboundUpgradeSend`], [`InboundUpgradeSend`], or +/// /// both, and implements [`OutboundUpgrade`](upgrade::OutboundUpgrade) and/or /// [`InboundUpgrade`](upgrade::InboundUpgrade). /// diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index 919ed0cab7f..667f68408cf 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -577,6 +577,8 @@ fn custom_out_event_no_type_parameters() { _connection: ConnectionId, message: THandlerOutEvent, ) { + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] void::unreachable(message); } diff --git a/transports/quic/src/hole_punching.rs b/transports/quic/src/hole_punching.rs index 605799af5e1..a38d123a6a4 100644 --- a/transports/quic/src/hole_punching.rs +++ b/transports/quic/src/hole_punching.rs @@ -20,6 +20,8 @@ pub(crate) async fn hole_puncher( match futures::future::select(P::sleep(timeout_duration), punch_holes_future).await { Either::Left(_) => Error::HandshakeTimedOut, Either::Right((Err(hole_punch_err), _)) => hole_punch_err, + // TODO: remove when Rust 1.82 is MSRV + #[allow(unreachable_patterns)] Either::Right((Ok(never), _)) => match never {}, } } From 8ceadaac5aec4b462463ef4082d6af577a3158b1 Mon Sep 17 00:00:00 2001 From: stormshield-frb <144998884+stormshield-frb@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:17:47 +0200 Subject: [PATCH 3/8] fix(swarm): don't report `NewExternalAddrCandidate` if already confirmed (#5582) ## Description Currently, `NewExternalAddrCandidate` events are emitted for every connections. However, we continue to get this event even when `autonat` has already confirmed that this address is external. So we should not continue to advertise the "candidate" event. ## Notes & open questions We have made the changes in the `swarm` instead of `identify` because it does not make it necessary to duplicate the `ConfirmedExternalAddr` vector in the `identify` Behaviour. Moreover, if any future Behaviour emit `NewExternalAddrCandidate`, the same rule will also be applied. I had to edit the `autonat_v2` tests which were always expecting a `NewExternalAddrCandidate` but the address was already confirmed. ## Change checklist - [x] I have performed a self-review of my own code - [ ] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [x] A changelog entry has been made in the appropriate crates --------- Co-authored-by: Darius Clark Co-authored-by: Guillaume Michel --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/autonat/tests/autonatv2.rs | 38 +++++++++++++--------------- swarm/CHANGELOG.md | 5 ++++ swarm/Cargo.toml | 2 +- swarm/src/lib.rs | 14 +++++----- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4c3498a0635..79eb2eb4ad5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3329,7 +3329,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.45.1" +version = "0.45.2" dependencies = [ "async-std", "criterion", diff --git a/Cargo.toml b/Cargo.toml index c9fe928096d..32f72c5e252 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,7 +102,7 @@ libp2p-rendezvous = { version = "0.15.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.27.0", path = "protocols/request-response" } libp2p-server = { version = "0.12.7", path = "misc/server" } libp2p-stream = { version = "0.2.0-alpha", path = "protocols/stream" } -libp2p-swarm = { version = "0.45.1", path = "swarm" } +libp2p-swarm = { version = "0.45.2", path = "swarm" } libp2p-swarm-derive = { version = "=0.35.0", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. libp2p-swarm-test = { version = "0.4.0", path = "swarm-test" } libp2p-tcp = { version = "0.42.0", path = "transports/tcp" } diff --git a/protocols/autonat/tests/autonatv2.rs b/protocols/autonat/tests/autonatv2.rs index abd0c4bd8eb..3d792172445 100644 --- a/protocols/autonat/tests/autonatv2.rs +++ b/protocols/autonat/tests/autonatv2.rs @@ -1,5 +1,6 @@ use libp2p_autonat::v2::client::{self, Config}; use libp2p_autonat::v2::server; +use libp2p_core::multiaddr::Protocol; use libp2p_core::transport::TransportError; use libp2p_core::Multiaddr; use libp2p_swarm::{ @@ -21,17 +22,10 @@ async fn confirm_successful() { let cor_server_peer = *alice.local_peer_id(); let cor_client_peer = *bob.local_peer_id(); - let bob_external_addrs = Arc::new(bob.external_addresses().cloned().collect::>()); - let alice_bob_external_addrs = bob_external_addrs.clone(); + let bob_tcp_listeners = Arc::new(tcp_listeners(&bob)); + let alice_bob_tcp_listeners = bob_tcp_listeners.clone(); let alice_task = async { - let _ = alice - .wait(|event| match event { - SwarmEvent::NewExternalAddrCandidate { .. } => Some(()), - _ => None, - }) - .await; - let (dialed_peer_id, dialed_connection_id) = alice .wait(|event| match event { SwarmEvent::Dialing { @@ -76,10 +70,10 @@ async fn confirm_successful() { }) .await; - assert_eq!(tested_addr, bob_external_addrs.first().cloned().unwrap()); + assert_eq!(tested_addr, bob_tcp_listeners.first().cloned().unwrap()); assert_eq!(data_amount, 0); assert_eq!(client, cor_client_peer); - assert_eq!(&all_addrs[..], &bob_external_addrs[..]); + assert_eq!(&all_addrs[..], &bob_tcp_listeners[..]); assert!(result.is_ok(), "Result: {result:?}"); }; @@ -122,7 +116,7 @@ async fn confirm_successful() { .await; assert_eq!( tested_addr, - alice_bob_external_addrs.first().cloned().unwrap() + alice_bob_tcp_listeners.first().cloned().unwrap() ); assert_eq!(bytes_sent, 0); assert_eq!(server, cor_server_peer); @@ -446,7 +440,7 @@ async fn new_client() -> Swarm { identity.public().clone(), )), }); - node.listen().with_tcp_addr_external().await; + node.listen().await; node } @@ -490,13 +484,6 @@ async fn bootstrap() -> (Swarm, Swarm) { let cor_client_peer = *bob.local_peer_id(); let alice_task = async { - let _ = alice - .wait(|event| match event { - SwarmEvent::NewExternalAddrCandidate { .. } => Some(()), - _ => None, - }) - .await; - let (dialed_peer_id, dialed_connection_id) = alice .wait(|event| match event { SwarmEvent::Dialing { @@ -566,3 +553,14 @@ async fn bootstrap() -> (Swarm, Swarm) { tokio::join!(alice_task, bob_task); (alice, bob) } + +fn tcp_listeners(swarm: &Swarm) -> Vec { + swarm + .listeners() + .filter(|addr| { + addr.iter() + .any(|protocol| matches!(protocol, Protocol::Tcp(_))) + }) + .cloned() + .collect::>() +} diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index e7931a60de2..c5d10872d40 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.45.2 + +- Don't report `NewExternalAddrCandidate` for confirmed external addresses. + See [PR 5582](https://github.com/libp2p/rust-libp2p/pull/5582). + ## 0.45.1 - Update `libp2p-swarm-derive` to version `0.35.0`, see [PR 5545] diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 3d0b1a84eee..cdee67f3fb3 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-swarm" edition = "2021" rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.45.1" +version = "0.45.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 81b1ca1a68d..12280e99f07 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -1140,12 +1140,14 @@ where self.pending_handler_event = Some((peer_id, handler, event)); } ToSwarm::NewExternalAddrCandidate(addr) => { - self.behaviour - .on_swarm_event(FromSwarm::NewExternalAddrCandidate( - NewExternalAddrCandidate { addr: &addr }, - )); - self.pending_swarm_events - .push_back(SwarmEvent::NewExternalAddrCandidate { address: addr }); + if !self.confirmed_external_addr.contains(&addr) { + self.behaviour + .on_swarm_event(FromSwarm::NewExternalAddrCandidate( + NewExternalAddrCandidate { addr: &addr }, + )); + self.pending_swarm_events + .push_back(SwarmEvent::NewExternalAddrCandidate { address: addr }); + } } ToSwarm::ExternalAddrConfirmed(addr) => { self.add_external_address(addr.clone()); From 89d78dda296fc3747d3760f73d4b6c558e34c8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 4 Oct 2024 14:35:08 +0100 Subject: [PATCH 4/8] chore(autonat-v2): fix dial_back_to_non_libp2p test (#5621) ## Description By avoiding dialing an external address Co-authored-by: Guillaume Michel --- protocols/autonat/tests/autonatv2.rs | 147 +++++++++++++-------------- 1 file changed, 72 insertions(+), 75 deletions(-) diff --git a/protocols/autonat/tests/autonatv2.rs b/protocols/autonat/tests/autonatv2.rs index 3d792172445..f22a2e51470 100644 --- a/protocols/autonat/tests/autonatv2.rs +++ b/protocols/autonat/tests/autonatv2.rs @@ -232,87 +232,84 @@ async fn dial_back_to_non_libp2p() { let (mut alice, mut bob) = bootstrap().await; let alice_peer_id = *alice.local_peer_id(); - for addr_str in ["/ip4/169.150.247.38/tcp/32", "/ip6/::1/tcp/1000"] { - let addr: Multiaddr = addr_str.parse().unwrap(); - let bob_addr = addr.clone(); - bob.behaviour_mut() - .autonat - .on_swarm_event(FromSwarm::NewExternalAddrCandidate( - NewExternalAddrCandidate { addr: &addr }, - )); - - let alice_task = async { - let (alice_dialing_peer, alice_conn_id) = alice - .wait(|event| match event { - SwarmEvent::Dialing { - peer_id, - connection_id, - } => peer_id.map(|p| (p, connection_id)), - _ => None, - }) - .await; - let mut outgoing_conn_error = alice - .wait(|event| match event { - SwarmEvent::OutgoingConnectionError { - connection_id, - peer_id: Some(peer_id), - error: DialError::Transport(peers), - } if connection_id == alice_conn_id && peer_id == alice_dialing_peer => { - Some(peers) - } - _ => None, - }) - .await; - - if let Some((multiaddr, TransportError::Other(o))) = outgoing_conn_error.pop() { - assert_eq!( - multiaddr, - addr.clone().with_p2p(alice_dialing_peer).unwrap() - ); - let error_string = o.to_string(); - assert!( - error_string.contains("Connection refused"), - "Correct error string: {error_string} for {addr_str}" - ); - } else { - panic!("No outgoing connection errors"); - } + let addr_str = "/ip6/::1/tcp/1000"; + let addr: Multiaddr = addr_str.parse().unwrap(); + let bob_addr = addr.clone(); + bob.behaviour_mut() + .autonat + .on_swarm_event(FromSwarm::NewExternalAddrCandidate( + NewExternalAddrCandidate { addr: &addr }, + )); - alice - .wait(|event| match event { - SwarmEvent::Behaviour(CombinedServerEvent::Autonat(server::Event { - all_addrs, - tested_addr, - client, - data_amount, - result: Ok(()), - })) if all_addrs == vec![addr.clone()] - && tested_addr == addr - && alice_dialing_peer == client => - { - Some(data_amount) - } - _ => None, - }) - .await - }; - let bob_task = async { - bob.wait(|event| match event { - SwarmEvent::Behaviour(CombinedClientEvent::Autonat(client::Event { + let alice_task = async { + let (alice_dialing_peer, alice_conn_id) = alice + .wait(|event| match event { + SwarmEvent::Dialing { + peer_id, + connection_id, + } => peer_id.map(|p| (p, connection_id)), + _ => None, + }) + .await; + let mut outgoing_conn_error = alice + .wait(|event| match event { + SwarmEvent::OutgoingConnectionError { + connection_id, + peer_id: Some(peer_id), + error: DialError::Transport(peers), + } if connection_id == alice_conn_id && peer_id == alice_dialing_peer => Some(peers), + _ => None, + }) + .await; + + if let Some((multiaddr, TransportError::Other(o))) = outgoing_conn_error.pop() { + assert_eq!( + multiaddr, + addr.clone().with_p2p(alice_dialing_peer).unwrap() + ); + let error_string = o.to_string(); + assert!( + error_string.contains("Connection refused"), + "Correct error string: {error_string} for {addr_str}" + ); + } else { + panic!("No outgoing connection errors"); + } + + alice + .wait(|event| match event { + SwarmEvent::Behaviour(CombinedServerEvent::Autonat(server::Event { + all_addrs, tested_addr, - bytes_sent, - server, - result: Err(_), - })) if tested_addr == bob_addr && server == alice_peer_id => Some(bytes_sent), + client, + data_amount, + result: Ok(()), + })) if all_addrs == vec![addr.clone()] + && tested_addr == addr + && alice_dialing_peer == client => + { + Some(data_amount) + } _ => None, }) .await - }; + }; + let bob_task = async { + bob.wait(|event| match event { + SwarmEvent::Behaviour(CombinedClientEvent::Autonat(client::Event { + tested_addr, + bytes_sent, + server, + result: Err(_), + })) if tested_addr == bob_addr && server == alice_peer_id => Some(bytes_sent), + _ => None, + }) + .await + }; - let (alice_bytes_sent, bob_bytes_sent) = tokio::join!(alice_task, bob_task); - assert_eq!(alice_bytes_sent, bob_bytes_sent); - bob.behaviour_mut().autonat.validate_addr(&addr); - } + let (alice_bytes_sent, bob_bytes_sent) = tokio::join!(alice_task, bob_task); + assert_eq!(alice_bytes_sent, bob_bytes_sent); + bob.behaviour_mut().autonat.validate_addr(&addr); } #[tokio::test] From b83dd95c384fefc0aca489f5ffefa74c72db0d9d Mon Sep 17 00:00:00 2001 From: Guillaume Michel Date: Fri, 4 Oct 2024 15:50:57 +0200 Subject: [PATCH 5/8] chore: update interop test run condition (#5611) ## Description Follow up to https://github.com/libp2p/rust-libp2p/pull/5604. Interop tests only work on the main `rust-libp2p` repo, and not on forks, because of the S3 cache (introduced in https://github.com/libp2p/rust-libp2p/pull/5586). The interop tests currently don't run in the PRs, but they run after the PRs are merged to `master`. This PR is trying to run interop tests in PR that are branches of the main repo (not forks). --- .github/workflows/interop-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index 558adcda66c..57d0f1a692d 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -11,6 +11,7 @@ concurrency: jobs: run-transport-interop: name: Run transport interoperability tests + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository runs-on: ${{ fromJSON(github.repository == 'libp2p/rust-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }} strategy: matrix: @@ -39,6 +40,7 @@ jobs: worker-count: 16 run-holepunching-interop: name: Run hole-punch interoperability tests + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository runs-on: ${{ fromJSON(github.repository == 'libp2p/rust-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }} steps: - uses: actions/checkout@v4 From 7669b1696bf62fa82e2a1da959cf537dc98959ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Fri, 4 Oct 2024 15:45:16 +0100 Subject: [PATCH 6/8] deps: update metrics example dependencies (#5617) ## Description and address cargo-deny [RUSTSEC-2024-0376](https://rustsec.org/advisories/RUSTSEC-2024-0376.html) --- Cargo.lock | 196 +++++++++++++---------------------- examples/metrics/Cargo.toml | 8 +- examples/metrics/src/main.rs | 8 +- 3 files changed, 80 insertions(+), 132 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79eb2eb4ad5..38c3436237a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -545,34 +545,6 @@ dependencies = [ "tracing-subscriber", ] -[[package]] -name = "axum" -version = "0.6.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b829e4e32b91e643de6eafe82b1d90675f5874230191a4ffbc1b336dec4d6bf" -dependencies = [ - "async-trait", - "axum-core 0.3.4", - "bitflags 1.3.2", - "bytes", - "futures-util", - "http 0.2.9", - "http-body 0.4.5", - "hyper 0.14.27", - "itoa", - "matchit", - "memchr", - "mime", - "percent-encoding", - "pin-project-lite", - "rustversion", - "serde", - "sync_wrapper 0.1.2", - "tower", - "tower-layer", - "tower-service", -] - [[package]] name = "axum" version = "0.7.5" @@ -580,13 +552,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" dependencies = [ "async-trait", - "axum-core 0.4.3", + "axum-core", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", - "hyper 1.1.0", + "hyper 1.4.1", "hyper-util", "itoa", "matchit", @@ -607,23 +579,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "axum-core" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "759fa577a247914fd3f7f76d62972792636412fbfd634cd452f6a385a74d2d2c" -dependencies = [ - "async-trait", - "bytes", - "futures-util", - "http 0.2.9", - "http-body 0.4.5", - "mime", - "rustversion", - "tower-layer", - "tower-service", -] - [[package]] name = "axum-core" version = "0.4.3" @@ -633,7 +588,7 @@ dependencies = [ "async-trait", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "mime", @@ -779,7 +734,7 @@ name = "browser-webrtc-example" version = "0.1.0" dependencies = [ "anyhow", - "axum 0.7.5", + "axum", "futures", "js-sys", "libp2p", @@ -1940,7 +1895,7 @@ dependencies = [ "futures-core", "futures-sink", "futures-util", - "http 1.0.0", + "http 1.1.0", "indexmap 2.2.1", "slab", "tokio", @@ -2131,9 +2086,9 @@ dependencies = [ [[package]] name = "http" -version = "1.0.0" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b32afd38673a8016f7c9ae69e5af41a58f81b1d31689040f2f1959594ce194ea" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -2158,7 +2113,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", - "http 1.0.0", + "http 1.1.0", ] [[package]] @@ -2169,7 +2124,7 @@ checksum = "41cb79eb393015dadd30fc252023adb0b2400a0caee0fa2a077e6e21a551e840" dependencies = [ "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "pin-project-lite", ] @@ -2224,20 +2179,21 @@ dependencies = [ [[package]] name = "hyper" -version = "1.1.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5aa53871fc917b1a9ed87b683a5d86db645e23acb32c2e0785a353e522fb75" +checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" dependencies = [ "bytes", "futures-channel", "futures-util", "h2 0.4.4", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "httparse", "httpdate", "itoa", "pin-project-lite", + "smallvec", "tokio", "want", ] @@ -2249,8 +2205,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0bea761b46ae2b24eb4aef630d8d1c398157b6fc29e6350ecf090a0b70c952c" dependencies = [ "futures-util", - "http 1.0.0", - "hyper 1.1.0", + "http 1.1.0", + "hyper 1.4.1", "hyper-util", "rustls 0.22.4", "rustls-pki-types", @@ -2261,14 +2217,15 @@ dependencies = [ [[package]] name = "hyper-timeout" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbb958482e8c7be4bc3cf272a766a2b0bf1a6755e7a6ae777f017a31d11b13b1" +checksum = "3203a961e5c83b6f5498933e78b6b263e208c197b63e9c6c53cc82ffd3f63793" dependencies = [ - "hyper 0.14.27", + "hyper 1.4.1", + "hyper-util", "pin-project-lite", "tokio", - "tokio-io-timeout", + "tower-service", ] [[package]] @@ -2279,7 +2236,7 @@ checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", "http-body-util", - "hyper 1.1.0", + "hyper 1.4.1", "hyper-util", "native-tls", "tokio", @@ -2289,20 +2246,19 @@ dependencies = [ [[package]] name = "hyper-util" -version = "0.1.3" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca38ef113da30126bbff9cd1705f9273e15d45498615d138b0c20279ac7a76aa" +checksum = "41296eb09f183ac68eec06e03cdbea2e759633d4067b2f6552fc2e009bcad08b" dependencies = [ "bytes", "futures-channel", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", - "hyper 1.1.0", + "hyper 1.4.1", "pin-project-lite", "socket2 0.5.7", "tokio", - "tower", "tower-service", "tracing", ] @@ -2456,7 +2412,7 @@ name = "interop-tests" version = "0.1.0" dependencies = [ "anyhow", - "axum 0.7.5", + "axum", "console_error_panic_hook", "either", "futures", @@ -3295,7 +3251,7 @@ dependencies = [ name = "libp2p-server" version = "0.12.7" dependencies = [ - "axum 0.7.5", + "axum", "base64 0.22.1", "clap", "futures", @@ -3774,16 +3730,16 @@ dependencies = [ name = "metrics-example" version = "0.1.0" dependencies = [ - "axum 0.7.5", + "axum", "futures", "libp2p", - "opentelemetry 0.23.0", + "opentelemetry 0.25.0", "opentelemetry-otlp", - "opentelemetry_sdk 0.23.0", + "opentelemetry_sdk 0.25.0", "prometheus-client", "tokio", "tracing", - "tracing-opentelemetry 0.24.0", + "tracing-opentelemetry 0.26.0", "tracing-subscriber", ] @@ -4198,9 +4154,9 @@ dependencies = [ [[package]] name = "opentelemetry" -version = "0.23.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b69a91d4893e713e06f724597ad630f1fa76057a5e1026c0ca67054a9032a76" +checksum = "803801d3d3b71cd026851a53f974ea03df3d179cb758b260136a6c9e22e196af" dependencies = [ "futures-core", "futures-sink", @@ -4228,16 +4184,16 @@ dependencies = [ [[package]] name = "opentelemetry-otlp" -version = "0.16.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a94c69209c05319cdf7460c6d4c055ed102be242a0a6245835d7bc42c6ec7f54" +checksum = "596b1719b3cab83addb20bcbffdf21575279d9436d9ccccfe651a3bf0ab5ab06" dependencies = [ "async-trait", "futures-core", - "http 0.2.9", - "opentelemetry 0.23.0", + "http 1.1.0", + "opentelemetry 0.25.0", "opentelemetry-proto", - "opentelemetry_sdk 0.23.0", + "opentelemetry_sdk 0.25.0", "prost", "thiserror", "tokio", @@ -4246,12 +4202,12 @@ dependencies = [ [[package]] name = "opentelemetry-proto" -version = "0.6.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "984806e6cf27f2b49282e2a05e288f30594f3dbc74eb7a6e99422bc48ed78162" +checksum = "2c43620e8f93359eb7e627a3b16ee92d8585774986f24f2ab010817426c5ce61" dependencies = [ - "opentelemetry 0.23.0", - "opentelemetry_sdk 0.23.0", + "opentelemetry 0.25.0", + "opentelemetry_sdk 0.25.0", "prost", "tonic", ] @@ -4289,21 +4245,20 @@ dependencies = [ [[package]] name = "opentelemetry_sdk" -version = "0.23.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae312d58eaa90a82d2e627fd86e075cf5230b3f11794e2ed74199ebbe572d4fd" +checksum = "e0da0d6b47a3dbc6e9c9e36a0520e25cf943e046843818faaa3f87365a548c82" dependencies = [ "async-trait", "futures-channel", "futures-executor", "futures-util", "glob", - "lazy_static", "once_cell", - "opentelemetry 0.23.0", - "ordered-float 4.2.0", + "opentelemetry 0.25.0", "percent-encoding", "rand 0.8.5", + "serde_json", "thiserror", "tokio", "tokio-stream", @@ -4618,9 +4573,9 @@ dependencies = [ [[package]] name = "prost" -version = "0.12.3" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "146c289cda302b98a28d40c8b3b90498d6e526dd24ac2ecea73e4e491685b94a" +checksum = "7b0487d90e047de87f984913713b85c601c05609aad5b0df4b4573fbf69aa13f" dependencies = [ "bytes", "prost-derive", @@ -4628,9 +4583,9 @@ dependencies = [ [[package]] name = "prost-derive" -version = "0.12.3" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efb6c9a1dd1def8e2124d17e83a20af56f1570d6c2d2bd9e266ccb768df3840e" +checksum = "e9552f850d5f0964a4e4d0bf306459ac29323ddfbae05e35a7c0d35cb0803cc5" dependencies = [ "anyhow", "itertools", @@ -4978,10 +4933,10 @@ dependencies = [ "futures-core", "futures-util", "h2 0.4.4", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", - "hyper 1.1.0", + "hyper 1.4.1", "hyper-rustls", "hyper-tls", "hyper-util", @@ -5965,7 +5920,7 @@ dependencies = [ "async-trait", "base64 0.22.1", "futures", - "http 1.0.0", + "http 1.1.0", "indexmap 2.2.1", "parking_lot", "paste", @@ -6120,16 +6075,6 @@ dependencies = [ "windows-sys 0.48.0", ] -[[package]] -name = "tokio-io-timeout" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30b74022ada614a1b4834de765f9bb43877f910cc8ce4be40e89042c9223a8bf" -dependencies = [ - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-macros" version = "2.3.0" @@ -6164,9 +6109,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.14" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "397c988d37662c7dda6d2208364a706264bf3d6138b11d436cbac0ad38832842" +checksum = "4f4e6ce100d0eb49a2734f8c0812bcd324cf357d21810932c5df6b96ef2b86f1" dependencies = [ "futures-core", "pin-project-lite", @@ -6223,23 +6168,26 @@ dependencies = [ [[package]] name = "tonic" -version = "0.11.0" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76c4eb7a4e9ef9d4763600161f12f5070b92a578e1b634db88a6887844c91a13" +checksum = "877c5b330756d856ffcc4553ab34a5684481ade925ecc54bcd1bf02b1d0d4d52" dependencies = [ "async-stream", "async-trait", - "axum 0.6.20", - "base64 0.21.7", + "axum", + "base64 0.22.1", "bytes", - "h2 0.3.26", - "http 0.2.9", - "http-body 0.4.5", - "hyper 0.14.27", + "h2 0.4.4", + "http 1.1.0", + "http-body 1.0.0", + "http-body-util", + "hyper 1.4.1", "hyper-timeout", + "hyper-util", "percent-encoding", "pin-project", "prost", + "socket2 0.5.7", "tokio", "tokio-stream", "tower", @@ -6277,7 +6225,7 @@ dependencies = [ "bitflags 2.4.1", "bytes", "futures-util", - "http 1.0.0", + "http 1.1.0", "http-body 1.0.0", "http-body-util", "http-range-header", @@ -6369,14 +6317,14 @@ dependencies = [ [[package]] name = "tracing-opentelemetry" -version = "0.24.0" +version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f68803492bf28ab40aeccaecc7021096bd256baf7ca77c3d425d89b35a7be4e4" +checksum = "5eabc56d23707ad55ba2a0750fc24767125d5a0f51993ba41ad2c441cc7b8dea" dependencies = [ "js-sys", "once_cell", - "opentelemetry 0.23.0", - "opentelemetry_sdk 0.23.0", + "opentelemetry 0.25.0", + "opentelemetry_sdk 0.25.0", "smallvec", "tracing", "tracing-core", diff --git a/examples/metrics/Cargo.toml b/examples/metrics/Cargo.toml index 2b82668f52a..129b1abb1f3 100644 --- a/examples/metrics/Cargo.toml +++ b/examples/metrics/Cargo.toml @@ -12,13 +12,13 @@ release = false futures = { workspace = true } axum = "0.7" libp2p = { path = "../../libp2p", features = ["tokio", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] } -opentelemetry = { version = "0.23.0", features = ["metrics"] } -opentelemetry-otlp = { version = "0.16.0", features = ["metrics"] } -opentelemetry_sdk = { version = "0.23.0", features = ["rt-tokio", "metrics"] } +opentelemetry = { version = "0.25.0", features = ["metrics"] } +opentelemetry-otlp = { version = "0.25.0", features = ["metrics"] } +opentelemetry_sdk = { version = "0.25.0", features = ["rt-tokio", "metrics"] } prometheus-client = { workspace = true } tokio = { workspace = true, features = ["full"] } tracing = { workspace = true } -tracing-opentelemetry = "0.24.0" +tracing-opentelemetry = "0.26.0" tracing-subscriber = { workspace = true, features = ["env-filter"] } [lints] diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 99a9ca66aaf..1755c769053 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -25,7 +25,7 @@ use libp2p::core::Multiaddr; use libp2p::metrics::{Metrics, Recorder}; use libp2p::swarm::{NetworkBehaviour, SwarmEvent}; use libp2p::{identify, identity, noise, ping, tcp, yamux}; -use opentelemetry::KeyValue; +use opentelemetry::{trace::TracerProvider, KeyValue}; use prometheus_client::registry::Registry; use std::error::Error; use std::time::Duration; @@ -90,7 +90,7 @@ async fn main() -> Result<(), Box> { } fn setup_tracing() -> Result<(), Box> { - let tracer = opentelemetry_otlp::new_pipeline() + let provider = opentelemetry_otlp::new_pipeline() .tracing() .with_exporter(opentelemetry_otlp::new_exporter().tonic()) .with_trace_config(opentelemetry_sdk::trace::Config::default().with_resource( @@ -102,10 +102,10 @@ fn setup_tracing() -> Result<(), Box> { .with(tracing_subscriber::fmt::layer().with_filter(EnvFilter::from_default_env())) .with( tracing_opentelemetry::layer() - .with_tracer(tracer) + .with_tracer(provider.tracer("libp2p-subscriber")) .with_filter(EnvFilter::from_default_env()), ) - .try_init()?; + .init(); Ok(()) } From fcff3f80401895362060f8e448ec992b6db7fb9b Mon Sep 17 00:00:00 2001 From: P1R0 Date: Fri, 4 Oct 2024 16:40:47 -0600 Subject: [PATCH 7/8] refactor(examples): use tokio instead of async-std in relay-server (#5600) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Following on issue #4449 refactor: use tokio instead of async-std in the relay-servert example and remove unnecessary dependencies ## Notes & open questions Fails on testing with the [whole punch tutorial](https://docs.rs/libp2p/0.54.1/libp2p/tutorials/hole_punching/index.html) possibly because of my networking topology. connection established event registered. I will publish the logs and testing information as a comment ## Change checklist * Removed unnecessary dependencies on examples/relay-server/Cargo.toml * Updated tokio version to "1.37.0" - [ ] I have performed a self-review of my own code - [ ] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] A changelog entry has been made in the appropriate crates --------- Co-authored-by: David E. Perez Negron R. Co-authored-by: Guillaume Michel Co-authored-by: João Oliveira --- Cargo.lock | 3 +-- examples/relay-server/Cargo.toml | 5 ++-- examples/relay-server/src/main.rs | 42 +++++++++++++++---------------- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38c3436237a..91767968898 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4901,11 +4901,10 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" name = "relay-server-example" version = "0.1.0" dependencies = [ - "async-std", - "async-trait", "clap", "futures", "libp2p", + "tokio", "tracing", "tracing-subscriber", ] diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index 12d3e2467ce..7385cf6c033 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -10,10 +10,9 @@ release = false [dependencies] clap = { version = "4.5.6", features = ["derive"] } -async-std = { version = "1.12", features = ["attributes"] } -async-trait = "0.1" +tokio = { version = "1.37.0", features = ["full"] } futures = { workspace = true } -libp2p = { path = "../../libp2p", features = [ "async-std", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay", "quic"] } +libp2p = { path = "../../libp2p", features = ["tokio", "noise", "macros", "ping", "tcp", "identify", "yamux", "relay", "quic"] } tracing = { workspace = true } tracing-subscriber = { workspace = true, features = ["env-filter"] } diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index bf5817454f8..46a122d0717 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -22,8 +22,7 @@ #![doc = include_str!("../README.md")] use clap::Parser; -use futures::executor::block_on; -use futures::stream::StreamExt; +use futures::StreamExt; use libp2p::{ core::multiaddr::Protocol, core::Multiaddr, @@ -35,7 +34,8 @@ use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; use tracing_subscriber::EnvFilter; -fn main() -> Result<(), Box> { +#[tokio::main] +async fn main() -> Result<(), Box> { let _ = tracing_subscriber::fmt() .with_env_filter(EnvFilter::from_default_env()) .try_init(); @@ -46,7 +46,7 @@ fn main() -> Result<(), Box> { let local_key: identity::Keypair = generate_ed25519(opt.secret_key_seed); let mut swarm = libp2p::SwarmBuilder::with_existing_identity(local_key) - .with_async_std() + .with_tokio() .with_tcp( tcp::Config::default(), noise::Config::new, @@ -81,27 +81,25 @@ fn main() -> Result<(), Box> { .with(Protocol::QuicV1); swarm.listen_on(listen_addr_quic)?; - block_on(async { - loop { - match swarm.next().await.expect("Infinite Stream.") { - SwarmEvent::Behaviour(event) => { - if let BehaviourEvent::Identify(identify::Event::Received { - info: identify::Info { observed_addr, .. }, - .. - }) = &event - { - swarm.add_external_address(observed_addr.clone()); - } - - println!("{event:?}") + loop { + match swarm.next().await.expect("Infinite Stream.") { + SwarmEvent::Behaviour(event) => { + if let BehaviourEvent::Identify(identify::Event::Received { + info: identify::Info { observed_addr, .. }, + .. + }) = &event + { + swarm.add_external_address(observed_addr.clone()); } - SwarmEvent::NewListenAddr { address, .. } => { - println!("Listening on {address:?}"); - } - _ => {} + + println!("{event:?}") + } + SwarmEvent::NewListenAddr { address, .. } => { + println!("Listening on {address:?}"); } + _ => {} } - }) + } } #[derive(NetworkBehaviour)] From 93ad28c4cce236b1657241ba623ea30077565afd Mon Sep 17 00:00:00 2001 From: Guillaume Michel Date: Sat, 5 Oct 2024 01:07:49 +0200 Subject: [PATCH 8/8] fix(server): removing dependency on libp2p-lookup (#5610) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Description Remove dependency on [`libp2p-lookup`](https://github.com/mxinden/libp2p-lookup) which is no longer maintained, and [makes checks fail](https://github.com/libp2p/rust-libp2p/actions/runs/11016492372/job/30628121728). ## Change checklist - [x] I have performed a self-review of my own code - [x] I have made corresponding changes to the documentation - [ ] I have added tests that prove my fix is effective or that my feature works - [x] A changelog entry has been made in the appropriate crates --------- Co-authored-by: João Oliveira --- Cargo.lock | 2 +- Cargo.toml | 8 ++++++-- misc/server/CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ misc/server/Cargo.toml | 20 ++++++++++++++++++-- misc/server/Dockerfile | 2 -- misc/server/README.md | 7 ------- 6 files changed, 55 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 91767968898..28107c00ee9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3249,7 +3249,7 @@ dependencies = [ [[package]] name = "libp2p-server" -version = "0.12.7" +version = "0.12.8" dependencies = [ "axum", "base64 0.22.1", diff --git a/Cargo.toml b/Cargo.toml index 32f72c5e252..cc677013fa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,7 @@ libp2p-quic = { version = "0.11.1", path = "transports/quic" } libp2p-relay = { version = "0.18.0", path = "protocols/relay" } libp2p-rendezvous = { version = "0.15.0", path = "protocols/rendezvous" } libp2p-request-response = { version = "0.27.0", path = "protocols/request-response" } -libp2p-server = { version = "0.12.7", path = "misc/server" } +libp2p-server = { version = "0.12.8", path = "misc/server" } libp2p-stream = { version = "0.2.0-alpha", path = "protocols/stream" } libp2p-swarm = { version = "0.45.2", path = "swarm" } libp2p-swarm-derive = { version = "=0.35.0", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required. @@ -151,4 +151,8 @@ clippy.manual_let_else = "warn" clippy.dbg_macro = "warn" [workspace.metadata.release] -pre-release-hook = ["/bin/sh", '-c', '/bin/sh $WORKSPACE_ROOT/scripts/add-changelog-header.sh'] # Nested use of shell to expand variables. +pre-release-hook = [ + "/bin/sh", + '-c', + '/bin/sh $WORKSPACE_ROOT/scripts/add-changelog-header.sh', +] # Nested use of shell to expand variables. diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index 5369163460c..fe48de0f553 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.12.8 + +### Changed + +- Remove deprecated [`libp2p-lookup`](https://github.com/mxinden/libp2p-lookup) from Dockerfile. + See [PR 5610](https://github.com/libp2p/rust-libp2p/pull/5610). + ## 0.12.7 ### Changed @@ -31,6 +38,7 @@ ## 0.12.3 ### Changed + - Add libp2p-lookup to Dockerfile to enable healthchecks. ### Fixed @@ -42,14 +50,18 @@ [PR 4467]: https://github.com/libp2p/rust-libp2p/pull/4467 ## 0.12.2 + ### Fixed + - Adhere to `--metrics-path` flag and listen on `0.0.0.0:8888` (default IPFS metrics port). [PR 4392] [PR 4392]: https://github.com/libp2p/rust-libp2p/pull/4392 ## 0.12.1 + ### Changed + - Move to tokio and hyper. See [PR 4311]. - Move to distroless Docker base image. @@ -58,39 +70,57 @@ [PR 4311]: https://github.com/libp2p/rust-libp2p/pull/4311 ## 0.8.0 + ### Changed + - Remove mplex support. ## 0.7.0 + ### Changed + - Update to libp2p v0.47.0. ## 0.6.0 - 2022-05-05 + ### Changed + - Update to libp2p v0.44.0. ## 0.5.4 - 2022-01-11 + ### Changed + - Pull latest autonat changes. ## 0.5.3 - 2021-12-25 + ### Changed + - Update dependencies. - Pull in autonat fixes. ## 0.5.2 - 2021-12-20 + ### Added + - Add support for libp2p autonat protocol via `--enable-autonat`. ## 0.5.1 - 2021-12-20 + ### Fixed + - Update dependencies. - Fix typo in command line flag `--enable-kademlia`. ## 0.5.0 - 2021-11-18 + ### Changed + - Disable Kademlia protocol by default. ## 0.4.0 - 2021-11-18 + ### Fixed + - Update dependencies. diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index 798ecfa07a9..0954e2f38d8 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-server" -version = "0.12.7" +version = "0.12.8" authors = ["Max Inden "] edition = "2021" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,7 +16,23 @@ clap = { version = "4.5.6", features = ["derive"] } futures = { workspace = true } futures-timer = "3" axum = "0.7" -libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic", "websocket"] } +libp2p = { workspace = true, features = [ + "autonat", + "dns", + "tokio", + "noise", + "tcp", + "yamux", + "identify", + "kad", + "ping", + "relay", + "metrics", + "rsa", + "macros", + "quic", + "websocket", +] } prometheus-client = { workspace = true } serde = "1.0.203" serde_derive = "1.0.125" diff --git a/misc/server/Dockerfile b/misc/server/Dockerfile index 24ae2b9fd99..12a8982eb3f 100644 --- a/misc/server/Dockerfile +++ b/misc/server/Dockerfile @@ -1,7 +1,6 @@ # syntax=docker/dockerfile:1.5-labs FROM rust:1.81.0 as chef RUN wget -q -O- https://github.com/LukeMathWalker/cargo-chef/releases/download/v0.1.62/cargo-chef-x86_64-unknown-linux-gnu.tar.gz | tar -zx -C /usr/local/bin -RUN cargo install --locked --root /usr/local libp2p-lookup --version 0.6.4 WORKDIR /app FROM chef AS planner @@ -17,5 +16,4 @@ COPY . . RUN cargo build --release --package libp2p-server FROM gcr.io/distroless/cc -COPY --from=builder /usr/local/bin/libp2p-server /usr/local/bin/libp2p-lookup /usr/local/bin/ CMD ["libp2p-server"] diff --git a/misc/server/README.md b/misc/server/README.md index 0da1bd8abd9..f9a5d65124a 100644 --- a/misc/server/README.md +++ b/misc/server/README.md @@ -25,7 +25,6 @@ Options: -h, --help Print help ``` - ``` cargo run -- --config ~/.ipfs/config @@ -33,9 +32,3 @@ Local peer id: PeerId("12D3KooWSa1YEeQVSwvoqAMhwjKQ6kqZQckhWPb3RWEGV3sZGU6Z") Listening on "/ip4/127.0.0.1/udp/4001/quic" [...] ``` - -The Docker container includes [libp2-lookup](https://github.com/mxinden/libp2p-lookup/) to enable adding a proper healthcheck for container startup, e.g. - -``` shell -docker run --health-cmd 'libp2p-lookup direct --address /ip4/127.0.0.1/tcp/4001/p2p/QmQCU2EcMqAqQPR2i9bChDtGNJchTbq5TbXJJ16u19uLTa' /home/ipfs/.ipfs:/ipfs ghcr.io/libp2p/rust-libp2p-server --config /ipfs/config -```