From 5c498f656c54756c6de548d69d2bbcd051b2a1bb Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 12 Oct 2023 07:01:34 +1100 Subject: [PATCH 01/10] ci: use new "transport-interop" action Resolves: #4592. Pull-Request: #4594. --- .github/workflows/interop-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index 8fa00f0a..7584380a 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -10,8 +10,8 @@ concurrency: cancel-in-progress: true jobs: - run-multidim-interop: - name: Run multidimensional interoperability tests + run-transport-interop: + name: Run transport interoperability tests runs-on: ${{ fromJSON(github.repository == 'libp2p/rust-libp2p' && '["self-hosted", "linux", "x64", "4xlarge"]' || '"ubuntu-latest"') }} strategy: matrix: @@ -29,7 +29,7 @@ jobs: FLAVOUR: ${{ matrix.flavour }} - name: Run ${{ matrix.flavour }} tests - uses: libp2p/test-plans/.github/actions/run-interop-ping-test@master + uses: libp2p/test-plans/.github/actions/run-transport-interop-test@master with: test-filter: ${{ matrix.flavour }}-rust-libp2p-head extra-versions: ${{ github.workspace }}/interop-tests/${{ matrix.flavour }}-ping-version.json From 497f393987db80972f8b832fc2f9e3a57745b576 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Oliveira?= Date: Thu, 12 Oct 2023 10:05:07 +0100 Subject: [PATCH 02/10] fix(quic): don't report error for gracefully closed connections Closes quinn's `Endpoint` with `Ok(())` when `Accept` returns `None`. Resolves: #4588. Related: https://github.com/quinn-rs/quinn/issues/1676. Pull-Request: #4621. --- transports/quic/CHANGELOG.md | 4 ++++ transports/quic/src/lib.rs | 1 + transports/quic/src/transport.rs | 2 +- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/transports/quic/CHANGELOG.md b/transports/quic/CHANGELOG.md index a7ad810b..fdd8c24b 100644 --- a/transports/quic/CHANGELOG.md +++ b/transports/quic/CHANGELOG.md @@ -1,7 +1,11 @@ ## 0.9.3 - unreleased +- No longer report error when explicit closing of a QUIC endpoint succeeds. + See [PR 4621]. + - Support QUIC stateless resets for supported `libp2p_identity::Keypair`s. See [PR 4554]. +[PR 4621]: https://github.com/libp2p/rust-libp2p/pull/4621 [PR 4554]: https://github.com/libp2p/rust-libp2p/pull/4554 ## 0.9.2 diff --git a/transports/quic/src/lib.rs b/transports/quic/src/lib.rs index 494ecfdc..85fa3c7e 100644 --- a/transports/quic/src/lib.rs +++ b/transports/quic/src/lib.rs @@ -91,6 +91,7 @@ pub enum Error { Io(#[from] std::io::Error), /// The task to drive a quic endpoint has crashed. + #[deprecated(since = "0.9.3", note = "No longer emitted")] #[error("Endpoint driver crashed")] EndpointDriverCrashed, diff --git a/transports/quic/src/transport.rs b/transports/quic/src/transport.rs index 16ffbc5a..12126b86 100644 --- a/transports/quic/src/transport.rs +++ b/transports/quic/src/transport.rs @@ -588,7 +588,7 @@ impl Stream for Listener

{ return Poll::Ready(Some(event)); } Poll::Ready(None) => { - self.close(Err(Error::EndpointDriverCrashed)); + self.close(Ok(())); continue; } Poll::Pending => {} From 7120529c6d112c8ddee697e2a0847b1bae69e96c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 13 Oct 2023 15:18:19 +1100 Subject: [PATCH 03/10] fix(kad): rewrite tests to be less flaky Not sure why but these tests have recently been quite flaky and are blocking several PRs. Pull-Request: #4634. --- protocols/kad/tests/client_mode.rs | 110 ++++++++++++++--------------- 1 file changed, 53 insertions(+), 57 deletions(-) diff --git a/protocols/kad/tests/client_mode.rs b/protocols/kad/tests/client_mode.rs index bc162ff6..ff91dec0 100644 --- a/protocols/kad/tests/client_mode.rs +++ b/protocols/kad/tests/client_mode.rs @@ -2,8 +2,10 @@ use libp2p_identify as identify; use libp2p_identity as identity; use libp2p_kad::store::MemoryStore; use libp2p_kad::{Behaviour, Config, Event, Mode}; -use libp2p_swarm::Swarm; +use libp2p_swarm::{Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; +use Event::*; +use MyBehaviourEvent::*; #[async_std::test] async fn server_gets_added_to_routing_table_by_client() { @@ -16,16 +18,16 @@ async fn server_gets_added_to_routing_table_by_client() { client.connect(&mut server).await; let server_peer_id = *server.local_peer_id(); + async_std::task::spawn(server.loop_on_next()); - match libp2p_swarm_test::drive(&mut client, &mut server).await { - ( - [MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_), MyBehaviourEvent::Kad(Event::RoutingUpdated { peer, .. })], - [MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_)], - ) => { - assert_eq!(peer, server_peer_id) - } - other => panic!("Unexpected events: {other:?}"), - } + let peer = client + .wait(|e| match e { + SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer), + _ => None, + }) + .await; + + assert_eq!(peer, server_peer_id); } #[async_std::test] @@ -41,12 +43,10 @@ async fn two_servers_add_each_other_to_routing_table() { let server1_peer_id = *server1.local_peer_id(); let server2_peer_id = *server2.local_peer_id(); - use Event::*; - use MyBehaviourEvent::*; - match libp2p_swarm_test::drive(&mut server1, &mut server2).await { ( - [Identify(_), Identify(_), Kad(RoutingUpdated { peer: peer1, .. })], + [Identify(_), Identify(_), Kad(RoutingUpdated { peer: peer1, .. })] + | [Identify(_), Kad(RoutingUpdated { peer: peer1, .. }), Identify(_)], [Identify(_), Identify(_)], ) => { assert_eq!(peer1, server2_peer_id); @@ -57,19 +57,16 @@ async fn two_servers_add_each_other_to_routing_table() { server1.listen().await; server2.connect(&mut server1).await; - match libp2p_swarm_test::drive(&mut server2, &mut server1).await { - ( - [Identify(_), Kad(RoutingUpdated { peer: peer2, .. }), Identify(_)], - [Identify(_), Identify(_)], - ) - | ( - [Identify(_), Identify(_), Kad(RoutingUpdated { peer: peer2, .. })], - [Identify(_), Identify(_)], - ) => { - assert_eq!(peer2, server1_peer_id); - } - other => panic!("Unexpected events: {other:?}"), - } + async_std::task::spawn(server1.loop_on_next()); + + let peer = server2 + .wait(|e| match e { + SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer), + _ => None, + }) + .await; + + assert_eq!(peer, server1_peer_id); } #[async_std::test] @@ -85,17 +82,12 @@ async fn adding_an_external_addresses_activates_server_mode_on_existing_connecti // Remove memory address to simulate a server that doesn't know its external address. server.remove_external_address(&memory_addr); client.dial(memory_addr.clone()).unwrap(); - - use MyBehaviourEvent::*; - // Do the usual identify send/receive dance. match libp2p_swarm_test::drive(&mut client, &mut server).await { ([Identify(_), Identify(_)], [Identify(_), Identify(_)]) => {} other => panic!("Unexpected events: {other:?}"), } - use Event::*; - // Server learns its external address (this could be through AutoNAT or some other mechanism). server.add_external_address(memory_addr); @@ -125,34 +117,38 @@ async fn set_client_to_server_mode() { let server_peer_id = *server.local_peer_id(); - match libp2p_swarm_test::drive(&mut client, &mut server).await { - ( - [MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(_), MyBehaviourEvent::Kad(Event::RoutingUpdated { peer, .. })], - [MyBehaviourEvent::Identify(_), MyBehaviourEvent::Identify(identify::Event::Received { info, .. })], - ) => { - assert_eq!(peer, server_peer_id); - assert!(info - .protocols - .iter() - .all(|proto| libp2p_kad::PROTOCOL_NAME.ne(proto))) - } - other => panic!("Unexpected events: {other:?}"), - } + let client_event = client.wait(|e| match e { + SwarmEvent::Behaviour(Kad(RoutingUpdated { peer, .. })) => Some(peer), + _ => None, + }); + let server_event = server.wait(|e| match e { + SwarmEvent::Behaviour(Identify(identify::Event::Received { info, .. })) => Some(info), + _ => None, + }); + + let (peer, info) = futures::future::join(client_event, server_event).await; + + assert_eq!(peer, server_peer_id); + assert!(info + .protocols + .iter() + .all(|proto| libp2p_kad::PROTOCOL_NAME.ne(proto))); client.behaviour_mut().kad.set_mode(Some(Mode::Server)); - match libp2p_swarm_test::drive(&mut client, &mut server).await { - ( - [MyBehaviourEvent::Identify(_)], - [MyBehaviourEvent::Identify(identify::Event::Received { info, .. }), MyBehaviourEvent::Kad(_)], - ) => { - assert!(info - .protocols - .iter() - .any(|proto| libp2p_kad::PROTOCOL_NAME.eq(proto))) - } - other => panic!("Unexpected events: {other:?}"), - } + async_std::task::spawn(client.loop_on_next()); + + let info = server + .wait(|e| match e { + SwarmEvent::Behaviour(Identify(identify::Event::Received { info, .. })) => Some(info), + _ => None, + }) + .await; + + assert!(info + .protocols + .iter() + .any(|proto| libp2p_kad::PROTOCOL_NAME.eq(proto))); } #[derive(libp2p_swarm::NetworkBehaviour)] From 0626e2e329152c36c152e1ac9be6a0c66bb5ad3a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 13 Oct 2023 15:29:38 +1100 Subject: [PATCH 04/10] docs: fix misc. errors around changelogs and manifests Detected by #4620. Pull-Request: #4630. --- Cargo.lock | 2 +- Cargo.toml | 2 +- misc/server/CHANGELOG.md | 29 ++++++++++-------------- transports/quic/Cargo.toml | 2 +- transports/websocket-websys/CHANGELOG.md | 4 ++-- 5 files changed, 17 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 96f5b8e7..ef31ddd9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2918,7 +2918,7 @@ dependencies = [ [[package]] name = "libp2p-quic" -version = "0.9.2" +version = "0.9.3" dependencies = [ "async-std", "bytes", diff --git a/Cargo.toml b/Cargo.toml index 5334d279..587b8970 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -95,7 +95,7 @@ libp2p-perf = { version = "0.2.0", path = "protocols/perf" } libp2p-ping = { version = "0.43.1", path = "protocols/ping" } libp2p-plaintext = { version = "0.40.1", path = "transports/plaintext" } libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } -libp2p-quic = { version = "0.9.2", path = "transports/quic" } +libp2p-quic = { version = "0.9.3", path = "transports/quic" } libp2p-relay = { version = "0.16.1", path = "protocols/relay" } libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } libp2p-upnp = { version = "0.1.1", path = "protocols/upnp" } diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index 5fd4313f..60ef7f82 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -1,10 +1,5 @@ -# Changelog -All notable changes to this project will be documented in this file. +## 0.12.3 -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), -and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - -## [0.12.3] ### Changed - Add libp2p-lookup to Dockerfile to enable healthchecks. @@ -16,14 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [PR 4467]: https://github.com/libp2p/rust-libp2p/pull/4467 -## [0.12.2] +## 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] +## 0.12.1 ### Changed - Move to tokio and hyper. See [PR 4311]. @@ -32,40 +27,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [PR 4311]: https://github.com/libp2p/rust-libp2p/pull/4311 -## [0.8.0] +## 0.8.0 ### Changed - Remove mplex support. -## [0.7.0] +## 0.7.0 ### Changed - Update to libp2p v0.47.0. -## [0.6.0] - [2022-05-05] +## 0.6.0 - 2022-05-05 ### Changed - Update to libp2p v0.44.0. -## [0.5.4] - [2022-01-11] +## 0.5.4 - 2022-01-11 ### Changed - Pull latest autonat changes. -## [0.5.3] - [2021-12-25] +## 0.5.3 - 2021-12-25 ### Changed - Update dependencies. - Pull in autonat fixes. -## [0.5.2] - [2021-12-20] +## 0.5.2 - 2021-12-20 ### Added - Add support for libp2p autonat protocol via `--enable-autonat`. -## [0.5.1] - [2021-12-20] +## 0.5.1 - 2021-12-20 ### Fixed - Update dependencies. - Fix typo in command line flag `--enable-kademlia`. -## [0.5.0] - 2021-11-18 +## 0.5.0 - 2021-11-18 ### Changed - Disable Kademlia protocol by default. -## [0.4.0] - 2021-11-18 +## 0.4.0 - 2021-11-18 ### Fixed - Update dependencies. diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 57c24067..39d025e8 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-quic" -version = "0.9.2" +version = "0.9.3" authors = ["Parity Technologies "] edition = "2021" rust-version = { workspace = true } diff --git a/transports/websocket-websys/CHANGELOG.md b/transports/websocket-websys/CHANGELOG.md index 22728548..1eb27b83 100644 --- a/transports/websocket-websys/CHANGELOG.md +++ b/transports/websocket-websys/CHANGELOG.md @@ -1,7 +1,7 @@ -# 0.2.0 - unreleased +## 0.2.0 - unreleased - Add Websys Websocket transport. -# 0.1.0 +## 0.1.0 - Crate claimed. From 7947a9fdedd2fe01f31269d79203889c7416963f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 04:47:56 +0000 Subject: [PATCH 05/10] deps: bump serde from 1.0.188 to 1.0.189 Pull-Request: #4637. --- Cargo.lock | 8 ++++---- misc/keygen/Cargo.toml | 2 +- misc/server/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ef31ddd9..eb91ba88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5013,18 +5013,18 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e" +checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.188" +version = "1.0.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2" +checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5" dependencies = [ "proc-macro2", "quote", diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index da3e4a14..4ef663c4 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -12,7 +12,7 @@ publish = false [dependencies] clap = { version = "4.3.23", features = ["derive"] } zeroize = "1" -serde = { version = "1.0.188", features = ["derive"] } +serde = { version = "1.0.189", features = ["derive"] } serde_json = "1.0.107" libp2p-core = { workspace = true } base64 = "0.21.4" diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index e0d7af3a..a0e3883f 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -20,7 +20,7 @@ hyper = { version = "0.14", features = ["server", "tcp", "http1"] } libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] } log = "0.4" prometheus-client = "0.21.2" -serde = "1.0.188" +serde = "1.0.189" serde_derive = "1.0.125" serde_json = "1.0" tokio = { version = "1", features = ["rt-multi-thread", "macros"] } From 6aa805d581981adf4fe9c910fc4b2bb9e3a5ed04 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 13 Oct 2023 16:23:11 +1100 Subject: [PATCH 06/10] refactor: make debug-print of `StreamProtocol` more concise The` fmt::Debug` implementation of a type should in most cases reveal its internal structure. `StreamProtocol` is likely to be debug-printed a lot and in many cases, the only contract is the `fmt::Debug` impl. The internals of `StreamProtocol` only exist for performance reasons to avoid allocations for statically-known protocol strings. Revealing this implementation detail isn't particularly beneficial to end users. At the same time, the current implementation is very noise. Previously, the `protocols` field of an `identify::Info` would e.g. read as: ``` protocols: [StreamProtocol { inner: Right("/ipfs/id/1.0.0") }, StreamProtocol { inner: Right("/ipfs/id/push/1.0.0") }, StreamProtocol { inner: Right("/ipfs/kad/1.0.0") }] ``` With this patch, it reads as: ``` protocols: ["/ipfs/id/1.0.0", "/ipfs/kad/1.0.0", "/ipfs/id/push/1.0.0"] ``` Pull-Request: #4631. --- swarm/CHANGELOG.md | 2 ++ swarm/src/stream_protocol.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index d0567f7d..3e4ccd00 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -4,6 +4,8 @@ Most users should use `libp2p::SwarmBuilder`. In some special cases, users may need to use `Swarm::new` and `Config` instead of the new `libp2p::SwarmBuilder`. See [PR 4120]. +- Make the `Debug` implementation of `StreamProtocol` more concise. + See [PR 4631](https://github.com/libp2p/rust-libp2p/pull/4631). [PR 4120]: https://github.com/libp2p/rust-libp2p/pull/4120 diff --git a/swarm/src/stream_protocol.rs b/swarm/src/stream_protocol.rs index bce0ec51..f746429a 100644 --- a/swarm/src/stream_protocol.rs +++ b/swarm/src/stream_protocol.rs @@ -7,7 +7,7 @@ use std::sync::Arc; /// /// libp2p nodes use stream protocols to negotiate what to do with a newly opened stream. /// Stream protocols are string-based and must start with a forward slash: `/`. -#[derive(Debug, Clone, Eq)] +#[derive(Clone, Eq)] pub struct StreamProtocol { inner: Either<&'static str, Arc>, } @@ -50,6 +50,12 @@ impl AsRef for StreamProtocol { } } +impl fmt::Debug for StreamProtocol { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + either::for_both!(&self.inner, s => s.fmt(f)) + } +} + impl fmt::Display for StreamProtocol { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.inner.fmt(f) @@ -102,3 +108,25 @@ impl fmt::Display for InvalidProtocol { } impl std::error::Error for InvalidProtocol {} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn stream_protocol_print() { + let protocol = StreamProtocol::new("/foo/bar/1.0.0"); + + let debug = format!("{protocol:?}"); + let display = format!("{protocol}"); + + assert_eq!( + debug, r#""/foo/bar/1.0.0""#, + "protocol to debug print as string with quotes" + ); + assert_eq!( + display, "/foo/bar/1.0.0", + "protocol to display print as string without quotes" + ); + } +} From d6351eead789780fde725a3ca0a355880c4988c6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 13 Oct 2023 06:10:06 +0000 Subject: [PATCH 07/10] deps: bump if-watch from 3.0.1 to 3.1.0 Pull-Request: #4635. --- Cargo.lock | 96 ++++++++++++++---------------------- protocols/mdns/Cargo.toml | 2 +- transports/quic/Cargo.toml | 2 +- transports/tcp/Cargo.toml | 2 +- transports/webrtc/Cargo.toml | 2 +- 5 files changed, 40 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index eb91ba88..7b1defce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2094,9 +2094,9 @@ dependencies = [ [[package]] name = "if-watch" -version = "3.0.1" +version = "3.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9465340214b296cd17a0009acdb890d6160010b8adf8f78a00d0d7ab270f79f" +checksum = "bbb892e5777fe09e16f3d44de7802f4daa7267ecbe8c466f19d94e25bb0c303e" dependencies = [ "async-io", "core-foundation", @@ -6469,15 +6469,21 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows" -version = "0.34.0" +version = "0.51.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45296b64204227616fdbf2614cefa4c236b98ee64dfaaaa435207ed99fe7829f" +checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9" dependencies = [ - "windows_aarch64_msvc 0.34.0", - "windows_i686_gnu 0.34.0", - "windows_i686_msvc 0.34.0", - "windows_x86_64_gnu 0.34.0", - "windows_x86_64_msvc 0.34.0", + "windows-core", + "windows-targets", +] + +[[package]] +name = "windows-core" +version = "0.51.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64" +dependencies = [ + "windows-targets", ] [[package]] @@ -6491,90 +6497,60 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.48.1" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.48.0", + "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_msvc" -version = "0.34.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cffbe740121affb56fad0fc0e421804adf0ae00891205213b5cecd30db881d" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_i686_gnu" -version = "0.34.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2564fde759adb79129d9b4f54be42b32c89970c18ebf93124ca8870a498688ed" - -[[package]] -name = "windows_i686_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_msvc" -version = "0.34.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cd9d32ba70453522332c14d38814bceeb747d80b3958676007acadd7e166956" - -[[package]] -name = "windows_i686_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_x86_64_gnu" -version = "0.34.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cfce6deae227ee8d356d19effc141a509cc503dfd1f850622ec4b0f84428e1f4" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_msvc" -version = "0.34.0" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d19538ccc21819d01deaf88d6a17eae6596a12e9aafdbb97916fb49896d89de9" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "winreg" diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 74530d41..7ddf4e3e 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] async-io = { version = "1.13.0", optional = true } data-encoding = "2.4.0" futures = "0.3.28" -if-watch = "3.0.1" +if-watch = "3.1.0" libp2p-core = { workspace = true } libp2p-swarm = { workspace = true } libp2p-identity = { workspace = true } diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 39d025e8..b7d3537e 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -13,7 +13,7 @@ async-std = { version = "1.12.0", optional = true } bytes = "1.5.0" futures = "0.3.28" futures-timer = "3.0.2" -if-watch = "3.0.1" +if-watch = "3.1.0" libp2p-core = { workspace = true } libp2p-tls = { workspace = true } libp2p-identity = { workspace = true } diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index a0097440..0b475ce3 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -14,7 +14,7 @@ categories = ["network-programming", "asynchronous"] async-io = { version = "1.13.0", optional = true } futures = "0.3.28" futures-timer = "3.0" -if-watch = "3.0.1" +if-watch = "3.1.0" libc = "0.2.149" libp2p-core = { workspace = true } libp2p-identity = { workspace = true } diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index b9b181a5..641a966b 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -16,7 +16,7 @@ bytes = "1" futures = "0.3" futures-timer = "3" hex = "0.4" -if-watch = "3.0" +if-watch = "3.1" libp2p-core = { workspace = true } libp2p-noise = { workspace = true } libp2p-identity = { workspace = true } From 50a7ffe11931444b060101bca5cdd8d1e6a28bd8 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 13 Oct 2023 19:00:02 +1100 Subject: [PATCH 08/10] refactor(kad): delete unused code We have a fair bit of unused code in `libp2p-kad` that was ignored because we had `#[allow(dead_code)]` at the top of the crate. Pull-Request: #4633. --- protocols/kad/src/jobs.rs | 6 ++++ protocols/kad/src/kbucket/bucket.rs | 17 ++--------- protocols/kad/src/kbucket/entry.rs | 29 ------------------- protocols/kad/src/lib.rs | 3 -- protocols/kad/src/query.rs | 9 ------ protocols/kad/src/query/peers/closest.rs | 1 + .../kad/src/query/peers/closest/disjoint.rs | 7 +---- protocols/kad/src/query/peers/fixed.rs | 4 --- 8 files changed, 11 insertions(+), 65 deletions(-) diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index af070760..e65dcd40 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -87,6 +87,7 @@ struct PeriodicJob { } impl PeriodicJob { + #[cfg(test)] fn is_running(&self) -> bool { match self.state { PeriodicJobState::Running(..) => true, @@ -96,6 +97,7 @@ impl PeriodicJob { /// Cuts short the remaining delay, if the job is currently waiting /// for the delay to expire. + #[cfg(test)] fn asap(&mut self) { if let PeriodicJobState::Waiting(delay, deadline) = &mut self.state { let new_deadline = Instant::now().checked_sub(Duration::from_secs(1)).unwrap(); @@ -169,6 +171,7 @@ impl PutRecordJob { } /// Checks whether the job is currently running. + #[cfg(test)] pub(crate) fn is_running(&self) -> bool { self.inner.is_running() } @@ -177,6 +180,7 @@ impl PutRecordJob { /// for the delay to expire. /// /// The job is guaranteed to run on the next invocation of `poll`. + #[cfg(test)] pub(crate) fn asap(&mut self, publish: bool) { if publish { self.next_publish = Some(Instant::now().checked_sub(Duration::from_secs(1)).unwrap()) @@ -273,6 +277,7 @@ impl AddProviderJob { } /// Checks whether the job is currently running. + #[cfg(test)] pub(crate) fn is_running(&self) -> bool { self.inner.is_running() } @@ -281,6 +286,7 @@ impl AddProviderJob { /// for the delay to expire. /// /// The job is guaranteed to run on the next invocation of `poll`. + #[cfg(test)] pub(crate) fn asap(&mut self) { self.inner.asap() } diff --git a/protocols/kad/src/kbucket/bucket.rs b/protocols/kad/src/kbucket/bucket.rs index bd0c5903..d7016191 100644 --- a/protocols/kad/src/kbucket/bucket.rs +++ b/protocols/kad/src/kbucket/bucket.rs @@ -54,10 +54,6 @@ pub enum NodeStatus { } impl PendingNode { - pub(crate) fn key(&self) -> &TKey { - &self.node.key - } - pub(crate) fn status(&self) -> NodeStatus { self.status } @@ -70,6 +66,7 @@ impl PendingNode { Instant::now() >= self.replace } + #[cfg(test)] pub(crate) fn set_ready_at(&mut self, t: Instant) { self.replace = t; } @@ -191,11 +188,6 @@ where .filter(|p| p.node.key.as_ref() == key.as_ref()) } - /// Returns a reference to a node in the bucket. - pub(crate) fn get(&self, key: &TKey) -> Option<&Node> { - self.position(key).map(|p| &self.nodes[p.0]) - } - /// Returns an iterator over the nodes in the bucket, together with their status. pub(crate) fn iter(&self) -> impl Iterator, NodeStatus)> { self.nodes @@ -398,22 +390,19 @@ where } } - /// Checks whether the given position refers to a connected node. - pub(crate) fn is_connected(&self, pos: Position) -> bool { - self.status(pos) == NodeStatus::Connected - } - /// Gets the number of entries currently in the bucket. pub(crate) fn num_entries(&self) -> usize { self.nodes.len() } /// Gets the number of entries in the bucket that are considered connected. + #[cfg(test)] pub(crate) fn num_connected(&self) -> usize { self.first_connected_pos.map_or(0, |i| self.nodes.len() - i) } /// Gets the number of entries in the bucket that are considered disconnected. + #[cfg(test)] pub(crate) fn num_disconnected(&self) -> usize { self.nodes.len() - self.num_connected() } diff --git a/protocols/kad/src/kbucket/entry.rs b/protocols/kad/src/kbucket/entry.rs index 0794ace4..c38aac4a 100644 --- a/protocols/kad/src/kbucket/entry.rs +++ b/protocols/kad/src/kbucket/entry.rs @@ -135,20 +135,6 @@ where } } - /// Returns the key of the entry. - /// - /// Returns `None` if the `Key` used to construct this `Entry` is not a valid - /// key for an entry in a bucket, which is the case for the `local_key` of - /// the `KBucketsTable` referring to the local node. - pub(crate) fn key(&self) -> Option<&TKey> { - match self { - Entry::Present(entry, _) => Some(entry.key()), - Entry::Pending(entry, _) => Some(entry.key()), - Entry::Absent(entry) => Some(entry.key()), - Entry::SelfEntry => None, - } - } - /// Returns the value associated with the entry. /// /// Returns `None` if the entry is absent from any bucket or refers to the @@ -175,11 +161,6 @@ where PresentEntry(EntryRef { bucket, key }) } - /// Returns the key of the entry. - pub(crate) fn key(&self) -> &TKey { - self.0.key - } - /// Returns the value associated with the key. pub(crate) fn value(&mut self) -> &mut TVal { &mut self @@ -218,11 +199,6 @@ where PendingEntry(EntryRef { bucket, key }) } - /// Returns the key of the entry. - pub(crate) fn key(&self) -> &TKey { - self.0.key - } - /// Returns the value associated with the key. pub(crate) fn value(&mut self) -> &mut TVal { self.0 @@ -262,11 +238,6 @@ where AbsentEntry(EntryRef { bucket, key }) } - /// Returns the key of the entry. - pub(crate) fn key(&self) -> &TKey { - self.0.key - } - /// Attempts to insert the entry into a bucket. pub(crate) fn insert(self, value: TVal, status: NodeStatus) -> InsertResult { self.0.bucket.insert( diff --git a/protocols/kad/src/lib.rs b/protocols/kad/src/lib.rs index dd9f7f56..4f1c7f0f 100644 --- a/protocols/kad/src/lib.rs +++ b/protocols/kad/src/lib.rs @@ -33,9 +33,6 @@ //! existing nodes in the kademlia network cannot obtain the listen addresses //! of nodes querying them, and thus will not be able to add them to their routing table. -// TODO: we allow dead_code for now because this library contains a lot of unused code that will -// be useful later for record store -#![allow(dead_code)] #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] mod record_priv; diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index 6cc15861..20faff77 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -326,15 +326,6 @@ impl Query { } } - /// Checks whether the query is currently waiting for a result from `peer`. - pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool { - match &self.peer_iter { - QueryPeerIter::Closest(iter) => iter.is_waiting(peer), - QueryPeerIter::ClosestDisjoint(iter) => iter.is_waiting(peer), - QueryPeerIter::Fixed(iter) => iter.is_waiting(peer), - } - } - /// Advances the state of the underlying peer iterator. fn next(&mut self, now: Instant) -> PeersIterState<'_> { let state = match &mut self.peer_iter { diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index a9011803..01155b7f 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -788,6 +788,7 @@ mod tests { QuickCheck::new().tests(10).quickcheck(prop as fn(_)) } + #[test] fn stalled_at_capacity() { fn prop(mut iter: ClosestPeersIter) { iter.state = State::Stalled; diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 3906b65b..151e26f6 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -31,7 +31,6 @@ use std::{ /// Wraps around a set of [`ClosestPeersIter`], enforcing a disjoint discovery /// path per configured parallelism according to the S/Kademlia paper. pub(crate) struct ClosestDisjointPeersIter { - config: ClosestPeersIterConfig, target: KeyBytes, /// The set of wrapped [`ClosestPeersIter`]. @@ -51,6 +50,7 @@ pub(crate) struct ClosestDisjointPeersIter { impl ClosestDisjointPeersIter { /// Creates a new iterator with a default configuration. + #[cfg(test)] pub(crate) fn new(target: KeyBytes, known_closest_peers: I) -> Self where I: IntoIterator>, @@ -88,7 +88,6 @@ impl ClosestDisjointPeersIter { let iters_len = iters.len(); ClosestDisjointPeersIter { - config, target: target.into(), iters, iter_order: (0..iters_len) @@ -190,10 +189,6 @@ impl ClosestDisjointPeersIter { updated } - pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool { - self.iters.iter().any(|i| i.is_waiting(peer)) - } - pub(crate) fn next(&mut self, now: Instant) -> PeersIterState<'_> { let mut state = None; diff --git a/protocols/kad/src/query/peers/fixed.rs b/protocols/kad/src/query/peers/fixed.rs index 1169feee..50a96938 100644 --- a/protocols/kad/src/query/peers/fixed.rs +++ b/protocols/kad/src/query/peers/fixed.rs @@ -115,10 +115,6 @@ impl FixedPeersIter { false } - pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool { - self.peers.get(peer) == Some(&PeerState::Waiting) - } - pub(crate) fn finish(&mut self) { if let State::Waiting { .. } = self.state { self.state = State::Finished From 56cb08a9b05e0fdb89404cb60b2453f6968b2836 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 13 Oct 2023 19:10:33 +1100 Subject: [PATCH 09/10] fix(quic): delete flaky `dial_failure` test This test is sometimes flaky. Instead of fixing it, I am proposing to delete it because it doesn't test anything meaningful. Dialing a non-existent transport should fail? Yes probably. Should we test that dropping a value destroys the relevant tasks? I don't think so. That is covered by Rust's ownership rules. Pull-Request: #4640. --- transports/quic/tests/smoke.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 5581ceb7..f72a6494 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -39,24 +39,6 @@ async fn async_std_smoke() { smoke::().await } -#[cfg(feature = "async-std")] -#[async_std::test] -async fn dial_failure() { - let _ = env_logger::try_init(); - let mut a = create_default_transport::().1; - let mut b = create_default_transport::().1; - - let addr = start_listening(&mut a, "/ip4/127.0.0.1/udp/0/quic-v1").await; - drop(a); // stop a so b can never reach it - - match dial(&mut b, addr).await { - Ok(_) => panic!("Expected dial to fail"), - Err(error) => { - assert_eq!("Handshake with the remote timed out.", error.to_string()) - } - }; -} - #[cfg(feature = "tokio")] #[tokio::test] async fn endpoint_reuse() { From 74c087dcefe9e7c6893b0833417bcb61c39da413 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Fri, 13 Oct 2023 14:17:10 +0200 Subject: [PATCH 10/10] fix(libp2p): add shortcut `with_tcp(...).with_bandwidth_logging()` Add the shortcut method `.with_bandwidth_logging` to `SwarmBuilder<_, QuicPhase<_>>`, thus allowing `with_tcp(...).with_bandwidth_logging()`. Pull-Request: #4626. --- libp2p/src/builder.rs | 57 ++++++++++++++++++++++++++++++-- libp2p/src/builder/phase/quic.rs | 20 ++++++++++- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/libp2p/src/builder.rs b/libp2p/src/builder.rs index 1b07689d..83541378 100644 --- a/libp2p/src/builder.rs +++ b/libp2p/src/builder.rs @@ -66,6 +66,8 @@ pub struct SwarmBuilder { #[cfg(test)] mod tests { use crate::SwarmBuilder; + use libp2p_core::{muxing::StreamMuxerBox, transport::dummy::DummyTransport}; + use libp2p_identity::PeerId; use libp2p_swarm::{NetworkBehaviour, Swarm}; #[test] @@ -228,9 +230,6 @@ mod tests { #[test] #[cfg(feature = "tokio")] fn other_transport() -> Result<(), Box> { - use libp2p_core::{muxing::StreamMuxerBox, transport::dummy::DummyTransport}; - use libp2p_identity::PeerId; - let _ = SwarmBuilder::with_new_identity() .with_tokio() // Closure can either return a Transport directly. @@ -319,4 +318,56 @@ mod tests { .unwrap() .build(); } + + #[test] + #[cfg(all(feature = "tokio", feature = "tcp", feature = "tls", feature = "yamux"))] + fn tcp_bandwidth_logging() -> Result<(), Box> { + let (builder, _logging) = SwarmBuilder::with_new_identity() + .with_tokio() + .with_tcp( + Default::default(), + libp2p_tls::Config::new, + libp2p_yamux::Config::default, + )? + .with_bandwidth_logging(); + + builder + .with_behaviour(|_| libp2p_swarm::dummy::Behaviour) + .unwrap() + .build(); + + Ok(()) + } + + #[test] + #[cfg(all(feature = "tokio", feature = "quic"))] + fn quic_bandwidth_logging() -> Result<(), Box> { + let (builder, _logging) = SwarmBuilder::with_new_identity() + .with_tokio() + .with_quic() + .with_bandwidth_logging(); + + builder + .with_behaviour(|_| libp2p_swarm::dummy::Behaviour) + .unwrap() + .build(); + + Ok(()) + } + + #[test] + #[cfg(feature = "tokio")] + fn other_transport_bandwidth_logging() -> Result<(), Box> { + let (builder, _logging) = SwarmBuilder::with_new_identity() + .with_tokio() + .with_other_transport(|_| DummyTransport::<(PeerId, StreamMuxerBox)>::new())? + .with_bandwidth_logging(); + + builder + .with_behaviour(|_| libp2p_swarm::dummy::Behaviour) + .unwrap() + .build(); + + Ok(()) + } } diff --git a/libp2p/src/builder/phase/quic.rs b/libp2p/src/builder/phase/quic.rs index 6ef056ae..e49b3b07 100644 --- a/libp2p/src/builder/phase/quic.rs +++ b/libp2p/src/builder/phase/quic.rs @@ -7,7 +7,7 @@ use libp2p_core::muxing::StreamMuxer; all(not(target_arch = "wasm32"), feature = "websocket") ))] use libp2p_core::{InboundUpgrade, Negotiated, OutboundUpgrade, UpgradeInfo}; -use std::marker::PhantomData; +use std::{marker::PhantomData, sync::Arc}; pub struct QuicPhase { pub(crate) transport: T, @@ -237,3 +237,21 @@ impl_quic_phase_with_websocket!( super::provider::Tokio, rw_stream_sink::RwStreamSink> ); +impl SwarmBuilder> { + pub fn with_bandwidth_logging( + self, + ) -> ( + SwarmBuilder< + Provider, + BehaviourPhase, + >, + Arc, + ) { + self.without_quic() + .without_any_other_transports() + .without_dns() + .without_relay() + .without_websocket() + .with_bandwidth_logging() + } +}