From 5df321d8b90e6b025a7c052572bc802ca1c6a86a Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 19 Apr 2023 17:51:20 +0200 Subject: [PATCH 01/57] fix(allowblocklist): correctly remove `Peer` from sets Previously, we reinserted the `Peer` in the "undo" function which is obviously wrong. This patch fixes the behaviour to be correct and adds two regression tests. Pull-Request: #3789. --- Cargo.lock | 2 +- misc/allow-block-list/CHANGELOG.md | 7 +++++ misc/allow-block-list/Cargo.toml | 2 +- misc/allow-block-list/src/lib.rs | 43 ++++++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 27e08c402a4..690fb17998b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2269,7 +2269,7 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.1.0" +version = "0.1.1" dependencies = [ "async-std", "libp2p-core", diff --git a/misc/allow-block-list/CHANGELOG.md b/misc/allow-block-list/CHANGELOG.md index 951a5a3f138..52633fb6629 100644 --- a/misc/allow-block-list/CHANGELOG.md +++ b/misc/allow-block-list/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.1.1 - unreleased + +- Correctly unblock and disallow peer in `unblock_peer` and `disallow_peer` functions. + See [PR 3789]. + +[PR 3789]: https://github.com/libp2p/rust-libp2p/pull/3789 + ## 0.1.0 - Initial release. diff --git a/misc/allow-block-list/Cargo.toml b/misc/allow-block-list/Cargo.toml index 1d812ee2764..e65f93c53de 100644 --- a/misc/allow-block-list/Cargo.toml +++ b/misc/allow-block-list/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-allow-block-list" edition = "2021" rust-version = "1.62.0" description = "Allow/block list connection management for libp2p." -version = "0.1.0" +version = "0.1.1" license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] diff --git a/misc/allow-block-list/src/lib.rs b/misc/allow-block-list/src/lib.rs index d43e2e890f1..d501ab73324 100644 --- a/misc/allow-block-list/src/lib.rs +++ b/misc/allow-block-list/src/lib.rs @@ -105,7 +105,7 @@ impl Behaviour { /// /// All active connections to this peer will be closed immediately. pub fn disallow_peer(&mut self, peer: PeerId) { - self.state.peers.insert(peer); + self.state.peers.remove(&peer); self.close_connections.push_back(peer); if let Some(waker) = self.waker.take() { waker.wake() @@ -127,7 +127,7 @@ impl Behaviour { /// Unblock connections to a given peer. pub fn unblock_peer(&mut self, peer: PeerId) { - self.state.peers.insert(peer); + self.state.peers.remove(&peer); if let Some(waker) = self.waker.take() { waker.wake() } @@ -297,6 +297,24 @@ mod tests { assert!(cause.downcast::().is_ok()); } + #[async_std::test] + async fn can_dial_unblocked_peer() { + let mut dialer = Swarm::new_ephemeral(|_| Behaviour::::new()); + let mut listener = Swarm::new_ephemeral(|_| Behaviour::::new()); + listener.listen().await; + + dialer + .behaviour_mut() + .list + .block_peer(*listener.local_peer_id()); + dialer + .behaviour_mut() + .list + .unblock_peer(*listener.local_peer_id()); + + dial(&mut dialer, &listener).unwrap(); + } + #[async_std::test] async fn blocked_peer_cannot_dial_us() { let mut dialer = Swarm::new_ephemeral(|_| Behaviour::::new()); @@ -362,6 +380,27 @@ mod tests { assert!(dial(&mut dialer, &listener).is_ok()); } + #[async_std::test] + async fn cannot_dial_disallowed_peer() { + let mut dialer = Swarm::new_ephemeral(|_| Behaviour::::new()); + let mut listener = Swarm::new_ephemeral(|_| Behaviour::::new()); + listener.listen().await; + + dialer + .behaviour_mut() + .list + .allow_peer(*listener.local_peer_id()); + dialer + .behaviour_mut() + .list + .disallow_peer(*listener.local_peer_id()); + + let DialError::Denied { cause } = dial(&mut dialer, &listener).unwrap_err() else { + panic!("unexpected dial error") + }; + assert!(cause.downcast::().is_ok()); + } + #[async_std::test] async fn not_allowed_peer_cannot_dial_us() { let mut dialer = Swarm::new_ephemeral(|_| Behaviour::::new()); From 0fe9791829150f0c6036b06f3357959d9845cd18 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 20 Apr 2023 00:07:42 +0200 Subject: [PATCH 02/57] feat(core): deprecate `upgrade::from_fn` This functionality isn't needed anywhere in `rust-libp2p` so we can deprecate and later remove it and thus reduce our API surface. Users relying on this function can vendor it. Pull-Request: #3747. --- Cargo.lock | 2 +- core/CHANGELOG.md | 8 ++++++++ core/Cargo.toml | 2 +- core/src/upgrade.rs | 3 ++- core/src/upgrade/from_fn.rs | 11 +++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 690fb17998b..ea9b4943d24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2319,7 +2319,7 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.39.1" +version = "0.39.2" dependencies = [ "async-std", "either", diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 5aefe3dda27..99dc371b595 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.39.2 - unreleased + +- Deprecate `upgrade::from_fn` without replacement as it is not used within `rust-libp2p`. + If you depend on it, we suggest you vendor it. + See [PR 3747]. + +[PR 3747]: https://github.com/libp2p/rust-libp2p/pull/3747 + ## 0.39.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/core/Cargo.toml b/core/Cargo.toml index 210f7c3569c..60fa51c904b 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-core" edition = "2021" rust-version = "1.60.0" description = "Core traits and structs of libp2p" -version = "0.39.1" +version = "0.39.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/core/src/upgrade.rs b/core/src/upgrade.rs index 62b3e278cf1..003590fd00c 100644 --- a/core/src/upgrade.rs +++ b/core/src/upgrade.rs @@ -71,11 +71,12 @@ mod transfer; use futures::future::Future; +#[allow(deprecated)] +pub use self::from_fn::{from_fn, FromFnUpgrade}; pub use self::{ apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, denied::DeniedUpgrade, error::UpgradeError, - from_fn::{from_fn, FromFnUpgrade}, map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr}, optional::OptionalUpgrade, pending::PendingUpgrade, diff --git a/core/src/upgrade/from_fn.rs b/core/src/upgrade/from_fn.rs index 97bbc2eb292..d6da7b6ed5a 100644 --- a/core/src/upgrade/from_fn.rs +++ b/core/src/upgrade/from_fn.rs @@ -35,6 +35,7 @@ use std::iter; /// # use libp2p_core::{upgrade, Negotiated}; /// # use std::io; /// # use futures::AsyncWriteExt; +/// # #[allow(deprecated)] /// let _transport = MemoryTransport::default() /// .and_then(move |out, cp| { /// upgrade::apply(out, upgrade::from_fn("/foo/1", move |mut sock: Negotiated>>, endpoint| async move { @@ -52,6 +53,10 @@ use std::iter; /// }); /// ``` /// +#[deprecated( + note = "`from_fn` upgrade will be removed without replacement as it is not used within `rust-libp2p`." +)] +#[allow(deprecated)] pub fn from_fn(protocol_name: P, fun: F) -> FromFnUpgrade where // Note: these bounds are there in order to help the compiler infer types @@ -66,11 +71,15 @@ where /// /// The upgrade consists in calling the function passed when creating this struct. #[derive(Debug, Clone)] +#[deprecated( + note = "`from_fn` upgrade will be removed without replacement as it is not used within `rust-libp2p`." +)] pub struct FromFnUpgrade { protocol_name: P, fun: F, } +#[allow(deprecated)] impl UpgradeInfo for FromFnUpgrade where P: ProtocolName + Clone, @@ -83,6 +92,7 @@ where } } +#[allow(deprecated)] impl InboundUpgrade for FromFnUpgrade where P: ProtocolName + Clone, @@ -98,6 +108,7 @@ where } } +#[allow(deprecated)] impl OutboundUpgrade for FromFnUpgrade where P: ProtocolName + Clone, From 28da3d41800fadbe161975ddb06ab8f3f8108dfa Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 21 Apr 2023 11:58:08 +0200 Subject: [PATCH 03/57] fix(ci): ensure all examples compile with the specified feature-set Due to cargo's feature unification, a full build of our workspace doesn't actually check whether the examples compile as standalone projects. We add a new CI check that iterates through all crates in the `examples/` directory and runs a plain `cargo check` on them. Any failure is bubbled up via `set -e`, thus failing CI in case one of the `cargo check` commands fails. To fix the current failures, we construct a simple TCP transport everywhere where we were previously using `development_transport`. That is because `development_transport` requires `mplex` which is now deprecated. Related #3657. Related #3809. Pull-Request: #3811. --- .github/workflows/ci.yml | 22 +++++++++++++++++++ examples/autonat/src/bin/autonat_client.rs | 2 +- examples/autonat/src/bin/autonat_server.rs | 2 +- examples/chat-example/src/main.rs | 2 +- examples/dcutr/src/main.rs | 2 +- .../distributed-key-value-store/src/main.rs | 12 ++++++---- examples/file-sharing/src/network.rs | 12 ++++++++-- examples/identify/src/main.rs | 2 +- examples/ipfs-private/src/main.rs | 2 +- examples/metrics/src/main.rs | 2 +- examples/ping-example/src/main.rs | 11 +++++++--- examples/relay-server/src/main.rs | 2 +- examples/rendezvous/src/bin/rzv-discover.rs | 2 +- examples/rendezvous/src/bin/rzv-identify.rs | 2 +- examples/rendezvous/src/bin/rzv-register.rs | 2 +- examples/rendezvous/src/main.rs | 2 +- 16 files changed, 60 insertions(+), 21 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 388b80135f5..3ec0bb8eae0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -195,6 +195,28 @@ jobs: - name: Run ipfs-kad example run: cd ./examples/ipfs-kad/ && RUST_LOG=libp2p_swarm=debug,libp2p_kad=trace,libp2p_tcp=debug cargo run + examples: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: dtolnay/rust-toolchain@stable + + - uses: r7kamura/rust-problem-matchers@d58b70c4a13c4866d96436315da451d8106f8f08 #v1.3.0 + + - uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1 + with: + shared-key: stable-cache + save-if: false + + - name: Compile all examples + run: | + set -e; + + for toml in examples/**/Cargo.toml; do + cargo check --manifest-path "$toml"; + done + rustfmt: runs-on: ubuntu-latest steps: diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index e934e76e521..32ecc9aca67 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -63,7 +63,7 @@ async fn main() -> Result<(), Box> { println!("Local peer id: {local_peer_id:?}"); let transport = tcp::async_io::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index 7189420e467..e3ad9665e30 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -52,7 +52,7 @@ async fn main() -> Result<(), Box> { println!("Local peer id: {local_peer_id:?}"); let transport = tcp::async_io::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/chat-example/src/main.rs b/examples/chat-example/src/main.rs index 4b0ffed478a..368d270a371 100644 --- a/examples/chat-example/src/main.rs +++ b/examples/chat-example/src/main.rs @@ -76,7 +76,7 @@ async fn main() -> Result<(), Box> { // Set up an encrypted DNS-enabled TCP Transport over the Mplex protocol. let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)) - .upgrade(upgrade::Version::V1) + .upgrade(upgrade::Version::V1Lazy) .authenticate( noise::NoiseAuthenticated::xx(&id_keys).expect("signing libp2p-noise static keypair"), ) diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index e7dd716723f..1cafa2411a0 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -96,7 +96,7 @@ fn main() -> Result<(), Box> { ))) .unwrap(), ) - .upgrade(upgrade::Version::V1) + .upgrade(upgrade::Version::V1Lazy) .authenticate( noise::NoiseAuthenticated::xx(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 9e8779b2dd1..404062199cc 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -42,15 +42,16 @@ use async_std::io; use futures::{prelude::*, select}; +use libp2p::core::upgrade::Version; use libp2p::kad::record::store::MemoryStore; use libp2p::kad::{ record::Key, AddProviderOk, GetProvidersOk, GetRecordOk, Kademlia, KademliaEvent, PeerRecord, PutRecordOk, QueryResult, Quorum, Record, }; use libp2p::{ - development_transport, identity, mdns, + identity, mdns, noise, swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}, - PeerId, + tcp, yamux, PeerId, Transport, }; use std::error::Error; @@ -62,8 +63,11 @@ async fn main() -> Result<(), Box> { let local_key = identity::Keypair::generate_ed25519(); let local_peer_id = PeerId::from(local_key.public()); - // Set up a an encrypted DNS-enabled TCP Transport over the Mplex protocol. - let transport = development_transport(local_key).await?; + let transport = tcp::async_io::Transport::default() + .upgrade(Version::V1Lazy) + .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .multiplex(yamux::YamuxConfig::default()) + .boxed(); // We create a custom network behaviour that combines Kademlia and mDNS. #[derive(NetworkBehaviour)] diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index f21ff95276d..0f9ff32863e 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -14,11 +14,13 @@ use libp2p::{ record::store::MemoryStore, GetProvidersOk, Kademlia, KademliaEvent, QueryId, QueryResult, }, multiaddr::Protocol, + noise, request_response::{self, ProtocolSupport, RequestId, ResponseChannel}, swarm::{ConnectionHandlerUpgrErr, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent}, - PeerId, + tcp, yamux, PeerId, Transport, }; +use libp2p::core::upgrade::Version; use std::collections::{hash_map, HashMap, HashSet}; use std::error::Error; use std::iter; @@ -45,10 +47,16 @@ pub async fn new( }; let peer_id = id_keys.public().to_peer_id(); + let transport = tcp::async_io::Transport::default() + .upgrade(Version::V1Lazy) + .authenticate(noise::NoiseAuthenticated::xx(&id_keys)?) + .multiplex(yamux::YamuxConfig::default()) + .boxed(); + // Build the Swarm, connecting the lower layer transport logic with the // higher layer network behaviour logic. let swarm = SwarmBuilder::with_async_std_executor( - libp2p::development_transport(id_keys).await?, + transport, ComposedBehaviour { kademlia: Kademlia::new(peer_id, MemoryStore::new(peer_id)), request_response: request_response::Behaviour::new( diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index c20dfa5783a..7159be53b66 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -52,7 +52,7 @@ async fn main() -> Result<(), Box> { println!("Local peer id: {local_peer_id:?}"); let transport = tcp::async_io::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index fac77206af6..fadc6cfd06f 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -63,7 +63,7 @@ pub fn build_transport( None => Either::Right(base_transport), }; maybe_encrypted - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise_config) .multiplex(yamux_config) .timeout(Duration::from_secs(20)) diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 789b53419d1..7eda36d9715 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -73,7 +73,7 @@ fn main() -> Result<(), Box> { let mut swarm = SwarmBuilder::without_executor( tcp::async_io::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(), diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index 242f95924aa..3cb0aa69ae3 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -41,10 +41,11 @@ //! and begin pinging each other. use futures::prelude::*; +use libp2p::core::upgrade::Version; use libp2p::{ - identity, ping, + identity, noise, ping, swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent}, - Multiaddr, PeerId, + tcp, yamux, Multiaddr, PeerId, Transport, }; use std::error::Error; @@ -54,7 +55,11 @@ async fn main() -> Result<(), Box> { let local_peer_id = PeerId::from(local_key.public()); println!("Local peer id: {local_peer_id:?}"); - let transport = libp2p::development_transport(local_key).await?; + let transport = tcp::async_io::Transport::default() + .upgrade(Version::V1Lazy) + .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .multiplex(yamux::YamuxConfig::default()) + .boxed(); let mut swarm = SwarmBuilder::with_async_std_executor(transport, Behaviour::default(), local_peer_id) diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index 583b6695708..3484d236986 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -49,7 +49,7 @@ fn main() -> Result<(), Box> { let tcp_transport = tcp::async_io::Transport::default(); let transport = tcp_transport - .upgrade(upgrade::Version::V1) + .upgrade(upgrade::Version::V1Lazy) .authenticate( noise::NoiseAuthenticated::xx(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index e4ec21c3e74..2f31dc9d390 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -43,7 +43,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index 2f07daf6b32..bb5157fba78 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -39,7 +39,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index 4f93e4661e8..5429fb8efa1 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -39,7 +39,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index e731509f678..78e48cee7d4 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -53,7 +53,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() - .upgrade(Version::V1) + .upgrade(Version::V1Lazy) .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), From e6f9d49109d030dfa6b953b9318fe32ca47cccdc Mon Sep 17 00:00:00 2001 From: Doug A Date: Sat, 22 Apr 2023 07:16:58 -0300 Subject: [PATCH 04/57] fix(identity): add `From` & `Into` for public keys This patch removes the `version 0.2.0` for deprecations as libp2p-identity is only at `0.1.1` and this can be confusing to the reader. It also adds `impl From for PublicKey` (et al.) so that `PublicKey::from(ed25519::PublicKey)` works. Fixes https://github.com/libp2p/rust-libp2p/issues/3802. Pull-Request: #3805. --- identity/CHANGELOG.md | 5 +++ identity/src/keypair.rs | 91 ++++++++++++++++++++++++++++++++++------- 2 files changed, 82 insertions(+), 14 deletions(-) diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 5ab5cfc2528..50876f4c156 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -1,5 +1,10 @@ ## 0.1.2 - unreleased +- Add `impl From for PublicKey` so that `PublicKey::from(ed25519::PublicKey)` works. + See [PR 3805]. + +[PR 3805]: https://github.com/libp2p/rust-libp2p/pull/3805 + - Follow Rust naming conventions for conversion methods. See [PR 3775]. diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index a080fcfb690..6b76f5638de 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -110,7 +110,6 @@ impl Keypair { #[cfg(feature = "ed25519")] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_ed25519` instead." )] pub fn into_ed25519(self) -> Option { @@ -124,7 +123,6 @@ impl Keypair { #[cfg(feature = "secp256k1")] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_secp256k1` instead." )] pub fn into_secp256k1(self) -> Option { @@ -138,7 +136,6 @@ impl Keypair { #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_rsa` instead." )] pub fn into_rsa(self) -> Option { @@ -152,7 +149,6 @@ impl Keypair { #[cfg(feature = "ecdsa")] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `Keypair::try_into_ecdsa` instead." )] pub fn into_ecdsa(self) -> Option { @@ -396,7 +392,7 @@ pub enum PublicKey { #[cfg(feature = "ed25519")] #[deprecated( since = "0.1.0", - note = "This enum will be made opaque in the future, use `PublicKey::into_ed25519` instead." + note = "This enum will be made opaque in the future, use `PublicKey::from` and `PublicKey::into_ed25519` instead." )] Ed25519(ed25519::PublicKey), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] @@ -404,21 +400,21 @@ pub enum PublicKey { #[deprecated( since = "0.1.0", - note = "This enum will be made opaque in the future, use `PublicKey::into_rsa` instead." + note = "This enum will be made opaque in the future, use `PublicKey::from` and `PublicKey::into_rsa` instead." )] Rsa(rsa::PublicKey), #[cfg(feature = "secp256k1")] /// A public Secp256k1 key. #[deprecated( since = "0.1.0", - note = "This enum will be made opaque in the future, use `PublicKey::into_secp256k1` instead." + note = "This enum will be made opaque in the future, use `PublicKey::from` and `PublicKey::into_secp256k1` instead." )] Secp256k1(secp256k1::PublicKey), /// A public ECDSA key. #[cfg(feature = "ecdsa")] #[deprecated( since = "0.1.0", - note = "This enum will be made opaque in the future, use `PublicKey::into_ecdsa` instead." + note = "This enum will be made opaque in the future, use `PublicKey::from` and `PublicKey::into_ecdsa` instead." )] Ecdsa(ecdsa::PublicKey), } @@ -446,7 +442,6 @@ impl PublicKey { #[cfg(feature = "ed25519")] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_ed25519` instead." )] pub fn into_ed25519(self) -> Option { @@ -460,7 +455,6 @@ impl PublicKey { #[cfg(feature = "secp256k1")] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_secp256k1` instead." )] pub fn into_secp256k1(self) -> Option { @@ -474,7 +468,6 @@ impl PublicKey { #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_rsa` instead." )] pub fn into_rsa(self) -> Option { @@ -488,7 +481,6 @@ impl PublicKey { #[cfg(feature = "ecdsa")] #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `PublicKey::try_into_ecdsa` instead." )] pub fn into_ecdsa(self) -> Option { @@ -502,7 +494,7 @@ impl PublicKey { /// Encode the public key into a protobuf structure for storage or /// exchange with other nodes. - #[deprecated(since = "0.2.0", note = "Renamed to `PublicKey::encode_protobuf`.")] + #[deprecated(note = "Renamed to `PublicKey::encode_protobuf`.")] pub fn to_protobuf_encoding(&self) -> Vec { Self::encode_protobuf(self) } @@ -526,7 +518,6 @@ impl PublicKey { /// Decode a public key from a protobuf structure, e.g. read from storage /// or received from another node. #[deprecated( - since = "0.2.0", note = "This method name does not follow Rust naming conventions, use `PublicKey::try_decode_protobuf` instead." )] pub fn from_protobuf_encoding(bytes: &[u8]) -> Result { @@ -669,15 +660,49 @@ impl TryInto for PublicKey { } } +#[cfg(feature = "ed25519")] +impl From for PublicKey { + fn from(key: ed25519::PublicKey) -> Self { + #[allow(deprecated)] // TODO: Remove when PublicKey::Ed25519 is made opaque + PublicKey::Ed25519(key) + } +} + +#[cfg(feature = "secp256k1")] +impl From for PublicKey { + fn from(key: secp256k1::PublicKey) -> Self { + #[allow(deprecated)] // TODO: Remove when PublicKey::Secp256k1 is made opaque + PublicKey::Secp256k1(key) + } +} + +#[cfg(feature = "ecdsa")] +impl From for PublicKey { + fn from(key: ecdsa::PublicKey) -> Self { + #[allow(deprecated)] // TODO: Remove when PublicKey::Ecdsa is made opaque + PublicKey::Ecdsa(key) + } +} + +#[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] +impl From for PublicKey { + fn from(key: rsa::PublicKey) -> Self { + #[allow(deprecated)] // TODO: Remove when PublicKey::Rsa is made opaque + PublicKey::Rsa(key) + } +} + #[cfg(test)] mod tests { use super::*; + #[cfg(feature = "peerid")] use crate::PeerId; use base64::prelude::*; use std::str::FromStr; #[test] #[cfg(feature = "ed25519")] + #[cfg(feature = "peerid")] fn keypair_protobuf_roundtrip() { let expected_keypair = Keypair::generate_ed25519(); let expected_peer_id = expected_keypair.public().to_peer_id(); @@ -691,6 +716,7 @@ mod tests { } #[test] + #[cfg(feature = "peerid")] fn keypair_from_protobuf_encoding() { // E.g. retrieved from an IPFS config file. let base_64_encoded = "CAESQL6vdKQuznQosTrW7FWI9At+XX7EBf0BnZLhb6w+N+XSQSdfInl6c7U4NuxXJlhKcRBlBw9d0tj2dfBIVf6mcPA="; @@ -724,4 +750,41 @@ mod tests { assert_implements_ord::(); } + + #[test] + #[cfg(feature = "ed25519")] + fn test_publickey_from_ed25519_public_key() { + let pubkey = Keypair::generate_ed25519().public(); + let ed25519_pubkey = pubkey + .clone() + .try_into_ed25519() + .expect("A ed25519 keypair"); + + let converted_pubkey = PublicKey::from(ed25519_pubkey); + + assert_eq!(converted_pubkey, pubkey); + } + + #[test] + #[cfg(feature = "secp256k1")] + fn test_publickey_from_secp256k1_public_key() { + let pubkey = Keypair::generate_secp256k1().public(); + let secp256k1_pubkey = pubkey + .clone() + .try_into_secp256k1() + .expect("A secp256k1 keypair"); + let converted_pubkey = PublicKey::from(secp256k1_pubkey); + + assert_eq!(converted_pubkey, pubkey); + } + + #[test] + #[cfg(feature = "ecdsa")] + fn test_publickey_from_ecdsa_public_key() { + let pubkey = Keypair::generate_ecdsa().public(); + let ecdsa_pubkey = pubkey.clone().try_into_ecdsa().expect("A ecdsa keypair"); + let converted_pubkey = PublicKey::from(ecdsa_pubkey); + + assert_eq!(converted_pubkey, pubkey); + } } From 270d204db2877bb73462cb71810791aa877f26d3 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Sun, 23 Apr 2023 23:00:23 +0200 Subject: [PATCH 05/57] feat(gossipsub): make gossipsub modules private Resolves #3494. Pull-Request: #3777. --- Cargo.lock | 2 +- protocols/gossipsub/CHANGELOG.md | 6 ++ protocols/gossipsub/Cargo.toml | 2 +- protocols/gossipsub/src/behaviour.rs | 10 +-- protocols/gossipsub/src/behaviour/tests.rs | 2 +- protocols/gossipsub/src/config.rs | 2 +- protocols/gossipsub/src/handler.rs | 2 +- protocols/gossipsub/src/lib.rs | 46 +++++++++- .../src/{metrics.rs => metrics_priv.rs} | 0 protocols/gossipsub/src/peer_score.rs | 4 +- .../src/{protocol.rs => protocol_priv.rs} | 0 ..._filter.rs => subscription_filter_priv.rs} | 83 ++++++++----------- .../src/{time_cache.rs => time_cache_priv.rs} | 0 13 files changed, 95 insertions(+), 64 deletions(-) rename protocols/gossipsub/src/{metrics.rs => metrics_priv.rs} (100%) rename protocols/gossipsub/src/{protocol.rs => protocol_priv.rs} (100%) rename protocols/gossipsub/src/{subscription_filter.rs => subscription_filter_priv.rs} (89%) rename protocols/gossipsub/src/{time_cache.rs => time_cache_priv.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index ea9b4943d24..0bade7cd1fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2431,7 +2431,7 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.44.3" +version = "0.44.4" dependencies = [ "async-std", "asynchronous-codec", diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 3006727df17..fc63a305923 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.44.4 - unreleased + +- Deprecate `metrics`, `protocol`, `subscription_filter`, `time_cache` modules to make them private. See [PR 3777]. + +[PR 3777]: https://github.com/libp2p/rust-libp2p/pull/3777 + ## 0.44.3 - Fix erroneously duplicate message IDs. See [PR 3716]. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index d59e1375315..204ec47c856 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-gossipsub" edition = "2021" rust-version = "1.62.0" description = "Gossipsub protocol for libp2p" -version = "0.44.3" +version = "0.44.4" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index fb58e55f24a..9e06f448afa 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -50,11 +50,11 @@ use crate::config::{Config, ValidationMode}; use crate::gossip_promises::GossipPromises; use crate::handler::{Handler, HandlerEvent, HandlerIn}; use crate::mcache::MessageCache; -use crate::metrics::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty}; +use crate::metrics_priv::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty}; use crate::peer_score::{PeerScore, PeerScoreParams, PeerScoreThresholds, RejectReason}; -use crate::protocol::{ProtocolConfig, SIGNING_PREFIX}; -use crate::subscription_filter::{AllowAllSubscriptionFilter, TopicSubscriptionFilter}; -use crate::time_cache::{DuplicateCache, TimeCache}; +use crate::protocol_priv::{ProtocolConfig, SIGNING_PREFIX}; +use crate::subscription_filter_priv::{AllowAllSubscriptionFilter, TopicSubscriptionFilter}; +use crate::time_cache_priv::{DuplicateCache, TimeCache}; use crate::topic::{Hasher, Topic, TopicHash}; use crate::transform::{DataTransform, IdentityTransform}; use crate::types::{ @@ -3824,7 +3824,7 @@ mod local_test { let mut length_codec = unsigned_varint::codec::UviBytes::default(); length_codec.set_max_len(max_transmit_size); let mut codec = - crate::protocol::GossipsubCodec::new(length_codec, ValidationMode::Permissive); + crate::protocol_priv::GossipsubCodec::new(length_codec, ValidationMode::Permissive); let rpc_proto = rpc.into_protobuf(); let fragmented_messages = gs diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index bafceafe585..ca94e4ac15f 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -21,7 +21,7 @@ // Collection of tests for the gossipsub network behaviour use super::*; -use crate::subscription_filter::WhitelistSubscriptionFilter; +use crate::subscription_filter_priv::WhitelistSubscriptionFilter; use crate::transform::{DataTransform, IdentityTransform}; use crate::types::FastMessageId; use crate::ValidationError; diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index 1f0b23848d6..098a3eb7e0b 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -884,7 +884,7 @@ impl std::fmt::Debug for Config { #[cfg(test)] mod test { use super::*; - use crate::protocol::ProtocolConfig; + use crate::protocol_priv::ProtocolConfig; use crate::topic::IdentityHash; use crate::types::PeerKind; use crate::Topic; diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 609bb81a306..269bdcd404f 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::protocol::{GossipsubCodec, ProtocolConfig}; +use crate::protocol_priv::{GossipsubCodec, ProtocolConfig}; use crate::rpc_proto::proto; use crate::types::{PeerKind, RawMessage, Rpc}; use crate::ValidationError; diff --git a/protocols/gossipsub/src/lib.rs b/protocols/gossipsub/src/lib.rs index 4a1d63d93da..556cb904fdd 100644 --- a/protocols/gossipsub/src/lib.rs +++ b/protocols/gossipsub/src/lib.rs @@ -139,10 +139,42 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] pub mod error; -pub mod metrics; -pub mod protocol; -pub mod subscription_filter; -pub mod time_cache; + +mod metrics_priv; +#[deprecated( + note = "The `metrics` module will be made private in the future and should not be depended on." +)] +pub mod metrics { + pub use super::metrics_priv::*; +} + +mod protocol_priv; +#[deprecated( + note = "The `protocol` module will be made private in the future and should not be depended on." +)] +pub mod protocol { + pub use super::protocol_priv::*; +} + +mod subscription_filter_priv; +#[deprecated( + note = "The `subscription_filter` module will be made private in the future, import the types from the crate root instead." +)] +pub mod subscription_filter { + pub use super::subscription_filter_priv::*; + + pub mod regex { + pub use crate::subscription_filter_priv::RegexSubscriptionFilter; + } +} + +mod time_cache_priv; +#[deprecated( + note = "The `time_cache` module will be made private in the future and should not be depended on." +)] +pub mod time_cache { + pub use super::time_cache_priv::*; +} mod backoff; mod behaviour; @@ -164,10 +196,16 @@ pub type HandlerError = error_priv::HandlerError; pub use self::behaviour::{Behaviour, Event, MessageAuthenticity}; pub use self::config::{Config, ConfigBuilder, ValidationMode, Version}; pub use self::error_priv::{PublishError, SubscriptionError, ValidationError}; +pub use self::metrics_priv::Config as MetricsConfig; pub use self::peer_score::{ score_parameter_decay, score_parameter_decay_with_base, PeerScoreParams, PeerScoreThresholds, TopicScoreParams, }; +pub use self::subscription_filter_priv::{ + AllowAllSubscriptionFilter, CallbackSubscriptionFilter, CombinedSubscriptionFilters, + MaxCountSubscriptionFilter, RegexSubscriptionFilter, TopicSubscriptionFilter, + WhitelistSubscriptionFilter, +}; pub use self::topic::{Hasher, Topic, TopicHash}; pub use self::transform::{DataTransform, IdentityTransform}; pub use self::types::{FastMessageId, Message, MessageAcceptance, MessageId, RawMessage, Rpc}; diff --git a/protocols/gossipsub/src/metrics.rs b/protocols/gossipsub/src/metrics_priv.rs similarity index 100% rename from protocols/gossipsub/src/metrics.rs rename to protocols/gossipsub/src/metrics_priv.rs diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index acf37967d13..1270ad1274b 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -21,8 +21,8 @@ //! //! Manages and stores the Scoring logic of a particular peer on the gossipsub behaviour. -use crate::metrics::{Metrics, Penalty}; -use crate::time_cache::TimeCache; +use crate::metrics_priv::{Metrics, Penalty}; +use crate::time_cache_priv::TimeCache; use crate::{MessageId, TopicHash}; use libp2p_identity::PeerId; use log::{debug, trace, warn}; diff --git a/protocols/gossipsub/src/protocol.rs b/protocols/gossipsub/src/protocol_priv.rs similarity index 100% rename from protocols/gossipsub/src/protocol.rs rename to protocols/gossipsub/src/protocol_priv.rs diff --git a/protocols/gossipsub/src/subscription_filter.rs b/protocols/gossipsub/src/subscription_filter_priv.rs similarity index 89% rename from protocols/gossipsub/src/subscription_filter.rs rename to protocols/gossipsub/src/subscription_filter_priv.rs index f6b72e09c4e..8ec633d0717 100644 --- a/protocols/gossipsub/src/subscription_filter.rs +++ b/protocols/gossipsub/src/subscription_filter_priv.rs @@ -200,55 +200,12 @@ where } } -pub mod regex { - use super::TopicSubscriptionFilter; - use crate::TopicHash; - use regex::Regex; +///A subscription filter that filters topics based on a regular expression. +pub struct RegexSubscriptionFilter(pub regex::Regex); - ///A subscription filter that filters topics based on a regular expression. - pub struct RegexSubscriptionFilter(pub Regex); - - impl TopicSubscriptionFilter for RegexSubscriptionFilter { - fn can_subscribe(&mut self, topic_hash: &TopicHash) -> bool { - self.0.is_match(topic_hash.as_str()) - } - } - - #[cfg(test)] - mod test { - use super::*; - use crate::types::Subscription; - use crate::types::SubscriptionAction::*; - - #[test] - fn test_regex_subscription_filter() { - let t1 = TopicHash::from_raw("tt"); - let t2 = TopicHash::from_raw("et3t3te"); - let t3 = TopicHash::from_raw("abcdefghijklmnopqrsuvwxyz"); - - let mut filter = RegexSubscriptionFilter(Regex::new("t.*t").unwrap()); - - let old = Default::default(); - let subscriptions = vec![ - Subscription { - action: Subscribe, - topic_hash: t1, - }, - Subscription { - action: Subscribe, - topic_hash: t2, - }, - Subscription { - action: Subscribe, - topic_hash: t3, - }, - ]; - - let result = filter - .filter_incoming_subscriptions(&subscriptions, &old) - .unwrap(); - assert_eq!(result, subscriptions[..2].iter().collect()); - } +impl TopicSubscriptionFilter for RegexSubscriptionFilter { + fn can_subscribe(&mut self, topic_hash: &TopicHash) -> bool { + self.0.is_match(topic_hash.as_str()) } } @@ -447,4 +404,34 @@ mod test { .unwrap(); assert_eq!(result, vec![&subscriptions[0]].into_iter().collect()); } + + #[test] + fn test_regex_subscription_filter() { + let t1 = TopicHash::from_raw("tt"); + let t2 = TopicHash::from_raw("et3t3te"); + let t3 = TopicHash::from_raw("abcdefghijklmnopqrsuvwxyz"); + + let mut filter = RegexSubscriptionFilter(regex::Regex::new("t.*t").unwrap()); + + let old = Default::default(); + let subscriptions = vec![ + Subscription { + action: Subscribe, + topic_hash: t1, + }, + Subscription { + action: Subscribe, + topic_hash: t2, + }, + Subscription { + action: Subscribe, + topic_hash: t3, + }, + ]; + + let result = filter + .filter_incoming_subscriptions(&subscriptions, &old) + .unwrap(); + assert_eq!(result, subscriptions[..2].iter().collect()); + } } diff --git a/protocols/gossipsub/src/time_cache.rs b/protocols/gossipsub/src/time_cache_priv.rs similarity index 100% rename from protocols/gossipsub/src/time_cache.rs rename to protocols/gossipsub/src/time_cache_priv.rs From 1f508095dc9e789fdaea79047e242a316575ade5 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Mon, 24 Apr 2023 02:55:46 -0600 Subject: [PATCH 06/57] fix(kad): preserve deadline in keep alive logic Previous to this change if the ConnectionHandler::poll for kad was called more frequently than the connection idle timeout the timeout would continually be pushed further into the future. After this change kad now will preserve the existing idle deadline. Pull-Request: #3801. --- Cargo.lock | 2 +- protocols/kad/CHANGELOG.md | 7 +++++++ protocols/kad/Cargo.toml | 2 +- protocols/kad/src/handler_priv.rs | 15 +++++++++------ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0bade7cd1fc..68b4259b4ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2523,7 +2523,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.43.2" +version = "0.43.3" dependencies = [ "arrayvec", "asynchronous-codec", diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index e8498f084db..cb33d9d62ff 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.43.3 - unreleased + +- Preserve existing `KeepAlive::Until` timeout instead of continuously setting new `KeepAlive::Until(Instant::now() + self.config.idle_timeout)`. + See [PR 3801]. + +[PR 3801]: https://github.com/libp2p/rust-libp2p/pull/3801 + ## 0.43.2 - Export pub enum `RoutingUpdate`. See [PR 3739]. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index e3c8a4f5e0a..c555bf8b768 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition = "2021" rust-version = "1.65.0" description = "Kademlia protocol for libp2p" -version = "0.43.2" +version = "0.43.3" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/handler_priv.rs b/protocols/kad/src/handler_priv.rs index 7901b7e10a2..ed2d05219bd 100644 --- a/protocols/kad/src/handler_priv.rs +++ b/protocols/kad/src/handler_priv.rs @@ -757,12 +757,15 @@ where } } - if self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty() { - // We destroyed all substreams in this function. - self.keep_alive = KeepAlive::Until(Instant::now() + self.config.idle_timeout); - } else { - self.keep_alive = KeepAlive::Yes; - } + let no_streams = self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty(); + self.keep_alive = match (no_streams, self.keep_alive) { + // No open streams. Preserve the existing idle timeout. + (true, k @ KeepAlive::Until(_)) => k, + // No open streams. Set idle timeout. + (true, _) => KeepAlive::Until(Instant::now() + self.config.idle_timeout), + // Keep alive for open streams. + (false, _) => KeepAlive::Yes, + }; Poll::Pending } From b4bfaacd056a8478f2596f8929742ca3232af329 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:23:39 +0000 Subject: [PATCH 07/57] deps: bump regex from 1.7.3 to 1.8.1 Pull-Request: #3816. --- Cargo.lock | 12 ++++++------ protocols/gossipsub/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 68b4259b4ff..1dd83458091 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -111,9 +111,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "67fc08ce920c31afb70f013dcce1bfc3a3195de6a228474e45e1f145b36f8d04" dependencies = [ "memchr", ] @@ -4089,9 +4089,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.3" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "af83e617f331cc6ae2da5443c602dfa5af81e517212d9d611a5b3ba1777b5370" dependencies = [ "aho-corasick", "memchr", @@ -4100,9 +4100,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "a5996294f19bd3aae0453a862ad728f60e6600695733dd5df01da90c54363a3c" [[package]] name = "relay-server-example" diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 204ec47c856..39a5b3a2d7f 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -29,7 +29,7 @@ smallvec = "1.6.1" quick-protobuf = "0.8" quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } hex_fmt = "0.3.0" -regex = "1.7.3" +regex = "1.8.1" serde = { version = "1", optional = true, features = ["derive"] } thiserror = "1.0" wasm-timer = "0.2.5" From 2065348867dd47036af0be01b9c49a7487017290 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:09:41 +0000 Subject: [PATCH 08/57] deps: bump libc from 0.2.141 to 0.2.142 Pull-Request: #3815. --- Cargo.lock | 4 ++-- transports/tcp/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1dd83458091..c8936ced4f1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2206,9 +2206,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.141" +version = "0.2.142" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "6a987beff54b60ffa6d51982e1aa1146bc42f19bd26be28b0586f252fccf5317" [[package]] name = "libm" diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index b7a97ff0ce8..f3442aa7a45 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -15,7 +15,7 @@ async-io = { version = "1.13.0", optional = true } futures = "0.3.28" futures-timer = "3.0" if-watch = "3.0.1" -libc = "0.2.141" +libc = "0.2.142" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.11" From df19abbbf27983e9352af90f2051554b96e13b16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 18:41:38 +0000 Subject: [PATCH 09/57] deps: bump serde from 1.0.159 to 1.0.160 Pull-Request: #3796. --- Cargo.lock | 8 ++++---- misc/keygen/Cargo.toml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c8936ced4f1..1cde7b8a409 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4410,9 +4410,9 @@ checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" [[package]] name = "serde" -version = "1.0.159" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +checksum = "bb2f3770c8bce3bcda7e149193a069a0f4365bda1fa5cd88e03bca26afc1216c" dependencies = [ "serde_derive", ] @@ -4428,9 +4428,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.159" +version = "1.0.160" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 52c75cf59e4..6284fae8aa4 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -12,7 +12,7 @@ publish = false [dependencies] clap = { version = "4.2.1", features = ["derive"] } zeroize = "1" -serde = { version = "1.0.159", features = ["derive"] } +serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.95" libp2p-core = { version = "0.39.0", path = "../../core" } base64 = "0.21.0" From 5657f5c9aa09054180425e0058a9ad84a8b64554 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 Apr 2023 11:18:40 +0200 Subject: [PATCH 10/57] fix: apply suggestions from clippy beta (1.70) Pull-Request: #3819. --- transports/webrtc/src/tokio/substream/state.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/transports/webrtc/src/tokio/substream/state.rs b/transports/webrtc/src/tokio/substream/state.rs index a064c424ec3..5e843519ed6 100644 --- a/transports/webrtc/src/tokio/substream/state.rs +++ b/transports/webrtc/src/tokio/substream/state.rs @@ -189,7 +189,6 @@ impl State { /// Acts as a "barrier" for [`futures::AsyncRead::poll_read`]. pub(crate) fn read_barrier(&self) -> io::Result<()> { - use crate::tokio::substream::State::{Open, ReadClosed, WriteClosed}; use State::*; let kind = match self { @@ -212,7 +211,6 @@ impl State { /// Acts as a "barrier" for [`futures::AsyncWrite::poll_write`]. pub(crate) fn write_barrier(&self) -> io::Result<()> { - use crate::tokio::substream::State::{Open, ReadClosed, WriteClosed}; use State::*; let kind = match self { From 585a84e182bada33d56b8e0b6f6f376317c2692d Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 25 Apr 2023 14:26:16 +0200 Subject: [PATCH 11/57] feat(core): deprecate `{In,Out}boundUpgradeExt` These functions were only used for some code in the interop-tests which is easily mitigated and perhaps even easier to understand now. We can thus deprecate these functions and their related types and thereby reduce the API surface of `libp2p-core` and the maintenance burden. This change is motivated by the work around making protocols always strings which requires/required updates to all these upgrades. Related #3806. Related #3271. Related #3745. Pull-Request: #3807. --- core/CHANGELOG.md | 4 ++ core/src/upgrade.rs | 14 +++++- core/src/upgrade/map.rs | 6 +++ interop-tests/src/bin/ping.rs | 86 +++++++++++++++-------------------- libp2p/src/lib.rs | 4 +- 5 files changed, 62 insertions(+), 52 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 99dc371b595..e9913310aec 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -4,7 +4,11 @@ If you depend on it, we suggest you vendor it. See [PR 3747]. +- Deprecate `{In,Out}boundUpgradeExt`, as they are not used in rust-libp2p. + See [PR 3807]. + [PR 3747]: https://github.com/libp2p/rust-libp2p/pull/3747 +[PR 3807]: https://github.com/libp2p/rust-libp2p/pull/3807 ## 0.39.1 diff --git a/core/src/upgrade.rs b/core/src/upgrade.rs index 003590fd00c..0eba81aebc8 100644 --- a/core/src/upgrade.rs +++ b/core/src/upgrade.rs @@ -77,7 +77,6 @@ pub use self::{ apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, denied::DeniedUpgrade, error::UpgradeError, - map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr}, optional::OptionalUpgrade, pending::PendingUpgrade, ready::ReadyUpgrade, @@ -87,6 +86,9 @@ pub use self::{ pub use crate::Negotiated; pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError, Version}; +#[allow(deprecated)] +pub use map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr}; + /// Types serving as protocol names. /// /// # Context @@ -164,6 +166,10 @@ pub trait InboundUpgrade: UpgradeInfo { /// Extension trait for `InboundUpgrade`. Automatically implemented on all types that implement /// `InboundUpgrade`. +#[deprecated( + note = "Will be removed without replacement because it is not used within rust-libp2p." +)] +#[allow(deprecated)] pub trait InboundUpgradeExt: InboundUpgrade { /// Returns a new object that wraps around `Self` and applies a closure to the `Output`. fn map_inbound(self, f: F) -> MapInboundUpgrade @@ -184,6 +190,7 @@ pub trait InboundUpgradeExt: InboundUpgrade { } } +#[allow(deprecated)] impl> InboundUpgradeExt for U {} /// Possible upgrade on an outbound connection or substream. @@ -204,6 +211,10 @@ pub trait OutboundUpgrade: UpgradeInfo { /// Extention trait for `OutboundUpgrade`. Automatically implemented on all types that implement /// `OutboundUpgrade`. +#[deprecated( + note = "Will be removed without replacement because it is not used within rust-libp2p." +)] +#[allow(deprecated)] pub trait OutboundUpgradeExt: OutboundUpgrade { /// Returns a new object that wraps around `Self` and applies a closure to the `Output`. fn map_outbound(self, f: F) -> MapOutboundUpgrade @@ -224,4 +235,5 @@ pub trait OutboundUpgradeExt: OutboundUpgrade { } } +#[allow(deprecated)] impl> OutboundUpgradeExt for U {} diff --git a/core/src/upgrade/map.rs b/core/src/upgrade/map.rs index c5fe34f44b5..4287665c88f 100644 --- a/core/src/upgrade/map.rs +++ b/core/src/upgrade/map.rs @@ -18,12 +18,15 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#![allow(deprecated)] + use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use futures::prelude::*; use std::{pin::Pin, task::Context, task::Poll}; /// Wraps around an upgrade and applies a closure to the output. #[derive(Debug, Clone)] +#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] pub struct MapInboundUpgrade { upgrade: U, fun: F, @@ -79,6 +82,7 @@ where /// Wraps around an upgrade and applies a closure to the output. #[derive(Debug, Clone)] +#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] pub struct MapOutboundUpgrade { upgrade: U, fun: F, @@ -134,6 +138,7 @@ where /// Wraps around an upgrade and applies a closure to the error. #[derive(Debug, Clone)] +#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] pub struct MapInboundUpgradeErr { upgrade: U, fun: F, @@ -189,6 +194,7 @@ where /// Wraps around an upgrade and applies a closure to the error. #[derive(Debug, Clone)] +#[deprecated(note = "Deprecated without replacement because it is not used within rust-libp2p.")] pub struct MapOutboundUpgradeErr { upgrade: U, fun: F, diff --git a/interop-tests/src/bin/ping.rs b/interop-tests/src/bin/ping.rs index c0a11d3c2ab..63160f8c8d0 100644 --- a/interop-tests/src/bin/ping.rs +++ b/interop-tests/src/bin/ping.rs @@ -5,16 +5,13 @@ use std::time::{Duration, Instant}; use anyhow::{bail, Context, Result}; use either::Either; use env_logger::{Env, Target}; -use futures::{future, AsyncRead, AsyncWrite, StreamExt}; +use futures::StreamExt; use libp2p::core::muxing::StreamMuxerBox; -use libp2p::core::upgrade::{MapInboundUpgrade, MapOutboundUpgrade, Version}; -use libp2p::noise::{NoiseOutput, X25519Spec, XX}; +use libp2p::core::upgrade::Version; use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmEvent}; -use libp2p::tls::TlsStream; use libp2p::websocket::WsConfig; use libp2p::{ - identity, noise, ping, swarm::SwarmBuilder, tcp, tls, yamux, InboundUpgradeExt, Multiaddr, - OutboundUpgradeExt, PeerId, Transport as _, + identity, noise, ping, swarm::SwarmBuilder, tcp, tls, yamux, Multiaddr, PeerId, Transport as _, }; use libp2p_mplex as mplex; use libp2p_quic as quic; @@ -45,32 +42,56 @@ async fn main() -> Result<()> { let client = redis::Client::open(redis_addr).context("Could not connect to redis")?; // Build the transport from the passed ENV var. - let (boxed_transport, local_addr) = match transport_param { - Transport::QuicV1 => ( + let (boxed_transport, local_addr) = match (transport_param, from_env("security")) { + (Transport::QuicV1, _) => ( quic::tokio::Transport::new(quic::Config::new(&local_key)) .map(|(p, c), _| (p, StreamMuxerBox::new(c))) .boxed(), format!("/ip4/{ip}/udp/0/quic-v1"), ), - Transport::Tcp => ( + (Transport::Tcp, Ok(SecProtocol::Tls)) => ( tcp::tokio::Transport::new(tcp::Config::new()) .upgrade(Version::V1Lazy) - .authenticate(secure_channel_protocol_from_env(&local_key)?) + .authenticate(tls::Config::new(&local_key).context("failed to initialise tls")?) .multiplex(muxer_protocol_from_env()?) .timeout(Duration::from_secs(5)) .boxed(), format!("/ip4/{ip}/tcp/0"), ), - Transport::Ws => ( + (Transport::Tcp, Ok(SecProtocol::Noise)) => ( + tcp::tokio::Transport::new(tcp::Config::new()) + .upgrade(Version::V1Lazy) + .authenticate( + noise::NoiseAuthenticated::xx(&local_key) + .context("failed to intialise noise")?, + ) + .multiplex(muxer_protocol_from_env()?) + .timeout(Duration::from_secs(5)) + .boxed(), + format!("/ip4/{ip}/tcp/0"), + ), + (Transport::Ws, Ok(SecProtocol::Tls)) => ( + WsConfig::new(tcp::tokio::Transport::new(tcp::Config::new())) + .upgrade(Version::V1Lazy) + .authenticate(tls::Config::new(&local_key).context("failed to initialise tls")?) + .multiplex(muxer_protocol_from_env()?) + .timeout(Duration::from_secs(5)) + .boxed(), + format!("/ip4/{ip}/tcp/0/ws"), + ), + (Transport::Ws, Ok(SecProtocol::Noise)) => ( WsConfig::new(tcp::tokio::Transport::new(tcp::Config::new())) .upgrade(Version::V1Lazy) - .authenticate(secure_channel_protocol_from_env(&local_key)?) + .authenticate( + noise::NoiseAuthenticated::xx(&local_key) + .context("failed to intialise noise")?, + ) .multiplex(muxer_protocol_from_env()?) .timeout(Duration::from_secs(5)) .boxed(), format!("/ip4/{ip}/tcp/0/ws"), ), - Transport::WebRtcDirect => ( + (Transport::WebRtcDirect, _) => ( webrtc::tokio::Transport::new( local_key, webrtc::tokio::Certificate::generate(&mut rand::thread_rng())?, @@ -79,6 +100,8 @@ async fn main() -> Result<()> { .boxed(), format!("/ip4/{ip}/udp/0/webrtc-direct"), ), + (Transport::Tcp, Err(_)) => bail!("Missing security protocol for TCP transport"), + (Transport::Ws, Err(_)) => bail!("Missing security protocol for Websocket transport"), }; let mut swarm = SwarmBuilder::with_tokio_executor( @@ -164,43 +187,6 @@ async fn main() -> Result<()> { Ok(()) } -fn secure_channel_protocol_from_env( - identity: &identity::Keypair, -) -> Result< - MapOutboundUpgrade< - MapInboundUpgrade< - Either, tls::Config>, - MapSecOutputFn, - >, - MapSecOutputFn, - >, -> { - let either_sec_upgrade = match from_env("security")? { - SecProtocol::Noise => Either::Left( - noise::NoiseAuthenticated::xx(identity).context("failed to intialise noise")?, - ), - SecProtocol::Tls => { - Either::Right(tls::Config::new(identity).context("failed to initialise tls")?) - } - }; - - Ok(either_sec_upgrade - .map_inbound(factor_peer_id as MapSecOutputFn) - .map_outbound(factor_peer_id as MapSecOutputFn)) -} - -type SecOutput = future::Either<(PeerId, NoiseOutput), (PeerId, TlsStream)>; -type MapSecOutputFn = fn(SecOutput) -> (PeerId, future::Either, TlsStream>); - -fn factor_peer_id( - output: SecOutput, -) -> (PeerId, future::Either, TlsStream>) { - match output { - future::Either::Left((peer, stream)) => (peer, future::Either::Left(stream)), - future::Either::Right((peer, stream)) => (peer, future::Either::Right(stream)), - } -} - fn muxer_protocol_from_env() -> Result> { Ok(match from_env("muxer")? { Muxer::Yamux => Either::Left(yamux::YamuxConfig::default()), diff --git a/libp2p/src/lib.rs b/libp2p/src/lib.rs index 93378478ab1..79acd4249b8 100644 --- a/libp2p/src/lib.rs +++ b/libp2p/src/lib.rs @@ -167,9 +167,11 @@ pub mod bandwidth; #[cfg(doc)] pub mod tutorials; +#[allow(deprecated)] +pub use self::core::upgrade::{InboundUpgradeExt, OutboundUpgradeExt}; pub use self::core::{ transport::TransportError, - upgrade::{InboundUpgrade, InboundUpgradeExt, OutboundUpgrade, OutboundUpgradeExt}, + upgrade::{InboundUpgrade, OutboundUpgrade}, Transport, }; pub use self::multiaddr::{multiaddr as build_multiaddr, Multiaddr}; From 70ca3243adb39e7e74b8ce4554848cb6520b4adb Mon Sep 17 00:00:00 2001 From: Vinay Keerthi <11478411+stonecharioteer@users.noreply.github.com> Date: Tue, 25 Apr 2023 18:46:12 +0530 Subject: [PATCH 12/57] fix(docs): correct link to chat-example in examples readme Resolves #3830. Pull-Request: #3831. --- examples/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/README.md b/examples/README.md index 3b347c4c7a2..a8a07be0cbf 100644 --- a/examples/README.md +++ b/examples/README.md @@ -7,7 +7,7 @@ A set of examples showcasing how to use rust-libp2p. ## Individual libp2p features -- [Chat](./autonat) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols. +- [Chat](./chat-example) A basic chat application demonstrating libp2p and the mDNS and Gossipsub protocols. - [Distributed key-value store](./distributed-key-value-store) A basic key value store demonstrating libp2p and the mDNS and Kademlia protocol. - [File sharing application](./file-sharing) Basic file sharing application with peers either providing or locating and getting files by name. From 13623b2da7378d8be09ace0bdfcc3fba0706a316 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Tue, 25 Apr 2023 16:06:54 +0200 Subject: [PATCH 13/57] fix(identity): build with all features on docs.rs Resolves #3810. Pull-Request: #3828. --- identity/Cargo.toml | 7 +++++++ identity/src/lib.rs | 2 ++ 2 files changed, 9 insertions(+) diff --git a/identity/Cargo.toml b/identity/Cargo.toml index a87010c53ed..99012eeab6f 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -49,3 +49,10 @@ criterion = "0.4" [[bench]] name = "peer_id" harness = false + +# Passing arguments to the docsrs builder in order to properly document cfg's. +# More information: https://docs.rs/about/builds#cross-compiling +[package.metadata.docs.rs] +all-features = true +rustdoc-args = ["--cfg", "docsrs"] +rustc-args = ["--cfg", "docsrs"] diff --git a/identity/src/lib.rs b/identity/src/lib.rs index 87b02cd5a2e..332b3b08763 100644 --- a/identity/src/lib.rs +++ b/identity/src/lib.rs @@ -33,6 +33,8 @@ //! (e.g. [ed25519 binary format](https://datatracker.ietf.org/doc/html/rfc8032#section-5.1.5)). //! All key types have functions to enable conversion to/from their binary representations. +#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] + #[cfg(any( feature = "ecdsa", feature = "secp256k1", From e5300fac78d83e387095bc0010bf90363ecfd5ce Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Apr 2023 14:42:24 +0000 Subject: [PATCH 14/57] deps: bump syn from 2.0.11 to 2.0.15 Pull-Request: #3824. --- Cargo.lock | 22 +++++++++++----------- swarm-derive/Cargo.toml | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1cde7b8a409..a6b95261f82 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -446,7 +446,7 @@ checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] @@ -797,7 +797,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] @@ -1592,7 +1592,7 @@ checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] @@ -2877,7 +2877,7 @@ version = "0.32.0" dependencies = [ "heck", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] @@ -3819,9 +3819,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.52" +version = "1.0.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" +checksum = "2b63bdb0cd06f1f4dedf69b254734f9b45af66e4a031e42a7480257d9898b435" dependencies = [ "unicode-ident", ] @@ -4434,7 +4434,7 @@ checksum = "291a097c63d8497e00160b166a967a4a79c64f3facdd01cbd7502231688d77df" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] @@ -4684,9 +4684,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.11" +version = "2.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21e3787bb71465627110e7d87ed4faaa36c1f61042ee67badb9e2ef173accc40" +checksum = "a34fcf3e8b60f57e6a14301a2e916d323af98b0ea63c599441eec8558660c822" dependencies = [ "proc-macro2", "quote", @@ -4771,7 +4771,7 @@ checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] @@ -4853,7 +4853,7 @@ checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" dependencies = [ "proc-macro2", "quote", - "syn 2.0.11", + "syn 2.0.15", ] [[package]] diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index de8e2db60f0..31f70a01b5b 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -16,7 +16,7 @@ proc-macro = true [dependencies] heck = "0.4" quote = "1.0" -syn = { version = "2.0.11", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } +syn = { version = "2.0.15", default-features = false, features = ["clone-impls", "derive", "parsing", "printing", "proc-macro"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling From 9d78331ca17235cd1dd5bdd88259e4a5570bdf11 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Tue, 25 Apr 2023 16:57:06 +0200 Subject: [PATCH 15/57] ci: run test on self-hosted runners This PR moves Test jobs from Continuous Integration workflow and Interoperability Testing job to self-hosted runners. The former are moved to machines backed by either c5.large/m5.large, c5.xlarge/m5.xlarge or c5.2xlarge AWS instances while the latter c5.4xlarge. The self-hosted runners are set up using https://github.com/pl-strflt/tf-aws-gh-runner. The jobs are being moved to self-hosted because we're exhausting hosted GHA limits. Pull-Request: #3782. --- .github/workflows/ci.yml | 13 +++++++++++-- .github/workflows/interop-test.yml | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ec0bb8eae0..3ab01206348 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,7 +16,13 @@ env: jobs: test: name: Test ${{ matrix.crate }} - runs-on: ubuntu-latest + runs-on: ${{ fromJSON( + github.repository == 'libp2p/rust-libp2p' && ( + (contains(fromJSON('["libp2p-webrtc", "libp2p"]'), matrix.crate) && '["self-hosted", "linux", "x64", "2xlarge"]') || + (contains(fromJSON('["libp2p-quic", "libp2p-perf"]'), matrix.crate) && '["self-hosted", "linux", "x64", "xlarge"]') || + '["self-hosted", "linux", "x64", "large"]' + ) || '"ubuntu-latest"') }} + timeout-minutes: 10 needs: gather_published_crates strategy: fail-fast: false @@ -24,7 +30,9 @@ jobs: crate: ${{ fromJSON(needs.gather_published_crates.outputs.members) }} steps: - name: Install Protoc - run: sudo apt-get install protobuf-compiler + run: sudo apt-get install -y protobuf-compiler + + - uses: dtolnay/rust-toolchain@stable - uses: actions/checkout@v3 @@ -33,6 +41,7 @@ jobs: run: | RUST_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "${{ matrix.crate }}") | .rust_version') echo "version=${RUST_VERSION}" >> $GITHUB_OUTPUT + shell: bash - name: Install Rust ${{ steps.parse-msrv.outputs.version }} for MSRV check uses: dtolnay/rust-toolchain@master diff --git a/.github/workflows/interop-test.yml b/.github/workflows/interop-test.yml index 3804cc1d549..e6527709aa3 100644 --- a/.github/workflows/interop-test.yml +++ b/.github/workflows/interop-test.yml @@ -12,7 +12,7 @@ concurrency: jobs: run-multidim-interop: name: Run multidimensional interoperability tests - runs-on: ubuntu-22.04 + runs-on: ${{ fromJSON(github.repository == 'libp2p/rust-libp2p' && '["self-hosted", "linux", "x64", "xlarge"]' || '"ubuntu-latest"') }} steps: - uses: actions/checkout@v3 - uses: docker/setup-buildx-action@v2 From 9681116b025104dfd20f7a48deb789db18ab18f2 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 07:29:17 +0200 Subject: [PATCH 16/57] ci(mergify): automatically approve PRs from maintainers We have a limit of 1 approval for each PR in order to go into the merge queue. To make life for us maintainers easier, we configure mergify to approve our and only our PRs. This allows a single maintainer to land small PRs without having to ping another maintainer. Pull-Request: #3832. --- .github/mergify.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/mergify.yml b/.github/mergify.yml index d7eff473d66..eafca0cf87b 100644 --- a/.github/mergify.yml +++ b/.github/mergify.yml @@ -41,6 +41,14 @@ pull_request_rules: message: Approvals have been dismissed because the PR was updated after the `send-it` label was applied. changes_requested: false + - name: Approve trivial maintainer PRs + conditions: + - base=master + - label=trivial + - author=@libp2p/rust-libp2p-maintainers + actions: + review: + queue_rules: - name: default conditions: [] From e5dbeb3e08fee812f49c17ce4030eb76c3d0d16c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 08:05:45 +0200 Subject: [PATCH 17/57] feat(core): deprecate `OptionalUpgrade` This is dead-code, we don't use it in our codebase. I am suggesting to remove it because it creates an unnecessary API surface. Related: https://github.com/libp2p/rust-libp2p/pull/3747. Related: https://github.com/libp2p/rust-libp2p/issues/3271. Pull-Request: #3806. --- core/CHANGELOG.md | 4 ++++ core/src/upgrade.rs | 6 +++--- core/src/upgrade/optional.rs | 5 +++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index e9913310aec..9cd4ca30de0 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -7,8 +7,12 @@ - Deprecate `{In,Out}boundUpgradeExt`, as they are not used in rust-libp2p. See [PR 3807]. +- Deprecate `OptionalUpgrade` without replacement. + See [PR 3806]. + [PR 3747]: https://github.com/libp2p/rust-libp2p/pull/3747 [PR 3807]: https://github.com/libp2p/rust-libp2p/pull/3807 +[PR 3806]: https://github.com/libp2p/rust-libp2p/pull/3806 ## 0.39.1 diff --git a/core/src/upgrade.rs b/core/src/upgrade.rs index 0eba81aebc8..4c46418e7a7 100644 --- a/core/src/upgrade.rs +++ b/core/src/upgrade.rs @@ -77,17 +77,17 @@ pub use self::{ apply::{apply, apply_inbound, apply_outbound, InboundUpgradeApply, OutboundUpgradeApply}, denied::DeniedUpgrade, error::UpgradeError, - optional::OptionalUpgrade, pending::PendingUpgrade, ready::ReadyUpgrade, select::SelectUpgrade, transfer::{read_length_prefixed, read_varint, write_length_prefixed, write_varint}, }; pub use crate::Negotiated; -pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError, Version}; - #[allow(deprecated)] pub use map::{MapInboundUpgrade, MapInboundUpgradeErr, MapOutboundUpgrade, MapOutboundUpgradeErr}; +pub use multistream_select::{NegotiatedComplete, NegotiationError, ProtocolError, Version}; +#[allow(deprecated)] +pub use optional::OptionalUpgrade; /// Types serving as protocol names. /// diff --git a/core/src/upgrade/optional.rs b/core/src/upgrade/optional.rs index c661a4f0170..40303db2bdf 100644 --- a/core/src/upgrade/optional.rs +++ b/core/src/upgrade/optional.rs @@ -18,6 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. +#![allow(deprecated)] + use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; /// Upgrade that can be disabled at runtime. @@ -25,6 +27,9 @@ use crate::upgrade::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; /// Wraps around an `Option` and makes it available or not depending on whether it contains or /// not an upgrade. #[derive(Debug, Clone)] +#[deprecated( + note = "Will be removed without replacement because it is not used within rust-libp2p." +)] pub struct OptionalUpgrade(Option); impl OptionalUpgrade { From 135942d3190634beebdc614c70117ced61c9cd99 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 09:31:56 +0200 Subject: [PATCH 18/57] chore: enforce `unreachable_pub` lint The `unreachable_pub` lint makes us aware of uses of `pub` that are not actually reachable from the crate root. This is considered good because it means reading a `pub` somewhere means it is actually public API. Some of our crates are quite large and keeping their entire API surface in your head is difficult. We should strive for most items being `pub(crate)`. This lint helps us enforce that. Pull-Request: #3735. --- .cargo/config.toml | 2 +- core/src/lib.rs | 1 + core/src/signed_envelope.rs | 2 +- core/src/transport/boxed.rs | 2 +- core/src/upgrade/apply.rs | 4 +- examples/file-sharing/src/network.rs | 32 +- examples/metrics/src/http_service.rs | 8 +- identity/src/lib.rs | 3 +- identity/src/rsa.rs | 4 +- misc/keygen/src/config.rs | 17 +- misc/metrics/src/dcutr.rs | 4 +- misc/metrics/src/gossipsub.rs | 4 +- misc/metrics/src/identify.rs | 4 +- misc/metrics/src/kad.rs | 4 +- misc/metrics/src/ping.rs | 4 +- misc/metrics/src/protocol_stack.rs | 2 +- misc/metrics/src/relay.rs | 4 +- misc/metrics/src/swarm.rs | 4 +- .../src/length_delimited.rs | 17 +- misc/multistream-select/src/protocol.rs | 23 +- muxers/mplex/src/codec.rs | 22 +- muxers/mplex/src/io.rs | 31 +- protocols/autonat/src/behaviour/as_client.rs | 43 +- protocols/autonat/src/behaviour/as_server.rs | 20 +- protocols/autonat/src/lib.rs | 3 +- protocols/dcutr/src/handler.rs | 4 +- protocols/dcutr/src/lib.rs | 3 +- protocols/dcutr/src/protocol.rs | 5 +- protocols/floodsub/src/lib.rs | 3 +- protocols/gossipsub/src/backoff.rs | 12 +- protocols/gossipsub/src/behaviour.rs | 2 +- protocols/gossipsub/src/behaviour/tests.rs | 2 +- protocols/gossipsub/src/gossip_promises.rs | 10 +- protocols/gossipsub/src/mcache.rs | 28 +- protocols/gossipsub/src/peer_score.rs | 54 ++- protocols/gossipsub/src/rpc_proto.rs | 3 +- protocols/gossipsub/src/types.rs | 6 +- protocols/identify/src/lib.rs | 3 +- protocols/kad/src/jobs.rs | 33 +- protocols/kad/src/kbucket_priv/bucket.rs | 64 +-- protocols/kad/src/lib.rs | 1 + protocols/kad/src/query.rs | 78 ++-- protocols/kad/src/query/peers.rs | 5 +- protocols/kad/src/query/peers/closest.rs | 3 +- .../kad/src/query/peers/closest/disjoint.rs | 24 +- protocols/kad/src/query/peers/fixed.rs | 18 +- protocols/mdns/src/behaviour/iface.rs | 10 +- protocols/mdns/src/behaviour/iface/dns.rs | 11 +- protocols/mdns/src/behaviour/iface/query.rs | 34 +- protocols/mdns/src/behaviour/socket.rs | 11 +- protocols/mdns/src/behaviour/timer.rs | 11 +- protocols/perf/src/protocol.rs | 4 +- protocols/ping/src/protocol.rs | 7 +- protocols/relay/src/behaviour.rs | 3 +- protocols/relay/src/behaviour/handler.rs | 2 +- protocols/relay/src/behaviour/rate_limiter.rs | 400 +++++++++--------- protocols/relay/src/copy_future.rs | 9 +- protocols/relay/src/lib.rs | 7 +- protocols/relay/src/protocol.rs | 9 +- protocols/rendezvous/src/codec.rs | 3 +- protocols/rendezvous/src/handler.rs | 14 +- protocols/rendezvous/src/substream_handler.rs | 8 +- scripts/fix-unreachable-pub.py | 68 +++ swarm/src/connection.rs | 32 +- swarm/src/connection/error.rs | 4 +- swarm/src/connection/pool.rs | 69 ++- swarm/src/connection/pool/concurrent_dial.rs | 2 +- swarm/src/connection/pool/task.rs | 12 +- swarm/src/executor.rs | 9 +- swarm/src/registry.rs | 14 +- swarm/src/test.rs | 58 +-- swarm/tests/swarm_derive.rs | 2 +- transports/noise/src/io.rs | 3 +- transports/noise/src/io/framed.rs | 13 +- transports/noise/src/io/handshake.rs | 17 +- transports/noise/src/protocol.rs | 5 +- transports/plaintext/src/handshake.rs | 9 +- transports/plaintext/src/lib.rs | 3 +- transports/pnet/src/crypt_writer.rs | 6 +- transports/quic/src/endpoint.rs | 21 +- transports/quic/src/transport.rs | 4 +- transports/tls/src/verifier.rs | 11 +- transports/webrtc/src/lib.rs | 3 +- transports/webrtc/src/tokio/req_res_chan.rs | 10 +- transports/webrtc/src/tokio/sdp.rs | 18 +- transports/webrtc/src/tokio/substream.rs | 3 +- .../src/tokio/substream/drop_listener.rs | 6 +- .../webrtc/src/tokio/substream/framed_dc.rs | 5 +- .../webrtc/src/tokio/substream/state.rs | 6 +- transports/webrtc/src/tokio/udp_mux.rs | 24 +- transports/webrtc/src/tokio/upgrade.rs | 4 +- transports/webrtc/src/tokio/upgrade/noise.rs | 9 +- transports/webrtc/tests/smoke.rs | 2 +- 93 files changed, 857 insertions(+), 763 deletions(-) create mode 100644 scripts/fix-unreachable-pub.py diff --git a/.cargo/config.toml b/.cargo/config.toml index b98b715c9ab..e55adcc9ed1 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -1,3 +1,3 @@ [alias] # Temporary solution to have clippy config in a single place until https://github.com/rust-lang/rust-clippy/blob/master/doc/roadmap-2021.md#lintstoml-configuration is shipped. -custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -D warnings" +custom-clippy = "clippy --workspace --all-features --all-targets -- -A clippy::type_complexity -A clippy::pedantic -W clippy::used_underscore_binding -W unreachable_pub -D warnings" diff --git a/core/src/lib.rs b/core/src/lib.rs index 84e39fdafb1..ba531c919f2 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -38,6 +38,7 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); pub use self::{ envelope_proto::*, peer_record_proto::mod_PeerRecord::*, peer_record_proto::PeerRecord, diff --git a/core/src/signed_envelope.rs b/core/src/signed_envelope.rs index a9d7ecd5208..a50146f87d1 100644 --- a/core/src/signed_envelope.rs +++ b/core/src/signed_envelope.rs @@ -182,7 +182,7 @@ mod tests { use super::*; #[test] - pub fn test_roundtrip() { + fn test_roundtrip() { let kp = Keypair::generate_ed25519(); let payload = "some payload".as_bytes(); let domain_separation = "domain separation".to_string(); diff --git a/core/src/transport/boxed.rs b/core/src/transport/boxed.rs index b2560c4a662..a55e4db8466 100644 --- a/core/src/transport/boxed.rs +++ b/core/src/transport/boxed.rs @@ -29,7 +29,7 @@ use std::{ }; /// Creates a new [`Boxed`] transport from the given transport. -pub fn boxed(transport: T) -> Boxed +pub(crate) fn boxed(transport: T) -> Boxed where T: Transport + Send + Unpin + 'static, T::Error: Send + Sync, diff --git a/core/src/upgrade/apply.rs b/core/src/upgrade/apply.rs index 76a48baed04..0b4b4d6b992 100644 --- a/core/src/upgrade/apply.rs +++ b/core/src/upgrade/apply.rs @@ -25,7 +25,7 @@ use log::debug; use multistream_select::{self, DialerSelectFuture, ListenerSelectFuture}; use std::{iter, mem, pin::Pin, task::Context, task::Poll}; -pub use multistream_select::Version; +pub(crate) use multistream_select::Version; use smallvec::SmallVec; use std::fmt; @@ -275,7 +275,7 @@ impl AsRef<[u8]> for NameWrap { } /// Wrapper for printing a [`ProtocolName`] that is expected to be mostly ASCII -pub(crate) struct DisplayProtocolName(pub N); +pub(crate) struct DisplayProtocolName(pub(crate) N); impl fmt::Display for DisplayProtocolName { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index 0f9ff32863e..62496172e4a 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -33,7 +33,7 @@ use std::iter; /// - The network event stream, e.g. for incoming requests. /// /// - The network task driving the network itself. -pub async fn new( +pub(crate) async fn new( secret_key_seed: Option, ) -> Result<(Client, impl Stream, EventLoop), Box> { // Create a public/private key pair, either random or based on a seed. @@ -82,13 +82,16 @@ pub async fn new( } #[derive(Clone)] -pub struct Client { +pub(crate) struct Client { sender: mpsc::Sender, } impl Client { /// Listen for incoming connections on the given address. - pub async fn start_listening(&mut self, addr: Multiaddr) -> Result<(), Box> { + pub(crate) async fn start_listening( + &mut self, + addr: Multiaddr, + ) -> Result<(), Box> { let (sender, receiver) = oneshot::channel(); self.sender .send(Command::StartListening { addr, sender }) @@ -98,7 +101,7 @@ impl Client { } /// Dial the given peer at the given address. - pub async fn dial( + pub(crate) async fn dial( &mut self, peer_id: PeerId, peer_addr: Multiaddr, @@ -116,7 +119,7 @@ impl Client { } /// Advertise the local node as the provider of the given file on the DHT. - pub async fn start_providing(&mut self, file_name: String) { + pub(crate) async fn start_providing(&mut self, file_name: String) { let (sender, receiver) = oneshot::channel(); self.sender .send(Command::StartProviding { file_name, sender }) @@ -126,7 +129,7 @@ impl Client { } /// Find the providers for the given file on the DHT. - pub async fn get_providers(&mut self, file_name: String) -> HashSet { + pub(crate) async fn get_providers(&mut self, file_name: String) -> HashSet { let (sender, receiver) = oneshot::channel(); self.sender .send(Command::GetProviders { file_name, sender }) @@ -136,7 +139,7 @@ impl Client { } /// Request the content of the given file from the given peer. - pub async fn request_file( + pub(crate) async fn request_file( &mut self, peer: PeerId, file_name: String, @@ -154,7 +157,11 @@ impl Client { } /// Respond with the provided file content to the given request. - pub async fn respond_file(&mut self, file: Vec, channel: ResponseChannel) { + pub(crate) async fn respond_file( + &mut self, + file: Vec, + channel: ResponseChannel, + ) { self.sender .send(Command::RespondFile { file, channel }) .await @@ -162,7 +169,7 @@ impl Client { } } -pub struct EventLoop { +pub(crate) struct EventLoop { swarm: Swarm, command_receiver: mpsc::Receiver, event_sender: mpsc::Sender, @@ -190,7 +197,7 @@ impl EventLoop { } } - pub async fn run(mut self) { + pub(crate) async fn run(mut self) { loop { futures::select! { event = self.swarm.next() => self.handle_event(event.expect("Swarm stream to be infinite.")).await , @@ -452,7 +459,7 @@ enum Command { } #[derive(Debug)] -pub enum Event { +pub(crate) enum Event { InboundRequest { request: String, channel: ResponseChannel, @@ -468,8 +475,7 @@ struct FileExchangeCodec(); #[derive(Debug, Clone, PartialEq, Eq)] struct FileRequest(String); #[derive(Debug, Clone, PartialEq, Eq)] -pub struct FileResponse(Vec); - +pub(crate) struct FileResponse(Vec); impl ProtocolName for FileExchangeProtocol { fn protocol_name(&self) -> &[u8] { "/file-exchange/1".as_bytes() diff --git a/examples/metrics/src/http_service.rs b/examples/metrics/src/http_service.rs index d1baf946d77..84102c2b558 100644 --- a/examples/metrics/src/http_service.rs +++ b/examples/metrics/src/http_service.rs @@ -31,7 +31,7 @@ use std::task::{Context, Poll}; const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0"; -pub async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> { +pub(crate) async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> { // Serve on localhost. let addr = ([127, 0, 0, 1], 0).into(); @@ -47,7 +47,7 @@ pub async fn metrics_server(registry: Registry) -> Result<(), std::io::Error> { }) } -pub struct MetricService { +pub(crate) struct MetricService { reg: Arc>, } @@ -102,12 +102,12 @@ impl Service> for MetricService { } } -pub struct MakeMetricService { +pub(crate) struct MakeMetricService { reg: SharedRegistry, } impl MakeMetricService { - pub fn new(registry: Registry) -> MakeMetricService { + pub(crate) fn new(registry: Registry) -> MakeMetricService { MakeMetricService { reg: Arc::new(Mutex::new(registry)), } diff --git a/identity/src/lib.rs b/identity/src/lib.rs index 332b3b08763..ea9ced51622 100644 --- a/identity/src/lib.rs +++ b/identity/src/lib.rs @@ -42,8 +42,9 @@ feature = "rsa" ))] mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::keys_proto::*; + pub(crate) use self::keys_proto::*; } #[cfg(feature = "ecdsa")] diff --git a/identity/src/rsa.rs b/identity/src/rsa.rs index b598b093b7e..e4e16af206c 100644 --- a/identity/src/rsa.rs +++ b/identity/src/rsa.rs @@ -159,12 +159,12 @@ struct Asn1RawOid<'a> { impl<'a> Asn1RawOid<'a> { /// The underlying OID as byte literal. - pub fn oid(&self) -> &[u8] { + pub(crate) fn oid(&self) -> &[u8] { self.object.value() } /// Writes an OID raw `value` as DER-object to `sink`. - pub fn write(value: &[u8], sink: &mut S) -> Result<(), Asn1DerError> { + pub(crate) fn write(value: &[u8], sink: &mut S) -> Result<(), Asn1DerError> { DerObject::write(Self::TAG, value.len(), &mut value.iter(), sink) } } diff --git a/misc/keygen/src/config.rs b/misc/keygen/src/config.rs index 30ec8f8324e..e6c563b3c32 100644 --- a/misc/keygen/src/config.rs +++ b/misc/keygen/src/config.rs @@ -8,16 +8,19 @@ use libp2p_identity::PeerId; #[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] -pub struct Config { - pub identity: Identity, +pub(crate) struct Config { + pub(crate) identity: Identity, } impl Config { - pub fn from_file(path: &Path) -> Result> { + pub(crate) fn from_file(path: &Path) -> Result> { Ok(serde_json::from_str(&std::fs::read_to_string(path)?)?) } - pub fn from_key_material(peer_id: PeerId, keypair: &Keypair) -> Result> { + pub(crate) fn from_key_material( + peer_id: PeerId, + keypair: &Keypair, + ) -> Result> { let priv_key = BASE64_STANDARD.encode(keypair.to_protobuf_encoding()?); let peer_id = peer_id.to_base58(); Ok(Self { @@ -28,10 +31,10 @@ impl Config { #[derive(Clone, Serialize, Deserialize)] #[serde(rename_all = "PascalCase")] -pub struct Identity { +pub(crate) struct Identity { #[serde(rename = "PeerID")] - pub peer_id: String, - pub priv_key: String, + pub(crate) peer_id: String, + pub(crate) priv_key: String, } impl zeroize::Zeroize for Config { diff --git a/misc/metrics/src/dcutr.rs b/misc/metrics/src/dcutr.rs index d2f0c63961c..18ee8a14d1e 100644 --- a/misc/metrics/src/dcutr.rs +++ b/misc/metrics/src/dcutr.rs @@ -23,12 +23,12 @@ use prometheus_client::metrics::counter::Counter; use prometheus_client::metrics::family::Family; use prometheus_client::registry::Registry; -pub struct Metrics { +pub(crate) struct Metrics { events: Family, } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("dcutr"); let events = Family::default(); diff --git a/misc/metrics/src/gossipsub.rs b/misc/metrics/src/gossipsub.rs index b00671ac636..2d90b92fbc6 100644 --- a/misc/metrics/src/gossipsub.rs +++ b/misc/metrics/src/gossipsub.rs @@ -21,12 +21,12 @@ use prometheus_client::metrics::counter::Counter; use prometheus_client::registry::Registry; -pub struct Metrics { +pub(crate) struct Metrics { messages: Counter, } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("gossipsub"); let messages = Counter::default(); diff --git a/misc/metrics/src/identify.rs b/misc/metrics/src/identify.rs index e93620b4fef..91f7d78722d 100644 --- a/misc/metrics/src/identify.rs +++ b/misc/metrics/src/identify.rs @@ -30,7 +30,7 @@ use std::collections::HashMap; use std::iter; use std::sync::{Arc, Mutex}; -pub struct Metrics { +pub(crate) struct Metrics { protocols: Protocols, error: Counter, pushed: Counter, @@ -42,7 +42,7 @@ pub struct Metrics { } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("identify"); let protocols = Protocols::default(); diff --git a/misc/metrics/src/kad.rs b/misc/metrics/src/kad.rs index af56eb08491..bc83146f937 100644 --- a/misc/metrics/src/kad.rs +++ b/misc/metrics/src/kad.rs @@ -24,7 +24,7 @@ use prometheus_client::metrics::family::Family; use prometheus_client::metrics::histogram::{exponential_buckets, Histogram}; use prometheus_client::registry::{Registry, Unit}; -pub struct Metrics { +pub(crate) struct Metrics { query_result_get_record_ok: Counter, query_result_get_record_error: Family, @@ -45,7 +45,7 @@ pub struct Metrics { } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("kad"); let query_result_get_record_ok = Counter::default(); diff --git a/misc/metrics/src/ping.rs b/misc/metrics/src/ping.rs index 0e7a7f26320..195cb302675 100644 --- a/misc/metrics/src/ping.rs +++ b/misc/metrics/src/ping.rs @@ -52,14 +52,14 @@ enum Failure { Other, } -pub struct Metrics { +pub(crate) struct Metrics { rtt: Histogram, failure: Family, pong_received: Counter, } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("ping"); let rtt = Histogram::new(exponential_buckets(0.001, 2.0, 12)); diff --git a/misc/metrics/src/protocol_stack.rs b/misc/metrics/src/protocol_stack.rs index 1715b51f034..59e8c0bfa6a 100644 --- a/misc/metrics/src/protocol_stack.rs +++ b/misc/metrics/src/protocol_stack.rs @@ -1,6 +1,6 @@ use libp2p_core::multiaddr::Multiaddr; -pub fn as_string(ma: &Multiaddr) -> String { +pub(crate) fn as_string(ma: &Multiaddr) -> String { let len = ma .protocol_stack() .fold(0, |acc, proto| acc + proto.len() + 1); diff --git a/misc/metrics/src/relay.rs b/misc/metrics/src/relay.rs index 479a518eeaf..4b8f63588fe 100644 --- a/misc/metrics/src/relay.rs +++ b/misc/metrics/src/relay.rs @@ -23,12 +23,12 @@ use prometheus_client::metrics::counter::Counter; use prometheus_client::metrics::family::Family; use prometheus_client::registry::Registry; -pub struct Metrics { +pub(crate) struct Metrics { events: Family, } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("relay"); let events = Family::default(); diff --git a/misc/metrics/src/swarm.rs b/misc/metrics/src/swarm.rs index c913710cbce..d04fd028a00 100644 --- a/misc/metrics/src/swarm.rs +++ b/misc/metrics/src/swarm.rs @@ -25,7 +25,7 @@ use prometheus_client::metrics::family::Family; use prometheus_client::metrics::histogram::{exponential_buckets, Histogram}; use prometheus_client::registry::Registry; -pub struct Metrics { +pub(crate) struct Metrics { connections_incoming: Family, connections_incoming_error: Family, @@ -45,7 +45,7 @@ pub struct Metrics { } impl Metrics { - pub fn new(registry: &mut Registry) -> Self { + pub(crate) fn new(registry: &mut Registry) -> Self { let sub_registry = registry.sub_registry_with_prefix("swarm"); let connections_incoming = Family::default(); diff --git a/misc/multistream-select/src/length_delimited.rs b/misc/multistream-select/src/length_delimited.rs index 981dfff82f8..d1de7cd292e 100644 --- a/misc/multistream-select/src/length_delimited.rs +++ b/misc/multistream-select/src/length_delimited.rs @@ -40,7 +40,7 @@ const DEFAULT_BUFFER_SIZE: usize = 64; /// unlikely to be more than 16KiB long. #[pin_project::pin_project] #[derive(Debug)] -pub struct LengthDelimited { +pub(crate) struct LengthDelimited { /// The inner I/O resource. #[pin] inner: R, @@ -76,7 +76,7 @@ impl Default for ReadState { impl LengthDelimited { /// Creates a new I/O resource for reading and writing unsigned-varint /// length delimited frames. - pub fn new(inner: R) -> LengthDelimited { + pub(crate) fn new(inner: R) -> LengthDelimited { LengthDelimited { inner, read_state: ReadState::default(), @@ -93,7 +93,7 @@ impl LengthDelimited { /// The read buffer is guaranteed to be empty whenever `Stream::poll` yields /// a new `Bytes` frame. The write buffer is guaranteed to be empty after /// flushing. - pub fn into_inner(self) -> R { + pub(crate) fn into_inner(self) -> R { assert!(self.read_buffer.is_empty()); assert!(self.write_buffer.is_empty()); self.inner @@ -106,7 +106,7 @@ impl LengthDelimited { /// This is typically done if further uvi-framed messages are expected to be /// received but no more such messages are written, allowing the writing of /// follow-up protocol data to commence. - pub fn into_reader(self) -> LengthDelimitedReader { + pub(crate) fn into_reader(self) -> LengthDelimitedReader { LengthDelimitedReader { inner: self } } @@ -115,10 +115,7 @@ impl LengthDelimited { /// /// After this method returns `Poll::Ready`, the write buffer of frames /// submitted to the `Sink` is guaranteed to be empty. - pub fn poll_write_buffer( - self: Pin<&mut Self>, - cx: &mut Context<'_>, - ) -> Poll> + fn poll_write_buffer(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> where R: AsyncWrite, { @@ -300,7 +297,7 @@ where /// frames on an underlying I/O resource combined with direct `AsyncWrite` access. #[pin_project::pin_project] #[derive(Debug)] -pub struct LengthDelimitedReader { +pub(crate) struct LengthDelimitedReader { #[pin] inner: LengthDelimited, } @@ -318,7 +315,7 @@ impl LengthDelimitedReader { /// yield a new `Message`. The write buffer is guaranteed to be empty whenever /// [`LengthDelimited::poll_write_buffer`] yields [`Poll::Ready`] or after /// the [`Sink`] has been completely flushed via [`Sink::poll_flush`]. - pub fn into_inner(self) -> R { + pub(crate) fn into_inner(self) -> R { self.inner.into_inner() } } diff --git a/misc/multistream-select/src/protocol.rs b/misc/multistream-select/src/protocol.rs index 65cdb40fedd..a560d116e53 100644 --- a/misc/multistream-select/src/protocol.rs +++ b/misc/multistream-select/src/protocol.rs @@ -53,7 +53,7 @@ const MSG_LS: &[u8] = b"ls\n"; /// /// Every [`Version`] has a corresponding header line. #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub enum HeaderLine { +pub(crate) enum HeaderLine { /// The `/multistream/1.0.0` header line. V1, } @@ -68,8 +68,7 @@ impl From for HeaderLine { /// A protocol (name) exchanged during protocol negotiation. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct Protocol(Bytes); - +pub(crate) struct Protocol(Bytes); impl AsRef<[u8]> for Protocol { fn as_ref(&self) -> &[u8] { self.0.as_ref() @@ -106,7 +105,7 @@ impl fmt::Display for Protocol { /// Multistream-select protocol messages are exchanged with the goal /// of agreeing on a application-layer protocol to use on an I/O stream. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Message { +pub(crate) enum Message { /// A header message identifies the multistream-select protocol /// that the sender wishes to speak. Header(HeaderLine), @@ -123,7 +122,7 @@ pub enum Message { impl Message { /// Encodes a `Message` into its byte representation. - pub fn encode(&self, dest: &mut BytesMut) -> Result<(), ProtocolError> { + fn encode(&self, dest: &mut BytesMut) -> Result<(), ProtocolError> { match self { Message::Header(HeaderLine::V1) => { dest.reserve(MSG_MULTISTREAM_1_0.len()); @@ -164,7 +163,7 @@ impl Message { } /// Decodes a `Message` from its byte representation. - pub fn decode(mut msg: Bytes) -> Result { + fn decode(mut msg: Bytes) -> Result { if msg == MSG_MULTISTREAM_1_0 { return Ok(Message::Header(HeaderLine::V1)); } @@ -220,14 +219,14 @@ impl Message { /// A `MessageIO` implements a [`Stream`] and [`Sink`] of [`Message`]s. #[pin_project::pin_project] -pub struct MessageIO { +pub(crate) struct MessageIO { #[pin] inner: LengthDelimited, } impl MessageIO { /// Constructs a new `MessageIO` resource wrapping the given I/O stream. - pub fn new(inner: R) -> MessageIO + pub(crate) fn new(inner: R) -> MessageIO where R: AsyncRead + AsyncWrite, { @@ -243,7 +242,7 @@ impl MessageIO { /// This is typically done if further negotiation messages are expected to be /// received but no more messages are written, allowing the writing of /// follow-up protocol data to commence. - pub fn into_reader(self) -> MessageReader { + pub(crate) fn into_reader(self) -> MessageReader { MessageReader { inner: self.inner.into_reader(), } @@ -258,7 +257,7 @@ impl MessageIO { /// has not yet been flushed. The read buffer is guaranteed to be empty whenever /// `MessageIO::poll` returned a message. The write buffer is guaranteed to be empty /// when the sink has been flushed. - pub fn into_inner(self) -> R { + pub(crate) fn into_inner(self) -> R { self.inner.into_inner() } } @@ -311,7 +310,7 @@ where /// I/O resource combined with direct `AsyncWrite` access. #[pin_project::pin_project] #[derive(Debug)] -pub struct MessageReader { +pub(crate) struct MessageReader { #[pin] inner: LengthDelimitedReader, } @@ -328,7 +327,7 @@ impl MessageReader { /// outgoing frame has not yet been flushed. The read buffer is guaranteed to /// be empty whenever `MessageReader::poll` returned a message. The write /// buffer is guaranteed to be empty whenever the sink has been flushed. - pub fn into_inner(self) -> R { + pub(crate) fn into_inner(self) -> R { self.inner.into_inner() } } diff --git a/muxers/mplex/src/codec.rs b/muxers/mplex/src/codec.rs index 48dbd243a09..ec605edc6a7 100644 --- a/muxers/mplex/src/codec.rs +++ b/muxers/mplex/src/codec.rs @@ -50,7 +50,7 @@ pub(crate) const MAX_FRAME_SIZE: usize = 1024 * 1024; /// > Conversely, when receiving a frame with a flag identifying the remote as a "sender", /// > the corresponding local ID has the role `Endpoint::Listener`. #[derive(Copy, Clone, Eq, Debug)] -pub struct LocalStreamId { +pub(crate) struct LocalStreamId { num: u64, role: Endpoint, } @@ -91,13 +91,13 @@ impl nohash_hasher::IsEnabled for LocalStreamId {} /// and mapped by the receiver to `LocalStreamId`s via /// [`RemoteStreamId::into_local()`]. #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] -pub struct RemoteStreamId { +pub(crate) struct RemoteStreamId { num: u64, role: Endpoint, } impl LocalStreamId { - pub fn dialer(num: u64) -> Self { + pub(crate) fn dialer(num: u64) -> Self { Self { num, role: Endpoint::Dialer, @@ -105,14 +105,14 @@ impl LocalStreamId { } #[cfg(test)] - pub fn listener(num: u64) -> Self { + pub(crate) fn listener(num: u64) -> Self { Self { num, role: Endpoint::Listener, } } - pub fn next(self) -> Self { + pub(crate) fn next(self) -> Self { Self { num: self .num @@ -123,7 +123,7 @@ impl LocalStreamId { } #[cfg(test)] - pub fn into_remote(self) -> RemoteStreamId { + pub(crate) fn into_remote(self) -> RemoteStreamId { RemoteStreamId { num: self.num, role: !self.role, @@ -148,7 +148,7 @@ impl RemoteStreamId { /// Converts this `RemoteStreamId` into the corresponding `LocalStreamId` /// that identifies the same substream. - pub fn into_local(self) -> LocalStreamId { + pub(crate) fn into_local(self) -> LocalStreamId { LocalStreamId { num: self.num, role: !self.role, @@ -158,7 +158,7 @@ impl RemoteStreamId { /// An Mplex protocol frame. #[derive(Debug, Clone, PartialEq, Eq)] -pub enum Frame { +pub(crate) enum Frame { Open { stream_id: T }, Data { stream_id: T, data: Bytes }, Close { stream_id: T }, @@ -166,7 +166,7 @@ pub enum Frame { } impl Frame { - pub fn remote_id(&self) -> RemoteStreamId { + pub(crate) fn remote_id(&self) -> RemoteStreamId { match *self { Frame::Open { stream_id } => stream_id, Frame::Data { stream_id, .. } => stream_id, @@ -176,7 +176,7 @@ impl Frame { } } -pub struct Codec { +pub(crate) struct Codec { varint_decoder: codec::Uvi, decoder_state: CodecDecodeState, } @@ -190,7 +190,7 @@ enum CodecDecodeState { } impl Codec { - pub fn new() -> Codec { + pub(crate) fn new() -> Codec { Codec { varint_decoder: codec::Uvi::default(), decoder_state: CodecDecodeState::Begin, diff --git a/muxers/mplex/src/io.rs b/muxers/mplex/src/io.rs index f1d6fa9bd1b..85b58820823 100644 --- a/muxers/mplex/src/io.rs +++ b/muxers/mplex/src/io.rs @@ -35,8 +35,7 @@ use std::{ task::{Context, Poll, Waker}, }; -pub use std::io::{Error, ErrorKind, Result}; - +pub(crate) use std::io::{Error, Result}; /// A connection identifier. /// /// Randomly generated and mainly intended to improve log output @@ -56,7 +55,7 @@ impl fmt::Display for ConnectionId { } } /// A multiplexed I/O stream. -pub struct Multiplexed { +pub(crate) struct Multiplexed { /// A unique ID for the multiplexed stream (i.e. connection). id: ConnectionId, /// The current operating status of the multiplex stream. @@ -116,7 +115,7 @@ where C: AsyncRead + AsyncWrite + Unpin, { /// Creates a new multiplexed I/O stream. - pub fn new(io: C, config: MplexConfig) -> Self { + pub(crate) fn new(io: C, config: MplexConfig) -> Self { let id = ConnectionId(rand::random()); debug!("New multiplexed connection: {}", id); Multiplexed { @@ -144,7 +143,7 @@ where } /// Flushes the underlying I/O stream. - pub fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_flush(&mut self, cx: &mut Context<'_>) -> Poll> { match &self.status { Status::Closed => return Poll::Ready(Ok(())), Status::Err(e) => return Poll::Ready(Err(io::Error::new(e.kind(), e.to_string()))), @@ -170,7 +169,7 @@ where /// > **Note**: No `Close` or `Reset` frames are sent on open substreams /// > before closing the underlying connection. However, the connection /// > close implies a flush of any frames already sent. - pub fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_close(&mut self, cx: &mut Context<'_>) -> Poll> { match &self.status { Status::Closed => return Poll::Ready(Ok(())), Status::Err(e) => return Poll::Ready(Err(io::Error::new(e.kind(), e.to_string()))), @@ -209,7 +208,10 @@ where /// [`MaxBufferBehaviour::Block`] is used, this method is blocked /// (i.e. `Pending`) on some task reading from the substream whose /// buffer is full. - pub fn poll_next_stream(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_next_stream( + &mut self, + cx: &mut Context<'_>, + ) -> Poll> { self.guard_open()?; // Try to read from the buffer first. @@ -250,7 +252,10 @@ where } /// Creates a new (outbound) substream, returning the allocated stream ID. - pub fn poll_open_stream(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_open_stream( + &mut self, + cx: &mut Context<'_>, + ) -> Poll> { self.guard_open()?; // Check the stream limits. @@ -317,7 +322,7 @@ where /// > **Note**: All substreams obtained via `poll_next_stream` /// > or `poll_open_stream` must eventually be "dropped" by /// > calling this method when they are no longer used. - pub fn drop_stream(&mut self, id: LocalStreamId) { + pub(crate) fn drop_stream(&mut self, id: LocalStreamId) { // Check if the underlying stream is ok. match self.status { Status::Closed | Status::Err(_) => return, @@ -367,7 +372,7 @@ where } /// Writes data to a substream. - pub fn poll_write_stream( + pub(crate) fn poll_write_stream( &mut self, cx: &mut Context<'_>, id: LocalStreamId, @@ -417,7 +422,7 @@ where /// and under consideration of the number of already used substreams, /// thereby waking the task that last called `poll_next_stream`, if any. /// Inbound substreams received in excess of that limit are immediately reset. - pub fn poll_read_stream( + pub(crate) fn poll_read_stream( &mut self, cx: &mut Context<'_>, id: LocalStreamId, @@ -509,7 +514,7 @@ where /// > **Note**: This is equivalent to `poll_flush()`, i.e. to flushing /// > all substreams, except that this operation returns an error if /// > the underlying I/O stream is already closed. - pub fn poll_flush_stream( + pub(crate) fn poll_flush_stream( &mut self, cx: &mut Context<'_>, id: LocalStreamId, @@ -525,7 +530,7 @@ where /// Closes a stream for writing. /// /// > **Note**: As opposed to `poll_close()`, a flush it not implied. - pub fn poll_close_stream( + pub(crate) fn poll_close_stream( &mut self, cx: &mut Context<'_>, id: LocalStreamId, diff --git a/protocols/autonat/src/behaviour/as_client.rs b/protocols/autonat/src/behaviour/as_client.rs index 1c1eea9b723..e0c0b2e9e0a 100644 --- a/protocols/autonat/src/behaviour/as_client.rs +++ b/protocols/autonat/src/behaviour/as_client.rs @@ -83,26 +83,21 @@ pub enum OutboundProbeEvent { } /// View over [`super::Behaviour`] in a client role. -pub struct AsClient<'a> { - pub inner: &'a mut request_response::Behaviour, - pub local_peer_id: PeerId, - pub config: &'a Config, - pub connected: &'a HashMap>>, - pub probe_id: &'a mut ProbeId, - - pub servers: &'a HashSet, - pub throttled_servers: &'a mut Vec<(PeerId, Instant)>, - - pub nat_status: &'a mut NatStatus, - pub confidence: &'a mut usize, - - pub ongoing_outbound: &'a mut HashMap, - - pub last_probe: &'a mut Option, - pub schedule_probe: &'a mut Delay, - - pub listen_addresses: &'a ListenAddresses, - pub external_addresses: &'a ExternalAddresses, +pub(crate) struct AsClient<'a> { + pub(crate) inner: &'a mut request_response::Behaviour, + pub(crate) local_peer_id: PeerId, + pub(crate) config: &'a Config, + pub(crate) connected: &'a HashMap>>, + pub(crate) probe_id: &'a mut ProbeId, + pub(crate) servers: &'a HashSet, + pub(crate) throttled_servers: &'a mut Vec<(PeerId, Instant)>, + pub(crate) nat_status: &'a mut NatStatus, + pub(crate) confidence: &'a mut usize, + pub(crate) ongoing_outbound: &'a mut HashMap, + pub(crate) last_probe: &'a mut Option, + pub(crate) schedule_probe: &'a mut Delay, + pub(crate) listen_addresses: &'a ListenAddresses, + pub(crate) external_addresses: &'a ExternalAddresses, } impl<'a> HandleInnerEvent for AsClient<'a> { @@ -200,7 +195,7 @@ impl<'a> HandleInnerEvent for AsClient<'a> { } impl<'a> AsClient<'a> { - pub fn poll_auto_probe(&mut self, cx: &mut Context<'_>) -> Poll { + pub(crate) fn poll_auto_probe(&mut self, cx: &mut Context<'_>) -> Poll { match self.schedule_probe.poll_unpin(cx) { Poll::Ready(()) => { self.schedule_probe.reset(self.config.retry_interval); @@ -231,7 +226,7 @@ impl<'a> AsClient<'a> { } // An inbound connection can indicate that we are public; adjust the delay to the next probe. - pub fn on_inbound_connection(&mut self) { + pub(crate) fn on_inbound_connection(&mut self) { if *self.confidence == self.config.confidence_max { if self.nat_status.is_public() { self.schedule_next_probe(self.config.refresh_interval * 2); @@ -241,7 +236,7 @@ impl<'a> AsClient<'a> { } } - pub fn on_new_address(&mut self) { + pub(crate) fn on_new_address(&mut self) { if !self.nat_status.is_public() { // New address could be publicly reachable, trigger retry. if *self.confidence > 0 { @@ -251,7 +246,7 @@ impl<'a> AsClient<'a> { } } - pub fn on_expired_address(&mut self, addr: &Multiaddr) { + pub(crate) fn on_expired_address(&mut self, addr: &Multiaddr) { if let NatStatus::Public(public_address) = self.nat_status { if public_address == addr { *self.confidence = 0; diff --git a/protocols/autonat/src/behaviour/as_server.rs b/protocols/autonat/src/behaviour/as_server.rs index 822b0552e7f..063943392f3 100644 --- a/protocols/autonat/src/behaviour/as_server.rs +++ b/protocols/autonat/src/behaviour/as_server.rs @@ -74,16 +74,14 @@ pub enum InboundProbeEvent { } /// View over [`super::Behaviour`] in a server role. -pub struct AsServer<'a> { - pub inner: &'a mut request_response::Behaviour, - pub config: &'a Config, - pub connected: &'a HashMap>>, - pub probe_id: &'a mut ProbeId, - - pub throttled_clients: &'a mut Vec<(PeerId, Instant)>, - +pub(crate) struct AsServer<'a> { + pub(crate) inner: &'a mut request_response::Behaviour, + pub(crate) config: &'a Config, + pub(crate) connected: &'a HashMap>>, + pub(crate) probe_id: &'a mut ProbeId, + pub(crate) throttled_clients: &'a mut Vec<(PeerId, Instant)>, #[allow(clippy::type_complexity)] - pub ongoing_inbound: &'a mut HashMap< + pub(crate) ongoing_inbound: &'a mut HashMap< PeerId, ( ProbeId, @@ -197,7 +195,7 @@ impl<'a> HandleInnerEvent for AsServer<'a> { } impl<'a> AsServer<'a> { - pub fn on_outbound_connection( + pub(crate) fn on_outbound_connection( &mut self, peer: &PeerId, address: &Multiaddr, @@ -229,7 +227,7 @@ impl<'a> AsServer<'a> { }) } - pub fn on_outbound_dial_error( + pub(crate) fn on_outbound_dial_error( &mut self, peer: Option, error: &DialError, diff --git a/protocols/autonat/src/lib.rs b/protocols/autonat/src/lib.rs index e0fc3e9bc81..10c87b1e984 100644 --- a/protocols/autonat/src/lib.rs +++ b/protocols/autonat/src/lib.rs @@ -35,6 +35,7 @@ pub use self::{ pub use libp2p_request_response::{InboundFailure, OutboundFailure}; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::structs::{mod_Message::*, Message}; + pub(crate) use self::structs::{mod_Message::*, Message}; } diff --git a/protocols/dcutr/src/handler.rs b/protocols/dcutr/src/handler.rs index cc59e3ab4ce..0339b9654d3 100644 --- a/protocols/dcutr/src/handler.rs +++ b/protocols/dcutr/src/handler.rs @@ -18,5 +18,5 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -pub mod direct; -pub mod relayed; +pub(crate) mod direct; +pub(crate) mod relayed; diff --git a/protocols/dcutr/src/lib.rs b/protocols/dcutr/src/lib.rs index 8d5db45000c..b35849319d2 100644 --- a/protocols/dcutr/src/lib.rs +++ b/protocols/dcutr/src/lib.rs @@ -28,8 +28,9 @@ mod handler; mod protocol; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::holepunch::pb::{mod_HolePunch::*, HolePunch}; + pub(crate) use self::holepunch::pb::{mod_HolePunch::*, HolePunch}; } pub use behaviour_impl::Behaviour; diff --git a/protocols/dcutr/src/protocol.rs b/protocols/dcutr/src/protocol.rs index 67f9af69f70..4da255fc1d9 100644 --- a/protocols/dcutr/src/protocol.rs +++ b/protocols/dcutr/src/protocol.rs @@ -18,9 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -pub mod inbound; -pub mod outbound; - +pub(crate) mod inbound; +pub(crate) mod outbound; pub const PROTOCOL_NAME: &[u8; 13] = b"/libp2p/dcutr"; const MAX_MESSAGE_SIZE_BYTES: usize = 4096; diff --git a/protocols/floodsub/src/lib.rs b/protocols/floodsub/src/lib.rs index 6bd4dfac9bf..94766d5fdca 100644 --- a/protocols/floodsub/src/lib.rs +++ b/protocols/floodsub/src/lib.rs @@ -30,8 +30,9 @@ mod layer; mod topic; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::floodsub::pb::{mod_RPC::SubOpts, Message, RPC}; + pub(crate) use self::floodsub::pb::{mod_RPC::SubOpts, Message, RPC}; } pub use self::layer::{Floodsub, FloodsubEvent}; diff --git a/protocols/gossipsub/src/backoff.rs b/protocols/gossipsub/src/backoff.rs index b05d338deff..e6f05047a3e 100644 --- a/protocols/gossipsub/src/backoff.rs +++ b/protocols/gossipsub/src/backoff.rs @@ -32,7 +32,7 @@ use wasm_timer::Instant; struct HeartbeatIndex(usize); /// Stores backoffs in an efficient manner. -pub struct BackoffStorage { +pub(crate) struct BackoffStorage { /// Stores backoffs and the index in backoffs_by_heartbeat per peer per topic. backoffs: HashMap>, /// Stores peer topic pairs per heartbeat (this is cyclic the current index is @@ -52,7 +52,7 @@ impl BackoffStorage { as usize } - pub fn new( + pub(crate) fn new( prune_backoff: &Duration, heartbeat_interval: Duration, backoff_slack: u32, @@ -71,7 +71,7 @@ impl BackoffStorage { /// Updates the backoff for a peer (if there is already a more restrictive backoff then this call /// doesn't change anything). - pub fn update_backoff(&mut self, topic: &TopicHash, peer: &PeerId, time: Duration) { + pub(crate) fn update_backoff(&mut self, topic: &TopicHash, peer: &PeerId, time: Duration) { let instant = Instant::now() + time; let insert_into_backoffs_by_heartbeat = |heartbeat_index: HeartbeatIndex, @@ -127,13 +127,13 @@ impl BackoffStorage { /// /// This method should be used for deciding if we can already send a GRAFT to a previously /// backoffed peer. - pub fn is_backoff_with_slack(&self, topic: &TopicHash, peer: &PeerId) -> bool { + pub(crate) fn is_backoff_with_slack(&self, topic: &TopicHash, peer: &PeerId) -> bool { self.backoffs .get(topic) .map_or(false, |m| m.contains_key(peer)) } - pub fn get_backoff_time(&self, topic: &TopicHash, peer: &PeerId) -> Option { + pub(crate) fn get_backoff_time(&self, topic: &TopicHash, peer: &PeerId) -> Option { Self::get_backoff_time_from_backoffs(&self.backoffs, topic, peer) } @@ -149,7 +149,7 @@ impl BackoffStorage { /// Applies a heartbeat. That should be called regularly in intervals of length /// `heartbeat_interval`. - pub fn heartbeat(&mut self) { + pub(crate) fn heartbeat(&mut self) { // Clean up backoffs_by_heartbeat if let Some(s) = self.backoffs_by_heartbeat.get_mut(self.heartbeat_index.0) { let backoffs = &mut self.backoffs; diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 9e06f448afa..13ce3fcee35 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -189,7 +189,7 @@ impl SequenceNumber { } impl PublishConfig { - pub fn get_own_id(&self) -> Option<&PeerId> { + pub(crate) fn get_own_id(&self) -> Option<&PeerId> { match self { Self::Signing { author, .. } => Some(author), Self::Author(author) => Some(author), diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index ca94e4ac15f..9b662f765d5 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -61,7 +61,7 @@ where D: DataTransform + Default + Clone + Send + 'static, F: TopicSubscriptionFilter + Clone + Default + Send + 'static, { - pub fn create_network(self) -> (Behaviour, Vec, Vec) { + pub(crate) fn create_network(self) -> (Behaviour, Vec, Vec) { let keypair = libp2p_identity::Keypair::generate_ed25519(); // create a gossipsub struct let mut gs: Behaviour = Behaviour::new_with_subscription_filter_and_transform( diff --git a/protocols/gossipsub/src/gossip_promises.rs b/protocols/gossipsub/src/gossip_promises.rs index a5804c82c01..cae3b169033 100644 --- a/protocols/gossipsub/src/gossip_promises.rs +++ b/protocols/gossipsub/src/gossip_promises.rs @@ -38,12 +38,12 @@ pub(crate) struct GossipPromises { impl GossipPromises { /// Returns true if the message id exists in the promises. - pub fn contains(&self, message: &MessageId) -> bool { + pub(crate) fn contains(&self, message: &MessageId) -> bool { self.promises.contains_key(message) } /// Track a promise to deliver a message from a list of [`MessageId`]s we are requesting. - pub fn add_promise(&mut self, peer: PeerId, messages: &[MessageId], expires: Instant) { + pub(crate) fn add_promise(&mut self, peer: PeerId, messages: &[MessageId], expires: Instant) { for message_id in messages { // If a promise for this message id and peer already exists we don't update the expiry! self.promises @@ -54,12 +54,12 @@ impl GossipPromises { } } - pub fn message_delivered(&mut self, message_id: &MessageId) { + pub(crate) fn message_delivered(&mut self, message_id: &MessageId) { // Someone delivered a message, we can stop tracking all promises for it. self.promises.remove(message_id); } - pub fn reject_message(&mut self, message_id: &MessageId, reason: &RejectReason) { + pub(crate) fn reject_message(&mut self, message_id: &MessageId, reason: &RejectReason) { // A message got rejected, so we can stop tracking promises and let the score penalty apply // from invalid message delivery. // We do take exception and apply promise penalty regardless in the following cases, where @@ -77,7 +77,7 @@ impl GossipPromises { /// request. /// This should be called not too often relative to the expire times, since it iterates over /// the whole stored data. - pub fn get_broken_promises(&mut self) -> HashMap { + pub(crate) fn get_broken_promises(&mut self) -> HashMap { let now = Instant::now(); let mut result = HashMap::new(); self.promises.retain(|msg, peers| { diff --git a/protocols/gossipsub/src/mcache.rs b/protocols/gossipsub/src/mcache.rs index 7fa08a6ac6a..e85a5bf9c6a 100644 --- a/protocols/gossipsub/src/mcache.rs +++ b/protocols/gossipsub/src/mcache.rs @@ -31,14 +31,14 @@ use std::{ /// CacheEntry stored in the history. #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CacheEntry { +pub(crate) struct CacheEntry { mid: MessageId, topic: TopicHash, } /// MessageCache struct holding history of messages. #[derive(Clone)] -pub struct MessageCache { +pub(crate) struct MessageCache { msgs: HashMap)>, /// For every message and peer the number of times this peer asked for the message iwant_counts: HashMap>, @@ -61,7 +61,7 @@ impl fmt::Debug for MessageCache { /// Implementation of the MessageCache. impl MessageCache { - pub fn new(gossip: usize, history_capacity: usize) -> Self { + pub(crate) fn new(gossip: usize, history_capacity: usize) -> Self { MessageCache { gossip, msgs: HashMap::default(), @@ -73,7 +73,7 @@ impl MessageCache { /// Put a message into the memory cache. /// /// Returns true if the message didn't already exist in the cache. - pub fn put(&mut self, message_id: &MessageId, msg: RawMessage) -> bool { + pub(crate) fn put(&mut self, message_id: &MessageId, msg: RawMessage) -> bool { match self.msgs.entry(message_id.clone()) { Entry::Occupied(_) => { // Don't add duplicate entries to the cache. @@ -94,7 +94,7 @@ impl MessageCache { } /// Keeps track of peers we know have received the message to prevent forwarding to said peers. - pub fn observe_duplicate(&mut self, message_id: &MessageId, source: &PeerId) { + pub(crate) fn observe_duplicate(&mut self, message_id: &MessageId, source: &PeerId) { if let Some((message, originating_peers)) = self.msgs.get_mut(message_id) { // if the message is already validated, we don't need to store extra peers sending us // duplicates as the message has already been forwarded @@ -108,13 +108,13 @@ impl MessageCache { /// Get a message with `message_id` #[cfg(test)] - pub fn get(&self, message_id: &MessageId) -> Option<&RawMessage> { + pub(crate) fn get(&self, message_id: &MessageId) -> Option<&RawMessage> { self.msgs.get(message_id).map(|(message, _)| message) } /// Increases the iwant count for the given message by one and returns the message together /// with the iwant if the message exists. - pub fn get_with_iwant_counts( + pub(crate) fn get_with_iwant_counts( &mut self, message_id: &MessageId, peer: &PeerId, @@ -140,7 +140,10 @@ impl MessageCache { /// Gets a message with [`MessageId`] and tags it as validated. /// This function also returns the known peers that have sent us this message. This is used to /// prevent us sending redundant messages to peers who have already propagated it. - pub fn validate(&mut self, message_id: &MessageId) -> Option<(&RawMessage, HashSet)> { + pub(crate) fn validate( + &mut self, + message_id: &MessageId, + ) -> Option<(&RawMessage, HashSet)> { self.msgs.get_mut(message_id).map(|(message, known_peers)| { message.validated = true; // Clear the known peers list (after a message is validated, it is forwarded and we no @@ -151,7 +154,7 @@ impl MessageCache { } /// Get a list of [`MessageId`]s for a given topic. - pub fn get_gossip_message_ids(&self, topic: &TopicHash) -> Vec { + pub(crate) fn get_gossip_message_ids(&self, topic: &TopicHash) -> Vec { self.history[..self.gossip] .iter() .fold(vec![], |mut current_entries, entries| { @@ -181,7 +184,7 @@ impl MessageCache { /// Shift the history array down one and delete messages associated with the /// last entry. - pub fn shift(&mut self) { + pub(crate) fn shift(&mut self) { for entry in self.history.pop().expect("history is always > 1") { if let Some((msg, _)) = self.msgs.remove(&entry.mid) { if !msg.validated { @@ -204,7 +207,10 @@ impl MessageCache { } /// Removes a message from the cache and returns it if existent - pub fn remove(&mut self, message_id: &MessageId) -> Option<(RawMessage, HashSet)> { + pub(crate) fn remove( + &mut self, + message_id: &MessageId, + ) -> Option<(RawMessage, HashSet)> { //We only remove the message from msgs and iwant_count and keep the message_id in the // history vector. Zhe id in the history vector will simply be ignored on popping. diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 1270ad1274b..2f17b14b7a6 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -95,7 +95,7 @@ impl Default for PeerStats { impl PeerStats { /// Returns a mutable reference to topic stats if they exist, otherwise if the supplied parameters score the /// topic, inserts the default stats and returns a reference to those. If neither apply, returns None. - pub fn stats_or_default_mut( + pub(crate) fn stats_or_default_mut( &mut self, topic_hash: TopicHash, params: &PeerScoreParams, @@ -125,7 +125,7 @@ struct TopicStats { impl TopicStats { /// Returns true if the peer is in the `mesh`. - pub fn in_mesh(&self) -> bool { + pub(crate) fn in_mesh(&self) -> bool { matches!(self.mesh_status, MeshStatus::Active { .. }) } } @@ -143,7 +143,7 @@ enum MeshStatus { impl MeshStatus { /// Initialises a new [`MeshStatus::Active`] mesh status. - pub fn new_active() -> Self { + pub(crate) fn new_active() -> Self { MeshStatus::Active { graft_time: Instant::now(), mesh_time: Duration::from_secs(0), @@ -196,11 +196,11 @@ impl Default for DeliveryRecord { impl PeerScore { /// Creates a new [`PeerScore`] using a given set of peer scoring parameters. #[allow(dead_code)] - pub fn new(params: PeerScoreParams) -> Self { + pub(crate) fn new(params: PeerScoreParams) -> Self { Self::new_with_message_delivery_time_callback(params, None) } - pub fn new_with_message_delivery_time_callback( + pub(crate) fn new_with_message_delivery_time_callback( params: PeerScoreParams, callback: Option, ) -> Self { @@ -214,13 +214,13 @@ impl PeerScore { } /// Returns the score for a peer - pub fn score(&self, peer_id: &PeerId) -> f64 { + pub(crate) fn score(&self, peer_id: &PeerId) -> f64 { self.metric_score(peer_id, None) } /// Returns the score for a peer, logging metrics. This is called from the heartbeat and /// increments the metric counts for penalties. - pub fn metric_score(&self, peer_id: &PeerId, mut metrics: Option<&mut Metrics>) -> f64 { + pub(crate) fn metric_score(&self, peer_id: &PeerId, mut metrics: Option<&mut Metrics>) -> f64 { let peer_stats = match self.peer_stats.get(peer_id) { Some(v) => v, None => return 0.0, @@ -345,7 +345,7 @@ impl PeerScore { score } - pub fn add_penalty(&mut self, peer_id: &PeerId, count: usize) { + pub(crate) fn add_penalty(&mut self, peer_id: &PeerId, count: usize) { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { debug!( "[Penalty] Behavioral penalty for peer {}, count = {}.", @@ -367,7 +367,7 @@ impl PeerScore { } } - pub fn refresh_scores(&mut self) { + pub(crate) fn refresh_scores(&mut self) { let now = Instant::now(); let params_ref = &self.params; let peer_ips_ref = &mut self.peer_ips; @@ -436,7 +436,7 @@ impl PeerScore { /// Adds a connected peer to [`PeerScore`], initialising with empty ips (ips get added later /// through add_ip. - pub fn add_peer(&mut self, peer_id: PeerId) { + pub(crate) fn add_peer(&mut self, peer_id: PeerId) { let peer_stats = self.peer_stats.entry(peer_id).or_default(); // mark the peer as connected @@ -444,7 +444,7 @@ impl PeerScore { } /// Adds a new ip to a peer, if the peer is not yet known creates a new peer_stats entry for it - pub fn add_ip(&mut self, peer_id: &PeerId, ip: IpAddr) { + pub(crate) fn add_ip(&mut self, peer_id: &PeerId, ip: IpAddr) { trace!("Add ip for peer {}, ip: {}", peer_id, ip); let peer_stats = self.peer_stats.entry(*peer_id).or_default(); @@ -461,7 +461,7 @@ impl PeerScore { } /// Removes an ip from a peer - pub fn remove_ip(&mut self, peer_id: &PeerId, ip: &IpAddr) { + pub(crate) fn remove_ip(&mut self, peer_id: &PeerId, ip: &IpAddr) { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { peer_stats.known_ips.remove(ip); if let Some(peer_ids) = self.peer_ips.get_mut(ip) { @@ -485,7 +485,7 @@ impl PeerScore { /// Removes a peer from the score table. This retains peer statistics if their score is /// non-positive. - pub fn remove_peer(&mut self, peer_id: &PeerId) { + pub(crate) fn remove_peer(&mut self, peer_id: &PeerId) { // we only retain non-positive scores of peers if self.score(peer_id) > 0f64 { if let hash_map::Entry::Occupied(entry) = self.peer_stats.entry(*peer_id) { @@ -527,7 +527,7 @@ impl PeerScore { } /// Handles scoring functionality as a peer GRAFTs to a topic. - pub fn graft(&mut self, peer_id: &PeerId, topic: impl Into) { + pub(crate) fn graft(&mut self, peer_id: &PeerId, topic: impl Into) { let topic = topic.into(); if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { // if we are scoring the topic, update the mesh status. @@ -539,7 +539,7 @@ impl PeerScore { } /// Handles scoring functionality as a peer PRUNEs from a topic. - pub fn prune(&mut self, peer_id: &PeerId, topic: TopicHash) { + pub(crate) fn prune(&mut self, peer_id: &PeerId, topic: TopicHash) { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { // if we are scoring the topic, update the mesh status. if let Some(topic_stats) = peer_stats.stats_or_default_mut(topic.clone(), &self.params) @@ -563,7 +563,12 @@ impl PeerScore { } } - pub fn validate_message(&mut self, from: &PeerId, msg_id: &MessageId, topic_hash: &TopicHash) { + pub(crate) fn validate_message( + &mut self, + from: &PeerId, + msg_id: &MessageId, + topic_hash: &TopicHash, + ) { // adds an empty record with the message id self.deliveries .entry(msg_id.clone()) @@ -582,7 +587,12 @@ impl PeerScore { } } - pub fn deliver_message(&mut self, from: &PeerId, msg_id: &MessageId, topic_hash: &TopicHash) { + pub(crate) fn deliver_message( + &mut self, + from: &PeerId, + msg_id: &MessageId, + topic_hash: &TopicHash, + ) { self.mark_first_message_delivery(from, topic_hash); let record = self @@ -608,7 +618,7 @@ impl PeerScore { } /// Similar to `reject_message` except does not require the message id or reason for an invalid message. - pub fn reject_invalid_message(&mut self, from: &PeerId, topic_hash: &TopicHash) { + pub(crate) fn reject_invalid_message(&mut self, from: &PeerId, topic_hash: &TopicHash) { debug!( "[Penalty] Message from {} rejected because of ValidationError or SelfOrigin", from @@ -618,7 +628,7 @@ impl PeerScore { } // Reject a message. - pub fn reject_message( + pub(crate) fn reject_message( &mut self, from: &PeerId, msg_id: &MessageId, @@ -670,7 +680,7 @@ impl PeerScore { } } - pub fn duplicated_message( + pub(crate) fn duplicated_message( &mut self, from: &PeerId, msg_id: &MessageId, @@ -726,7 +736,7 @@ impl PeerScore { /// Sets the application specific score for a peer. Returns true if the peer is the peer is /// connected or if the score of the peer is not yet expired and false otherwise. - pub fn set_application_score(&mut self, peer_id: &PeerId, new_score: f64) -> bool { + pub(crate) fn set_application_score(&mut self, peer_id: &PeerId, new_score: f64) -> bool { if let Some(peer_stats) = self.peer_stats.get_mut(peer_id) { peer_stats.application_score = new_score; true @@ -736,7 +746,7 @@ impl PeerScore { } /// Sets scoring parameters for a topic. - pub fn set_topic_params(&mut self, topic_hash: TopicHash, params: TopicScoreParams) { + pub(crate) fn set_topic_params(&mut self, topic_hash: TopicHash, params: TopicScoreParams) { use hash_map::Entry::*; match self.params.topics.entry(topic_hash.clone()) { Occupied(mut entry) => { diff --git a/protocols/gossipsub/src/rpc_proto.rs b/protocols/gossipsub/src/rpc_proto.rs index 470475070b9..94c7aafbc3e 100644 --- a/protocols/gossipsub/src/rpc_proto.rs +++ b/protocols/gossipsub/src/rpc_proto.rs @@ -18,7 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -pub mod proto { +pub(crate) mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); pub use self::gossipsub::pb::{mod_RPC::SubOpts, *}; } diff --git a/protocols/gossipsub/src/types.rs b/protocols/gossipsub/src/types.rs index ae9b5a09f35..9c9cd3f97f1 100644 --- a/protocols/gossipsub/src/types.rs +++ b/protocols/gossipsub/src/types.rs @@ -88,11 +88,11 @@ declare_message_id_type!(MessageId, "MessageId"); declare_message_id_type!(FastMessageId, "FastMessageId"); #[derive(Debug, Clone, PartialEq, Eq)] -pub struct PeerConnections { +pub(crate) struct PeerConnections { /// The kind of protocol the peer supports. - pub kind: PeerKind, + pub(crate) kind: PeerKind, /// Its current connections. - pub connections: Vec, + pub(crate) connections: Vec, } /// Describes the types of peers that can exist in the gossipsub context. diff --git a/protocols/identify/src/lib.rs b/protocols/identify/src/lib.rs index 7fb8df253ff..f7a4a1ecbd8 100644 --- a/protocols/identify/src/lib.rs +++ b/protocols/identify/src/lib.rs @@ -70,6 +70,7 @@ mod handler; mod protocol; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::structs::Identify; + pub(crate) use self::structs::Identify; } diff --git a/protocols/kad/src/jobs.rs b/protocols/kad/src/jobs.rs index 22e3dfc6797..cfc4f92941b 100644 --- a/protocols/kad/src/jobs.rs +++ b/protocols/kad/src/jobs.rs @@ -75,12 +75,10 @@ use std::vec; /// The maximum number of queries towards which background jobs /// are allowed to start new queries on an invocation of /// `Kademlia::poll`. -pub const JOBS_MAX_QUERIES: usize = 100; - +pub(crate) const JOBS_MAX_QUERIES: usize = 100; /// The maximum number of new queries started by a background job /// per invocation of `Kademlia::poll`. -pub const JOBS_MAX_NEW_QUERIES: usize = 10; - +pub(crate) const JOBS_MAX_NEW_QUERIES: usize = 10; /// A background job run periodically. #[derive(Debug)] struct PeriodicJob { @@ -129,7 +127,7 @@ enum PeriodicJobState { // PutRecordJob /// Periodic job for replicating / publishing records. -pub struct PutRecordJob { +pub(crate) struct PutRecordJob { local_id: PeerId, next_publish: Option, publish_interval: Option, @@ -141,7 +139,7 @@ pub struct PutRecordJob { impl PutRecordJob { /// Creates a new periodic job for replicating and re-publishing /// locally stored records. - pub fn new( + pub(crate) fn new( local_id: PeerId, replicate_interval: Duration, publish_interval: Option, @@ -166,12 +164,12 @@ impl PutRecordJob { /// Adds the key of a record that is ignored on the current or /// next run of the job. - pub fn skip(&mut self, key: record_priv::Key) { + pub(crate) fn skip(&mut self, key: record_priv::Key) { self.skipped.insert(key); } /// Checks whether the job is currently running. - pub fn is_running(&self) -> bool { + pub(crate) fn is_running(&self) -> bool { self.inner.is_running() } @@ -179,7 +177,7 @@ impl PutRecordJob { /// for the delay to expire. /// /// The job is guaranteed to run on the next invocation of `poll`. - pub fn asap(&mut self, publish: bool) { + pub(crate) fn asap(&mut self, publish: bool) { if publish { self.next_publish = Some(Instant::now().checked_sub(Duration::from_secs(1)).unwrap()) } @@ -191,7 +189,12 @@ impl PutRecordJob { /// Must be called in the context of a task. When `NotReady` is returned, /// the current task is registered to be notified when the job is ready /// to be run. - pub fn poll(&mut self, cx: &mut Context<'_>, store: &mut T, now: Instant) -> Poll + pub(crate) fn poll( + &mut self, + cx: &mut Context<'_>, + store: &mut T, + now: Instant, + ) -> Poll where T: RecordStore, { @@ -250,13 +253,13 @@ impl PutRecordJob { // AddProviderJob /// Periodic job for replicating provider records. -pub struct AddProviderJob { +pub(crate) struct AddProviderJob { inner: PeriodicJob>, } impl AddProviderJob { /// Creates a new periodic job for provider announcements. - pub fn new(interval: Duration) -> Self { + pub(crate) fn new(interval: Duration) -> Self { let now = Instant::now(); Self { inner: PeriodicJob { @@ -270,7 +273,7 @@ impl AddProviderJob { } /// Checks whether the job is currently running. - pub fn is_running(&self) -> bool { + pub(crate) fn is_running(&self) -> bool { self.inner.is_running() } @@ -278,7 +281,7 @@ impl AddProviderJob { /// for the delay to expire. /// /// The job is guaranteed to run on the next invocation of `poll`. - pub fn asap(&mut self) { + pub(crate) fn asap(&mut self) { self.inner.asap() } @@ -287,7 +290,7 @@ impl AddProviderJob { /// Must be called in the context of a task. When `NotReady` is returned, /// the current task is registered to be notified when the job is ready /// to be run. - pub fn poll( + pub(crate) fn poll( &mut self, cx: &mut Context<'_>, store: &mut T, diff --git a/protocols/kad/src/kbucket_priv/bucket.rs b/protocols/kad/src/kbucket_priv/bucket.rs index 1f560676608..78bcd95261b 100644 --- a/protocols/kad/src/kbucket_priv/bucket.rs +++ b/protocols/kad/src/kbucket_priv/bucket.rs @@ -30,7 +30,7 @@ pub use crate::K_VALUE; /// A `PendingNode` is a `Node` that is pending insertion into a `KBucket`. #[derive(Debug, Clone)] -pub struct PendingNode { +pub(crate) struct PendingNode { /// The pending node to insert. node: Node, @@ -55,27 +55,27 @@ pub enum NodeStatus { } impl PendingNode { - pub fn key(&self) -> &TKey { + pub(crate) fn key(&self) -> &TKey { &self.node.key } - pub fn status(&self) -> NodeStatus { + pub(crate) fn status(&self) -> NodeStatus { self.status } - pub fn value_mut(&mut self) -> &mut TVal { + pub(crate) fn value_mut(&mut self) -> &mut TVal { &mut self.node.value } - pub fn is_ready(&self) -> bool { + pub(crate) fn is_ready(&self) -> bool { Instant::now() >= self.replace } - pub fn set_ready_at(&mut self, t: Instant) { + pub(crate) fn set_ready_at(&mut self, t: Instant) { self.replace = t; } - pub fn into_node(self) -> Node { + pub(crate) fn into_node(self) -> Node { self.node } } @@ -94,12 +94,11 @@ pub struct Node { /// The position of a node in a `KBucket`, i.e. a non-negative integer /// in the range `[0, K_VALUE)`. #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] -pub struct Position(usize); - +pub(crate) struct Position(usize); /// A `KBucket` is a list of up to `K_VALUE` keys and associated values, /// ordered from least-recently connected to most-recently connected. #[derive(Debug, Clone)] -pub struct KBucket { +pub(crate) struct KBucket { /// The nodes contained in the bucket. nodes: ArrayVec, { K_VALUE.get() }>, @@ -167,7 +166,7 @@ where TVal: Clone, { /// Creates a new `KBucket` with the given timeout for pending entries. - pub fn new(pending_timeout: Duration) -> Self { + pub(crate) fn new(pending_timeout: Duration) -> Self { KBucket { nodes: ArrayVec::new(), first_connected_pos: None, @@ -177,29 +176,29 @@ where } /// Returns a reference to the pending node of the bucket, if there is any. - pub fn pending(&self) -> Option<&PendingNode> { + pub(crate) fn pending(&self) -> Option<&PendingNode> { self.pending.as_ref() } /// Returns a mutable reference to the pending node of the bucket, if there is any. - pub fn pending_mut(&mut self) -> Option<&mut PendingNode> { + pub(crate) fn pending_mut(&mut self) -> Option<&mut PendingNode> { self.pending.as_mut() } /// Returns a reference to the pending node of the bucket, if there is any /// with a matching key. - pub fn as_pending(&self, key: &TKey) -> Option<&PendingNode> { + pub(crate) fn as_pending(&self, key: &TKey) -> Option<&PendingNode> { self.pending() .filter(|p| p.node.key.as_ref() == key.as_ref()) } /// Returns a reference to a node in the bucket. - pub fn get(&self, key: &TKey) -> Option<&Node> { + 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 fn iter(&self) -> impl Iterator, NodeStatus)> { + pub(crate) fn iter(&self) -> impl Iterator, NodeStatus)> { self.nodes .iter() .enumerate() @@ -212,7 +211,7 @@ where /// If a pending node has been inserted, its key is returned together with /// the node that was replaced. `None` indicates that the nodes in the /// bucket remained unchanged. - pub fn apply_pending(&mut self) -> Option> { + pub(crate) fn apply_pending(&mut self) -> Option> { if let Some(pending) = self.pending.take() { if pending.replace <= Instant::now() { if self.nodes.is_full() { @@ -269,20 +268,20 @@ where } /// Updates the status of the pending node, if any. - pub fn update_pending(&mut self, status: NodeStatus) { + pub(crate) fn update_pending(&mut self, status: NodeStatus) { if let Some(pending) = &mut self.pending { pending.status = status } } /// Removes the pending node from the bucket, if any. - pub fn remove_pending(&mut self) -> Option> { + pub(crate) fn remove_pending(&mut self) -> Option> { self.pending.take() } /// Updates the status of the node referred to by the given key, if it is /// in the bucket. - pub fn update(&mut self, key: &TKey, status: NodeStatus) { + pub(crate) fn update(&mut self, key: &TKey, status: NodeStatus) { // Remove the node from its current position and then reinsert it // with the desired status, which puts it at the end of either the // prefix list of disconnected nodes or the suffix list of connected @@ -319,7 +318,11 @@ where /// i.e. as the most-recently disconnected node. If there are no connected nodes, /// the new node is added as the last element of the bucket. /// - pub fn insert(&mut self, node: Node, status: NodeStatus) -> InsertResult { + pub(crate) fn insert( + &mut self, + node: Node, + status: NodeStatus, + ) -> InsertResult { match status { NodeStatus::Connected => { if self.nodes.is_full() { @@ -357,7 +360,10 @@ where } /// Removes the node with the given key from the bucket, if it exists. - pub fn remove(&mut self, key: &TKey) -> Option<(Node, NodeStatus, Position)> { + pub(crate) fn remove( + &mut self, + key: &TKey, + ) -> Option<(Node, NodeStatus, Position)> { if let Some(pos) = self.position(key) { // Remove the node from its current position. let status = self.status(pos); @@ -385,7 +391,7 @@ where } /// Returns the status of the node at the given position. - pub fn status(&self, pos: Position) -> NodeStatus { + pub(crate) fn status(&self, pos: Position) -> NodeStatus { if self.first_connected_pos.map_or(false, |i| pos.0 >= i) { NodeStatus::Connected } else { @@ -394,27 +400,27 @@ where } /// Checks whether the given position refers to a connected node. - pub fn is_connected(&self, pos: Position) -> bool { + pub(crate) fn is_connected(&self, pos: Position) -> bool { self.status(pos) == NodeStatus::Connected } /// Gets the number of entries currently in the bucket. - pub fn num_entries(&self) -> usize { + pub(crate) fn num_entries(&self) -> usize { self.nodes.len() } /// Gets the number of entries in the bucket that are considered connected. - pub fn num_connected(&self) -> usize { + 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. - pub fn num_disconnected(&self) -> usize { + pub(crate) fn num_disconnected(&self) -> usize { self.nodes.len() - self.num_connected() } /// Gets the position of an node in the bucket. - pub fn position(&self, key: &TKey) -> Option { + pub(crate) fn position(&self, key: &TKey) -> Option { self.nodes .iter() .position(|p| p.key.as_ref() == key.as_ref()) @@ -425,7 +431,7 @@ where /// /// Returns `None` if the given key does not refer to a node in the /// bucket. - pub fn get_mut(&mut self, key: &TKey) -> Option<&mut Node> { + pub(crate) fn get_mut(&mut self, key: &TKey) -> Option<&mut Node> { self.nodes .iter_mut() .find(move |p| p.key.as_ref() == key.as_ref()) diff --git a/protocols/kad/src/lib.rs b/protocols/kad/src/lib.rs index 36f2c74bb41..c3a705900d8 100644 --- a/protocols/kad/src/lib.rs +++ b/protocols/kad/src/lib.rs @@ -76,6 +76,7 @@ mod jobs; mod query; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); pub use self::dht::pb::{ mod_Message::{ConnectionType, MessageType, Peer}, diff --git a/protocols/kad/src/query.rs b/protocols/kad/src/query.rs index ab29c812b01..d06b4920404 100644 --- a/protocols/kad/src/query.rs +++ b/protocols/kad/src/query.rs @@ -39,14 +39,14 @@ use std::{num::NonZeroUsize, time::Duration}; /// Internally, a `Query` is in turn driven by an underlying `QueryPeerIter` /// that determines the peer selection strategy, i.e. the order in which the /// peers involved in the query should be contacted. -pub struct QueryPool { +pub(crate) struct QueryPool { next_id: usize, config: QueryConfig, queries: FnvHashMap>, } /// The observable states emitted by [`QueryPool::poll`]. -pub enum QueryPoolState<'a, TInner> { +pub(crate) enum QueryPoolState<'a, TInner> { /// The pool is idle, i.e. there are no queries to process. Idle, /// At least one query is waiting for results. `Some(request)` indicates @@ -60,7 +60,7 @@ pub enum QueryPoolState<'a, TInner> { impl QueryPool { /// Creates a new `QueryPool` with the given configuration. - pub fn new(config: QueryConfig) -> Self { + pub(crate) fn new(config: QueryConfig) -> Self { QueryPool { next_id: 0, config, @@ -69,27 +69,27 @@ impl QueryPool { } /// Gets a reference to the `QueryConfig` used by the pool. - pub fn config(&self) -> &QueryConfig { + pub(crate) fn config(&self) -> &QueryConfig { &self.config } /// Returns an iterator over the queries in the pool. - pub fn iter(&self) -> impl Iterator> { + pub(crate) fn iter(&self) -> impl Iterator> { self.queries.values() } /// Gets the current size of the pool, i.e. the number of running queries. - pub fn size(&self) -> usize { + pub(crate) fn size(&self) -> usize { self.queries.len() } /// Returns an iterator that allows modifying each query in the pool. - pub fn iter_mut(&mut self) -> impl Iterator> { + pub(crate) fn iter_mut(&mut self) -> impl Iterator> { self.queries.values_mut() } /// Adds a query to the pool that contacts a fixed set of peers. - pub fn add_fixed(&mut self, peers: I, inner: TInner) -> QueryId + pub(crate) fn add_fixed(&mut self, peers: I, inner: TInner) -> QueryId where I: IntoIterator, { @@ -101,7 +101,7 @@ impl QueryPool { /// Continues an earlier query with a fixed set of peers, reusing /// the given query ID, which must be from a query that finished /// earlier. - pub fn continue_fixed(&mut self, id: QueryId, peers: I, inner: TInner) + pub(crate) fn continue_fixed(&mut self, id: QueryId, peers: I, inner: TInner) where I: IntoIterator, { @@ -113,7 +113,7 @@ impl QueryPool { } /// Adds a query to the pool that iterates towards the closest peers to the target. - pub fn add_iter_closest(&mut self, target: T, peers: I, inner: TInner) -> QueryId + pub(crate) fn add_iter_closest(&mut self, target: T, peers: I, inner: TInner) -> QueryId where T: Into + Clone, I: IntoIterator>, @@ -124,8 +124,13 @@ impl QueryPool { } /// Adds a query to the pool that iterates towards the closest peers to the target. - pub fn continue_iter_closest(&mut self, id: QueryId, target: T, peers: I, inner: TInner) - where + pub(crate) fn continue_iter_closest( + &mut self, + id: QueryId, + target: T, + peers: I, + inner: TInner, + ) where T: Into + Clone, I: IntoIterator>, { @@ -154,17 +159,17 @@ impl QueryPool { } /// Returns a reference to a query with the given ID, if it is in the pool. - pub fn get(&self, id: &QueryId) -> Option<&Query> { + pub(crate) fn get(&self, id: &QueryId) -> Option<&Query> { self.queries.get(id) } /// Returns a mutablereference to a query with the given ID, if it is in the pool. - pub fn get_mut(&mut self, id: &QueryId) -> Option<&mut Query> { + pub(crate) fn get_mut(&mut self, id: &QueryId) -> Option<&mut Query> { self.queries.get_mut(id) } /// Polls the pool to advance the queries. - pub fn poll(&mut self, now: Instant) -> QueryPoolState<'_, TInner> { + pub(crate) fn poll(&mut self, now: Instant) -> QueryPoolState<'_, TInner> { let mut finished = None; let mut timeout = None; let mut waiting = None; @@ -222,26 +227,23 @@ pub struct QueryId(usize); /// The configuration for queries in a `QueryPool`. #[derive(Debug, Clone)] -pub struct QueryConfig { +pub(crate) struct QueryConfig { /// Timeout of a single query. /// /// See [`crate::behaviour::KademliaConfig::set_query_timeout`] for details. - pub timeout: Duration, - + pub(crate) timeout: Duration, /// The replication factor to use. /// /// See [`crate::behaviour::KademliaConfig::set_replication_factor`] for details. - pub replication_factor: NonZeroUsize, - + pub(crate) replication_factor: NonZeroUsize, /// Allowed level of parallelism for iterative queries. /// /// See [`crate::behaviour::KademliaConfig::set_parallelism`] for details. - pub parallelism: NonZeroUsize, - + pub(crate) parallelism: NonZeroUsize, /// Whether to use disjoint paths on iterative lookups. /// /// See [`crate::behaviour::KademliaConfig::disjoint_query_paths`] for details. - pub disjoint_query_paths: bool, + pub(crate) disjoint_query_paths: bool, } impl Default for QueryConfig { @@ -256,7 +258,7 @@ impl Default for QueryConfig { } /// A query in a `QueryPool`. -pub struct Query { +pub(crate) struct Query { /// The unique ID of the query. id: QueryId, /// The peer iterator that drives the query state. @@ -264,7 +266,7 @@ pub struct Query { /// Execution statistics of the query. stats: QueryStats, /// The opaque inner query state. - pub inner: TInner, + pub(crate) inner: TInner, } /// The peer selection strategies that can be used by queries. @@ -286,17 +288,17 @@ impl Query { } /// Gets the unique ID of the query. - pub fn id(&self) -> QueryId { + pub(crate) fn id(&self) -> QueryId { self.id } /// Gets the current execution statistics of the query. - pub fn stats(&self) -> &QueryStats { + pub(crate) fn stats(&self) -> &QueryStats { &self.stats } /// Informs the query that the attempt to contact `peer` failed. - pub fn on_failure(&mut self, peer: &PeerId) { + pub(crate) fn on_failure(&mut self, peer: &PeerId) { let updated = match &mut self.peer_iter { QueryPeerIter::Closest(iter) => iter.on_failure(peer), QueryPeerIter::ClosestDisjoint(iter) => iter.on_failure(peer), @@ -310,7 +312,7 @@ impl Query { /// Informs the query that the attempt to contact `peer` succeeded, /// possibly resulting in new peers that should be incorporated into /// the query, if applicable. - pub fn on_success(&mut self, peer: &PeerId, new_peers: I) + pub(crate) fn on_success(&mut self, peer: &PeerId, new_peers: I) where I: IntoIterator, { @@ -325,7 +327,7 @@ impl Query { } /// Checks whether the query is currently waiting for a result from `peer`. - pub fn is_waiting(&self, peer: &PeerId) -> bool { + 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), @@ -365,7 +367,7 @@ impl Query { /// A finished query immediately stops yielding new peers to contact and /// will be reported by [`QueryPool::poll`] via /// [`QueryPoolState::Finished`]. - pub fn try_finish<'a, I>(&mut self, peers: I) -> bool + pub(crate) fn try_finish<'a, I>(&mut self, peers: I) -> bool where I: IntoIterator, { @@ -386,7 +388,7 @@ impl Query { /// /// A finished query immediately stops yielding new peers to contact and will be /// reported by [`QueryPool::poll`] via [`QueryPoolState::Finished`]. - pub fn finish(&mut self) { + pub(crate) fn finish(&mut self) { match &mut self.peer_iter { QueryPeerIter::Closest(iter) => iter.finish(), QueryPeerIter::ClosestDisjoint(iter) => iter.finish(), @@ -398,7 +400,7 @@ impl Query { /// /// A finished query is eventually reported by `QueryPool::next()` and /// removed from the pool. - pub fn is_finished(&self) -> bool { + pub(crate) fn is_finished(&self) -> bool { match &self.peer_iter { QueryPeerIter::Closest(iter) => iter.is_finished(), QueryPeerIter::ClosestDisjoint(iter) => iter.is_finished(), @@ -407,7 +409,7 @@ impl Query { } /// Consumes the query, producing the final `QueryResult`. - pub fn into_result(self) -> QueryResult> { + pub(crate) fn into_result(self) -> QueryResult> { let peers = match self.peer_iter { QueryPeerIter::Closest(iter) => Either::Left(Either::Left(iter.into_result())), QueryPeerIter::ClosestDisjoint(iter) => Either::Left(Either::Right(iter.into_result())), @@ -422,13 +424,13 @@ impl Query { } /// The result of a `Query`. -pub struct QueryResult { +pub(crate) struct QueryResult { /// The opaque inner query state. - pub inner: TInner, + pub(crate) inner: TInner, /// The successfully contacted peers. - pub peers: TPeers, + pub(crate) peers: TPeers, /// The collected query statistics. - pub stats: QueryStats, + pub(crate) stats: QueryStats, } /// Execution statistics of a query. diff --git a/protocols/kad/src/query/peers.rs b/protocols/kad/src/query/peers.rs index 824fb658e7c..11b8f974de9 100644 --- a/protocols/kad/src/query/peers.rs +++ b/protocols/kad/src/query/peers.rs @@ -38,9 +38,8 @@ //! //! [`Finished`]: PeersIterState::Finished -pub mod closest; -pub mod fixed; - +pub(crate) mod closest; +pub(crate) mod fixed; use libp2p_identity::PeerId; use std::borrow::Cow; diff --git a/protocols/kad/src/query/peers/closest.rs b/protocols/kad/src/query/peers/closest.rs index 11486796c29..66ea9d9ce52 100644 --- a/protocols/kad/src/query/peers/closest.rs +++ b/protocols/kad/src/query/peers/closest.rs @@ -27,8 +27,7 @@ use libp2p_identity::PeerId; use std::collections::btree_map::{BTreeMap, Entry}; use std::{iter::FromIterator, num::NonZeroUsize, time::Duration}; -pub mod disjoint; - +pub(crate) mod disjoint; /// A peer iterator for a dynamically changing list of peers, sorted by increasing /// distance to a chosen target. #[derive(Debug, Clone)] diff --git a/protocols/kad/src/query/peers/closest/disjoint.rs b/protocols/kad/src/query/peers/closest/disjoint.rs index 22a6051f3de..2ea484ed43c 100644 --- a/protocols/kad/src/query/peers/closest/disjoint.rs +++ b/protocols/kad/src/query/peers/closest/disjoint.rs @@ -30,7 +30,7 @@ use std::{ /// Wraps around a set of [`ClosestPeersIter`], enforcing a disjoint discovery /// path per configured parallelism according to the S/Kademlia paper. -pub struct ClosestDisjointPeersIter { +pub(crate) struct ClosestDisjointPeersIter { config: ClosestPeersIterConfig, target: KeyBytes, @@ -51,7 +51,7 @@ pub struct ClosestDisjointPeersIter { impl ClosestDisjointPeersIter { /// Creates a new iterator with a default configuration. - pub fn new(target: KeyBytes, known_closest_peers: I) -> Self + pub(crate) fn new(target: KeyBytes, known_closest_peers: I) -> Self where I: IntoIterator>, { @@ -63,7 +63,7 @@ impl ClosestDisjointPeersIter { } /// Creates a new iterator with the given configuration. - pub fn with_config( + pub(crate) fn with_config( config: ClosestPeersIterConfig, target: T, known_closest_peers: I, @@ -108,7 +108,7 @@ impl ClosestDisjointPeersIter { /// If the iterator is finished, it is not currently waiting for a /// result from `peer`, or a result for `peer` has already been reported, /// calling this function has no effect and `false` is returned. - pub fn on_failure(&mut self, peer: &PeerId) -> bool { + pub(crate) fn on_failure(&mut self, peer: &PeerId) -> bool { let mut updated = false; if let Some(PeerState { @@ -151,7 +151,7 @@ impl ClosestDisjointPeersIter { /// If the iterator is finished, it is not currently waiting for a /// result from `peer`, or a result for `peer` has already been reported, /// calling this function has no effect and `false` is returned. - pub fn on_success(&mut self, peer: &PeerId, closer_peers: I) -> bool + pub(crate) fn on_success(&mut self, peer: &PeerId, closer_peers: I) -> bool where I: IntoIterator, { @@ -190,11 +190,11 @@ impl ClosestDisjointPeersIter { updated } - pub fn is_waiting(&self, peer: &PeerId) -> bool { + pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool { self.iters.iter().any(|i| i.is_waiting(peer)) } - pub fn next(&mut self, now: Instant) -> PeersIterState<'_> { + pub(crate) fn next(&mut self, now: Instant) -> PeersIterState<'_> { let mut state = None; // Ensure querying each iterator at most once. @@ -290,7 +290,7 @@ impl ClosestDisjointPeersIter { /// Finishes all paths containing one of the given peers. /// /// See [`crate::query::Query::try_finish`] for details. - pub fn finish_paths<'a, I>(&mut self, peers: I) -> bool + pub(crate) fn finish_paths<'a, I>(&mut self, peers: I) -> bool where I: IntoIterator, { @@ -304,14 +304,14 @@ impl ClosestDisjointPeersIter { } /// Immediately transitions the iterator to [`PeersIterState::Finished`]. - pub fn finish(&mut self) { + pub(crate) fn finish(&mut self) { for iter in &mut self.iters { iter.finish(); } } /// Checks whether the iterator has finished. - pub fn is_finished(&self) -> bool { + pub(crate) fn is_finished(&self) -> bool { self.iters.iter().all(|i| i.is_finished()) } @@ -323,7 +323,7 @@ impl ClosestDisjointPeersIter { /// `num_results` closest benign peers, but as it can not /// differentiate benign from faulty paths it as well returns faulty /// peers and thus overall returns more than `num_results` peers. - pub fn into_result(self) -> impl Iterator { + pub(crate) fn into_result(self) -> impl Iterator { let result_per_path = self .iters .into_iter() @@ -609,7 +609,7 @@ mod tests { } #[derive(Debug, Clone)] - struct PeerVec(pub Vec>); + struct PeerVec(Vec>); impl Arbitrary for PeerVec { fn arbitrary(g: &mut Gen) -> Self { diff --git a/protocols/kad/src/query/peers/fixed.rs b/protocols/kad/src/query/peers/fixed.rs index 07ec6cf9f4e..1169feee87f 100644 --- a/protocols/kad/src/query/peers/fixed.rs +++ b/protocols/kad/src/query/peers/fixed.rs @@ -25,7 +25,7 @@ use libp2p_identity::PeerId; use std::{collections::hash_map::Entry, num::NonZeroUsize, vec}; /// A peer iterator for a fixed set of peers. -pub struct FixedPeersIter { +pub(crate) struct FixedPeersIter { /// Ther permitted parallelism, i.e. number of pending results. parallelism: NonZeroUsize, @@ -59,7 +59,7 @@ enum PeerState { impl FixedPeersIter { #[allow(clippy::needless_collect)] - pub fn new(peers: I, parallelism: NonZeroUsize) -> Self + pub(crate) fn new(peers: I, parallelism: NonZeroUsize) -> Self where I: IntoIterator, { @@ -83,7 +83,7 @@ impl FixedPeersIter { /// If the iterator is finished, it is not currently waiting for a /// result from `peer`, or a result for `peer` has already been reported, /// calling this function has no effect and `false` is returned. - pub fn on_success(&mut self, peer: &PeerId) -> bool { + pub(crate) fn on_success(&mut self, peer: &PeerId) -> bool { if let State::Waiting { num_waiting } = &mut self.state { if let Some(state @ PeerState::Waiting) = self.peers.get_mut(peer) { *state = PeerState::Succeeded; @@ -104,7 +104,7 @@ impl FixedPeersIter { /// If the iterator is finished, it is not currently waiting for a /// result from `peer`, or a result for `peer` has already been reported, /// calling this function has no effect and `false` is returned. - pub fn on_failure(&mut self, peer: &PeerId) -> bool { + pub(crate) fn on_failure(&mut self, peer: &PeerId) -> bool { if let State::Waiting { num_waiting } = &mut self.state { if let Some(state @ PeerState::Waiting) = self.peers.get_mut(peer) { *state = PeerState::Failed; @@ -115,22 +115,22 @@ impl FixedPeersIter { false } - pub fn is_waiting(&self, peer: &PeerId) -> bool { + pub(crate) fn is_waiting(&self, peer: &PeerId) -> bool { self.peers.get(peer) == Some(&PeerState::Waiting) } - pub fn finish(&mut self) { + pub(crate) fn finish(&mut self) { if let State::Waiting { .. } = self.state { self.state = State::Finished } } /// Checks whether the iterator has finished. - pub fn is_finished(&self) -> bool { + pub(crate) fn is_finished(&self) -> bool { self.state == State::Finished } - pub fn next(&mut self) -> PeersIterState<'_> { + pub(crate) fn next(&mut self) -> PeersIterState<'_> { match &mut self.state { State::Finished => PeersIterState::Finished, State::Waiting { num_waiting } => { @@ -161,7 +161,7 @@ impl FixedPeersIter { } } - pub fn into_result(self) -> impl Iterator { + pub(crate) fn into_result(self) -> impl Iterator { self.peers.into_iter().filter_map(|(p, s)| { if let PeerState::Succeeded = s { Some(p) diff --git a/protocols/mdns/src/behaviour/iface.rs b/protocols/mdns/src/behaviour/iface.rs index 4b5580e0869..0f556e1b237 100644 --- a/protocols/mdns/src/behaviour/iface.rs +++ b/protocols/mdns/src/behaviour/iface.rs @@ -41,7 +41,7 @@ use std::{ /// An mDNS instance for a networking interface. To discover all peers when having multiple /// interfaces an [`InterfaceState`] is required for each interface. #[derive(Debug)] -pub struct InterfaceState { +pub(crate) struct InterfaceState { /// Address this instance is bound to. addr: IpAddr, /// Receive socket. @@ -77,7 +77,7 @@ where T: Builder + futures::Stream, { /// Builds a new [`InterfaceState`]. - pub fn new(addr: IpAddr, config: Config, local_peer_id: PeerId) -> io::Result { + pub(crate) fn new(addr: IpAddr, config: Config, local_peer_id: PeerId) -> io::Result { log::info!("creating instance on iface {}", addr); let recv_socket = match addr { IpAddr::V4(addr) => { @@ -141,15 +141,15 @@ where }) } - pub fn reset_timer(&mut self) { + pub(crate) fn reset_timer(&mut self) { self.timeout = T::interval(self.query_interval); } - pub fn fire_timer(&mut self) { + pub(crate) fn fire_timer(&mut self) { self.timeout = T::interval_at(Instant::now(), self.query_interval); } - pub fn poll( + pub(crate) fn poll( &mut self, cx: &mut Context, listen_addresses: &ListenAddresses, diff --git a/protocols/mdns/src/behaviour/iface/dns.rs b/protocols/mdns/src/behaviour/iface/dns.rs index 0e277d65cbe..6a10497e69f 100644 --- a/protocols/mdns/src/behaviour/iface/dns.rs +++ b/protocols/mdns/src/behaviour/iface/dns.rs @@ -47,11 +47,10 @@ const MAX_PACKET_SIZE: usize = 9000 - 68; const MAX_RECORDS_PER_PACKET: usize = (MAX_PACKET_SIZE - 100) / MAX_TXT_RECORD_SIZE; /// An encoded MDNS packet. -pub type MdnsPacket = Vec; - +pub(crate) type MdnsPacket = Vec; /// Decodes a `` (as defined by RFC1035) into a `Vec` of ASCII characters. // TODO: better error type? -pub fn decode_character_string(mut from: &[u8]) -> Result, ()> { +pub(crate) fn decode_character_string(mut from: &[u8]) -> Result, ()> { if from.is_empty() { return Ok(Cow::Owned(Vec::new())); } @@ -70,7 +69,7 @@ pub fn decode_character_string(mut from: &[u8]) -> Result, ()> { } /// Builds the binary representation of a DNS query to send on the network. -pub fn build_query() -> MdnsPacket { +pub(crate) fn build_query() -> MdnsPacket { let mut out = Vec::with_capacity(33); // Program-generated transaction ID; unused by our implementation. @@ -104,7 +103,7 @@ pub fn build_query() -> MdnsPacket { /// Builds the response to an address discovery DNS query. /// /// If there are more than 2^16-1 addresses, ignores the rest. -pub fn build_query_response<'a>( +pub(crate) fn build_query_response<'a>( id: u16, peer_id: PeerId, addresses: impl ExactSizeIterator, @@ -166,7 +165,7 @@ pub fn build_query_response<'a>( } /// Builds the response to a service discovery DNS query. -pub fn build_service_discovery_response(id: u16, ttl: Duration) -> MdnsPacket { +pub(crate) fn build_service_discovery_response(id: u16, ttl: Duration) -> MdnsPacket { // Convert the TTL into seconds. let ttl = duration_to_secs(ttl); diff --git a/protocols/mdns/src/behaviour/iface/query.rs b/protocols/mdns/src/behaviour/iface/query.rs index 5eb491dbbf6..745926cf658 100644 --- a/protocols/mdns/src/behaviour/iface/query.rs +++ b/protocols/mdns/src/behaviour/iface/query.rs @@ -34,7 +34,7 @@ use trust_dns_proto::{ /// A valid mDNS packet received by the service. #[derive(Debug)] -pub enum MdnsPacket { +pub(crate) enum MdnsPacket { /// A query made by a remote. Query(MdnsQuery), /// A response sent by a remote in response to one of our queries. @@ -44,7 +44,7 @@ pub enum MdnsPacket { } impl MdnsPacket { - pub fn new_from_bytes( + pub(crate) fn new_from_bytes( buf: &[u8], from: SocketAddr, ) -> Result, trust_dns_proto::error::ProtoError> { @@ -82,7 +82,7 @@ impl MdnsPacket { } /// A received mDNS query. -pub struct MdnsQuery { +pub(crate) struct MdnsQuery { /// Sender of the address. from: SocketAddr, /// Id of the received DNS query. We need to pass this ID back in the results. @@ -91,12 +91,12 @@ pub struct MdnsQuery { impl MdnsQuery { /// Source address of the packet. - pub fn remote_addr(&self) -> &SocketAddr { + pub(crate) fn remote_addr(&self) -> &SocketAddr { &self.from } /// Query id of the packet. - pub fn query_id(&self) -> u16 { + pub(crate) fn query_id(&self) -> u16 { self.query_id } } @@ -111,7 +111,7 @@ impl fmt::Debug for MdnsQuery { } /// A received mDNS service discovery query. -pub struct MdnsServiceDiscovery { +pub(crate) struct MdnsServiceDiscovery { /// Sender of the address. from: SocketAddr, /// Id of the received DNS query. We need to pass this ID back in the results. @@ -120,12 +120,12 @@ pub struct MdnsServiceDiscovery { impl MdnsServiceDiscovery { /// Source address of the packet. - pub fn remote_addr(&self) -> &SocketAddr { + pub(crate) fn remote_addr(&self) -> &SocketAddr { &self.from } /// Query id of the packet. - pub fn query_id(&self) -> u16 { + pub(crate) fn query_id(&self) -> u16 { self.query_id } } @@ -140,14 +140,14 @@ impl fmt::Debug for MdnsServiceDiscovery { } /// A received mDNS response. -pub struct MdnsResponse { +pub(crate) struct MdnsResponse { peers: Vec, from: SocketAddr, } impl MdnsResponse { /// Creates a new `MdnsResponse` based on the provided `Packet`. - pub fn new(packet: &Message, from: SocketAddr) -> MdnsResponse { + pub(crate) fn new(packet: &Message, from: SocketAddr) -> MdnsResponse { let peers = packet .answers() .iter() @@ -168,7 +168,7 @@ impl MdnsResponse { MdnsResponse { peers, from } } - pub fn extract_discovered( + pub(crate) fn extract_discovered( &self, now: Instant, local_peer_id: PeerId, @@ -188,7 +188,7 @@ impl MdnsResponse { } /// Source address of the packet. - pub fn remote_addr(&self) -> &SocketAddr { + pub(crate) fn remote_addr(&self) -> &SocketAddr { &self.from } @@ -218,7 +218,7 @@ impl fmt::Debug for MdnsResponse { } /// A peer discovered by the service. -pub struct MdnsPeer { +pub(crate) struct MdnsPeer { addrs: Vec, /// Id of the peer. peer_id: PeerId, @@ -228,7 +228,7 @@ pub struct MdnsPeer { impl MdnsPeer { /// Creates a new `MdnsPeer` based on the provided `Packet`. - pub fn new(packet: &Message, record_value: &Name, ttl: u32) -> Option { + pub(crate) fn new(packet: &Message, record_value: &Name, ttl: u32) -> Option { let mut my_peer_id: Option = None; let addrs = packet .additionals() @@ -291,20 +291,20 @@ impl MdnsPeer { /// Returns the id of the peer. #[inline] - pub fn id(&self) -> &PeerId { + pub(crate) fn id(&self) -> &PeerId { &self.peer_id } /// Returns the requested time-to-live for the record. #[inline] - pub fn ttl(&self) -> Duration { + pub(crate) fn ttl(&self) -> Duration { Duration::from_secs(u64::from(self.ttl)) } /// Returns the list of addresses the peer says it is listening on. /// /// Filters out invalid addresses. - pub fn addresses(&self) -> &Vec { + pub(crate) fn addresses(&self) -> &Vec { &self.addrs } } diff --git a/protocols/mdns/src/behaviour/socket.rs b/protocols/mdns/src/behaviour/socket.rs index 4406ed33fde..fa9e0fbaf1e 100644 --- a/protocols/mdns/src/behaviour/socket.rs +++ b/protocols/mdns/src/behaviour/socket.rs @@ -26,6 +26,7 @@ use std::{ }; /// Interface that must be implemented by the different runtimes to use the [`UdpSocket`] in async mode +#[allow(unreachable_pub)] // Users should not depend on this. pub trait AsyncSocket: Unpin + Send + 'static { /// Create the async socket from the [`std::net::UdpSocket`] fn from_std(socket: UdpSocket) -> std::io::Result @@ -49,14 +50,13 @@ pub trait AsyncSocket: Unpin + Send + 'static { } #[cfg(feature = "async-io")] -pub mod asio { +pub(crate) mod asio { use super::*; use async_io::Async; use futures::FutureExt; /// AsyncIo UdpSocket - pub type AsyncUdpSocket = Async; - + pub(crate) type AsyncUdpSocket = Async; impl AsyncSocket for AsyncUdpSocket { fn from_std(socket: UdpSocket) -> std::io::Result { Async::new(socket) @@ -92,13 +92,12 @@ pub mod asio { } #[cfg(feature = "tokio")] -pub mod tokio { +pub(crate) mod tokio { use super::*; use ::tokio::{io::ReadBuf, net::UdpSocket as TkUdpSocket}; /// Tokio ASync Socket` - pub type TokioUdpSocket = TkUdpSocket; - + pub(crate) type TokioUdpSocket = TkUdpSocket; impl AsyncSocket for TokioUdpSocket { fn from_std(socket: UdpSocket) -> std::io::Result { socket.set_nonblocking(true)?; diff --git a/protocols/mdns/src/behaviour/timer.rs b/protocols/mdns/src/behaviour/timer.rs index b503459258c..29622be9a38 100644 --- a/protocols/mdns/src/behaviour/timer.rs +++ b/protocols/mdns/src/behaviour/timer.rs @@ -31,6 +31,7 @@ pub struct Timer { } /// Builder interface to homogenize the different implementations +#[allow(unreachable_pub)] // Users should not depend on this. pub trait Builder: Send + Unpin + 'static { /// Creates a timer that emits an event once at the given time instant. fn at(instant: Instant) -> Self; @@ -43,7 +44,7 @@ pub trait Builder: Send + Unpin + 'static { } #[cfg(feature = "async-io")] -pub mod asio { +pub(crate) mod asio { use super::*; use async_io::Timer as AsioTimer; use futures::Stream; @@ -53,8 +54,7 @@ pub mod asio { }; /// Async Timer - pub type AsyncTimer = Timer; - + pub(crate) type AsyncTimer = Timer; impl Builder for AsyncTimer { fn at(instant: Instant) -> Self { Self { @@ -85,7 +85,7 @@ pub mod asio { } #[cfg(feature = "tokio")] -pub mod tokio { +pub(crate) mod tokio { use super::*; use ::tokio::time::{self, Instant as TokioInstant, Interval, MissedTickBehavior}; use futures::Stream; @@ -95,8 +95,7 @@ pub mod tokio { }; /// Tokio wrapper - pub type TokioTimer = Timer; - + pub(crate) type TokioTimer = Timer; impl Builder for TokioTimer { fn at(instant: Instant) -> Self { // Taken from: https://docs.rs/async-io/1.7.0/src/async_io/lib.rs.html#91 diff --git a/protocols/perf/src/protocol.rs b/protocols/perf/src/protocol.rs index 808ea45752b..7f9c5137c9a 100644 --- a/protocols/perf/src/protocol.rs +++ b/protocols/perf/src/protocol.rs @@ -26,7 +26,7 @@ use crate::{client, server}; const BUF: [u8; 1024] = [0; 1024]; -pub async fn send_receive( +pub(crate) async fn send_receive( params: client::RunParams, mut stream: S, ) -> Result { @@ -67,7 +67,7 @@ pub async fn send_receive( }) } -pub async fn receive_send( +pub(crate) async fn receive_send( mut stream: S, ) -> Result { let to_send = { diff --git a/protocols/ping/src/protocol.rs b/protocols/ping/src/protocol.rs index 3c44adcd0b4..032b4aa0a0a 100644 --- a/protocols/ping/src/protocol.rs +++ b/protocols/ping/src/protocol.rs @@ -45,12 +45,11 @@ pub const PROTOCOL_NAME: &[u8] = b"/ipfs/ping/1.0.0"; /// > which can affect latencies especially on otherwise low-volume /// > connections. #[derive(Default, Debug, Copy, Clone)] -pub struct Ping; - +pub(crate) struct Ping; const PING_SIZE: usize = 32; /// Sends a ping and waits for the pong. -pub async fn send_ping(mut stream: S) -> io::Result<(S, Duration)> +pub(crate) async fn send_ping(mut stream: S) -> io::Result<(S, Duration)> where S: AsyncRead + AsyncWrite + Unpin, { @@ -71,7 +70,7 @@ where } /// Waits for a ping and sends a pong. -pub async fn recv_ping(mut stream: S) -> io::Result +pub(crate) async fn recv_ping(mut stream: S) -> io::Result where S: AsyncRead + AsyncWrite + Unpin, { diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index f21b699114b..9f2852dd19e 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -21,8 +21,7 @@ //! [`NetworkBehaviour`] to act as a circuit relay v2 **relay**. mod handler; -pub mod rate_limiter; - +pub(crate) mod rate_limiter; use crate::behaviour::handler::Handler; use crate::multiaddr_ext::MultiaddrExt; use crate::proto; diff --git a/protocols/relay/src/behaviour/handler.rs b/protocols/relay/src/behaviour/handler.rs index 88147a307e7..29b5c4b9dbd 100644 --- a/protocols/relay/src/behaviour/handler.rs +++ b/protocols/relay/src/behaviour/handler.rs @@ -962,7 +962,7 @@ pub struct OutboundOpenInfo { src_connection_id: ConnectionId, } -pub struct CircuitParts { +pub(crate) struct CircuitParts { circuit_id: CircuitId, src_stream: NegotiatedSubstream, src_pending_data: Bytes, diff --git a/protocols/relay/src/behaviour/rate_limiter.rs b/protocols/relay/src/behaviour/rate_limiter.rs index 542b23e5c43..31223c309f2 100644 --- a/protocols/relay/src/behaviour/rate_limiter.rs +++ b/protocols/relay/src/behaviour/rate_limiter.rs @@ -18,13 +18,15 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -pub use generic::{ - RateLimiter as GenericRateLimiter, RateLimiterConfig as GenericRateLimiterConfig, -}; use instant::Instant; use libp2p_core::multiaddr::{Multiaddr, Protocol}; use libp2p_identity::PeerId; +use std::collections::{HashMap, VecDeque}; +use std::convert::TryInto; +use std::hash::Hash; use std::net::IpAddr; +use std::num::NonZeroU32; +use std::time::Duration; /// Allows rate limiting access to some resource based on the [`PeerId`] and /// [`Multiaddr`] of a remote peer. @@ -36,12 +38,12 @@ pub trait RateLimiter: Send { fn try_next(&mut self, peer: PeerId, addr: &Multiaddr, now: Instant) -> bool; } -pub fn new_per_peer(config: GenericRateLimiterConfig) -> Box { +pub(crate) fn new_per_peer(config: GenericRateLimiterConfig) -> Box { let mut limiter = GenericRateLimiter::new(config); Box::new(move |peer_id, _addr: &Multiaddr, now| limiter.try_next(peer_id, now)) } -pub fn new_per_ip(config: GenericRateLimiterConfig) -> Box { +pub(crate) fn new_per_ip(config: GenericRateLimiterConfig) -> Box { let mut limiter = GenericRateLimiter::new(config); Box::new(move |_peer_id, addr: &Multiaddr, now| { multiaddr_to_ip(addr) @@ -64,249 +66,235 @@ fn multiaddr_to_ip(addr: &Multiaddr) -> Option { }) } -mod generic { - use instant::Instant; - use std::collections::{HashMap, VecDeque}; - use std::convert::TryInto; - use std::hash::Hash; - use std::num::NonZeroU32; - use std::time::Duration; - - /// Rate limiter using the [Token Bucket] algorithm. - /// - /// [Token Bucket]: https://en.wikipedia.org/wiki/Token_bucket - pub struct RateLimiter { - limit: u32, - interval: Duration, +/// Rate limiter using the [Token Bucket] algorithm. +/// +/// [Token Bucket]: https://en.wikipedia.org/wiki/Token_bucket +pub(crate) struct GenericRateLimiter { + limit: u32, + interval: Duration, - refill_schedule: VecDeque<(Instant, Id)>, - buckets: HashMap, - } + refill_schedule: VecDeque<(Instant, Id)>, + buckets: HashMap, +} - /// Configuration for a [`RateLimiter`]. - #[derive(Debug, Clone, Copy)] - pub struct RateLimiterConfig { - /// The maximum number of tokens in the bucket at any point in time. - pub limit: NonZeroU32, - /// The interval at which a single token is added to the bucket. - pub interval: Duration, - } +/// Configuration for a [`GenericRateLimiter`]. +#[derive(Debug, Clone, Copy)] +pub(crate) struct GenericRateLimiterConfig { + /// The maximum number of tokens in the bucket at any point in time. + pub(crate) limit: NonZeroU32, + /// The interval at which a single token is added to the bucket. + pub(crate) interval: Duration, +} - impl RateLimiter { - pub(crate) fn new(config: RateLimiterConfig) -> Self { - assert!(!config.interval.is_zero()); +impl GenericRateLimiter { + pub(crate) fn new(config: GenericRateLimiterConfig) -> Self { + assert!(!config.interval.is_zero()); - Self { - limit: config.limit.into(), - interval: config.interval, - refill_schedule: Default::default(), - buckets: Default::default(), - } + Self { + limit: config.limit.into(), + interval: config.interval, + refill_schedule: Default::default(), + buckets: Default::default(), } + } - pub(crate) fn try_next(&mut self, id: Id, now: Instant) -> bool { - self.refill(now); - - match self.buckets.get_mut(&id) { - // If the bucket exists, try to take a token. - Some(balance) => match balance.checked_sub(1) { - Some(a) => { - *balance = a; - true - } - None => false, - }, - // If the bucket is missing, act like the bucket has `limit` number of tokens. Take one - // token and track the new bucket balance. - None => { - self.buckets.insert(id.clone(), self.limit - 1); - self.refill_schedule.push_back((now, id)); + pub(crate) fn try_next(&mut self, id: Id, now: Instant) -> bool { + self.refill(now); + + match self.buckets.get_mut(&id) { + // If the bucket exists, try to take a token. + Some(balance) => match balance.checked_sub(1) { + Some(a) => { + *balance = a; true } + None => false, + }, + // If the bucket is missing, act like the bucket has `limit` number of tokens. Take one + // token and track the new bucket balance. + None => { + self.buckets.insert(id.clone(), self.limit - 1); + self.refill_schedule.push_back((now, id)); + true } } + } - fn refill(&mut self, now: Instant) { - // Note when used with a high number of buckets: This loop refills all the to-be-refilled - // buckets at once, thus potentially delaying the parent call to `try_next`. - loop { - match self.refill_schedule.get(0) { - // Only continue if (a) there is a bucket and (b) the bucket has not already been - // refilled recently. - Some((last_refill, _)) if now.duration_since(*last_refill) >= self.interval => { - } - // Otherwise stop refilling. Items in `refill_schedule` are sorted, thus, if the - // first ain't ready, none of them are. - _ => return, - }; - - let (last_refill, id) = self - .refill_schedule - .pop_front() - .expect("Queue not to be empty."); - - // Get the current balance of the bucket. - let balance = self - .buckets - .get(&id) - .expect("Entry can only be removed via refill."); - - // Calculate the new balance. - let duration_since = now.duration_since(last_refill); - let new_tokens = duration_since - .as_micros() - // Note that the use of `as_micros` limits the number of tokens to 10^6 per second. - .checked_div(self.interval.as_micros()) - .and_then(|i| i.try_into().ok()) - .unwrap_or(u32::MAX); - let new_balance = balance.checked_add(new_tokens).unwrap_or(u32::MAX); - - // If the new balance is below the limit, update the bucket. - if new_balance < self.limit { - self.buckets - .insert(id.clone(), new_balance) - .expect("To override value."); - self.refill_schedule.push_back((now, id)); - } else { - // If the balance is above the limit, the bucket can be removed, given that a - // non-existing bucket is equivalent to a bucket with `limit` tokens. - self.buckets.remove(&id); - } + fn refill(&mut self, now: Instant) { + // Note when used with a high number of buckets: This loop refills all the to-be-refilled + // buckets at once, thus potentially delaying the parent call to `try_next`. + loop { + match self.refill_schedule.get(0) { + // Only continue if (a) there is a bucket and (b) the bucket has not already been + // refilled recently. + Some((last_refill, _)) if now.duration_since(*last_refill) >= self.interval => {} + // Otherwise stop refilling. Items in `refill_schedule` are sorted, thus, if the + // first ain't ready, none of them are. + _ => return, + }; + + let (last_refill, id) = self + .refill_schedule + .pop_front() + .expect("Queue not to be empty."); + + // Get the current balance of the bucket. + let balance = self + .buckets + .get(&id) + .expect("Entry can only be removed via refill."); + + // Calculate the new balance. + let duration_since = now.duration_since(last_refill); + let new_tokens = duration_since + .as_micros() + // Note that the use of `as_micros` limits the number of tokens to 10^6 per second. + .checked_div(self.interval.as_micros()) + .and_then(|i| i.try_into().ok()) + .unwrap_or(u32::MAX); + let new_balance = balance.checked_add(new_tokens).unwrap_or(u32::MAX); + + // If the new balance is below the limit, update the bucket. + if new_balance < self.limit { + self.buckets + .insert(id.clone(), new_balance) + .expect("To override value."); + self.refill_schedule.push_back((now, id)); + } else { + // If the balance is above the limit, the bucket can be removed, given that a + // non-existing bucket is equivalent to a bucket with `limit` tokens. + self.buckets.remove(&id); } } } +} - #[cfg(test)] - mod tests { - use super::*; - use quickcheck::{QuickCheck, TestResult}; - use std::num::NonZeroU32; - - #[test] - fn first() { - let id = 1; - let mut l = RateLimiter::new(RateLimiterConfig { - limit: NonZeroU32::new(10).unwrap(), - interval: Duration::from_secs(1), - }); - assert!(l.try_next(id, Instant::now())); - } +#[cfg(test)] +mod tests { + use super::*; + use quickcheck::{QuickCheck, TestResult}; + use std::num::NonZeroU32; - #[test] - fn limits() { - let id = 1; - let now = Instant::now(); - let mut l = RateLimiter::new(RateLimiterConfig { - limit: NonZeroU32::new(10).unwrap(), - interval: Duration::from_secs(1), - }); - for _ in 0..10 { - assert!(l.try_next(id, now)); - } + #[test] + fn first() { + let id = 1; + let mut l = GenericRateLimiter::new(GenericRateLimiterConfig { + limit: NonZeroU32::new(10).unwrap(), + interval: Duration::from_secs(1), + }); + assert!(l.try_next(id, Instant::now())); + } - assert!(!l.try_next(id, now)); + #[test] + fn limits() { + let id = 1; + let now = Instant::now(); + let mut l = GenericRateLimiter::new(GenericRateLimiterConfig { + limit: NonZeroU32::new(10).unwrap(), + interval: Duration::from_secs(1), + }); + for _ in 0..10 { + assert!(l.try_next(id, now)); } - #[test] - fn refills() { - let id = 1; - let now = Instant::now(); - let mut l = RateLimiter::new(RateLimiterConfig { - limit: NonZeroU32::new(10).unwrap(), - interval: Duration::from_secs(1), - }); - - for _ in 0..10 { - assert!(l.try_next(id, now)); - } - assert!(!l.try_next(id, now)); + assert!(!l.try_next(id, now)); + } - let now = now + Duration::from_secs(1); - assert!(l.try_next(id, now)); - assert!(!l.try_next(id, now)); + #[test] + fn refills() { + let id = 1; + let now = Instant::now(); + let mut l = GenericRateLimiter::new(GenericRateLimiterConfig { + limit: NonZeroU32::new(10).unwrap(), + interval: Duration::from_secs(1), + }); - let now = now + Duration::from_secs(10); - for _ in 0..10 { - assert!(l.try_next(id, now)); - } + for _ in 0..10 { + assert!(l.try_next(id, now)); } + assert!(!l.try_next(id, now)); - #[test] - fn move_at_half_interval_steps() { - let id = 1; - let now = Instant::now(); - let mut l = RateLimiter::new(RateLimiterConfig { - limit: NonZeroU32::new(1).unwrap(), - interval: Duration::from_secs(2), - }); + let now = now + Duration::from_secs(1); + assert!(l.try_next(id, now)); + assert!(!l.try_next(id, now)); + let now = now + Duration::from_secs(10); + for _ in 0..10 { assert!(l.try_next(id, now)); - assert!(!l.try_next(id, now)); + } + } - let now = now + Duration::from_secs(1); - assert!(!l.try_next(id, now)); + #[test] + fn move_at_half_interval_steps() { + let id = 1; + let now = Instant::now(); + let mut l = GenericRateLimiter::new(GenericRateLimiterConfig { + limit: NonZeroU32::new(1).unwrap(), + interval: Duration::from_secs(2), + }); - let now = now + Duration::from_secs(1); - assert!(l.try_next(id, now)); - } + assert!(l.try_next(id, now)); + assert!(!l.try_next(id, now)); - #[test] - fn garbage_collects() { - let now = Instant::now(); - let mut l = RateLimiter::new(RateLimiterConfig { - limit: NonZeroU32::new(1).unwrap(), - interval: Duration::from_secs(1), - }); + let now = now + Duration::from_secs(1); + assert!(!l.try_next(id, now)); - assert!(l.try_next(1, now)); + let now = now + Duration::from_secs(1); + assert!(l.try_next(id, now)); + } - let now = now + Duration::from_secs(1); - assert!(l.try_next(2, now)); + #[test] + fn garbage_collects() { + let now = Instant::now(); + let mut l = GenericRateLimiter::new(GenericRateLimiterConfig { + limit: NonZeroU32::new(1).unwrap(), + interval: Duration::from_secs(1), + }); - assert_eq!(l.buckets.len(), 1); - assert_eq!(l.refill_schedule.len(), 1); - } + assert!(l.try_next(1, now)); - #[test] - fn quick_check() { - fn prop( - limit: NonZeroU32, - interval: Duration, - events: Vec<(u32, Duration)>, - ) -> TestResult { - if interval.is_zero() { - return TestResult::discard(); - } + let now = now + Duration::from_secs(1); + assert!(l.try_next(2, now)); - let mut now = Instant::now(); - let mut l = RateLimiter::new(RateLimiterConfig { limit, interval }); + assert_eq!(l.buckets.len(), 1); + assert_eq!(l.refill_schedule.len(), 1); + } - for (id, d) in events { - now = if let Some(now) = now.checked_add(d) { - now - } else { - return TestResult::discard(); - }; - l.try_next(id, now); - } + #[test] + fn quick_check() { + fn prop(limit: NonZeroU32, interval: Duration, events: Vec<(u32, Duration)>) -> TestResult { + if interval.is_zero() { + return TestResult::discard(); + } + + let mut now = Instant::now(); + let mut l = GenericRateLimiter::new(GenericRateLimiterConfig { limit, interval }); - now = if let Some(now) = interval - .checked_mul(limit.into()) - .and_then(|full_interval| now.checked_add(full_interval)) - { + for (id, d) in events { + now = if let Some(now) = now.checked_add(d) { now } else { return TestResult::discard(); }; - assert!(l.try_next(1, now)); + l.try_next(id, now); + } - assert_eq!(l.buckets.len(), 1); - assert_eq!(l.refill_schedule.len(), 1); + now = if let Some(now) = interval + .checked_mul(limit.into()) + .and_then(|full_interval| now.checked_add(full_interval)) + { + now + } else { + return TestResult::discard(); + }; + assert!(l.try_next(1, now)); - TestResult::passed() - } + assert_eq!(l.buckets.len(), 1); + assert_eq!(l.refill_schedule.len(), 1); - QuickCheck::new().quickcheck(prop as fn(_, _, _) -> _) + TestResult::passed() } + + QuickCheck::new().quickcheck(prop as fn(_, _, _) -> _) } } diff --git a/protocols/relay/src/copy_future.rs b/protocols/relay/src/copy_future.rs index 2f9eabed349..755344cd698 100644 --- a/protocols/relay/src/copy_future.rs +++ b/protocols/relay/src/copy_future.rs @@ -36,7 +36,7 @@ use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; -pub struct CopyFuture { +pub(crate) struct CopyFuture { src: BufReader, dst: BufReader, @@ -46,7 +46,12 @@ pub struct CopyFuture { } impl CopyFuture { - pub fn new(src: S, dst: D, max_circuit_duration: Duration, max_circuit_bytes: u64) -> Self { + pub(crate) fn new( + src: S, + dst: D, + max_circuit_duration: Duration, + max_circuit_bytes: u64, + ) -> Self { CopyFuture { src: BufReader::new(src), dst: BufReader::new(dst), diff --git a/protocols/relay/src/lib.rs b/protocols/relay/src/lib.rs index 05b6292c9e2..8421026d984 100644 --- a/protocols/relay/src/lib.rs +++ b/protocols/relay/src/lib.rs @@ -31,10 +31,13 @@ mod protocol; pub mod v2; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::message_v2::pb::mod_HopMessage::Type as HopMessageType; + pub(crate) use self::message_v2::pb::mod_HopMessage::Type as HopMessageType; pub use self::message_v2::pb::mod_StopMessage::Type as StopMessageType; - pub use self::message_v2::pb::{HopMessage, Limit, Peer, Reservation, Status, StopMessage}; + pub(crate) use self::message_v2::pb::{ + HopMessage, Limit, Peer, Reservation, Status, StopMessage, + }; } pub use behaviour::{Behaviour, CircuitId, Config, Event}; diff --git a/protocols/relay/src/protocol.rs b/protocols/relay/src/protocol.rs index 4933eb6a523..2c471d36dd9 100644 --- a/protocols/relay/src/protocol.rs +++ b/protocols/relay/src/protocol.rs @@ -21,11 +21,10 @@ use crate::proto; use std::time::Duration; -pub mod inbound_hop; -pub mod inbound_stop; -pub mod outbound_hop; -pub mod outbound_stop; - +pub(crate) mod inbound_hop; +pub(crate) mod inbound_stop; +pub(crate) mod outbound_hop; +pub(crate) mod outbound_stop; pub const HOP_PROTOCOL_NAME: &[u8; 31] = b"/libp2p/circuit/relay/0.2.0/hop"; pub const STOP_PROTOCOL_NAME: &[u8; 32] = b"/libp2p/circuit/relay/0.2.0/stop"; diff --git a/protocols/rendezvous/src/codec.rs b/protocols/rendezvous/src/codec.rs index 39447a56bdb..716ad79893f 100644 --- a/protocols/rendezvous/src/codec.rs +++ b/protocols/rendezvous/src/codec.rs @@ -559,8 +559,9 @@ impl From for ConversionError { pub struct UnmappableStatusCode(proto::ResponseStatus); mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::rendezvous::pb::{mod_Message::*, Message}; + pub(crate) use self::rendezvous::pb::{mod_Message::*, Message}; } #[cfg(test)] diff --git a/protocols/rendezvous/src/handler.rs b/protocols/rendezvous/src/handler.rs index d07bf4d248f..f69748a400b 100644 --- a/protocols/rendezvous/src/handler.rs +++ b/protocols/rendezvous/src/handler.rs @@ -24,9 +24,8 @@ use void::Void; const PROTOCOL_IDENT: &[u8] = b"/rendezvous/1.0.0"; -pub mod inbound; -pub mod outbound; - +pub(crate) mod inbound; +pub(crate) mod outbound; /// Errors that can occur while interacting with a substream. #[allow(clippy::large_enum_variant)] #[derive(Debug, thiserror::Error)] @@ -41,9 +40,10 @@ pub enum Error { UnexpectedEndOfStream, } -pub type OutboundInEvent = crate::substream_handler::InEvent; -pub type OutboundOutEvent = +pub(crate) type OutboundInEvent = crate::substream_handler::InEvent; +pub(crate) type OutboundOutEvent = crate::substream_handler::OutEvent; -pub type InboundInEvent = crate::substream_handler::InEvent<(), inbound::InEvent, Void>; -pub type InboundOutEvent = crate::substream_handler::OutEvent; +pub(crate) type InboundInEvent = crate::substream_handler::InEvent<(), inbound::InEvent, Void>; +pub(crate) type InboundOutEvent = + crate::substream_handler::OutEvent; diff --git a/protocols/rendezvous/src/substream_handler.rs b/protocols/rendezvous/src/substream_handler.rs index 16a493ccc3a..f5f79451b09 100644 --- a/protocols/rendezvous/src/substream_handler.rs +++ b/protocols/rendezvous/src/substream_handler.rs @@ -503,18 +503,20 @@ where /// A helper struct for substream handlers that can be implemented as async functions. /// /// This only works for substreams without an `InEvent` because - once constructed - the state of an inner future is opaque. -pub struct FutureSubstream { +pub(crate) struct FutureSubstream { future: Fuse>>, } impl FutureSubstream { - pub fn new(future: impl Future> + Send + 'static) -> Self { + pub(crate) fn new( + future: impl Future> + Send + 'static, + ) -> Self { Self { future: future.boxed().fuse(), } } - pub fn advance(mut self, cx: &mut Context<'_>) -> Result, TError> { + pub(crate) fn advance(mut self, cx: &mut Context<'_>) -> Result, TError> { if self.future.is_terminated() { return Ok(Next::Done); } diff --git a/scripts/fix-unreachable-pub.py b/scripts/fix-unreachable-pub.py new file mode 100644 index 00000000000..2e3eb5d9037 --- /dev/null +++ b/scripts/fix-unreachable-pub.py @@ -0,0 +1,68 @@ +#!/usr/bin/env python3 + +import json +import re +import sys +from pathlib import Path + + +# Use this script by piping the output of clippy into it: +# > cargo clippy --workspace --all-features --all-targets --message-format=json -- -W unreachable_pub | python scripts/fix-unreachable-pub.py +# +# You might have to run this in a loop as restricting the visibility of one item can trigger the warning for another item. + +def fix_unreachable_pub_warning(warning): + file_path = Path(warning["spans"][0]["file_name"]) + + try: + line = warning["spans"][0]["line_start"] + + # Don't modify generated code + if "generated" in str(file_path): + return + + with file_path.open() as f: + lines = f.readlines() + + pub_pattern = re.compile(r"(\s*)pub(\s)(.*)") + match = pub_pattern.match(lines[line - 1]) + + if match: + indentation = match.group(1) + space = match.group(2) + rest_of_line = match.group(3) + lines[line - 1] = f"{indentation}pub(crate){space}{rest_of_line}" + + with file_path.open("w") as f: + f.writelines(lines) + except Exception as e: + print(f"Failed to apply suggestion in {file_path}: {e}") + + +def main(): + for line in sys.stdin: + # Ignore other compiler messages + if "unreachable_pub" not in line: + continue + + warning = json.loads(line.strip()) + + # Don't modify code that is not in the current workspace + if str(Path.cwd()) not in str(warning['target']['src_path']): + return + + m = warning["message"] + + if m is None: + continue + + code = m['code'] + + if code is None: + continue + + fix_unreachable_pub_warning(m) + + +if __name__ == "__main__": + main() diff --git a/swarm/src/connection.rs b/swarm/src/connection.rs index e7e71fdfebc..e813ad0c66d 100644 --- a/swarm/src/connection.rs +++ b/swarm/src/connection.rs @@ -22,9 +22,9 @@ mod error; pub(crate) mod pool; -pub use error::{ - ConnectionError, PendingConnectionError, PendingInboundConnectionError, - PendingOutboundConnectionError, +pub use error::ConnectionError; +pub(crate) use error::{ + PendingConnectionError, PendingInboundConnectionError, PendingOutboundConnectionError, }; use crate::handler::{ @@ -85,16 +85,16 @@ impl ConnectionId { /// Information about a successfully established connection. #[derive(Debug, Clone, PartialEq, Eq)] -pub struct Connected { +pub(crate) struct Connected { /// The connected endpoint, including network address information. - pub endpoint: ConnectedPoint, + pub(crate) endpoint: ConnectedPoint, /// Information obtained from the transport. - pub peer_id: PeerId, + pub(crate) peer_id: PeerId, } /// Event generated by a [`Connection`]. #[derive(Debug, Clone)] -pub enum Event { +pub(crate) enum Event { /// Event generated by the [`ConnectionHandler`]. Handler(T), /// Address of the remote has changed. @@ -102,7 +102,7 @@ pub enum Event { } /// A multiplexed connection to a peer with an associated [`ConnectionHandler`]. -pub struct Connection +pub(crate) struct Connection where THandler: ConnectionHandler, { @@ -167,7 +167,7 @@ where { /// Builds a new `Connection` from the given substream multiplexer /// and connection handler. - pub fn new( + pub(crate) fn new( muxer: StreamMuxerBox, handler: THandler, substream_upgrade_protocol_override: Option, @@ -186,19 +186,19 @@ where } /// Notifies the connection handler of an event. - pub fn on_behaviour_event(&mut self, event: THandler::InEvent) { + pub(crate) fn on_behaviour_event(&mut self, event: THandler::InEvent) { self.handler.on_behaviour_event(event); } /// Begins an orderly shutdown of the connection, returning the connection /// handler and a `Future` that resolves when connection shutdown is complete. - pub fn close(self) -> (THandler, impl Future>) { + pub(crate) fn close(self) -> (THandler, impl Future>) { (self.handler, self.muxing.close()) } /// Polls the handler and the substream, forwarding events from the former to the latter and /// vice versa. - pub fn poll( + pub(crate) fn poll( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll, ConnectionError>> { @@ -369,16 +369,16 @@ where /// Borrowed information about an incoming connection currently being negotiated. #[derive(Debug, Copy, Clone)] -pub struct IncomingInfo<'a> { +pub(crate) struct IncomingInfo<'a> { /// Local connection address. - pub local_addr: &'a Multiaddr, + pub(crate) local_addr: &'a Multiaddr, /// Address used to send back data to the remote. - pub send_back_addr: &'a Multiaddr, + pub(crate) send_back_addr: &'a Multiaddr, } impl<'a> IncomingInfo<'a> { /// Builds the [`ConnectedPoint`] corresponding to the incoming connection. - pub fn create_connected_point(&self) -> ConnectedPoint { + pub(crate) fn create_connected_point(&self) -> ConnectedPoint { ConnectedPoint::Listener { local_addr: self.local_addr.clone(), send_back_addr: self.send_back_addr.clone(), diff --git a/swarm/src/connection/error.rs b/swarm/src/connection/error.rs index 49a3ee65f12..9e0c58a4e7d 100644 --- a/swarm/src/connection/error.rs +++ b/swarm/src/connection/error.rs @@ -78,11 +78,11 @@ impl From for ConnectionError { /// Note: Addresses for an outbound connection are dialed in parallel. Thus, compared to /// [`PendingInboundConnectionError`], one or more [`TransportError`]s can occur for a single /// connection. -pub type PendingOutboundConnectionError = +pub(crate) type PendingOutboundConnectionError = PendingConnectionError)>>; /// Errors that can occur in the context of a pending incoming `Connection`. -pub type PendingInboundConnectionError = PendingConnectionError>; +pub(crate) type PendingInboundConnectionError = PendingConnectionError>; /// Errors that can occur in the context of a pending `Connection`. #[derive(Debug)] diff --git a/swarm/src/connection/pool.rs b/swarm/src/connection/pool.rs index 5cb70173a92..68ad16ad36a 100644 --- a/swarm/src/connection/pool.rs +++ b/swarm/src/connection/pool.rs @@ -84,7 +84,7 @@ impl ExecSwitch { } /// A connection `Pool` manages a set of connections for each peer. -pub struct Pool +pub(crate) struct Pool where THandler: ConnectionHandler, { @@ -140,7 +140,7 @@ where } #[derive(Debug)] -pub struct EstablishedConnection { +pub(crate) struct EstablishedConnection { endpoint: ConnectedPoint, /// Channel endpoint to send commands to the task. sender: mpsc::Sender>, @@ -157,7 +157,7 @@ impl EstablishedConnection { /// `poll_ready_notify_handler` without another intervening execution /// of `notify_handler`, it only fails if the connection is now about /// to close. - pub fn notify_handler(&mut self, event: TInEvent) -> Result<(), TInEvent> { + pub(crate) fn notify_handler(&mut self, event: TInEvent) -> Result<(), TInEvent> { let cmd = task::Command::NotifyHandler(event); self.sender.try_send(cmd).map_err(|e| match e.into_inner() { task::Command::NotifyHandler(event) => event, @@ -171,14 +171,17 @@ impl EstablishedConnection { /// /// Returns `Err(())` if the background task associated with the connection /// is terminating and the connection is about to close. - pub fn poll_ready_notify_handler(&mut self, cx: &mut Context<'_>) -> Poll> { + pub(crate) fn poll_ready_notify_handler( + &mut self, + cx: &mut Context<'_>, + ) -> Poll> { self.sender.poll_ready(cx).map_err(|_| ()) } /// Initiates a graceful close of the connection. /// /// Has no effect if the connection is already closing. - pub fn start_close(&mut self) { + pub(crate) fn start_close(&mut self) { // Clone the sender so that we are guaranteed to have // capacity for the close command (every sender gets a slot). match self.sender.clone().try_send(task::Command::Close) { @@ -221,7 +224,7 @@ impl fmt::Debug for Pool { /// Event that can happen on the `Pool`. #[derive(Debug)] -pub enum PoolEvent { +pub(crate) enum PoolEvent { /// A new connection has been established. ConnectionEstablished { id: ConnectionId, @@ -306,7 +309,7 @@ where { /// Creates a new empty `Pool`. #[allow(deprecated)] - pub fn new(local_id: PeerId, config: PoolConfig, limits: ConnectionLimits) -> Self { + pub(crate) fn new(local_id: PeerId, config: PoolConfig, limits: ConnectionLimits) -> Self { let (pending_connection_events_tx, pending_connection_events_rx) = mpsc::channel(0); let executor = match config.executor { Some(exec) => ExecSwitch::Executor(exec), @@ -332,12 +335,12 @@ where } /// Gets the dedicated connection counters. - pub fn counters(&self) -> &ConnectionCounters { + pub(crate) fn counters(&self) -> &ConnectionCounters { &self.counters } /// Gets an established connection from the pool by ID. - pub fn get_established( + pub(crate) fn get_established( &mut self, id: ConnectionId, ) -> Option<&mut EstablishedConnection> { @@ -349,13 +352,13 @@ where /// Returns true if we are connected to the given peer. /// /// This will return true only after a `NodeReached` event has been produced by `poll()`. - pub fn is_connected(&self, id: PeerId) -> bool { + pub(crate) fn is_connected(&self, id: PeerId) -> bool { self.established.contains_key(&id) } /// Returns the number of connected peers, i.e. those with at least one /// established connection in the pool. - pub fn num_peers(&self) -> usize { + pub(crate) fn num_peers(&self) -> usize { self.established.len() } @@ -364,7 +367,7 @@ where /// All connections to the peer, whether pending or established are /// closed asap and no more events from these connections are emitted /// by the pool effective immediately. - pub fn disconnect(&mut self, peer: PeerId) { + pub(crate) fn disconnect(&mut self, peer: PeerId) { if let Some(conns) = self.established.get_mut(&peer) { for (_, conn) in conns.iter_mut() { conn.start_close(); @@ -381,7 +384,7 @@ where } /// Returns an iterator over all established connections of `peer`. - pub fn iter_established_connections_of_peer( + pub(crate) fn iter_established_connections_of_peer( &mut self, peer: &PeerId, ) -> impl Iterator + '_ { @@ -392,7 +395,7 @@ where } /// Checks whether we are currently dialing the given peer. - pub fn is_dialing(&self, peer: PeerId) -> bool { + pub(crate) fn is_dialing(&self, peer: PeerId) -> bool { self.pending.iter().any(|(_, info)| { matches!(info.endpoint, PendingPoint::Dialer { .. }) && info.is_for_same_remote_as(peer) }) @@ -400,7 +403,7 @@ where /// Returns an iterator over all connected peers, i.e. those that have /// at least one established connection in the pool. - pub fn iter_connected(&self) -> impl Iterator { + pub(crate) fn iter_connected(&self) -> impl Iterator { self.established.keys() } @@ -410,7 +413,7 @@ where /// Returns an error if the limit of pending outgoing connections /// has been reached. #[allow(deprecated)] - pub fn add_outgoing( + pub(crate) fn add_outgoing( &mut self, dials: Vec< BoxFuture< @@ -465,7 +468,7 @@ where /// Returns an error if the limit of pending incoming connections /// has been reached. #[allow(deprecated)] - pub fn add_incoming( + pub(crate) fn add_incoming( &mut self, future: TFut, info: IncomingInfo<'_>, @@ -503,7 +506,7 @@ where } #[allow(deprecated)] - pub fn spawn_connection( + pub(crate) fn spawn_connection( &mut self, id: ConnectionId, obtained_peer_id: PeerId, @@ -548,7 +551,7 @@ where } /// Polls the connection pool for events. - pub fn poll(&mut self, cx: &mut Context<'_>) -> Poll> + pub(crate) fn poll(&mut self, cx: &mut Context<'_>) -> Poll> where THandler: ConnectionHandler + 'static, ::OutboundOpenInfo: Send, @@ -832,7 +835,7 @@ where /// /// On drop, this type send the connection back to the [`Pool`] where it will be gracefully closed. #[derive(Debug)] -pub struct NewConnection { +pub(crate) struct NewConnection { connection: Option, drop_sender: Option>, } @@ -1101,20 +1104,16 @@ impl ConnectionLimits { /// /// The default configuration specifies no dedicated task executor, a /// task event buffer size of 32, and a task command buffer size of 7. -pub struct PoolConfig { +pub(crate) struct PoolConfig { /// Executor to use to spawn tasks. - pub executor: Option>, - + pub(crate) executor: Option>, /// Size of the task command buffer (per task). - pub task_command_buffer_size: usize, - + pub(crate) task_command_buffer_size: usize, /// Size of the pending connection task event buffer and the established connection task event /// buffer. - pub per_connection_event_buffer_size: usize, - + pub(crate) per_connection_event_buffer_size: usize, /// Number of addresses concurrently dialed for a single outbound connection attempt. - pub dial_concurrency_factor: NonZeroU8, - + pub(crate) dial_concurrency_factor: NonZeroU8, /// The configured override for substream protocol upgrades, if any. substream_upgrade_protocol_override: Option, @@ -1125,7 +1124,7 @@ pub struct PoolConfig { } impl PoolConfig { - pub fn new(executor: Option>) -> Self { + pub(crate) fn new(executor: Option>) -> Self { Self { executor, task_command_buffer_size: 32, @@ -1143,7 +1142,7 @@ impl PoolConfig { /// When the buffer for a particular connection is full, `notify_handler` will no /// longer be able to deliver events to the associated [`Connection`](super::Connection), /// thus exerting back-pressure on the connection and peer API. - pub fn with_notify_handler_buffer_size(mut self, n: NonZeroUsize) -> Self { + pub(crate) fn with_notify_handler_buffer_size(mut self, n: NonZeroUsize) -> Self { self.task_command_buffer_size = n.get() - 1; self } @@ -1154,19 +1153,19 @@ impl PoolConfig { /// When the buffer is full, the background tasks of all connections will stall. /// In this way, the consumers of network events exert back-pressure on /// the network connection I/O. - pub fn with_per_connection_event_buffer_size(mut self, n: usize) -> Self { + pub(crate) fn with_per_connection_event_buffer_size(mut self, n: usize) -> Self { self.per_connection_event_buffer_size = n; self } /// Number of addresses concurrently dialed for a single outbound connection attempt. - pub fn with_dial_concurrency_factor(mut self, factor: NonZeroU8) -> Self { + pub(crate) fn with_dial_concurrency_factor(mut self, factor: NonZeroU8) -> Self { self.dial_concurrency_factor = factor; self } /// Configures an override for the substream upgrade protocol to use. - pub fn with_substream_upgrade_protocol_override( + pub(crate) fn with_substream_upgrade_protocol_override( mut self, v: libp2p_core::upgrade::Version, ) -> Self { @@ -1177,7 +1176,7 @@ impl PoolConfig { /// The maximum number of inbound streams concurrently negotiating on a connection. /// /// See [`Connection::max_negotiating_inbound_streams`]. - pub fn with_max_negotiating_inbound_streams(mut self, v: usize) -> Self { + pub(crate) fn with_max_negotiating_inbound_streams(mut self, v: usize) -> Self { self.max_negotiating_inbound_streams = v; self } diff --git a/swarm/src/connection/pool/concurrent_dial.rs b/swarm/src/connection/pool/concurrent_dial.rs index 024c21a568d..57e4b078098 100644 --- a/swarm/src/connection/pool/concurrent_dial.rs +++ b/swarm/src/connection/pool/concurrent_dial.rs @@ -40,7 +40,7 @@ type Dial = BoxFuture< ), >; -pub struct ConcurrentDial { +pub(crate) struct ConcurrentDial { dials: FuturesUnordered, pending_dials: Box + Send>, errors: Vec<(Multiaddr, TransportError)>, diff --git a/swarm/src/connection/pool/task.rs b/swarm/src/connection/pool/task.rs index 27a2a4780a3..dd318f77d30 100644 --- a/swarm/src/connection/pool/task.rs +++ b/swarm/src/connection/pool/task.rs @@ -41,7 +41,7 @@ use void::Void; /// Commands that can be sent to a task driving an established connection. #[derive(Debug)] -pub enum Command { +pub(crate) enum Command { /// Notify the connection handler of an event. NotifyHandler(T), /// Gracefully close the connection (active close) before @@ -49,7 +49,7 @@ pub enum Command { Close, } -pub enum PendingConnectionEvent { +pub(crate) enum PendingConnectionEvent { ConnectionEstablished { id: ConnectionId, output: (PeerId, StreamMuxerBox), @@ -66,7 +66,7 @@ pub enum PendingConnectionEvent { } #[derive(Debug)] -pub enum EstablishedConnectionEvent { +pub(crate) enum EstablishedConnectionEvent { /// A node we are connected to has changed its address. AddressChange { id: ConnectionId, @@ -91,7 +91,7 @@ pub enum EstablishedConnectionEvent { }, } -pub async fn new_for_pending_outgoing_connection( +pub(crate) async fn new_for_pending_outgoing_connection( connection_id: ConnectionId, dial: ConcurrentDial, abort_receiver: oneshot::Receiver, @@ -127,7 +127,7 @@ pub async fn new_for_pending_outgoing_connection( } } -pub async fn new_for_pending_incoming_connection( +pub(crate) async fn new_for_pending_incoming_connection( connection_id: ConnectionId, future: TFut, abort_receiver: oneshot::Receiver, @@ -167,7 +167,7 @@ pub async fn new_for_pending_incoming_connection( } } -pub async fn new_for_established_connection( +pub(crate) async fn new_for_established_connection( connection_id: ConnectionId, peer_id: PeerId, mut connection: crate::connection::Connection, diff --git a/swarm/src/executor.rs b/swarm/src/executor.rs index d4b97a1d8b8..e949bf3cbde 100644 --- a/swarm/src/executor.rs +++ b/swarm/src/executor.rs @@ -31,8 +31,7 @@ impl Executor for ThreadPool { not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")) ))] #[derive(Default, Debug, Clone, Copy)] -pub struct TokioExecutor; - +pub(crate) struct TokioExecutor; #[cfg(all( feature = "tokio", not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")) @@ -48,8 +47,7 @@ impl Executor for TokioExecutor { not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")) ))] #[derive(Default, Debug, Clone, Copy)] -pub struct AsyncStdExecutor; - +pub(crate) struct AsyncStdExecutor; #[cfg(all( feature = "async-std", not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")) @@ -62,8 +60,7 @@ impl Executor for AsyncStdExecutor { #[cfg(feature = "wasm-bindgen")] #[derive(Default, Debug, Clone, Copy, Hash, PartialEq, Eq, PartialOrd, Ord)] -pub struct WasmBindgenExecutor; - +pub(crate) struct WasmBindgenExecutor; #[cfg(feature = "wasm-bindgen")] impl Executor for WasmBindgenExecutor { fn exec(&self, future: Pin + Send>>) { diff --git a/swarm/src/registry.rs b/swarm/src/registry.rs index 04204930580..7f8225a6a25 100644 --- a/swarm/src/registry.rs +++ b/swarm/src/registry.rs @@ -42,7 +42,7 @@ use std::{cmp::Ordering, collections::VecDeque, num::NonZeroUsize}; /// it is removed from the collection. /// #[derive(Debug, Clone)] -pub struct Addresses { +pub(crate) struct Addresses { /// The ranked sequence of addresses, from highest to lowest score. /// /// By design, the number of finitely scored addresses stored here is @@ -171,7 +171,7 @@ pub enum AddAddressResult { impl Addresses { /// Create a new ranked address collection with the given size limit /// for [finitely scored](AddressScore::Finite) addresses. - pub fn new(limit: NonZeroUsize) -> Self { + pub(crate) fn new(limit: NonZeroUsize) -> Self { Addresses { registry: SmallVec::new(), limit, @@ -189,7 +189,7 @@ impl Addresses { /// as per this limited history has its score reduced by the amount /// used in this prior report, with removal from the collection /// occurring when the score drops to 0. - pub fn add(&mut self, addr: Multiaddr, score: AddressScore) -> AddAddressResult { + pub(crate) fn add(&mut self, addr: Multiaddr, score: AddressScore) -> AddAddressResult { // If enough reports (i.e. address additions) occurred, reduce // the score of the least-recently added address. if self.reports.len() == self.limit.get() { @@ -240,7 +240,7 @@ impl Addresses { /// /// Returns `true` if the address existed in the collection /// and was thus removed, false otherwise. - pub fn remove(&mut self, addr: &Multiaddr) -> bool { + pub(crate) fn remove(&mut self, addr: &Multiaddr) -> bool { if let Some(pos) = self.registry.iter().position(|r| &r.addr == addr) { self.registry.remove(pos); true @@ -252,7 +252,7 @@ impl Addresses { /// Return an iterator over all [`Multiaddr`] values. /// /// The iteration is ordered by descending score. - pub fn iter(&self) -> AddressIter<'_> { + pub(crate) fn iter(&self) -> AddressIter<'_> { AddressIter { items: &self.registry, offset: 0, @@ -262,7 +262,7 @@ impl Addresses { /// Return an iterator over all [`Multiaddr`] values. /// /// The iteration is ordered by descending score. - pub fn into_iter(self) -> AddressIntoIter { + pub(crate) fn into_iter(self) -> AddressIntoIter { AddressIntoIter { items: self.registry, } @@ -271,7 +271,7 @@ impl Addresses { /// An iterator over [`Multiaddr`] values. #[derive(Clone)] -pub struct AddressIter<'a> { +pub(crate) struct AddressIter<'a> { items: &'a [AddressRecord], offset: usize, } diff --git a/swarm/src/test.rs b/swarm/src/test.rs index ab5262ade6e..90738b6a6cf 100644 --- a/swarm/src/test.rs +++ b/swarm/src/test.rs @@ -34,7 +34,7 @@ use std::task::{Context, Poll}; /// A `MockBehaviour` is a `NetworkBehaviour` that allows for /// the instrumentation of return values, without keeping /// any further state. -pub struct MockBehaviour +pub(crate) struct MockBehaviour where THandler: ConnectionHandler + Clone, THandler::OutEvent: Clone, @@ -42,13 +42,13 @@ where { /// The prototype protocols handler that is cloned for every /// invocation of `new_handler`. - pub handler_proto: THandler, + pub(crate) handler_proto: THandler, /// The addresses to return from `addresses_of_peer`. - pub addresses: HashMap>, + pub(crate) addresses: HashMap>, /// The next action to return from `poll`. /// /// An action is only returned once. - pub next_action: Option>, + pub(crate) next_action: Option>, } impl MockBehaviour @@ -57,7 +57,7 @@ where THandler::OutEvent: Clone, TOutEvent: Send + 'static, { - pub fn new(handler_proto: THandler) -> Self { + pub(crate) fn new(handler_proto: THandler) -> Self { MockBehaviour { handler_proto, addresses: HashMap::new(), @@ -147,29 +147,31 @@ where /// A `CallTraceBehaviour` is a `NetworkBehaviour` that tracks /// invocations of callback methods and their arguments, wrapping /// around an inner behaviour. It ensures certain invariants are met. -pub struct CallTraceBehaviour +pub(crate) struct CallTraceBehaviour where TInner: NetworkBehaviour, { inner: TInner, - pub handle_pending_inbound_connection: Vec<(ConnectionId, Multiaddr, Multiaddr)>, - pub handle_pending_outbound_connection: + pub(crate) handle_pending_inbound_connection: Vec<(ConnectionId, Multiaddr, Multiaddr)>, + pub(crate) handle_pending_outbound_connection: Vec<(Option, Vec, Endpoint, ConnectionId)>, - pub handle_established_inbound_connection: Vec<(PeerId, ConnectionId, Multiaddr, Multiaddr)>, - pub handle_established_outbound_connection: Vec<(PeerId, Multiaddr, Endpoint, ConnectionId)>, - pub on_connection_established: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>, - pub on_connection_closed: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>, - pub on_connection_handler_event: Vec<(PeerId, ConnectionId, THandlerOutEvent)>, - pub on_dial_failure: Vec>, - pub on_new_listener: Vec, - pub on_new_listen_addr: Vec<(ListenerId, Multiaddr)>, - pub on_new_external_addr: Vec, - pub on_expired_listen_addr: Vec<(ListenerId, Multiaddr)>, - pub on_expired_external_addr: Vec, - pub on_listener_error: Vec, - pub on_listener_closed: Vec<(ListenerId, bool)>, - pub poll: usize, + pub(crate) handle_established_inbound_connection: + Vec<(PeerId, ConnectionId, Multiaddr, Multiaddr)>, + pub(crate) handle_established_outbound_connection: + Vec<(PeerId, Multiaddr, Endpoint, ConnectionId)>, + pub(crate) on_connection_established: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>, + pub(crate) on_connection_closed: Vec<(PeerId, ConnectionId, ConnectedPoint, usize)>, + pub(crate) on_connection_handler_event: Vec<(PeerId, ConnectionId, THandlerOutEvent)>, + pub(crate) on_dial_failure: Vec>, + pub(crate) on_new_listener: Vec, + pub(crate) on_new_listen_addr: Vec<(ListenerId, Multiaddr)>, + pub(crate) on_new_external_addr: Vec, + pub(crate) on_expired_listen_addr: Vec<(ListenerId, Multiaddr)>, + pub(crate) on_expired_external_addr: Vec, + pub(crate) on_listener_error: Vec, + pub(crate) on_listener_closed: Vec<(ListenerId, bool)>, + pub(crate) poll: usize, } impl CallTraceBehaviour @@ -177,7 +179,7 @@ where TInner: NetworkBehaviour, THandlerOutEvent: Clone, { - pub fn new(inner: TInner) -> Self { + pub(crate) fn new(inner: TInner) -> Self { Self { inner, handle_pending_inbound_connection: Vec::new(), @@ -200,7 +202,7 @@ where } #[allow(dead_code)] - pub fn reset(&mut self) { + pub(crate) fn reset(&mut self) { self.handle_pending_inbound_connection = Vec::new(); self.handle_pending_outbound_connection = Vec::new(); self.handle_established_inbound_connection = Vec::new(); @@ -217,11 +219,11 @@ where self.poll = 0; } - pub fn inner(&mut self) -> &mut TInner { + pub(crate) fn inner(&mut self) -> &mut TInner { &mut self.inner } - pub fn num_connections_to_peer(&self, peer: PeerId) -> usize { + pub(crate) fn num_connections_to_peer(&self, peer: PeerId) -> usize { self.on_connection_established .iter() .filter(|(peer_id, _, _, _)| *peer_id == peer) @@ -237,7 +239,7 @@ where /// given number of expected disconnections have been received as well. /// /// Returns if the first condition is met. - pub fn assert_disconnected( + pub(crate) fn assert_disconnected( &self, expected_closed_connections: usize, expected_disconnections: usize, @@ -260,7 +262,7 @@ where /// a given number of expected connections have been received as well. /// /// Returns if the first condition is met. - pub fn assert_connected( + pub(crate) fn assert_connected( &self, expected_established_connections: usize, expected_connections: usize, diff --git a/swarm/tests/swarm_derive.rs b/swarm/tests/swarm_derive.rs index 485e8b46139..87f99e35736 100644 --- a/swarm/tests/swarm_derive.rs +++ b/swarm/tests/swarm_derive.rs @@ -461,7 +461,7 @@ fn custom_out_event_no_type_parameters() { use std::task::Context; use std::task::Poll; - pub struct TemplatedBehaviour { + pub(crate) struct TemplatedBehaviour { _data: T, } diff --git a/transports/noise/src/io.rs b/transports/noise/src/io.rs index afeee65363a..314a3b87033 100644 --- a/transports/noise/src/io.rs +++ b/transports/noise/src/io.rs @@ -21,8 +21,7 @@ //! Noise protocol I/O. mod framed; -pub mod handshake; - +pub(crate) mod handshake; use bytes::Bytes; use framed::{NoiseFramed, MAX_FRAME_LEN}; use futures::prelude::*; diff --git a/transports/noise/src/io/framed.rs b/transports/noise/src/io/framed.rs index b04860375f9..1e74e46ac9b 100644 --- a/transports/noise/src/io/framed.rs +++ b/transports/noise/src/io/framed.rs @@ -38,8 +38,7 @@ const MAX_NOISE_MSG_LEN: usize = 65535; /// Space given to the encryption buffer to hold key material. const EXTRA_ENCRYPT_SPACE: usize = 1024; /// Max. length for Noise protocol message payloads. -pub const MAX_FRAME_LEN: usize = MAX_NOISE_MSG_LEN - EXTRA_ENCRYPT_SPACE; - +pub(crate) const MAX_FRAME_LEN: usize = MAX_NOISE_MSG_LEN - EXTRA_ENCRYPT_SPACE; static_assertions::const_assert! { MAX_FRAME_LEN + EXTRA_ENCRYPT_SPACE <= MAX_NOISE_MSG_LEN } @@ -49,7 +48,7 @@ static_assertions::const_assert! { /// /// `T` is the type of the underlying I/O resource and `S` the /// type of the Noise session state. -pub struct NoiseFramed { +pub(crate) struct NoiseFramed { io: T, session: S, read_state: ReadState, @@ -70,7 +69,7 @@ impl fmt::Debug for NoiseFramed { impl NoiseFramed { /// Creates a nwe `NoiseFramed` for beginning a Noise protocol handshake. - pub fn new(io: T, state: snow::HandshakeState) -> Self { + pub(crate) fn new(io: T, state: snow::HandshakeState) -> Self { NoiseFramed { io, session: state, @@ -90,7 +89,9 @@ impl NoiseFramed { /// transitioning to transport mode because the handshake is incomplete, /// an error is returned. Similarly if the remote's static DH key, if /// present, cannot be parsed. - pub fn into_transport(self) -> Result<(Option>, NoiseOutput), NoiseError> + pub(crate) fn into_transport( + self, + ) -> Result<(Option>, NoiseOutput), NoiseError> where C: Protocol + AsRef<[u8]>, { @@ -361,7 +362,7 @@ where } /// A stateful context in which Noise protocol messages can be read and written. -pub trait SessionState { +pub(crate) trait SessionState { fn read_message(&mut self, msg: &[u8], buf: &mut [u8]) -> Result; fn write_message(&mut self, msg: &[u8], buf: &mut [u8]) -> Result; } diff --git a/transports/noise/src/io/handshake.rs b/transports/noise/src/io/handshake.rs index e9428f8441c..d968c481ddd 100644 --- a/transports/noise/src/io/handshake.rs +++ b/transports/noise/src/io/handshake.rs @@ -21,6 +21,7 @@ //! Noise protocol handshake I/O. mod proto { + #![allow(unreachable_pub)] include!("../generated/mod.rs"); pub use self::payload::proto::NoiseHandshakePayload; } @@ -67,7 +68,7 @@ pub enum RemoteIdentity { // Internal /// Handshake state. -pub struct State { +pub(crate) struct State { /// The underlying I/O resource. io: NoiseFramed, /// The associated public identity of the local node's static DH keypair, @@ -89,7 +90,7 @@ impl State { /// provided session for cryptographic operations according to the chosen /// Noise handshake pattern. #[allow(deprecated)] - pub fn new( + pub(crate) fn new( io: T, session: snow::HandshakeState, identity: KeypairIdentity, @@ -109,7 +110,7 @@ impl State { impl State { /// Finish a handshake, yielding the established remote identity and the /// [`NoiseOutput`] for communicating on the encrypted channel. - pub fn finish(self) -> Result<(RemoteIdentity, NoiseOutput), NoiseError> + pub(crate) fn finish(self) -> Result<(RemoteIdentity, NoiseOutput), NoiseError> where C: Protocol + AsRef<[u8]>, { @@ -145,7 +146,7 @@ where } /// A future for receiving a Noise handshake message with an empty payload. -pub async fn recv_empty(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn recv_empty(state: &mut State) -> Result<(), NoiseError> where T: AsyncRead + Unpin, { @@ -159,7 +160,7 @@ where } /// A future for sending a Noise handshake message with an empty payload. -pub async fn send_empty(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn send_empty(state: &mut State) -> Result<(), NoiseError> where T: AsyncWrite + Unpin, { @@ -172,7 +173,7 @@ where /// /// In case `expected_key` is passed, this function will fail if the received key does not match the expected key. /// In case the remote does not send us a key, the expected key is assumed to be the remote's key. -pub async fn recv_identity(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn recv_identity(state: &mut State) -> Result<(), NoiseError> where T: AsyncRead + Unpin, { @@ -231,7 +232,7 @@ where } /// Send a Noise handshake message with a payload identifying the local node to the remote. -pub async fn send_identity(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn send_identity(state: &mut State) -> Result<(), NoiseError> where T: AsyncWrite + Unpin, { @@ -261,7 +262,7 @@ where } /// Send a Noise handshake message with a payload identifying the local node to the remote. -pub async fn send_signature_only(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn send_signature_only(state: &mut State) -> Result<(), NoiseError> where T: AsyncWrite + Unpin, { diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index e61bbd1f0ed..db42b5888b3 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -20,9 +20,8 @@ //! Components of a Noise protocol. -pub mod x25519; -pub mod x25519_spec; - +pub(crate) mod x25519; +pub(crate) mod x25519_spec; use crate::NoiseError; use libp2p_identity as identity; use rand::SeedableRng; diff --git a/transports/plaintext/src/handshake.rs b/transports/plaintext/src/handshake.rs index fb156190c57..b1e322459af 100644 --- a/transports/plaintext/src/handshake.rs +++ b/transports/plaintext/src/handshake.rs @@ -43,11 +43,10 @@ struct Local { } // HandshakeContext --with_remote-> HandshakeContext -pub struct Remote { +pub(crate) struct Remote { // The remote's peer ID: - pub peer_id: PeerId, - // The remote's public key: - pub public_key: PublicKey, + pub(crate) peer_id: PeerId, // The remote's public key: + pub(crate) public_key: PublicKey, } impl HandshakeContext { @@ -95,7 +94,7 @@ impl HandshakeContext { } } -pub async fn handshake( +pub(crate) async fn handshake( socket: S, config: PlainText2Config, ) -> Result<(S, Remote, Bytes), PlainTextError> diff --git a/transports/plaintext/src/lib.rs b/transports/plaintext/src/lib.rs index aeea2763d4d..fe4aba91a88 100644 --- a/transports/plaintext/src/lib.rs +++ b/transports/plaintext/src/lib.rs @@ -43,8 +43,9 @@ use void::Void; mod error; mod handshake; mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::structs::Exchange; + pub(crate) use self::structs::Exchange; } /// `PlainText1Config` is an insecure connection handshake for testing purposes only. diff --git a/transports/pnet/src/crypt_writer.rs b/transports/pnet/src/crypt_writer.rs index e921e278875..c5993548239 100644 --- a/transports/pnet/src/crypt_writer.rs +++ b/transports/pnet/src/crypt_writer.rs @@ -30,7 +30,7 @@ use std::{fmt, pin::Pin}; /// A writer that encrypts and forwards to an inner writer #[pin_project] -pub struct CryptWriter { +pub(crate) struct CryptWriter { #[pin] inner: W, buf: Vec, @@ -39,7 +39,7 @@ pub struct CryptWriter { impl CryptWriter { /// Creates a new `CryptWriter` with the specified buffer capacity. - pub fn with_capacity(capacity: usize, inner: W, cipher: XSalsa20) -> CryptWriter { + pub(crate) fn with_capacity(capacity: usize, inner: W, cipher: XSalsa20) -> CryptWriter { CryptWriter { inner, buf: Vec::with_capacity(capacity), @@ -50,7 +50,7 @@ impl CryptWriter { /// Gets a pinned mutable reference to the inner writer. /// /// It is inadvisable to directly write to the inner writer. - pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut W> { + pub(crate) fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut W> { self.project().inner } } diff --git a/transports/quic/src/endpoint.rs b/transports/quic/src/endpoint.rs index cf7b0fbafef..10e650ba41a 100644 --- a/transports/quic/src/endpoint.rs +++ b/transports/quic/src/endpoint.rs @@ -112,7 +112,7 @@ impl Config { /// Represents the inner configuration for [`quinn_proto`]. #[derive(Debug, Clone)] -pub struct QuinnConfig { +pub(crate) struct QuinnConfig { client_config: quinn_proto::ClientConfig, server_config: Arc, endpoint_config: Arc, @@ -169,7 +169,7 @@ impl From for QuinnConfig { /// Channel used to send commands to the [`Driver`]. #[derive(Debug, Clone)] -pub struct Channel { +pub(crate) struct Channel { /// Channel to the background of the endpoint. to_endpoint: mpsc::Sender, /// Address that the socket is bound to. @@ -179,7 +179,7 @@ pub struct Channel { impl Channel { /// Builds a new endpoint that is listening on the [`SocketAddr`]. - pub fn new_bidirectional( + pub(crate) fn new_bidirectional( quinn_config: QuinnConfig, socket_addr: SocketAddr, ) -> Result<(Self, mpsc::Receiver), Error> { @@ -190,7 +190,7 @@ impl Channel { } /// Builds a new endpoint that only supports outbound connections. - pub fn new_dialer( + pub(crate) fn new_dialer( quinn_config: QuinnConfig, socket_family: SocketFamily, ) -> Result { @@ -241,7 +241,7 @@ impl Channel { Ok(channel) } - pub fn socket_addr(&self) -> &SocketAddr { + pub(crate) fn socket_addr(&self) -> &SocketAddr { &self.socket_addr } @@ -252,7 +252,7 @@ impl Channel { /// and the context's waker is registered for wake-up. /// /// If the background task crashed `Err` is returned. - pub fn try_send( + pub(crate) fn try_send( &mut self, to_endpoint: ToEndpoint, cx: &mut Context<'_>, @@ -283,18 +283,17 @@ impl Channel { /// event caused by the owner of this [`Channel`] dropping. /// This clones the sender to the endpoint to guarantee delivery. /// This should *not* be called for regular messages. - pub fn send_on_drop(&mut self, to_endpoint: ToEndpoint) { + pub(crate) fn send_on_drop(&mut self, to_endpoint: ToEndpoint) { let _ = self.to_endpoint.clone().try_send(to_endpoint); } } #[derive(Debug, thiserror::Error, Clone, PartialEq, Eq)] #[error("Background task disconnected")] -pub struct Disconnected {} - +pub(crate) struct Disconnected {} /// Message sent to the endpoint background task. #[derive(Debug)] -pub enum ToEndpoint { +pub(crate) enum ToEndpoint { /// Instruct the [`quinn_proto::Endpoint`] to start connecting to the given address. Dial { /// UDP address to connect to. @@ -369,7 +368,7 @@ pub enum ToEndpoint { /// The background task shuts down if an [`ToEndpoint::Decoupled`] event was received and the /// last active connection has drained. #[derive(Debug)] -pub struct Driver { +pub(crate) struct Driver { // The actual QUIC state machine. endpoint: quinn_proto::Endpoint, // QuinnConfig for client connections. diff --git a/transports/quic/src/transport.rs b/transports/quic/src/transport.rs index 9aadbeb93f4..d68eb7f1928 100644 --- a/transports/quic/src/transport.rs +++ b/transports/quic/src/transport.rs @@ -536,13 +536,13 @@ impl Drop for Listener

{ } #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum ProtocolVersion { +pub(crate) enum ProtocolVersion { V1, // i.e. RFC9000 Draft29, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum SocketFamily { +pub(crate) enum SocketFamily { Ipv4, Ipv6, } diff --git a/transports/tls/src/verifier.rs b/transports/tls/src/verifier.rs index 29e4ab989e5..a9d9aecaa65 100644 --- a/transports/tls/src/verifier.rs +++ b/transports/tls/src/verifier.rs @@ -42,12 +42,11 @@ use rustls::{ /// /// > The libp2p handshake uses TLS 1.3 (and higher). /// > Endpoints MUST NOT negotiate lower TLS versions. -pub static PROTOCOL_VERSIONS: &[&SupportedProtocolVersion] = &[&rustls::version::TLS13]; - +pub(crate) static PROTOCOL_VERSIONS: &[&SupportedProtocolVersion] = &[&rustls::version::TLS13]; /// A list of the TLS 1.3 cipher suites supported by rustls. // By default rustls creates client/server configs with both // TLS 1.3 __and__ 1.2 cipher suites. But we don't need 1.2. -pub static CIPHERSUITES: &[SupportedCipherSuite] = &[ +pub(crate) static CIPHERSUITES: &[SupportedCipherSuite] = &[ // TLS1.3 suites TLS13_CHACHA20_POLY1305_SHA256, TLS13_AES_256_GCM_SHA384, @@ -57,7 +56,7 @@ pub static CIPHERSUITES: &[SupportedCipherSuite] = &[ /// Implementation of the `rustls` certificate verification traits for libp2p. /// /// Only TLS 1.3 is supported. TLS 1.2 should be disabled in the configuration of `rustls`. -pub struct Libp2pCertificateVerifier { +pub(crate) struct Libp2pCertificateVerifier { /// The peer ID we intend to connect to remote_peer_id: Option, } @@ -69,12 +68,12 @@ pub struct Libp2pCertificateVerifier { /// - The certificate must have a valid libp2p extension that includes a /// signature of its public key. impl Libp2pCertificateVerifier { - pub fn new() -> Self { + pub(crate) fn new() -> Self { Self { remote_peer_id: None, } } - pub fn with_remote_peer_id(remote_peer_id: Option) -> Self { + pub(crate) fn with_remote_peer_id(remote_peer_id: Option) -> Self { Self { remote_peer_id } } diff --git a/transports/webrtc/src/lib.rs b/transports/webrtc/src/lib.rs index 95bd0ac6d7e..012796a6b69 100644 --- a/transports/webrtc/src/lib.rs +++ b/transports/webrtc/src/lib.rs @@ -81,8 +81,9 @@ //! certificate verification off. mod proto { + #![allow(unreachable_pub)] include!("generated/mod.rs"); - pub use self::webrtc::pb::{mod_Message::Flag, Message}; + pub(crate) use self::webrtc::pb::{mod_Message::Flag, Message}; } #[cfg(feature = "tokio")] diff --git a/transports/webrtc/src/tokio/req_res_chan.rs b/transports/webrtc/src/tokio/req_res_chan.rs index a102aa0357a..fb29e16db27 100644 --- a/transports/webrtc/src/tokio/req_res_chan.rs +++ b/transports/webrtc/src/tokio/req_res_chan.rs @@ -28,7 +28,7 @@ use std::{ task::{Context, Poll}, }; -pub fn new(capacity: usize) -> (Sender, Receiver) { +pub(crate) fn new(capacity: usize) -> (Sender, Receiver) { let (sender, receiver) = mpsc::channel(capacity); ( @@ -39,12 +39,12 @@ pub fn new(capacity: usize) -> (Sender, Receiver) ) } -pub struct Sender { +pub(crate) struct Sender { inner: futures::lock::Mutex)>>, } impl Sender { - pub async fn send(&self, req: Req) -> io::Result { + pub(crate) async fn send(&self, req: Req) -> io::Result { let (sender, receiver) = oneshot::channel(); self.inner @@ -61,12 +61,12 @@ impl Sender { } } -pub struct Receiver { +pub(crate) struct Receiver { inner: mpsc::Receiver<(Req, oneshot::Sender)>, } impl Receiver { - pub fn poll_next_unpin( + pub(crate) fn poll_next_unpin( &mut self, cx: &mut Context<'_>, ) -> Poll)>> { diff --git a/transports/webrtc/src/tokio/sdp.rs b/transports/webrtc/src/tokio/sdp.rs index 659057788ff..d2f424e5d4e 100644 --- a/transports/webrtc/src/tokio/sdp.rs +++ b/transports/webrtc/src/tokio/sdp.rs @@ -27,7 +27,7 @@ use std::net::{IpAddr, SocketAddr}; use crate::tokio::fingerprint::Fingerprint; /// Creates the SDP answer used by the client. -pub fn answer( +pub(crate) fn answer( addr: SocketAddr, server_fingerprint: &Fingerprint, client_ufrag: &str, @@ -44,7 +44,7 @@ pub fn answer( /// Creates the SDP offer used by the server. /// /// Certificate verification is disabled which is why we hardcode a dummy fingerprint here. -pub fn offer(addr: SocketAddr, client_ufrag: &str) -> RTCSessionDescription { +pub(crate) fn offer(addr: SocketAddr, client_ufrag: &str) -> RTCSessionDescription { RTCSessionDescription::offer(render_description( CLIENT_SESSION_DESCRIPTION, addr, @@ -213,13 +213,13 @@ enum IpVersion { /// `{IP_VERSION}`) with real values. #[derive(Serialize)] struct DescriptionContext { - pub ip_version: IpVersion, - pub target_ip: IpAddr, - pub target_port: u16, - pub fingerprint_algorithm: String, - pub fingerprint_value: String, - pub ufrag: String, - pub pwd: String, + pub(crate) ip_version: IpVersion, + pub(crate) target_ip: IpAddr, + pub(crate) target_port: u16, + pub(crate) fingerprint_algorithm: String, + pub(crate) fingerprint_value: String, + pub(crate) ufrag: String, + pub(crate) pwd: String, } /// Renders a [`TinyTemplate`] description using the provided arguments. diff --git a/transports/webrtc/src/tokio/substream.rs b/transports/webrtc/src/tokio/substream.rs index e3f9ef9e074..89e52376a48 100644 --- a/transports/webrtc/src/tokio/substream.rs +++ b/transports/webrtc/src/tokio/substream.rs @@ -55,8 +55,7 @@ const PROTO_OVERHEAD: usize = 5; /// Maximum length of data, in bytes. const MAX_DATA_LEN: usize = MAX_MSG_LEN - VARINT_LEN - PROTO_OVERHEAD; -pub use drop_listener::DropListener; - +pub(crate) use drop_listener::DropListener; /// A substream on top of a WebRTC data channel. /// /// To be a proper libp2p substream, we need to implement [`AsyncRead`] and [`AsyncWrite`] as well diff --git a/transports/webrtc/src/tokio/substream/drop_listener.rs b/transports/webrtc/src/tokio/substream/drop_listener.rs index 3e3dc18a1d6..735240456fe 100644 --- a/transports/webrtc/src/tokio/substream/drop_listener.rs +++ b/transports/webrtc/src/tokio/substream/drop_listener.rs @@ -31,12 +31,12 @@ use crate::proto::{Flag, Message}; use crate::tokio::substream::framed_dc::FramedDc; #[must_use] -pub struct DropListener { +pub(crate) struct DropListener { state: State, } impl DropListener { - pub fn new(stream: FramedDc, receiver: oneshot::Receiver) -> Self { + pub(crate) fn new(stream: FramedDc, receiver: oneshot::Receiver) -> Self { let substream_id = stream.get_ref().stream_identifier(); Self { @@ -127,4 +127,4 @@ impl Future for DropListener { } /// Indicates that our substream got gracefully closed. -pub struct GracefullyClosed {} +pub(crate) struct GracefullyClosed {} diff --git a/transports/webrtc/src/tokio/substream/framed_dc.rs b/transports/webrtc/src/tokio/substream/framed_dc.rs index 1bf2b3cf769..1b3860b662b 100644 --- a/transports/webrtc/src/tokio/substream/framed_dc.rs +++ b/transports/webrtc/src/tokio/substream/framed_dc.rs @@ -28,9 +28,8 @@ use std::sync::Arc; use super::{MAX_DATA_LEN, MAX_MSG_LEN, VARINT_LEN}; use crate::proto::Message; -pub type FramedDc = Framed, quick_protobuf_codec::Codec>; - -pub fn new(data_channel: Arc) -> FramedDc { +pub(crate) type FramedDc = Framed, quick_protobuf_codec::Codec>; +pub(crate) fn new(data_channel: Arc) -> FramedDc { let mut inner = PollDataChannel::new(data_channel); inner.set_read_buf_capacity(MAX_MSG_LEN); diff --git a/transports/webrtc/src/tokio/substream/state.rs b/transports/webrtc/src/tokio/substream/state.rs index 5e843519ed6..b1768aa2165 100644 --- a/transports/webrtc/src/tokio/substream/state.rs +++ b/transports/webrtc/src/tokio/substream/state.rs @@ -25,7 +25,7 @@ use std::io; use crate::proto::Flag; #[derive(Debug, Copy, Clone)] -pub enum State { +pub(crate) enum State { Open, ReadClosed, WriteClosed, @@ -49,7 +49,7 @@ pub enum State { /// Gracefully closing the read or write requires sending the `STOP_SENDING` or `FIN` flag respectively /// and flushing the underlying connection. #[derive(Debug, Copy, Clone)] -pub enum Closing { +pub(crate) enum Closing { Requested, MessageSent, } @@ -278,7 +278,7 @@ impl State { } /// Acts as a "barrier" for [`Substream::poll_close_read`](super::Substream::poll_close_read). - pub fn close_read_barrier(&mut self) -> io::Result> { + pub(crate) fn close_read_barrier(&mut self) -> io::Result> { loop { match self { State::ReadClosed => return Ok(None), diff --git a/transports/webrtc/src/tokio/udp_mux.rs b/transports/webrtc/src/tokio/udp_mux.rs index 4e432c2e51f..f978121d01c 100644 --- a/transports/webrtc/src/tokio/udp_mux.rs +++ b/transports/webrtc/src/tokio/udp_mux.rs @@ -49,14 +49,14 @@ const RECEIVE_MTU: usize = 8192; /// A previously unseen address of a remote which has sent us an ICE binding request. #[derive(Debug)] -pub struct NewAddr { - pub addr: SocketAddr, - pub ufrag: String, +pub(crate) struct NewAddr { + pub(crate) addr: SocketAddr, + pub(crate) ufrag: String, } /// An event emitted by [`UDPMuxNewAddr`] when it's polled. #[derive(Debug)] -pub enum UDPMuxEvent { +pub(crate) enum UDPMuxEvent { /// Connection error. UDP mux should be stopped. Error(std::io::Error), /// Got a [`NewAddr`] from the socket. @@ -67,7 +67,7 @@ pub enum UDPMuxEvent { /// /// - It has been rewritten to work without locks and channels instead. /// - It reports previously unseen addresses instead of ignoring them. -pub struct UDPMuxNewAddr { +pub(crate) struct UDPMuxNewAddr { udp_sock: UdpSocket, listen_addr: SocketAddr, @@ -100,7 +100,7 @@ pub struct UDPMuxNewAddr { } impl UDPMuxNewAddr { - pub fn listen_on(addr: SocketAddr) -> Result { + pub(crate) fn listen_on(addr: SocketAddr) -> Result { let std_sock = std::net::UdpSocket::bind(addr)?; std_sock.set_nonblocking(true)?; @@ -131,11 +131,11 @@ impl UDPMuxNewAddr { }) } - pub fn listen_addr(&self) -> SocketAddr { + pub(crate) fn listen_addr(&self) -> SocketAddr { self.listen_addr } - pub fn udp_mux_handle(&self) -> Arc { + pub(crate) fn udp_mux_handle(&self) -> Arc { self.udp_mux_handle.clone() } @@ -183,7 +183,7 @@ impl UDPMuxNewAddr { /// Reads from the underlying UDP socket and either reports a new address or proxies data to the /// muxed connection. - pub fn poll(&mut self, cx: &mut Context) -> Poll { + pub(crate) fn poll(&mut self, cx: &mut Context) -> Poll { let mut recv_buf = [0u8; RECEIVE_MTU]; loop { @@ -419,7 +419,7 @@ impl UDPMuxNewAddr { /// Handle which utilizes [`req_res_chan`] to transmit commands (e.g. remove connection) from the /// WebRTC ICE agent to [`UDPMuxNewAddr::poll`]. -pub struct UdpMuxHandle { +pub(crate) struct UdpMuxHandle { close_sender: req_res_chan::Sender<(), Result<(), Error>>, get_conn_sender: req_res_chan::Sender, Error>>, remove_sender: req_res_chan::Sender, @@ -427,7 +427,7 @@ pub struct UdpMuxHandle { impl UdpMuxHandle { /// Returns a new `UdpMuxHandle` and `close`, `get_conn` and `remove` receivers. - pub fn new() -> ( + pub(crate) fn new() -> ( Self, req_res_chan::Receiver<(), Result<(), Error>>, req_res_chan::Receiver, Error>>, @@ -477,7 +477,7 @@ impl UDPMux for UdpMuxHandle { /// Handle which utilizes [`req_res_chan`] to transmit commands from [`UDPMuxConn`] connections to /// [`UDPMuxNewAddr::poll`]. -pub struct UdpMuxWriterHandle { +pub(crate) struct UdpMuxWriterHandle { registration_channel: req_res_chan::Sender<(UDPMuxConn, SocketAddr), ()>, send_channel: req_res_chan::Sender<(Vec, SocketAddr), Result>, } diff --git a/transports/webrtc/src/tokio/upgrade.rs b/transports/webrtc/src/tokio/upgrade.rs index 23dd978ae92..2d5e3fe2c10 100644 --- a/transports/webrtc/src/tokio/upgrade.rs +++ b/transports/webrtc/src/tokio/upgrade.rs @@ -43,7 +43,7 @@ use std::{net::SocketAddr, sync::Arc, time::Duration}; use crate::tokio::{error::Error, fingerprint::Fingerprint, sdp, substream::Substream, Connection}; /// Creates a new outbound WebRTC connection. -pub async fn outbound( +pub(crate) async fn outbound( addr: SocketAddr, config: RTCConfiguration, udp_mux: Arc, @@ -79,7 +79,7 @@ pub async fn outbound( } /// Creates a new inbound WebRTC connection. -pub async fn inbound( +pub(crate) async fn inbound( addr: SocketAddr, config: RTCConfiguration, udp_mux: Arc, diff --git a/transports/webrtc/src/tokio/upgrade/noise.rs b/transports/webrtc/src/tokio/upgrade/noise.rs index ad387510fc4..fb95a0f4b46 100644 --- a/transports/webrtc/src/tokio/upgrade/noise.rs +++ b/transports/webrtc/src/tokio/upgrade/noise.rs @@ -27,7 +27,7 @@ use libp2p_noise::{Keypair, NoiseConfig, X25519Spec}; use crate::tokio::fingerprint::Fingerprint; use crate::tokio::Error; -pub async fn inbound( +pub(crate) async fn inbound( id_keys: identity::Keypair, stream: T, client_fingerprint: Fingerprint, @@ -54,7 +54,7 @@ where Ok(peer_id) } -pub async fn outbound( +pub(crate) async fn outbound( id_keys: identity::Keypair, stream: T, server_fingerprint: Fingerprint, @@ -81,7 +81,10 @@ where Ok(peer_id) } -pub fn noise_prologue(client_fingerprint: Fingerprint, server_fingerprint: Fingerprint) -> Vec { +pub(crate) fn noise_prologue( + client_fingerprint: Fingerprint, + server_fingerprint: Fingerprint, +) -> Vec { let client = client_fingerprint.to_multihash().to_bytes(); let server = server_fingerprint.to_multihash().to_bytes(); const PREFIX: &[u8] = b"libp2p-webrtc-noise:"; diff --git a/transports/webrtc/tests/smoke.rs b/transports/webrtc/tests/smoke.rs index 16f64d058a4..bca159d785b 100644 --- a/transports/webrtc/tests/smoke.rs +++ b/transports/webrtc/tests/smoke.rs @@ -297,7 +297,7 @@ struct ListenUpgrade<'a> { } impl<'a> ListenUpgrade<'a> { - pub fn new(listener: &'a mut Boxed<(PeerId, StreamMuxerBox)>) -> Self { + pub(crate) fn new(listener: &'a mut Boxed<(PeerId, StreamMuxerBox)>) -> Self { Self { listener, listener_upgrade_task: None, From 58085418d1f1e75c0de529a8c18a6a272ff6c67c Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 10:17:07 +0200 Subject: [PATCH 19/57] feat(ci): bump version for stable clippy to 1.69 Pull-Request: #3820. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3ab01206348..3460d3ec148 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -167,7 +167,7 @@ jobs: fail-fast: false matrix: rust-version: [ - 1.68.0, # current stable + 1.69.0, # current stable beta ] steps: From ed392af86499667834b5c00a1a83836eb8cdb20e Mon Sep 17 00:00:00 2001 From: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Date: Wed, 26 Apr 2023 07:18:30 -0400 Subject: [PATCH 20/57] feat(ci): use cargo-semver-checks v0.20 for a massive perf improvement `cargo-semver-checks` v0.20 uses Trustfall's newly-added optimization API to make semver-checking scale as `O(n)` instead of `O(n^2)`. On one large crate this was a 2354x speedup: 5h3min turned into 7.7s! Pull-Request: #3822. --- .github/actions/cargo-semver-checks/action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/actions/cargo-semver-checks/action.yml b/.github/actions/cargo-semver-checks/action.yml index 6ae6240e452..7e982959608 100644 --- a/.github/actions/cargo-semver-checks/action.yml +++ b/.github/actions/cargo-semver-checks/action.yml @@ -7,7 +7,7 @@ inputs: runs: using: "composite" steps: - - run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.19.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin + - run: wget -q -O- https://github.com/obi1kenobi/cargo-semver-checks/releases/download/v0.20.0/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin shell: bash - name: Get released version From 7fa8beff213b85c767838e2a19d3f1d8fb71f718 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 14:37:28 +0200 Subject: [PATCH 21/57] refactor(deflate): implement tests with `futures_ringbuf` Previously, we used a TCP transport to test the deflate compression. Really, all we need is an in-memory ringbuffer that we can plug in at both ends. This PR uses `futures_ringbuf` for that. Related #3748. Pull-Request: #3771. --- Cargo.lock | 96 +++++++++++++++++++++++++++++--- transports/deflate/Cargo.toml | 3 +- transports/deflate/tests/test.rs | 80 +++++++++----------------- 3 files changed, 115 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a6b95261f82..b0412716b7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -631,6 +631,12 @@ dependencies = [ "serde", ] +[[package]] +name = "cache-padded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" + [[package]] name = "cast" version = "0.3.0" @@ -785,7 +791,7 @@ dependencies = [ "anstyle", "bitflags", "clap_lex 0.4.1", - "strsim", + "strsim 0.10.0", ] [[package]] @@ -1126,14 +1132,38 @@ dependencies = [ "zeroize", ] +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + [[package]] name = "darling" version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0dd3cd20dc6b5a876612a6e5accfe7f3dd883db6d07acfbf14c128f61550dfa" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.14.2", + "darling_macro 0.14.2", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.9.3", + "syn 1.0.109", ] [[package]] @@ -1146,7 +1176,18 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", + "syn 1.0.109", +] + +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core 0.10.2", + "quote", "syn 1.0.109", ] @@ -1156,7 +1197,7 @@ version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7618812407e9402654622dd402b0a89dff9ba93badd6540781526117b92aab7e" dependencies = [ - "darling_core", + "darling_core 0.14.2", "quote", "syn 1.0.109", ] @@ -1253,7 +1294,7 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f91d4cfa921f1c05904dc3c57b4a32c38aed3340cce209f3a6fd1478babafc4" dependencies = [ - "darling", + "darling 0.14.2", "proc-macro2", "quote", "syn 1.0.109", @@ -1646,6 +1687,19 @@ dependencies = [ "slab", ] +[[package]] +name = "futures_ringbuf" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b905098b5519bd63b2a1f9f4615198b0e38a473ce201ffdbd4dea6eb63087ddc" +dependencies = [ + "futures", + "log", + "log-derive", + "ringbuf", + "rustc_version", +] + [[package]] name = "generic-array" version = "0.14.6" @@ -2384,11 +2438,10 @@ dependencies = [ name = "libp2p-deflate" version = "0.39.0" dependencies = [ - "async-std", "flate2", "futures", + "futures_ringbuf", "libp2p-core", - "libp2p-tcp", "quickcheck-ext", "rand 0.8.5", ] @@ -3125,6 +3178,18 @@ dependencies = [ "value-bag", ] +[[package]] +name = "log-derive" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a42526bb432bcd1b43571d5f163984effa25409a29f1a3242a54d0577d55bcf" +dependencies = [ + "darling 0.10.2", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "lru" version = "0.10.0" @@ -4165,6 +4230,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "ringbuf" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f65af18d50f789e74aaf23bbb3f65dcd22a3cb6e029b5bced149f6bd57c5c2a2" +dependencies = [ + "cache-padded", +] + [[package]] name = "rmp" version = "0.8.11" @@ -4631,6 +4705,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + [[package]] name = "strsim" version = "0.10.0" diff --git a/transports/deflate/Cargo.toml b/transports/deflate/Cargo.toml index 59f25c88dfe..32c64e65c27 100644 --- a/transports/deflate/Cargo.toml +++ b/transports/deflate/Cargo.toml @@ -16,10 +16,9 @@ libp2p-core = { version = "0.39.0", path = "../../core" } flate2 = "1.0" [dev-dependencies] -async-std = "1.6.2" -libp2p-tcp = { path = "../tcp", features = ["async-io"] } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } rand = "0.8" +futures_ringbuf = "0.3.1" # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/deflate/tests/test.rs b/transports/deflate/tests/test.rs index c0fdd9dcdfc..b5fbe39ad53 100644 --- a/transports/deflate/tests/test.rs +++ b/transports/deflate/tests/test.rs @@ -18,10 +18,9 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use futures::{future, prelude::*}; -use libp2p_core::{transport::Transport, upgrade}; +use futures::prelude::*; +use libp2p_core::OutboundUpgrade; use libp2p_deflate::DeflateConfig; -use libp2p_tcp as tcp; use quickcheck::{QuickCheck, TestResult}; use rand::RngCore; @@ -31,7 +30,7 @@ fn deflate() { if message.is_empty() { return TestResult::discard(); } - async_std::task::block_on(run(message)); + futures::executor::block_on(run(message)); TestResult::passed() } QuickCheck::new().quickcheck(prop as fn(Vec) -> TestResult) @@ -41,68 +40,41 @@ fn deflate() { fn lot_of_data() { let mut v = vec![0; 2 * 1024 * 1024]; rand::thread_rng().fill_bytes(&mut v); - async_std::task::block_on(run(v)) + futures::executor::block_on(run(v)); } async fn run(message1: Vec) { - let new_transport = || { - tcp::async_io::Transport::default() - .and_then(|conn, endpoint| { - upgrade::apply( - conn, - DeflateConfig::default(), - endpoint, - upgrade::Version::V1, - ) - }) - .boxed() - }; - let mut listener_transport = new_transport(); - listener_transport - .listen_on("/ip4/0.0.0.0/tcp/0".parse().expect("multiaddr")) - .expect("listener"); - - let listen_addr = listener_transport - .next() - .await - .expect("some event") - .into_new_address() - .expect("new address"); + let (server, client) = futures_ringbuf::Endpoint::pair(100, 100); let message2 = message1.clone(); - let listener_task = async_std::task::spawn(async move { - let mut conn = listener_transport - .filter(|e| future::ready(e.is_upgrade())) - .next() + let client_task = async move { + let mut client = DeflateConfig::default() + .upgrade_outbound(client, b"") .await - .expect("some event") - .into_incoming() - .expect("upgrade") - .0 - .await - .expect("connection"); + .unwrap(); let mut buf = vec![0; message2.len()]; - conn.read_exact(&mut buf).await.expect("read_exact"); + client.read_exact(&mut buf).await.expect("read_exact"); assert_eq!(&buf[..], &message2[..]); - conn.write_all(&message2).await.expect("write_all"); - conn.close().await.expect("close") - }); + client.write_all(&message2).await.expect("write_all"); + client.close().await.expect("close") + }; - let mut dialer_transport = new_transport(); - let mut conn = dialer_transport - .dial(listen_addr) - .expect("dialer") - .await - .expect("connection"); - conn.write_all(&message1).await.expect("write_all"); - conn.close().await.expect("close"); + let server_task = async move { + let mut server = DeflateConfig::default() + .upgrade_outbound(server, b"") + .await + .unwrap(); + + server.write_all(&message1).await.expect("write_all"); + server.close().await.expect("close"); - let mut buf = Vec::new(); - conn.read_to_end(&mut buf).await.expect("read_to_end"); - assert_eq!(&buf[..], &message1[..]); + let mut buf = Vec::new(); + server.read_to_end(&mut buf).await.expect("read_to_end"); + assert_eq!(&buf[..], &message1[..]); + }; - listener_task.await + futures::future::join(server_task, client_task).await; } From 35132c4ab63ebb8ded40afdc157138f2110d1555 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 14:55:06 +0200 Subject: [PATCH 22/57] refactor(muxer): replace `MemoryTransport` with `futures_ringbuf` Instead of relying on the `MemoryTransport` to provide us with a duplex stream, we use the `futures_ringbuf` crate. This saves us several lines of code and removes the dependency on `libp2p_core::upgrade::apply`. Related #3748. Pull-Request: #3772. --- Cargo.lock | 1 + muxers/mplex/tests/compliance.rs | 4 +-- muxers/test-harness/Cargo.toml | 1 + muxers/test-harness/src/lib.rs | 57 ++++++++++++-------------------- muxers/yamux/tests/compliance.rs | 4 +-- 5 files changed, 27 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0412716b7b..afaa70a5b10 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2677,6 +2677,7 @@ version = "0.1.0" dependencies = [ "futures", "futures-timer", + "futures_ringbuf", "libp2p-core", "log", ] diff --git a/muxers/mplex/tests/compliance.rs b/muxers/mplex/tests/compliance.rs index 2e8089b968c..d3bcd37bf34 100644 --- a/muxers/mplex/tests/compliance.rs +++ b/muxers/mplex/tests/compliance.rs @@ -3,7 +3,7 @@ use libp2p_mplex::MplexConfig; #[async_std::test] async fn close_implies_flush() { let (alice, bob) = - libp2p_muxer_test_harness::connected_muxers_on_memory_transport::() + libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::() .await; libp2p_muxer_test_harness::close_implies_flush(alice, bob).await; @@ -12,7 +12,7 @@ async fn close_implies_flush() { #[async_std::test] async fn read_after_close() { let (alice, bob) = - libp2p_muxer_test_harness::connected_muxers_on_memory_transport::() + libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::() .await; libp2p_muxer_test_harness::read_after_close(alice, bob).await; diff --git a/muxers/test-harness/Cargo.toml b/muxers/test-harness/Cargo.toml index a1805f67e8e..f19c6656d75 100644 --- a/muxers/test-harness/Cargo.toml +++ b/muxers/test-harness/Cargo.toml @@ -12,3 +12,4 @@ libp2p-core = { path = "../../core" } futures = "0.3.28" log = "0.4" futures-timer = "3.0.2" +futures_ringbuf = "0.3.1" diff --git a/muxers/test-harness/src/lib.rs b/muxers/test-harness/src/lib.rs index 8eeafb363f5..544e057c108 100644 --- a/muxers/test-harness/src/lib.rs +++ b/muxers/test-harness/src/lib.rs @@ -2,57 +2,42 @@ use crate::future::{BoxFuture, Either, FutureExt}; use futures::{future, AsyncRead, AsyncWrite}; use futures::{AsyncReadExt, Stream}; use futures::{AsyncWriteExt, StreamExt}; -use libp2p_core::multiaddr::Protocol; use libp2p_core::muxing::StreamMuxerExt; -use libp2p_core::transport::memory::Channel; -use libp2p_core::transport::MemoryTransport; -use libp2p_core::{ - upgrade, InboundUpgrade, Negotiated, OutboundUpgrade, StreamMuxer, Transport, UpgradeInfo, -}; +use libp2p_core::{InboundUpgrade, OutboundUpgrade, StreamMuxer, UpgradeInfo}; use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; use std::time::Duration; use std::{fmt, mem}; -pub async fn connected_muxers_on_memory_transport() -> (M, M) +pub async fn connected_muxers_on_memory_ring_buffer() -> (M, M) where - MC: InboundUpgrade>>, Error = E, Output = M> - + OutboundUpgrade>>, Error = E, Output = M> + MC: InboundUpgrade + + OutboundUpgrade + Send + 'static + Default, ::Info: Send, <::InfoIter as IntoIterator>::IntoIter: Send, - >>>>::Future: Send, - >>>>::Future: Send, + >::Future: Send, + >::Future: Send, E: std::error::Error + Send + Sync + 'static, { - let mut alice = MemoryTransport::default() - .and_then(move |c, e| upgrade::apply(c, MC::default(), e, upgrade::Version::V1)) - .boxed(); - let mut bob = MemoryTransport::default() - .and_then(move |c, e| upgrade::apply(c, MC::default(), e, upgrade::Version::V1)) - .boxed(); - - alice.listen_on(Protocol::Memory(0).into()).unwrap(); - let listen_address = alice.next().await.unwrap().into_new_address().unwrap(); - - futures::future::join( - async { - alice - .next() - .await - .unwrap() - .into_incoming() - .unwrap() - .0 - .await - .unwrap() - }, - async { bob.dial(listen_address).unwrap().await.unwrap() }, - ) - .await + let (alice, bob) = futures_ringbuf::Endpoint::pair(100, 100); + + let alice_upgrade = MC::default().upgrade_inbound( + alice, + MC::default().protocol_info().into_iter().next().unwrap(), + ); + + let bob_upgrade = MC::default().upgrade_outbound( + bob, + MC::default().protocol_info().into_iter().next().unwrap(), + ); + + futures::future::try_join(alice_upgrade, bob_upgrade) + .await + .unwrap() } /// Verifies that Alice can send a message and immediately close the stream afterwards and Bob can use `read_to_end` to read the entire message. diff --git a/muxers/yamux/tests/compliance.rs b/muxers/yamux/tests/compliance.rs index 2937936e7dc..ba5161dde0d 100644 --- a/muxers/yamux/tests/compliance.rs +++ b/muxers/yamux/tests/compliance.rs @@ -3,7 +3,7 @@ use libp2p_yamux::YamuxConfig; #[async_std::test] async fn close_implies_flush() { let (alice, bob) = - libp2p_muxer_test_harness::connected_muxers_on_memory_transport::() + libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::() .await; libp2p_muxer_test_harness::close_implies_flush(alice, bob).await; @@ -12,7 +12,7 @@ async fn close_implies_flush() { #[async_std::test] async fn read_after_close() { let (alice, bob) = - libp2p_muxer_test_harness::connected_muxers_on_memory_transport::() + libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::() .await; libp2p_muxer_test_harness::read_after_close(alice, bob).await; From 4dd2e0eb5921f201c699cb7aaf19bec955280511 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 15:12:57 +0200 Subject: [PATCH 23/57] refactor(plaintext): implement tests with `futures_ringbuf` Instead of doing an entire connection establishment dance, we simply use a futures-aware ringbuffer to implement the test. This removes the dependency of `libp2p-plaintext` on the `libp2p_core::upgrade::apply` function. Related #3748. Pull-Request: #3770. --- Cargo.lock | 1 + transports/plaintext/Cargo.toml | 1 + transports/plaintext/tests/smoke.rs | 83 ++++++++--------------------- 3 files changed, 24 insertions(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index afaa70a5b10..6dacb389dcf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2760,6 +2760,7 @@ dependencies = [ "bytes", "env_logger 0.10.0", "futures", + "futures_ringbuf", "libp2p-core", "libp2p-identity", "log", diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index fea37124ed1..b8ccbcc2162 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -26,6 +26,7 @@ env_logger = "0.10.0" libp2p-identity = { path = "../../identity", features = ["ed25519"] } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } rand = "0.8" +futures_ringbuf = "0.3.1" # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/plaintext/tests/smoke.rs b/transports/plaintext/tests/smoke.rs index 047d606f8f7..b63bf2529ee 100644 --- a/transports/plaintext/tests/smoke.rs +++ b/transports/plaintext/tests/smoke.rs @@ -18,11 +18,8 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use futures::{ - io::{AsyncReadExt, AsyncWriteExt}, - StreamExt, -}; -use libp2p_core::{multiaddr::Multiaddr, transport::Transport, upgrade}; +use futures::io::{AsyncReadExt, AsyncWriteExt}; +use libp2p_core::InboundUpgrade; use libp2p_identity as identity; use libp2p_plaintext::PlainText2Config; use log::debug; @@ -42,54 +39,29 @@ fn variable_msg_length() { let client_id = identity::Keypair::generate_ed25519(); let client_id_public = client_id.public(); - futures::executor::block_on(async { - let mut server = libp2p_core::transport::MemoryTransport::new() - .and_then(move |output, endpoint| { - upgrade::apply( - output, - PlainText2Config { - local_public_key: server_id_public, - }, - endpoint, - libp2p_core::upgrade::Version::V1, - ) - }) - .boxed(); - - let mut client = libp2p_core::transport::MemoryTransport::new() - .and_then(move |output, endpoint| { - upgrade::apply( - output, - PlainText2Config { - local_public_key: client_id_public, - }, - endpoint, - libp2p_core::upgrade::Version::V1, - ) - }) - .boxed(); - - let server_address: Multiaddr = - format!("/memory/{}", std::cmp::Ord::max(1, rand::random::())) - .parse() - .unwrap(); + let (server, client) = futures_ringbuf::Endpoint::pair(100, 100); - server.listen_on(server_address.clone()).unwrap(); - - // Ignore server listen address event. - let _ = server - .next() - .await - .expect("some event") - .into_new_address() - .expect("listen address"); + futures::executor::block_on(async { + let ( + (received_client_id, mut server_channel), + (received_server_id, mut client_channel), + ) = futures::future::try_join( + PlainText2Config { + local_public_key: server_id_public, + } + .upgrade_inbound(server, b""), + PlainText2Config { + local_public_key: client_id_public, + } + .upgrade_inbound(client, b""), + ) + .await + .unwrap(); + + assert_eq!(received_server_id, server_id.public().to_peer_id()); + assert_eq!(received_client_id, client_id.public().to_peer_id()); let client_fut = async { - debug!("dialing {:?}", server_address); - let (received_server_id, mut client_channel) = - client.dial(server_address).unwrap().await.unwrap(); - assert_eq!(received_server_id, server_id.public().to_peer_id()); - debug!("Client: writing message."); client_channel .write_all(&msg_to_send) @@ -100,17 +72,6 @@ fn variable_msg_length() { }; let server_fut = async { - let mut server_channel = server - .next() - .await - .expect("some event") - .into_incoming() - .expect("no error") - .0 - .await - .map(|(_, session)| session) - .expect("no error"); - let mut server_buffer = vec![0; msg_to_receive.len()]; debug!("Server: reading message."); server_channel From e0d74bd78f4414e7cf37cc7834936442f2df2831 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Apr 2023 14:42:02 +0000 Subject: [PATCH 24/57] deps: bump tokio-util from 0.7.7 to 0.7.8 Pull-Request: #3833. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6dacb389dcf..851bfb00b4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4951,9 +4951,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.7" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +checksum = "806fe8c2c87eccc8b3267cbae29ed3ab2d0bd37fca70ab622e46aaa9375ddb7d" dependencies = [ "bytes", "futures-core", From 71805caaec85ccdb5ca43afc3dad3e6b52b38587 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Wed, 26 Apr 2023 19:05:08 +0200 Subject: [PATCH 25/57] refactor(gossipsub): miscellaneous tidy-up of config tests - Move helpers to the bottom - Restructure tests to follow arrange-act-assert - Only set necessary options on builder for each test Pull-Request: #3836. --- protocols/gossipsub/src/config.rs | 139 +++++++++++++----------------- 1 file changed, 59 insertions(+), 80 deletions(-) diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index 098a3eb7e0b..9fe5ee8cf5e 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -892,105 +892,65 @@ mod test { use std::collections::hash_map::DefaultHasher; use std::hash::{Hash, Hasher}; - #[test] - fn create_thing() { - let builder: Config = ConfigBuilder::default() - .protocol_id_prefix("purple") - .build() - .unwrap(); - - dbg!(builder); - } - - fn get_gossipsub_message() -> Message { - Message { - source: None, - data: vec![12, 34, 56], - sequence_number: None, - topic: Topic::::new("test").hash(), - } - } - - fn get_expected_message_id() -> MessageId { - MessageId::from([ - 49, 55, 56, 51, 56, 52, 49, 51, 52, 51, 52, 55, 51, 51, 53, 52, 54, 54, 52, 49, 101, - ]) - } - - fn message_id_plain_function(message: &Message) -> MessageId { - let mut s = DefaultHasher::new(); - message.data.hash(&mut s); - let mut v = s.finish().to_string(); - v.push('e'); - MessageId::from(v) - } - #[test] fn create_config_with_message_id_as_plain_function() { - let builder: Config = ConfigBuilder::default() - .protocol_id_prefix("purple") + let config = ConfigBuilder::default() .message_id_fn(message_id_plain_function) .build() .unwrap(); - let result = builder.message_id(&get_gossipsub_message()); + let result = config.message_id(&get_gossipsub_message()); + assert_eq!(result, get_expected_message_id()); } #[test] fn create_config_with_message_id_as_closure() { - let closure = |message: &Message| { - let mut s = DefaultHasher::new(); - message.data.hash(&mut s); - let mut v = s.finish().to_string(); - v.push('e'); - MessageId::from(v) - }; - - let builder: Config = ConfigBuilder::default() - .protocol_id_prefix("purple") - .message_id_fn(closure) + let config = ConfigBuilder::default() + .message_id_fn(|message: &Message| { + let mut s = DefaultHasher::new(); + message.data.hash(&mut s); + let mut v = s.finish().to_string(); + v.push('e'); + MessageId::from(v) + }) .build() .unwrap(); - let result = builder.message_id(&get_gossipsub_message()); + let result = config.message_id(&get_gossipsub_message()); + assert_eq!(result, get_expected_message_id()); } #[test] fn create_config_with_message_id_as_closure_with_variable_capture() { let captured: char = 'e'; - let closure = move |message: &Message| { - let mut s = DefaultHasher::new(); - message.data.hash(&mut s); - let mut v = s.finish().to_string(); - v.push(captured); - MessageId::from(v) - }; - - let builder: Config = ConfigBuilder::default() - .protocol_id_prefix("purple") - .message_id_fn(closure) + + let config = ConfigBuilder::default() + .message_id_fn(move |message: &Message| { + let mut s = DefaultHasher::new(); + message.data.hash(&mut s); + let mut v = s.finish().to_string(); + v.push(captured); + MessageId::from(v) + }) .build() .unwrap(); - let result = builder.message_id(&get_gossipsub_message()); + let result = config.message_id(&get_gossipsub_message()); + assert_eq!(result, get_expected_message_id()); } #[test] fn create_config_with_protocol_id_prefix() { - let builder: Config = ConfigBuilder::default() - .protocol_id_prefix("purple") - .validation_mode(ValidationMode::Anonymous) - .message_id_fn(message_id_plain_function) - .build() - .unwrap(); - - assert_eq!(builder.protocol_id(), "purple"); - assert_eq!(builder.custom_id_version(), &None); + let protocol_config = ProtocolConfig::new( + &ConfigBuilder::default() + .protocol_id_prefix("purple") + .build() + .unwrap(), + ); - let protocol_config = ProtocolConfig::new(&builder); let protocol_ids = protocol_config.protocol_info(); assert_eq!(protocol_ids.len(), 2); @@ -1004,17 +964,13 @@ mod test { #[test] fn create_config_with_custom_protocol_id() { - let builder: Config = ConfigBuilder::default() - .protocol_id("purple", Version::V1_0) - .validation_mode(ValidationMode::Anonymous) - .message_id_fn(message_id_plain_function) - .build() - .unwrap(); - - assert_eq!(builder.protocol_id(), "purple"); - assert_eq!(builder.custom_id_version(), &Some(Version::V1_0)); + let protocol_config = ProtocolConfig::new( + &ConfigBuilder::default() + .protocol_id("purple", Version::V1_0) + .build() + .unwrap(), + ); - let protocol_config = ProtocolConfig::new(&builder); let protocol_ids = protocol_config.protocol_info(); assert_eq!(protocol_ids.len(), 1); @@ -1022,4 +978,27 @@ mod test { assert_eq!(protocol_ids[0].protocol_id, b"purple".to_vec()); assert_eq!(protocol_ids[0].kind, PeerKind::Gossipsub); } + + fn get_gossipsub_message() -> Message { + Message { + source: None, + data: vec![12, 34, 56], + sequence_number: None, + topic: Topic::::new("test").hash(), + } + } + + fn get_expected_message_id() -> MessageId { + MessageId::from([ + 49, 55, 56, 51, 56, 52, 49, 51, 52, 51, 52, 55, 51, 51, 53, 52, 54, 54, 52, 49, 101, + ]) + } + + fn message_id_plain_function(message: &Message) -> MessageId { + let mut s = DefaultHasher::new(); + message.data.hash(&mut s); + let mut v = s.finish().to_string(); + v.push('e'); + MessageId::from(v) + } } From 9d1058df7b0fcb10afc72404c92385b11d964b53 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 27 Apr 2023 07:20:19 +0200 Subject: [PATCH 26/57] fix(gossipsub): always honor `support_floodsub` setting Previously, we only honored the `support_floodsub` setting when the user did not specify a custom protocol for gossipsub. This patch fixes this and allows users to advertise floodsub even when they use a custom protocol. Pull-Request: #3837. --- protocols/gossipsub/CHANGELOG.md | 4 +++ protocols/gossipsub/src/protocol_priv.rs | 40 +++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index fc63a305923..8e292b87b05 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,8 +1,12 @@ ## 0.44.4 - unreleased - Deprecate `metrics`, `protocol`, `subscription_filter`, `time_cache` modules to make them private. See [PR 3777]. +- Honor the `gossipsub::Config::support_floodsub` in all cases. + Previously, it was ignored when a custom protocol id was set via `gossipsub::Config::protocol_id`. + See [PR 3837]. [PR 3777]: https://github.com/libp2p/rust-libp2p/pull/3777 +[PR 3837]: https://github.com/libp2p/rust-libp2p/pull/3837 ## 0.44.3 diff --git a/protocols/gossipsub/src/protocol_priv.rs b/protocols/gossipsub/src/protocol_priv.rs index 34d931bbaf9..2145cd9dd4b 100644 --- a/protocols/gossipsub/src/protocol_priv.rs +++ b/protocols/gossipsub/src/protocol_priv.rs @@ -57,7 +57,7 @@ impl ProtocolConfig { /// /// Sets the maximum gossip transmission size. pub fn new(gossipsub_config: &Config) -> ProtocolConfig { - let protocol_ids = match gossipsub_config.custom_id_version() { + let mut protocol_ids = match gossipsub_config.custom_id_version() { Some(v) => match v { Version::V1_0 => vec![ProtocolId::new( gossipsub_config.protocol_id(), @@ -71,24 +71,22 @@ impl ProtocolConfig { )], }, None => { - let mut protocol_ids = vec![ + vec![ ProtocolId::new( gossipsub_config.protocol_id(), PeerKind::Gossipsubv1_1, true, ), ProtocolId::new(gossipsub_config.protocol_id(), PeerKind::Gossipsub, true), - ]; - - // add floodsub support if enabled. - if gossipsub_config.support_floodsub() { - protocol_ids.push(ProtocolId::new("", PeerKind::Floodsub, false)); - } - - protocol_ids + ] } }; + // add floodsub support if enabled. + if gossipsub_config.support_floodsub() { + protocol_ids.push(ProtocolId::new("", PeerKind::Floodsub, false)); + } + ProtocolConfig { protocol_ids, max_transmit_size: gossipsub_config.max_transmit_size(), @@ -556,8 +554,8 @@ impl Decoder for GossipsubCodec { mod tests { use super::*; use crate::config::Config; - use crate::Behaviour; use crate::IdentTopic as Topic; + use crate::{Behaviour, ConfigBuilder}; use libp2p_core::identity::Keypair; use quickcheck_ext::*; @@ -653,4 +651,24 @@ mod tests { QuickCheck::new().quickcheck(prop as fn(_) -> _) } + + #[test] + fn support_floodsub_with_custom_protocol() { + let gossipsub_config = ConfigBuilder::default() + .protocol_id("/foosub", Version::V1_1) + .support_floodsub() + .build() + .unwrap(); + + let protocol_config = ProtocolConfig::new(&gossipsub_config); + + assert_eq!( + String::from_utf8_lossy(&protocol_config.protocol_ids[0].protocol_id), + "/foosub" + ); + assert_eq!( + String::from_utf8_lossy(&protocol_config.protocol_ids[1].protocol_id), + "/floodsub/1.0.0" + ); + } } From 31dbcabe7cae942bbbdc791eeece842b860ec02e Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Thu, 27 Apr 2023 14:31:06 +0200 Subject: [PATCH 27/57] ci: enable cargo debug logging in semver-checks This PR enables debug logging on requests from cargo to the registry in semver-checks action (https://github.com/rust-lang/cargo/issues/7662#issuecomment-561809348). Hopefully, it will let us debug the network issue reported here: https://github.com/libp2p/rust-libp2p/pull/3782#issuecomment-1523346255 Pull-Request: #3838. --- .github/actions/cargo-semver-checks/action.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/actions/cargo-semver-checks/action.yml b/.github/actions/cargo-semver-checks/action.yml index 7e982959608..79151e6e98c 100644 --- a/.github/actions/cargo-semver-checks/action.yml +++ b/.github/actions/cargo-semver-checks/action.yml @@ -31,3 +31,6 @@ runs: shell: bash env: CARGO_TERM_VERBOSE: "true" + # debugging https://github.com/libp2p/rust-libp2p/pull/3782#issuecomment-1523346255 + CARGO_HTTP_DEBUG: "true" + CARGO_LOG: "cargo::ops::registry=debug" From fadcc43e69b87e856f7638bfadfd960e3653a765 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 27 Apr 2023 14:50:06 +0200 Subject: [PATCH 28/57] refactor(core): remove `InfoIterChain` This type can be replaced with std-lib components. Related: https://github.com/libp2p/rust-libp2p/pull/3746. Pull-Request: #3842. --- core/src/upgrade/select.rs | 52 ++++++++++++-------------------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/core/src/upgrade/select.rs b/core/src/upgrade/select.rs index 1d5ab9abe53..c823d791cf7 100644 --- a/core/src/upgrade/select.rs +++ b/core/src/upgrade/select.rs @@ -25,6 +25,7 @@ use crate::{ }; use either::Either; use futures::future; +use std::iter::{Chain, Map}; /// Upgrade that combines two upgrades into one. Supports all the protocols supported by either /// sub-upgrade. @@ -48,16 +49,24 @@ where B: UpgradeInfo, { type Info = EitherName; - type InfoIter = InfoIterChain< - ::IntoIter, - ::IntoIter, + type InfoIter = Chain< + Map<::IntoIter, fn(A::Info) -> Self::Info>, + Map<::IntoIter, fn(B::Info) -> Self::Info>, >; fn protocol_info(&self) -> Self::InfoIter { - InfoIterChain( - self.0.protocol_info().into_iter(), - self.1.protocol_info().into_iter(), - ) + let a = self + .0 + .protocol_info() + .into_iter() + .map(EitherName::A as fn(A::Info) -> _); + let b = self + .1 + .protocol_info() + .into_iter() + .map(EitherName::B as fn(B::Info) -> _); + + a.chain(b) } } @@ -94,32 +103,3 @@ where } } } - -/// Iterator that combines the protocol names of twp upgrades. -#[derive(Debug, Clone)] -pub struct InfoIterChain(A, B); - -impl Iterator for InfoIterChain -where - A: Iterator, - B: Iterator, -{ - type Item = EitherName; - - fn next(&mut self) -> Option { - if let Some(info) = self.0.next() { - return Some(EitherName::A(info)); - } - if let Some(info) = self.1.next() { - return Some(EitherName::B(info)); - } - None - } - - fn size_hint(&self) -> (usize, Option) { - let (min1, max1) = self.0.size_hint(); - let (min2, max2) = self.1.size_hint(); - let max = max1.and_then(move |m1| max2.and_then(move |m2| m1.checked_add(m2))); - (min1.saturating_add(min2), max) - } -} From d66c8271b52e6ebfd1deaa4b528dab7479b245b2 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Thu, 27 Apr 2023 15:04:16 +0200 Subject: [PATCH 29/57] refactor(core): remove `EitherIter` `EitherIter` is an implementation detail and can be removed without breaking users. Related: https://github.com/libp2p/rust-libp2p/pull/3746. Pull-Request: #3841. --- core/src/upgrade/either.rs | 40 ++++++-------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) diff --git a/core/src/upgrade/either.rs b/core/src/upgrade/either.rs index 563e7651c07..0bda47ca9d0 100644 --- a/core/src/upgrade/either.rs +++ b/core/src/upgrade/either.rs @@ -24,6 +24,7 @@ use crate::{ }; use either::Either; use futures::future; +use std::iter::Map; impl UpgradeInfo for Either where @@ -31,15 +32,15 @@ where B: UpgradeInfo, { type Info = EitherName; - type InfoIter = EitherIter< - ::IntoIter, - ::IntoIter, + type InfoIter = Either< + Map<::IntoIter, fn(A::Info) -> Self::Info>, + Map<::IntoIter, fn(B::Info) -> Self::Info>, >; fn protocol_info(&self) -> Self::InfoIter { match self { - Either::Left(a) => EitherIter::A(a.protocol_info().into_iter()), - Either::Right(b) => EitherIter::B(b.protocol_info().into_iter()), + Either::Left(a) => Either::Left(a.protocol_info().into_iter().map(EitherName::A)), + Either::Right(b) => Either::Right(b.protocol_info().into_iter().map(EitherName::B)), } } } @@ -87,32 +88,3 @@ where } } } - -/// A type to represent two possible `Iterator` types. -#[derive(Debug, Clone)] -pub enum EitherIter { - A(A), - B(B), -} - -impl Iterator for EitherIter -where - A: Iterator, - B: Iterator, -{ - type Item = EitherName; - - fn next(&mut self) -> Option { - match self { - EitherIter::A(a) => a.next().map(EitherName::A), - EitherIter::B(b) => b.next().map(EitherName::B), - } - } - - fn size_hint(&self) -> (usize, Option) { - match self { - EitherIter::A(a) => a.size_hint(), - EitherIter::B(b) => b.size_hint(), - } - } -} From 3f6f08d8e0e3921fa5e8aea4c27a5e0ac94f857d Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Fri, 28 Apr 2023 12:12:07 +0200 Subject: [PATCH 30/57] feat(request-response): make handler and codec modules private Resolves #3704. Pull-Request: #3847. --- Cargo.lock | 2 +- protocols/request-response/CHANGELOG.md | 6 +++ protocols/request-response/Cargo.toml | 2 +- .../src/{codec.rs => codec_priv.rs} | 0 .../src/{handler.rs => handler_priv.rs} | 2 +- .../src/{handler => handler_priv}/protocol.rs | 2 +- protocols/request-response/src/lib.rs | 43 ++++++++++++------- 7 files changed, 38 insertions(+), 19 deletions(-) rename protocols/request-response/src/{codec.rs => codec_priv.rs} (100%) rename protocols/request-response/src/{handler.rs => handler_priv.rs} (99%) rename protocols/request-response/src/{handler => handler_priv}/protocol.rs (99%) diff --git a/Cargo.lock b/Cargo.lock index 851bfb00b4a..b6063da23b0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2878,7 +2878,7 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.24.0" +version = "0.24.1" dependencies = [ "async-std", "async-trait", diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index e31581f6614..ac237dbdffd 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.24.1 - unreleased + +- Deprecate `handler`, `codec` modules to make them private. See [PR 3847]. + +[PR 3847]: https://github.com/libp2p/rust-libp2p/pull/3847 + ## 0.24.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index b6ece95cf2b..75cbdc369fa 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-request-response" edition = "2021" rust-version = "1.62.0" description = "Generic Request/Response Protocols" -version = "0.24.0" +version = "0.24.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/request-response/src/codec.rs b/protocols/request-response/src/codec_priv.rs similarity index 100% rename from protocols/request-response/src/codec.rs rename to protocols/request-response/src/codec_priv.rs diff --git a/protocols/request-response/src/handler.rs b/protocols/request-response/src/handler_priv.rs similarity index 99% rename from protocols/request-response/src/handler.rs rename to protocols/request-response/src/handler_priv.rs index 50cd6adb055..849c9e577fa 100644 --- a/protocols/request-response/src/handler.rs +++ b/protocols/request-response/src/handler_priv.rs @@ -20,7 +20,7 @@ mod protocol; -use crate::codec::Codec; +use crate::codec_priv::Codec; use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; use libp2p_swarm::handler::{ diff --git a/protocols/request-response/src/handler/protocol.rs b/protocols/request-response/src/handler_priv/protocol.rs similarity index 99% rename from protocols/request-response/src/handler/protocol.rs rename to protocols/request-response/src/handler_priv/protocol.rs index 84ef365734f..3ee08c7f764 100644 --- a/protocols/request-response/src/handler/protocol.rs +++ b/protocols/request-response/src/handler_priv/protocol.rs @@ -23,7 +23,7 @@ //! receives a request and sends a response, whereas the //! outbound upgrade send a request and receives a response. -use crate::codec::Codec; +use crate::codec_priv::Codec; use crate::RequestId; use futures::{channel::oneshot, future::BoxFuture, prelude::*}; diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index d9f2220d839..723c11d831e 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -58,18 +58,31 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -pub mod codec; -pub mod handler; +mod codec_priv; +#[deprecated( + note = "The `codec` module will be made private in the future and should not be depended on." +)] +pub mod codec { + pub use super::codec_priv::*; +} + +mod handler_priv; +#[deprecated( + note = "The `handler` module will be made private in the future and should not be depended on." +)] +pub mod handler { + pub use super::handler_priv::*; +} -pub use codec::{Codec, ProtocolName}; +pub use codec_priv::{Codec, ProtocolName}; #[allow(deprecated)] -pub use codec::RequestResponseCodec; +pub use codec_priv::RequestResponseCodec; -pub use handler::ProtocolSupport; +pub use handler_priv::ProtocolSupport; use futures::channel::oneshot; -use handler::{Handler, RequestProtocol}; +use handler_priv::{Handler, RequestProtocol}; use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ @@ -116,7 +129,7 @@ pub type RequestResponseMessage = since = "0.24.0", note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`" )] -pub type HandlerEvent = handler::Event; +pub type HandlerEvent = handler_priv::Event; /// An inbound request or response. #[derive(Debug)] @@ -802,7 +815,7 @@ where event: THandlerOutEvent, ) { match event { - handler::Event::Response { + handler_priv::Event::Response { request_id, response, } => { @@ -819,7 +832,7 @@ where self.pending_events .push_back(ToSwarm::GenerateEvent(Event::Message { peer, message })); } - handler::Event::Request { + handler_priv::Event::Request { request_id, request, sender, @@ -850,7 +863,7 @@ where } } } - handler::Event::ResponseSent(request_id) => { + handler_priv::Event::ResponseSent(request_id) => { let removed = self.remove_pending_outbound_response(&peer, connection, request_id); debug_assert!( removed, @@ -863,7 +876,7 @@ where request_id, })); } - handler::Event::ResponseOmission(request_id) => { + handler_priv::Event::ResponseOmission(request_id) => { let removed = self.remove_pending_outbound_response(&peer, connection, request_id); debug_assert!( removed, @@ -877,7 +890,7 @@ where error: InboundFailure::ResponseOmission, })); } - handler::Event::OutboundTimeout(request_id) => { + handler_priv::Event::OutboundTimeout(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( removed, @@ -891,7 +904,7 @@ where error: OutboundFailure::Timeout, })); } - handler::Event::InboundTimeout(request_id) => { + handler_priv::Event::InboundTimeout(request_id) => { // Note: `Event::InboundTimeout` is emitted both for timing // out to receive the request and for timing out sending the response. In the former // case the request is never added to `pending_outbound_responses` and thus one can @@ -905,7 +918,7 @@ where error: InboundFailure::Timeout, })); } - handler::Event::OutboundUnsupportedProtocols(request_id) => { + handler_priv::Event::OutboundUnsupportedProtocols(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( removed, @@ -919,7 +932,7 @@ where error: OutboundFailure::UnsupportedProtocols, })); } - handler::Event::InboundUnsupportedProtocols(request_id) => { + handler_priv::Event::InboundUnsupportedProtocols(request_id) => { // Note: No need to call `self.remove_pending_outbound_response`, // `Event::Request` was never emitted for this request and // thus request was never added to `pending_outbound_responses`. From 8a0e61e3acc189536b224b49d9b1bfc66bf7b4c1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 10:49:08 +0000 Subject: [PATCH 31/57] deps: bump tokio from 1.27.0 to 1.28.0 Pull-Request: #3834. --- Cargo.lock | 86 +++++++++++++++++++++++++++++---- examples/rendezvous/Cargo.toml | 2 +- interop-tests/Cargo.toml | 2 +- protocols/mdns/Cargo.toml | 4 +- protocols/rendezvous/Cargo.toml | 2 +- swarm/Cargo.toml | 2 +- transports/pnet/Cargo.toml | 2 +- transports/quic/Cargo.toml | 4 +- transports/tcp/Cargo.toml | 4 +- transports/tls/Cargo.toml | 2 +- transports/uds/Cargo.toml | 2 +- transports/webrtc/Cargo.toml | 4 +- 12 files changed, 91 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b6063da23b0..f1587412c67 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4910,9 +4910,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.27.0" +version = "1.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" +checksum = "c3c786bf8134e5a3a166db9b29ab8f48134739014a3eca7bc6bfa95d673b136f" dependencies = [ "autocfg", "bytes", @@ -4924,14 +4924,14 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", @@ -5674,12 +5674,12 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.1", "windows_aarch64_msvc 0.42.1", "windows_i686_gnu 0.42.1", "windows_i686_msvc 0.42.1", "windows_x86_64_gnu 0.42.1", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.1", "windows_x86_64_msvc 0.42.1", ] @@ -5689,7 +5689,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", ] [[package]] @@ -5698,21 +5707,42 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ - "windows_aarch64_gnullvm", + "windows_aarch64_gnullvm 0.42.1", "windows_aarch64_msvc 0.42.1", "windows_i686_gnu 0.42.1", "windows_i686_msvc 0.42.1", "windows_x86_64_gnu 0.42.1", - "windows_x86_64_gnullvm", + "windows_x86_64_gnullvm 0.42.1", "windows_x86_64_msvc 0.42.1", ] +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "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_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.34.0" @@ -5725,6 +5755,12 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.34.0" @@ -5737,6 +5773,12 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.34.0" @@ -5749,6 +5791,12 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.34.0" @@ -5761,12 +5809,24 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.34.0" @@ -5779,6 +5839,12 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winreg" version = "0.10.1" diff --git a/examples/rendezvous/Cargo.toml b/examples/rendezvous/Cargo.toml index 2d91a644803..591b738c98d 100644 --- a/examples/rendezvous/Cargo.toml +++ b/examples/rendezvous/Cargo.toml @@ -12,4 +12,4 @@ env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "identify", "macros", "noise", "ping", "rendezvous", "tcp", "tokio", "yamux"] } log = "0.4" -tokio = { version = "1.27", features = [ "rt-multi-thread", "macros", "time" ] } +tokio = { version = "1.28", features = [ "rt-multi-thread", "macros", "time" ] } diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index 7994d9bf37e..32c815f89a8 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -17,4 +17,4 @@ libp2p-mplex = { path = "../muxers/mplex" } log = "0.4" rand = "0.8.5" redis = { version = "0.23.0", default-features = false, features = ["tokio-comp"] } -tokio = { version = "1.27.0", features = ["full"] } +tokio = { version = "1.28.0", features = ["full"] } diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index f7f24d184ab..5f311f56bd5 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -22,7 +22,7 @@ log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" socket2 = { version = "0.4.0", features = ["all"] } -tokio = { version = "1.27", default-features = false, features = ["net", "time"], optional = true} +tokio = { version = "1.28", default-features = false, features = ["net", "time"], optional = true} trust-dns-proto = { version = "0.22.0", default-features = false, features = ["mdns", "tokio-runtime"] } void = "1.0.2" @@ -37,7 +37,7 @@ libp2p-noise = { path = "../../transports/noise" } libp2p-swarm = { path = "../../swarm", features = ["tokio", "async-std"] } libp2p-tcp = { path = "../../transports/tcp", features = ["tokio", "async-io"] } libp2p-yamux = { path = "../../muxers/yamux" } -tokio = { version = "1.27", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] } +tokio = { version = "1.28", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] } libp2p-swarm-test = { path = "../../swarm-test" } [[test]] diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index e7957ef755a..45945837b91 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -37,7 +37,7 @@ libp2p-identify = { path = "../identify" } libp2p-yamux = { path = "../../muxers/yamux" } libp2p-tcp = { path = "../../transports/tcp", features = ["tokio"] } rand = "0.8" -tokio = { version = "1.27", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } +tokio = { version = "1.28", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } libp2p-swarm-test = { path = "../../swarm-test" } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 820fabc3aac..140d0a6d854 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -28,7 +28,7 @@ getrandom = { version = "0.2.9", features = ["js"], optional = true } # Explicit [target.'cfg(not(any(target_os = "emscripten", target_os = "wasi", target_os = "unknown")))'.dependencies] async-std = { version = "1.6.2", optional = true } -tokio = { version = "1.27", features = ["rt"], optional = true } +tokio = { version = "1.28", features = ["rt"], optional = true } [features] macros = ["dep:libp2p-swarm-derive"] diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index 81b0302039d..80f6c62df0b 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -27,7 +27,7 @@ libp2p-tcp = { path = "../tcp", features = ["tokio"] } libp2p-websocket = { path = "../websocket" } libp2p-yamux = { path = "../../muxers/yamux" } quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } -tokio = { version = "1.27.0", features = ["full"] } +tokio = { version = "1.28.0", features = ["full"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index fc99b820b6a..9bb54dddcb3 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -23,7 +23,7 @@ quinn-proto = { version = "0.9.3", default-features = false, features = ["tls-ru rand = "0.8.5" rustls = { version = "0.20.2", default-features = false } thiserror = "1.0.40" -tokio = { version = "1.27.0", default-features = false, features = ["net", "rt"], optional = true } +tokio = { version = "1.28.0", default-features = false, features = ["net", "rt"], optional = true } [features] tokio = ["dep:tokio", "if-watch/tokio"] @@ -44,7 +44,7 @@ libp2p-noise = { path = "../noise" } libp2p-tcp = { path = "../tcp", features = ["async-io"] } libp2p-yamux = { path = "../../muxers/yamux" } quickcheck = "1" -tokio = { version = "1.27.0", features = ["macros", "rt-multi-thread", "time"] } +tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread", "time"] } [[test]] name = "stream_compliance" diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index f3442aa7a45..55507dd1dc4 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -20,7 +20,7 @@ libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4.11" socket2 = { version = "0.4.0", features = ["all"] } -tokio = { version = "1.27.0", default-features = false, features = ["net"], optional = true } +tokio = { version = "1.28.0", default-features = false, features = ["net"], optional = true } [features] tokio = ["dep:tokio", "if-watch/tokio"] @@ -28,7 +28,7 @@ async-io = ["dep:async-io", "if-watch/smol"] [dev-dependencies] async-std = { version = "1.6.5", features = ["attributes"] } -tokio = { version = "1.27.0", default-features = false, features = ["full"] } +tokio = { version = "1.28.0", default-features = false, features = ["full"] } env_logger = "0.10.0" # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 3658f92fc94..2a95d07aaba 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -33,7 +33,7 @@ libp2p-core = { path = "../../core" } libp2p-identity = { path = "../../identity", features = ["ed25519", "rsa", "secp256k1", "ecdsa"] } libp2p-swarm = { path = "../../swarm" } libp2p-yamux = { path = "../../muxers/yamux" } -tokio = { version = "1.27.0", features = ["full"] } +tokio = { version = "1.28.0", features = ["full"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index b90c02e150d..33fc9ed4337 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -15,7 +15,7 @@ async-std = { version = "1.6.2", optional = true } libp2p-core = { version = "0.39.0", path = "../../core" } log = "0.4.1" futures = "0.3.28" -tokio = { version = "1.27", default-features = false, features = ["net"], optional = true } +tokio = { version = "1.28", default-features = false, features = ["net"], optional = true } [dev-dependencies] tempfile = "3.5" diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index f26e6de77b8..f45d3004531 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -32,7 +32,7 @@ serde = { version = "1.0", features = ["derive"] } stun = "0.4" thiserror = "1" tinytemplate = "1.2" -tokio = { version = "1.27", features = ["net"], optional = true} +tokio = { version = "1.28", features = ["net"], optional = true} tokio-util = { version = "0.7", features = ["compat"], optional = true } webrtc = { version = "0.6.0", optional = true } @@ -46,7 +46,7 @@ env_logger = "0.10" hex-literal = "0.4" libp2p-swarm = { path = "../../swarm", features = ["macros", "tokio"] } libp2p-ping = { path = "../../protocols/ping" } -tokio = { version = "1.27", features = ["full"] } +tokio = { version = "1.28", features = ["full"] } unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } void = "1" quickcheck = "1.0.3" From a0613e4af8a3ba10f6559675ac12195be631f555 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 11:03:03 +0000 Subject: [PATCH 32/57] deps: bump hyper from 0.14.25 to 0.14.26 Pull-Request: #3797. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1587412c67..98c7fc2a139 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1977,9 +1977,9 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.25" +version = "0.14.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc5e554ff619822309ffd57d8734d77cd5ce6238bc956f037ea06c58238c9899" +checksum = "ab302d72a6f11a3b910431ff93aae7e773078c769f0a3ef15fb9ec692ed147d4" dependencies = [ "bytes", "futures-channel", From a836bb471fc612f265e04029d8d59ab4577d6ea8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 11:19:43 +0000 Subject: [PATCH 33/57] deps: bump clap from 4.2.1 to 4.2.4 Pull-Request: #3808. --- Cargo.lock | 76 ++++++++++++++++---------------- examples/autonat/Cargo.toml | 2 +- examples/dcutr/Cargo.toml | 2 +- examples/file-sharing/Cargo.toml | 2 +- examples/relay-server/Cargo.toml | 2 +- misc/keygen/Cargo.toml | 2 +- protocols/dcutr/Cargo.toml | 2 +- protocols/perf/Cargo.toml | 2 +- 8 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 98c7fc2a139..e1b23feb7b2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -126,42 +126,51 @@ checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" [[package]] name = "anstream" -version = "0.2.6" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "342258dd14006105c2b75ab1bd7543a03bdf0cfc94383303ac212a04939dff6f" +checksum = "9e579a7752471abc2a8268df8b20005e3eadd975f585398f17efcfd8d4927371" dependencies = [ "anstyle", "anstyle-parse", + "anstyle-query", "anstyle-wincon", - "concolor-override", - "concolor-query", + "colorchoice", "is-terminal", "utf8parse", ] [[package]] name = "anstyle" -version = "0.3.5" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23ea9e81bd02e310c216d080f6223c179012256e5151c41db88d12c88a1684d2" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" [[package]] name = "anstyle-parse" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7d1bb534e9efed14f3e5f44e7dd1a4f709384023a4165199a4241e18dff0116" +checksum = "e765fd216e48e067936442276d1d57399e37bce53c264d6fefbe298080cb57ee" dependencies = [ "utf8parse", ] +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys 0.48.0", +] + [[package]] name = "anstyle-wincon" -version = "0.2.0" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3127af6145b149f3287bb9a0d10ad9c5692dba8c53ad48285e5bec4063834fa" +checksum = "4bcd8291a340dd8ac70e18878bc4501dd7b4ff970cfa21c207d36ece51ea88fd" dependencies = [ "anstyle", - "windows-sys 0.45.0", + "windows-sys 0.48.0", ] [[package]] @@ -490,7 +499,7 @@ name = "autonat-example" version = "0.1.0" dependencies = [ "async-std", - "clap 4.2.1", + "clap 4.2.4", "env_logger 0.10.0", "futures", "libp2p", @@ -772,9 +781,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.1" +version = "4.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "046ae530c528f252094e4a77886ee1374437744b2bff1497aa898bbddbbb29b3" +checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62" dependencies = [ "clap_builder", "clap_derive", @@ -783,9 +792,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.1" +version = "4.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "223163f58c9a40c3b0a43e1c4b50a9ce09f007ea2cb1ec258a687945b4b7929f" +checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749" dependencies = [ "anstream", "anstyle", @@ -821,6 +830,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "combine" version = "4.6.6" @@ -835,21 +850,6 @@ dependencies = [ "tokio-util", ] -[[package]] -name = "concolor-override" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a855d4a1978dc52fb0536a04d384c2c0c1aa273597f08b77c8c4d3b2eec6037f" - -[[package]] -name = "concolor-query" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88d11d52c3d7ca2e6d0040212be9e4dbbcd78b6447f535b6b561f449427944cf" -dependencies = [ - "windows-sys 0.45.0", -] - [[package]] name = "concurrent-queue" version = "2.1.0" @@ -1232,7 +1232,7 @@ dependencies = [ name = "dcutr" version = "0.1.0" dependencies = [ - "clap 4.2.1", + "clap 4.2.4", "env_logger 0.10.0", "futures", "futures-timer", @@ -1527,7 +1527,7 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "clap 4.2.1", + "clap 4.2.4", "either", "env_logger 0.10.0", "futures", @@ -2235,7 +2235,7 @@ name = "keygen" version = "0.1.0" dependencies = [ "base64 0.21.0", - "clap 4.2.1", + "clap 4.2.4", "libp2p-core", "libp2p-identity", "serde", @@ -2277,7 +2277,7 @@ dependencies = [ "async-std", "async-trait", "bytes", - "clap 4.2.1", + "clap 4.2.4", "either", "env_logger 0.10.0", "futures", @@ -2408,7 +2408,7 @@ version = "0.9.1" dependencies = [ "async-std", "asynchronous-codec", - "clap 4.2.1", + "clap 4.2.4", "either", "env_logger 0.10.0", "futures", @@ -2713,7 +2713,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-std", - "clap 4.2.1", + "clap 4.2.4", "env_logger 0.10.0", "futures", "instant", @@ -4177,7 +4177,7 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "clap 4.2.1", + "clap 4.2.4", "env_logger 0.10.0", "futures", "libp2p", diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index 3fe677a889d..199472d0cb9 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index f2ad3b82fd5..60509557539 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -6,7 +6,7 @@ publish = false license = "MIT" [dependencies] -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" futures-timer = "3.0" diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index dc486ecff82..3a49e16b371 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } either = "1.8" env_logger = "0.10" futures = "0.3.28" diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index f500fad0002..4104c221015 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -6,7 +6,7 @@ publish = false license = "MIT" [dependencies] -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" env_logger = "0.10.0" diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 6284fae8aa4..984b0766961 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -10,7 +10,7 @@ categories = ["network-programming", "asynchronous"] publish = false [dependencies] -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } zeroize = "1" serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.95" diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index b870ac0317c..56854d6046e 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -27,7 +27,7 @@ void = "1" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } env_logger = "0.10.0" libp2p-dns = { path = "../../transports/dns", features = ["async-std"] } libp2p-identify = { path = "../../protocols/identify" } diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 94118ca35bd..03230a8ed13 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] anyhow = "1" async-std = { version = "1.9.0", features = ["attributes"] } -clap = { version = "4.2.1", features = ["derive"] } +clap = { version = "4.2.4", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" instant = "0.1.11" From 66466c43afabfe844a81c32a77a0a390b8b38910 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 28 Apr 2023 13:33:31 +0200 Subject: [PATCH 34/57] refactor(dcutr): don't use `OutboundOpenInfo` In a previous refactoring, we actually removed the usage of this openinfo so this is just removing dead code. Related: #3268. Pull-Request: #3762. --- protocols/dcutr/src/behaviour_impl.rs | 2 -- protocols/dcutr/src/handler/relayed.rs | 10 ++++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/protocols/dcutr/src/behaviour_impl.rs b/protocols/dcutr/src/behaviour_impl.rs index c6701ad80ee..42920b2f001 100644 --- a/protocols/dcutr/src/behaviour_impl.rs +++ b/protocols/dcutr/src/behaviour_impl.rs @@ -133,7 +133,6 @@ impl Behaviour { handler: NotifyHandler::One(connection_id), event: Either::Left(handler::relayed::Command::Connect { obs_addrs: self.observed_addreses(), - attempt: 1, }), }, ToSwarm::GenerateEvent(Event::InitiatedDirectConnectionUpgrade { @@ -190,7 +189,6 @@ impl Behaviour { handler: NotifyHandler::One(relayed_connection_id), peer_id, event: Either::Left(handler::relayed::Command::Connect { - attempt: attempt + 1, obs_addrs: self.observed_addreses(), }), }) diff --git a/protocols/dcutr/src/handler/relayed.rs b/protocols/dcutr/src/handler/relayed.rs index aefaaeec933..3b48303d2e9 100644 --- a/protocols/dcutr/src/handler/relayed.rs +++ b/protocols/dcutr/src/handler/relayed.rs @@ -44,7 +44,6 @@ use std::time::Duration; pub enum Command { Connect { obs_addrs: Vec, - attempt: u8, }, AcceptInboundConnect { obs_addrs: Vec, @@ -59,10 +58,9 @@ pub enum Command { impl fmt::Debug for Command { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Command::Connect { obs_addrs, attempt } => f + Command::Connect { obs_addrs } => f .debug_struct("Command::Connect") .field("obs_addrs", obs_addrs) - .field("attempt", attempt) .finish(), Command::AcceptInboundConnect { obs_addrs, @@ -301,7 +299,7 @@ impl ConnectionHandler for Handler { >; type InboundProtocol = Either; type OutboundProtocol = protocol::outbound::Upgrade; - type OutboundOpenInfo = u8; // Number of upgrade attempts. + type OutboundOpenInfo = (); type InboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { @@ -322,12 +320,12 @@ impl ConnectionHandler for Handler { fn on_behaviour_event(&mut self, event: Self::InEvent) { match event { - Command::Connect { obs_addrs, attempt } => { + Command::Connect { obs_addrs } => { self.queued_events .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol: SubstreamProtocol::new( protocol::outbound::Upgrade::new(obs_addrs), - attempt, + (), ), }); } From 8445079622626d868c05d7e0f59237445d231950 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 28 Apr 2023 13:47:10 +0200 Subject: [PATCH 35/57] refactor(perf): don't use `OutboundOpenInfo` Instead of passing the command along, we store it in a buffer and retrieve it once the stream is upgraded. Related: https://github.com/libp2p/rust-libp2p/issues/3268. Pull-Request: #3763. --- protocols/perf/src/client/handler.rs | 52 +++++++++++++++++----------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/protocols/perf/src/client/handler.rs b/protocols/perf/src/client/handler.rs index f75a43f0a4e..d8e3854a91d 100644 --- a/protocols/perf/src/client/handler.rs +++ b/protocols/perf/src/client/handler.rs @@ -61,6 +61,8 @@ pub struct Handler { >, >, + requested_streams: VecDeque, + outbound: FuturesUnordered>>, keep_alive: KeepAlive, @@ -70,6 +72,7 @@ impl Handler { pub fn new() -> Self { Self { queued_events: Default::default(), + requested_streams: Default::default(), outbound: Default::default(), keep_alive: KeepAlive::Yes, } @@ -88,7 +91,7 @@ impl ConnectionHandler for Handler { type Error = Void; type InboundProtocol = DeniedUpgrade; type OutboundProtocol = ReadyUpgrade<&'static [u8]>; - type OutboundOpenInfo = Command; + type OutboundOpenInfo = (); type InboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { @@ -96,9 +99,10 @@ impl ConnectionHandler for Handler { } fn on_behaviour_event(&mut self, command: Self::InEvent) { + self.requested_streams.push_back(command); self.queued_events .push_back(ConnectionHandlerEvent::OutboundSubstreamRequest { - protocol: SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), command), + protocol: SubstreamProtocol::new(ReadyUpgrade::new(crate::PROTOCOL_NAME), ()), }) } @@ -117,26 +121,34 @@ impl ConnectionHandler for Handler { }) => void::unreachable(protocol), ConnectionEvent::FullyNegotiatedOutbound(FullyNegotiatedOutbound { protocol, - info: Command { params, id }, - }) => self.outbound.push( - crate::protocol::send_receive(params, protocol) - .map_ok(move |timers| Event { - id, - result: Ok(RunStats { params, timers }), - }) - .boxed(), - ), + info: (), + }) => { + let Command { id, params } = self + .requested_streams + .pop_front() + .expect("opened a stream without a pending command"); + self.outbound.push( + crate::protocol::send_receive(params, protocol) + .map_ok(move |timers| Event { + id, + result: Ok(RunStats { params, timers }), + }) + .boxed(), + ); + } ConnectionEvent::AddressChange(_) => {} - ConnectionEvent::DialUpgradeError(DialUpgradeError { - info: Command { id, .. }, - error, - }) => self - .queued_events - .push_back(ConnectionHandlerEvent::Custom(Event { - id, - result: Err(error), - })), + ConnectionEvent::DialUpgradeError(DialUpgradeError { info: (), error }) => { + let Command { id, .. } = self + .requested_streams + .pop_front() + .expect("requested stream without pending command"); + self.queued_events + .push_back(ConnectionHandlerEvent::Custom(Event { + id, + result: Err(error), + })); + } ConnectionEvent::ListenUpgradeError(ListenUpgradeError { info: (), error }) => { match error { ConnectionHandlerUpgrErr::Timeout => {} From 4ebb4d0a30072cf946ea684bb2712311e2a034ef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 12:00:43 +0000 Subject: [PATCH 36/57] deps: bump serde_json from 1.0.95 to 1.0.96 Pull-Request: #3798. --- Cargo.lock | 4 ++-- misc/keygen/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e1b23feb7b2..a30d07f9a4e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4515,9 +4515,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.95" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 984b0766961..cd861e1e222 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -13,7 +13,7 @@ publish = false clap = { version = "4.2.4", features = ["derive"] } zeroize = "1" serde = { version = "1.0.160", features = ["derive"] } -serde_json = "1.0.95" +serde_json = "1.0.96" libp2p-core = { version = "0.39.0", path = "../../core" } base64 = "0.21.0" libp2p-identity = { version = "0.1.0", path = "../../identity" } From 99ad3b6eaf10dc2dcb931333ad7788fa07fea74b Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 28 Apr 2023 15:37:06 +0200 Subject: [PATCH 37/57] refactor(kad): don't use `OutboundOpenInfo` As part of pushing #3268 forward, remove the use of `OutboundOpenInfo` from `libp2p-kad`. Related #3268. Pull-Request: #3760. --- protocols/kad/src/handler_priv.rs | 76 +++++++++++++------------------ 1 file changed, 32 insertions(+), 44 deletions(-) diff --git a/protocols/kad/src/handler_priv.rs b/protocols/kad/src/handler_priv.rs index ed2d05219bd..b99eb2956ea 100644 --- a/protocols/kad/src/handler_priv.rs +++ b/protocols/kad/src/handler_priv.rs @@ -67,8 +67,7 @@ pub struct KademliaHandler { /// List of outbound substreams that are waiting to become active next. /// Contains the request we want to send, and the user data if we expect an answer. - requested_streams: - VecDeque)>>, + pending_messages: VecDeque<(KadRequestMsg, Option)>, /// List of active inbound substreams with the state they are in. inbound_substreams: SelectAll>, @@ -499,7 +498,7 @@ where inbound_substreams: Default::default(), outbound_substreams: Default::default(), num_requested_outbound_streams: 0, - requested_streams: Default::default(), + pending_messages: Default::default(), keep_alive, protocol_status: ProtocolStatus::Unconfirmed, } @@ -507,19 +506,22 @@ where fn on_fully_negotiated_outbound( &mut self, - FullyNegotiatedOutbound { - protocol, - info: (msg, user_data), - }: FullyNegotiatedOutbound< + FullyNegotiatedOutbound { protocol, info: () }: FullyNegotiatedOutbound< ::OutboundProtocol, ::OutboundOpenInfo, >, ) { - self.outbound_substreams - .push(OutboundSubstreamState::PendingSend( - protocol, msg, user_data, - )); + if let Some((msg, user_data)) = self.pending_messages.pop_front() { + self.outbound_substreams + .push(OutboundSubstreamState::PendingSend( + protocol, msg, user_data, + )); + } else { + debug_assert!(false, "Requested outbound stream without message") + } + self.num_requested_outbound_streams -= 1; + if let ProtocolStatus::Unconfirmed = self.protocol_status { // Upon the first successfully negotiated substream, we know that the // remote is configured with the same protocol name and we want @@ -587,9 +589,7 @@ where fn on_dial_upgrade_error( &mut self, DialUpgradeError { - info: (_, user_data), - error, - .. + info: (), error, .. }: DialUpgradeError< ::OutboundOpenInfo, ::OutboundProtocol, @@ -597,10 +597,12 @@ where ) { // TODO: cache the fact that the remote doesn't support kademlia at all, so that we don't // continue trying - if let Some(user_data) = user_data { + + if let Some((_, Some(user_data))) = self.pending_messages.pop_front() { self.outbound_substreams .push(OutboundSubstreamState::ReportError(error.into(), user_data)); } + self.num_requested_outbound_streams -= 1; } } @@ -614,8 +616,7 @@ where type Error = io::Error; // TODO: better error type? type InboundProtocol = Either; type OutboundProtocol = KademliaProtocolConfig; - // Message of the request to send to the remote, and user data if we expect an answer. - type OutboundOpenInfo = (KadRequestMsg, Option); + type OutboundOpenInfo = (); type InboundOpenInfo = (); fn listen_protocol(&self) -> SubstreamProtocol { @@ -645,10 +646,7 @@ where } KademliaHandlerIn::FindNodeReq { key, user_data } => { let msg = KadRequestMsg::FindNode { key }; - self.requested_streams.push_back(SubstreamProtocol::new( - self.config.protocol_config.clone(), - (msg, Some(user_data)), - )); + self.pending_messages.push_back((msg, Some(user_data))); } KademliaHandlerIn::FindNodeRes { closer_peers, @@ -656,10 +654,7 @@ where } => self.answer_pending_request(request_id, KadResponseMsg::FindNode { closer_peers }), KademliaHandlerIn::GetProvidersReq { key, user_data } => { let msg = KadRequestMsg::GetProviders { key }; - self.requested_streams.push_back(SubstreamProtocol::new( - self.config.protocol_config.clone(), - (msg, Some(user_data)), - )); + self.pending_messages.push_back((msg, Some(user_data))); } KademliaHandlerIn::GetProvidersRes { closer_peers, @@ -674,24 +669,15 @@ where ), KademliaHandlerIn::AddProvider { key, provider } => { let msg = KadRequestMsg::AddProvider { key, provider }; - self.requested_streams.push_back(SubstreamProtocol::new( - self.config.protocol_config.clone(), - (msg, None), - )); + self.pending_messages.push_back((msg, None)); } KademliaHandlerIn::GetRecord { key, user_data } => { let msg = KadRequestMsg::GetValue { key }; - self.requested_streams.push_back(SubstreamProtocol::new( - self.config.protocol_config.clone(), - (msg, Some(user_data)), - )); + self.pending_messages.push_back((msg, Some(user_data))); } KademliaHandlerIn::PutRecord { record, user_data } => { let msg = KadRequestMsg::PutValue { record }; - self.requested_streams.push_back(SubstreamProtocol::new( - self.config.protocol_config.clone(), - (msg, Some(user_data)), - )); + self.pending_messages.push_back((msg, Some(user_data))); } KademliaHandlerIn::GetRecordRes { record, @@ -750,11 +736,13 @@ where let num_in_progress_outbound_substreams = self.outbound_substreams.len() + self.num_requested_outbound_streams; - if num_in_progress_outbound_substreams < MAX_NUM_SUBSTREAMS { - if let Some(protocol) = self.requested_streams.pop_front() { - self.num_requested_outbound_streams += 1; - return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { protocol }); - } + if num_in_progress_outbound_substreams < MAX_NUM_SUBSTREAMS + && self.num_requested_outbound_streams < self.pending_messages.len() + { + self.num_requested_outbound_streams += 1; + return Poll::Ready(ConnectionHandlerEvent::OutboundSubstreamRequest { + protocol: SubstreamProtocol::new(self.config.protocol_config.clone(), ()), + }); } let no_streams = self.outbound_substreams.is_empty() && self.inbound_substreams.is_empty(); @@ -828,7 +816,7 @@ where { type Item = ConnectionHandlerEvent< KademliaProtocolConfig, - (KadRequestMsg, Option), + (), KademliaHandlerEvent, io::Error, >; @@ -964,7 +952,7 @@ where { type Item = ConnectionHandlerEvent< KademliaProtocolConfig, - (KadRequestMsg, Option), + (), KademliaHandlerEvent, io::Error, >; From 2f5270ba768e5ae1bca3615afcb68fe1dade72cf Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 28 Apr 2023 15:50:31 +0200 Subject: [PATCH 38/57] feat(noise): deprecate all handshake patterns apart from XX In the libp2p specs, the only handshake pattern that is specified is the XX handshake. Support for other handshake patterns can be added through external modules. While we are at it, we rename the remaining types to following the laid out naming convention. The tests for handshakes other than XX are removed. The handshakes still work as we don't touch them in this patch. Related #2217. Pull-Request: #3768. --- Cargo.lock | 2 +- core/tests/transport_upgrade.rs | 4 +- examples/autonat/src/bin/autonat_client.rs | 2 +- examples/autonat/src/bin/autonat_server.rs | 2 +- examples/chat-example/src/main.rs | 4 +- examples/dcutr/src/main.rs | 3 +- .../distributed-key-value-store/src/main.rs | 2 +- examples/file-sharing/src/network.rs | 2 +- examples/identify/src/main.rs | 2 +- examples/ipfs-private/src/main.rs | 2 +- examples/metrics/src/main.rs | 2 +- examples/ping-example/src/main.rs | 2 +- examples/relay-server/src/main.rs | 3 +- examples/rendezvous/src/bin/rzv-discover.rs | 2 +- examples/rendezvous/src/bin/rzv-identify.rs | 2 +- examples/rendezvous/src/bin/rzv-register.rs | 2 +- examples/rendezvous/src/main.rs | 2 +- interop-tests/src/bin/ping.rs | 10 +- libp2p/Cargo.toml | 2 +- libp2p/src/lib.rs | 4 +- protocols/identify/src/behaviour.rs | 5 +- protocols/kad/src/behaviour/test.rs | 2 +- protocols/perf/Cargo.toml | 2 +- protocols/perf/src/bin/perf-client.rs | 2 +- protocols/perf/src/bin/perf-server.rs | 2 +- transports/noise/CHANGELOG.md | 10 + transports/noise/Cargo.toml | 2 +- transports/noise/src/io.rs | 12 +- transports/noise/src/io/framed.rs | 10 +- transports/noise/src/io/handshake.rs | 35 ++- transports/noise/src/lib.rs | 246 +++++++++++++----- transports/noise/src/protocol.rs | 16 +- transports/noise/src/protocol/x25519.rs | 12 +- transports/noise/src/protocol/x25519_spec.rs | 16 +- transports/noise/tests/smoke.rs | 153 ++--------- transports/pnet/tests/smoke.rs | 2 +- transports/quic/tests/smoke.rs | 9 +- transports/webrtc/Cargo.toml | 2 +- transports/webrtc/src/tokio/error.rs | 2 +- transports/webrtc/src/tokio/upgrade/noise.rs | 24 +- 40 files changed, 295 insertions(+), 325 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a30d07f9a4e..ad9a1d5f15d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2684,7 +2684,7 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.42.1" +version = "0.42.2" dependencies = [ "async-io", "bytes", diff --git a/core/tests/transport_upgrade.rs b/core/tests/transport_upgrade.rs index e2c44f9f0d4..ac724a64ffa 100644 --- a/core/tests/transport_upgrade.rs +++ b/core/tests/transport_upgrade.rs @@ -81,7 +81,7 @@ fn upgrade_pipeline() { let listener_id = listener_keys.public().to_peer_id(); let mut listener_transport = MemoryTransport::default() .upgrade(upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&listener_keys).unwrap()) + .authenticate(noise::Config::new(&listener_keys).unwrap()) .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) @@ -92,7 +92,7 @@ fn upgrade_pipeline() { let dialer_id = dialer_keys.public().to_peer_id(); let mut dialer_transport = MemoryTransport::default() .upgrade(upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&dialer_keys).unwrap()) + .authenticate(noise::Config::new(&dialer_keys).unwrap()) .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) .apply(HelloUpgrade {}) diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index 32ecc9aca67..ff3e0805463 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -64,7 +64,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .authenticate(noise::Config::new(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index e3ad9665e30..b6c51ba8b5e 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .authenticate(noise::Config::new(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/chat-example/src/main.rs b/examples/chat-example/src/main.rs index 368d270a371..0d1c68a9d3b 100644 --- a/examples/chat-example/src/main.rs +++ b/examples/chat-example/src/main.rs @@ -77,9 +77,7 @@ async fn main() -> Result<(), Box> { // Set up an encrypted DNS-enabled TCP Transport over the Mplex protocol. let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)) .upgrade(upgrade::Version::V1Lazy) - .authenticate( - noise::NoiseAuthenticated::xx(&id_keys).expect("signing libp2p-noise static keypair"), - ) + .authenticate(noise::Config::new(&id_keys).expect("signing libp2p-noise static keypair")) .multiplex(yamux::YamuxConfig::default()) .timeout(std::time::Duration::from_secs(20)) .boxed(); diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 1cafa2411a0..62e28ca9c57 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -98,8 +98,7 @@ fn main() -> Result<(), Box> { ) .upgrade(upgrade::Version::V1Lazy) .authenticate( - noise::NoiseAuthenticated::xx(&local_key) - .expect("Signing libp2p-noise static DH keypair failed."), + noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 404062199cc..83adfa6b43c 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -65,7 +65,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .authenticate(noise::Config::new(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index 62496172e4a..5eedd22d765 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -49,7 +49,7 @@ pub(crate) async fn new( let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&id_keys)?) + .authenticate(noise::Config::new(&id_keys)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 7159be53b66..1b900043108 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -53,7 +53,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap()) + .authenticate(noise::Config::new(&local_key).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index fadc6cfd06f..1af5bebb4b6 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -52,7 +52,7 @@ pub fn build_transport( key_pair: identity::Keypair, psk: Option, ) -> transport::Boxed<(PeerId, StreamMuxerBox)> { - let noise_config = noise::NoiseAuthenticated::xx(&key_pair).unwrap(); + let noise_config = noise::Config::new(&key_pair).unwrap(); let yamux_config = YamuxConfig::default(); let base_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)); diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 7eda36d9715..7bbb533299c 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -74,7 +74,7 @@ fn main() -> Result<(), Box> { let mut swarm = SwarmBuilder::without_executor( tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .authenticate(noise::Config::new(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(), Behaviour::new(local_pub_key), diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index 3cb0aa69ae3..34113e1d50d 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -57,7 +57,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&local_key)?) + .authenticate(noise::Config::new(&local_key)?) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index 3484d236986..1a6088b5563 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -51,8 +51,7 @@ fn main() -> Result<(), Box> { let transport = tcp_transport .upgrade(upgrade::Version::V1Lazy) .authenticate( - noise::NoiseAuthenticated::xx(&local_key) - .expect("Signing libp2p-noise static DH keypair failed."), + noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(libp2p::yamux::YamuxConfig::default()) .boxed(); diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index 2f31dc9d390..b1ac6d7220e 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -44,7 +44,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) + .authenticate(noise::Config::new(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), MyBehaviour { diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index bb5157fba78..7cd28f73441 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -40,7 +40,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) + .authenticate(noise::Config::new(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), MyBehaviour { diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index 5429fb8efa1..7edd7dc1fdb 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -40,7 +40,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) + .authenticate(noise::Config::new(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), MyBehaviour { diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index 78e48cee7d4..929cdc097e2 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -54,7 +54,7 @@ async fn main() { let mut swarm = SwarmBuilder::with_tokio_executor( tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) - .authenticate(noise::NoiseAuthenticated::xx(&key_pair).unwrap()) + .authenticate(noise::Config::new(&key_pair).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(), MyBehaviour { diff --git a/interop-tests/src/bin/ping.rs b/interop-tests/src/bin/ping.rs index 63160f8c8d0..7aacfa82a99 100644 --- a/interop-tests/src/bin/ping.rs +++ b/interop-tests/src/bin/ping.rs @@ -61,10 +61,7 @@ async fn main() -> Result<()> { (Transport::Tcp, Ok(SecProtocol::Noise)) => ( tcp::tokio::Transport::new(tcp::Config::new()) .upgrade(Version::V1Lazy) - .authenticate( - noise::NoiseAuthenticated::xx(&local_key) - .context("failed to intialise noise")?, - ) + .authenticate(noise::Config::new(&local_key).context("failed to intialise noise")?) .multiplex(muxer_protocol_from_env()?) .timeout(Duration::from_secs(5)) .boxed(), @@ -82,10 +79,7 @@ async fn main() -> Result<()> { (Transport::Ws, Ok(SecProtocol::Noise)) => ( WsConfig::new(tcp::tokio::Transport::new(tcp::Config::new())) .upgrade(Version::V1Lazy) - .authenticate( - noise::NoiseAuthenticated::xx(&local_key) - .context("failed to intialise noise")?, - ) + .authenticate(noise::Config::new(&local_key).context("failed to intialise noise")?) .multiplex(muxer_protocol_from_env()?) .timeout(Duration::from_secs(5)) .boxed(), diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index aa35c2b84db..dcdbb00f79d 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -107,7 +107,7 @@ libp2p-identity = { version = "0.1.0", path = "../identity" } libp2p-kad = { version = "0.43.0", path = "../protocols/kad", optional = true } libp2p-metrics = { version = "0.12.0", path = "../misc/metrics", optional = true } libp2p-mplex = { version = "0.39.0", path = "../muxers/mplex", optional = true } -libp2p-noise = { version = "0.42.0", path = "../transports/noise", optional = true } +libp2p-noise = { version = "0.42.2", path = "../transports/noise", optional = true } libp2p-ping = { version = "0.42.0", path = "../protocols/ping", optional = true } libp2p-plaintext = { version = "0.39.0", path = "../transports/plaintext", optional = true } libp2p-pnet = { version = "0.22.2", path = "../transports/pnet", optional = true } diff --git a/libp2p/src/lib.rs b/libp2p/src/lib.rs index 79acd4249b8..f2764e88ef9 100644 --- a/libp2p/src/lib.rs +++ b/libp2p/src/lib.rs @@ -231,7 +231,7 @@ pub async fn development_transport( Ok(transport .upgrade(core::upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) + .authenticate(noise::Config::new(&keypair).unwrap()) .multiplex(core::upgrade::SelectUpgrade::new( yamux::YamuxConfig::default(), #[allow(deprecated)] @@ -288,7 +288,7 @@ pub fn tokio_development_transport( Ok(transport .upgrade(core::upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&keypair).unwrap()) + .authenticate(noise::Config::new(&keypair).unwrap()) .multiplex(core::upgrade::SelectUpgrade::new( yamux::YamuxConfig::default(), #[allow(deprecated)] diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 8ba50e2db4b..ec1c7596de0 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -564,13 +564,10 @@ mod tests { transport::Boxed<(PeerId, StreamMuxerBox)>, ) { let id_keys = identity::Keypair::generate_ed25519(); - let noise_keys = noise::Keypair::::new() - .into_authentic(&id_keys) - .unwrap(); let pubkey = id_keys.public(); let transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)) .upgrade(upgrade::Version::V1) - .authenticate(noise::NoiseConfig::xx(noise_keys).into_authenticated()) + .authenticate(noise::Config::new(&id_keys).unwrap()) .multiplex(MplexConfig::new()) .boxed(); (pubkey, transport) diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index 3a76e2f92b2..f361a31f756 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -59,7 +59,7 @@ fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) { let local_public_key = local_key.public(); let transport = MemoryTransport::default() .upgrade(upgrade::Version::V1) - .authenticate(noise::NoiseAuthenticated::xx(&local_key).unwrap()) + .authenticate(noise::Config::new(&local_key).unwrap()) .multiplex(yamux::YamuxConfig::default()) .boxed(); diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 03230a8ed13..d76024dfb37 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -20,7 +20,7 @@ instant = "0.1.11" libp2p-core = { version = "0.39.0", path = "../../core" } libp2p-dns = { version = "0.39.0", path = "../../transports/dns", features = ["async-std"] } libp2p-identity = { version = "0.1.0", path = "../../identity" } -libp2p-noise = { version = "0.42.0", path = "../../transports/noise" } +libp2p-noise = { version = "0.42.2", path = "../../transports/noise" } libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] } libp2p-swarm = { version = "0.42.1", path = "../../swarm", features = ["macros", "async-std"] } libp2p-tcp = { version = "0.39.0", path = "../../transports/tcp", features = ["async-io"] } diff --git a/protocols/perf/src/bin/perf-client.rs b/protocols/perf/src/bin/perf-client.rs index c12ab5cbe74..a1d809ac1cb 100644 --- a/protocols/perf/src/bin/perf-client.rs +++ b/protocols/perf/src/bin/perf-client.rs @@ -52,7 +52,7 @@ async fn main() -> Result<()> { libp2p_tcp::async_io::Transport::new(libp2p_tcp::Config::default().port_reuse(true)) .upgrade(upgrade::Version::V1Lazy) .authenticate( - libp2p_noise::NoiseAuthenticated::xx(&local_key) + libp2p_noise::Config::new(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(libp2p_yamux::YamuxConfig::default()); diff --git a/protocols/perf/src/bin/perf-server.rs b/protocols/perf/src/bin/perf-server.rs index b12972e3c38..8499ccc602b 100644 --- a/protocols/perf/src/bin/perf-server.rs +++ b/protocols/perf/src/bin/perf-server.rs @@ -46,7 +46,7 @@ async fn main() { libp2p_tcp::async_io::Transport::new(libp2p_tcp::Config::default().port_reuse(true)) .upgrade(upgrade::Version::V1Lazy) .authenticate( - libp2p_noise::NoiseAuthenticated::xx(&local_key) + libp2p_noise::Config::new(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), ) .multiplex(libp2p_yamux::YamuxConfig::default()); diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index 2f0698eccef..f9c51382a65 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,3 +1,13 @@ +## 0.42.2 - unreleased + +- Deprecate all noise handshakes apart from XX. + This deprecates `NoiseConfig` and `NoiseAuthenticated` in favor of a new `libp2p_noise::Config` struct. + In addition, we deprecate all types with a `Noise` prefix. + Users are encouraged to import the `noise` module and refer to types as `noise::Error` etc. + See [PR 3768]. + +[PR 3768]: https://github.com/libp2p/rust-libp2p/pull/3768 + ## 0.42.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 28a8ceeb0a8..b7da5a31090 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-noise" edition = "2021" rust-version = "1.60.0" description = "Cryptographic handshake protocol using the noise framework." -version = "0.42.1" +version = "0.42.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/transports/noise/src/io.rs b/transports/noise/src/io.rs index 314a3b87033..ee184695696 100644 --- a/transports/noise/src/io.rs +++ b/transports/noise/src/io.rs @@ -37,7 +37,7 @@ use std::{ /// A noise session to a remote. /// /// `T` is the type of the underlying I/O resource. -pub struct NoiseOutput { +pub struct Output { io: NoiseFramed, recv_buffer: Bytes, recv_offset: usize, @@ -45,15 +45,15 @@ pub struct NoiseOutput { send_offset: usize, } -impl fmt::Debug for NoiseOutput { +impl fmt::Debug for Output { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("NoiseOutput").field("io", &self.io).finish() } } -impl NoiseOutput { +impl Output { fn new(io: NoiseFramed) -> Self { - NoiseOutput { + Output { io, recv_buffer: Bytes::new(), recv_offset: 0, @@ -63,7 +63,7 @@ impl NoiseOutput { } } -impl AsyncRead for NoiseOutput { +impl AsyncRead for Output { fn poll_read( mut self: Pin<&mut Self>, cx: &mut Context<'_>, @@ -99,7 +99,7 @@ impl AsyncRead for NoiseOutput { } } -impl AsyncWrite for NoiseOutput { +impl AsyncWrite for Output { fn poll_write( self: Pin<&mut Self>, cx: &mut Context<'_>, diff --git a/transports/noise/src/io/framed.rs b/transports/noise/src/io/framed.rs index 1e74e46ac9b..01e1f9dbca1 100644 --- a/transports/noise/src/io/framed.rs +++ b/transports/noise/src/io/framed.rs @@ -21,8 +21,8 @@ //! This module provides a `Sink` and `Stream` for length-delimited //! Noise protocol messages in form of [`NoiseFramed`]. -use crate::io::NoiseOutput; -use crate::{NoiseError, Protocol, PublicKey}; +use crate::io::Output; +use crate::{Error, Protocol, PublicKey}; use bytes::{Bytes, BytesMut}; use futures::prelude::*; use futures::ready; @@ -89,9 +89,7 @@ impl NoiseFramed { /// transitioning to transport mode because the handshake is incomplete, /// an error is returned. Similarly if the remote's static DH key, if /// present, cannot be parsed. - pub(crate) fn into_transport( - self, - ) -> Result<(Option>, NoiseOutput), NoiseError> + pub(crate) fn into_transport(self) -> Result<(Option>, Output), Error> where C: Protocol + AsRef<[u8]>, { @@ -111,7 +109,7 @@ impl NoiseFramed { decrypt_buffer: self.decrypt_buffer, }; - Ok((dh_remote_pubkey, NoiseOutput::new(io))) + Ok((dh_remote_pubkey, Output::new(io))) } } diff --git a/transports/noise/src/io/handshake.rs b/transports/noise/src/io/handshake.rs index d968c481ddd..ea3331d5e68 100644 --- a/transports/noise/src/io/handshake.rs +++ b/transports/noise/src/io/handshake.rs @@ -26,11 +26,11 @@ mod proto { pub use self::payload::proto::NoiseHandshakePayload; } -use crate::io::{framed::NoiseFramed, NoiseOutput}; +use crate::io::{framed::NoiseFramed, Output}; use crate::protocol::{KeypairIdentity, Protocol, PublicKey}; -#[allow(deprecated)] + +use crate::Error; use crate::LegacyConfig; -use crate::NoiseError; use bytes::Bytes; use futures::prelude::*; use libp2p_identity as identity; @@ -38,6 +38,9 @@ use quick_protobuf::{BytesReader, MessageRead, MessageWrite, Writer}; use std::io; /// The identity of the remote established during a handshake. +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] pub enum RemoteIdentity { /// The remote provided no identifying information. /// @@ -79,7 +82,6 @@ pub(crate) struct State { /// The known or received public identity key of the remote, if any. id_remote_pubkey: Option, /// Legacy configuration parameters. - #[allow(deprecated)] legacy: LegacyConfig, } @@ -89,7 +91,7 @@ impl State { /// will be sent and received on the given I/O resource and using the /// provided session for cryptographic operations according to the chosen /// Noise handshake pattern. - #[allow(deprecated)] + pub(crate) fn new( io: T, session: snow::HandshakeState, @@ -109,8 +111,8 @@ impl State { impl State { /// Finish a handshake, yielding the established remote identity and the - /// [`NoiseOutput`] for communicating on the encrypted channel. - pub(crate) fn finish(self) -> Result<(RemoteIdentity, NoiseOutput), NoiseError> + /// [`Output`] for communicating on the encrypted channel. + pub(crate) fn finish(self) -> Result<(RemoteIdentity, Output), Error> where C: Protocol + AsRef<[u8]>, { @@ -122,7 +124,7 @@ impl State { if C::verify(&id_pk, &dh_pk, &self.dh_remote_pubkey_sig) { RemoteIdentity::IdentityKey(id_pk) } else { - return Err(NoiseError::BadSignature); + return Err(Error::BadSignature); } } }; @@ -134,7 +136,7 @@ impl State { // Handshake Message Futures /// A future for receiving a Noise handshake message. -async fn recv(state: &mut State) -> Result +async fn recv(state: &mut State) -> Result where T: AsyncRead + Unpin, { @@ -146,7 +148,7 @@ where } /// A future for receiving a Noise handshake message with an empty payload. -pub(crate) async fn recv_empty(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn recv_empty(state: &mut State) -> Result<(), Error> where T: AsyncRead + Unpin, { @@ -160,7 +162,7 @@ where } /// A future for sending a Noise handshake message with an empty payload. -pub(crate) async fn send_empty(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn send_empty(state: &mut State) -> Result<(), Error> where T: AsyncWrite + Unpin, { @@ -173,7 +175,7 @@ where /// /// In case `expected_key` is passed, this function will fail if the received key does not match the expected key. /// In case the remote does not send us a key, the expected key is assumed to be the remote's key. -pub(crate) async fn recv_identity(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn recv_identity(state: &mut State) -> Result<(), Error> where T: AsyncRead + Unpin, { @@ -182,7 +184,6 @@ where let mut reader = BytesReader::from_bytes(&msg[..]); let mut pb_result = proto::NoiseHandshakePayload::from_reader(&mut reader, &msg[..]); - #[allow(deprecated)] if pb_result.is_err() && state.legacy.recv_legacy_handshake { // NOTE: This is support for legacy handshake payloads. As long as // the frame length is less than 256 bytes, which is the case for @@ -218,7 +219,7 @@ where let pk = identity::PublicKey::try_decode_protobuf(&pb.identity_key)?; if let Some(ref k) = state.id_remote_pubkey { if k != &pk { - return Err(NoiseError::UnexpectedKey); + return Err(Error::UnexpectedKey); } } state.id_remote_pubkey = Some(pk); @@ -232,7 +233,7 @@ where } /// Send a Noise handshake message with a payload identifying the local node to the remote. -pub(crate) async fn send_identity(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn send_identity(state: &mut State) -> Result<(), Error> where T: AsyncWrite + Unpin, { @@ -245,7 +246,6 @@ where pb.identity_sig = sig.clone() } - #[allow(deprecated)] let mut msg = if state.legacy.send_legacy_handshake { let mut msg = Vec::with_capacity(2 + pb.get_size()); msg.extend_from_slice(&(pb.get_size() as u16).to_be_bytes()); @@ -262,7 +262,7 @@ where } /// Send a Noise handshake message with a payload identifying the local node to the remote. -pub(crate) async fn send_signature_only(state: &mut State) -> Result<(), NoiseError> +pub(crate) async fn send_signature_only(state: &mut State) -> Result<(), Error> where T: AsyncWrite + Unpin, { @@ -272,7 +272,6 @@ where pb.identity_sig = sig.clone() } - #[allow(deprecated)] let mut msg = if state.legacy.send_legacy_handshake { let mut msg = Vec::with_capacity(2 + pb.get_size()); msg.extend_from_slice(&(pb.get_size() as u16).to_be_bytes()); diff --git a/transports/noise/src/lib.rs b/transports/noise/src/lib.rs index c1c120f38a6..1e5b0a437e1 100644 --- a/transports/noise/src/lib.rs +++ b/transports/noise/src/lib.rs @@ -41,11 +41,11 @@ //! ``` //! use libp2p_core::{identity, Transport, upgrade}; //! use libp2p_tcp::TcpTransport; -//! use libp2p_noise::{Keypair, X25519Spec, NoiseAuthenticated}; +//! use libp2p_noise as noise; //! //! # fn main() { //! let id_keys = identity::Keypair::generate_ed25519(); -//! let noise = NoiseAuthenticated::xx(&id_keys).unwrap(); +//! let noise = noise::Config::new(&id_keys).unwrap(); //! let builder = TcpTransport::default().upgrade(upgrade::Version::V1).authenticate(noise); //! // let transport = builder.multiplex(...); //! # } @@ -54,19 +54,80 @@ //! [noise]: http://noiseprotocol.org/ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] +#![allow(deprecated)] // Temporarily until we remove deprecated items. mod io; mod protocol; pub use io::handshake::RemoteIdentity; -pub use io::NoiseOutput; -#[allow(deprecated)] -pub use protocol::x25519::X25519; -pub use protocol::x25519_spec::X25519Spec; -pub use protocol::{AuthenticKeypair, Keypair, KeypairIdentity, PublicKey, SecretKey}; -pub use protocol::{Protocol, ProtocolParams, IK, IX, XX}; -use std::fmt; -use std::fmt::Formatter; +pub use io::Output; + +pub use protocol::Protocol; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type X25519Spec = protocol::x25519_spec::X25519Spec; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type X25519 = protocol::x25519::X25519; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type AuthenticKeypair = protocol::AuthenticKeypair; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type Keypair = protocol::Keypair; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type KeypairIdentity = protocol::KeypairIdentity; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type PublicKey = protocol::PublicKey; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type SecretKey = protocol::SecretKey; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type ProtocolParams = protocol::ProtocolParams; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type IK = protocol::IK; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type IX = protocol::IX; + +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] +pub type XX = protocol::XX; + +#[deprecated( + note = "This type has been renamed to drop the `Noise` prefix, refer to it as `noise::Error` instead." +)] +pub type NoiseError = Error; + +#[deprecated( + note = "This type has been renamed to drop the `Noise` prefix, refer to it as `noise::Output` instead." +)] +pub type NoiseOutput = Output; use crate::handshake::State; use crate::io::handshake; @@ -75,15 +136,79 @@ use futures::prelude::*; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity as identity; use libp2p_identity::PeerId; +use std::fmt; +use std::fmt::Formatter; use std::pin::Pin; use zeroize::Zeroize; +/// The configuration for the noise handshake. +#[derive(Clone)] +pub struct Config { + inner: NoiseAuthenticated, +} + +impl Config { + /// Construct a new configuration for the noise handshake using the XX handshake pattern. + + pub fn new(identity: &identity::Keypair) -> Result { + Ok(Config { + inner: NoiseAuthenticated::xx(identity)?, + }) + } + + /// Set the noise prologue. + + pub fn with_prologue(mut self, prologue: Vec) -> Self { + self.inner.config.prologue = prologue; + + self + } +} + +impl UpgradeInfo for Config { + type Info = &'static [u8]; + type InfoIter = std::iter::Once; + + fn protocol_info(&self) -> Self::InfoIter { + std::iter::once(b"/noise") + } +} + +impl InboundUpgrade for Config +where + T: AsyncRead + AsyncWrite + Unpin + Send + 'static, +{ + type Output = (PeerId, Output); + type Error = Error; + type Future = Pin> + Send>>; + + fn upgrade_inbound(self, socket: T, info: Self::Info) -> Self::Future { + self.inner.upgrade_inbound(socket, info) + } +} + +impl OutboundUpgrade for Config +where + T: AsyncRead + AsyncWrite + Unpin + Send + 'static, +{ + type Output = (PeerId, Output); + type Error = Error; + type Future = Pin> + Send>>; + + fn upgrade_outbound(self, socket: T, info: Self::Info) -> Self::Future { + self.inner.upgrade_outbound(socket, info) + } +} + /// The protocol upgrade configuration. +#[deprecated( + note = "Use `libp2p_noise::Config` instead. All other handshake patterns are deprecated and will be removed." +)] #[derive(Clone)] pub struct NoiseConfig { dh_keys: AuthenticKeypair, params: ProtocolParams, - #[allow(deprecated)] + legacy: LegacyConfig, remote: R, _marker: std::marker::PhantomData

, @@ -114,7 +239,7 @@ impl NoiseConfig { since = "0.42.0", note = "`LegacyConfig` will be removed without replacement." )] - #[allow(deprecated)] + pub fn set_legacy_config(&mut self, cfg: LegacyConfig) -> &mut Self { self.legacy = cfg; self @@ -124,11 +249,12 @@ impl NoiseConfig { /// Implement `into_responder` and `into_initiator` for all configs where `R = ()`. /// /// This allows us to ignore the `remote` field. + impl NoiseConfig where C: Zeroize + Protocol + AsRef<[u8]>, { - fn into_responder(self, socket: S) -> Result, NoiseError> { + fn into_responder(self, socket: S) -> Result, Error> { let session = self .params .into_builder(&self.prologue, self.dh_keys.keypair.secret(), None) @@ -139,7 +265,7 @@ where Ok(state) } - fn into_initiator(self, socket: S) -> Result, NoiseError> { + fn into_initiator(self, socket: S) -> Result, Error> { let session = self .params .into_builder(&self.prologue, self.dh_keys.keypair.secret(), None) @@ -160,10 +286,7 @@ where NoiseConfig { dh_keys, params: C::params_ix(), - legacy: { - #[allow(deprecated)] - LegacyConfig::default() - }, + legacy: { LegacyConfig::default() }, remote: (), _marker: std::marker::PhantomData, prologue: Vec::default(), @@ -180,10 +303,7 @@ where NoiseConfig { dh_keys, params: C::params_xx(), - legacy: { - #[allow(deprecated)] - LegacyConfig::default() - }, + legacy: { LegacyConfig::default() }, remote: (), _marker: std::marker::PhantomData, prologue: Vec::default(), @@ -203,10 +323,7 @@ where NoiseConfig { dh_keys, params: C::params_ik(), - legacy: { - #[allow(deprecated)] - LegacyConfig::default() - }, + legacy: { LegacyConfig::default() }, remote: (), _marker: std::marker::PhantomData, prologue: Vec::default(), @@ -230,10 +347,7 @@ where NoiseConfig { dh_keys, params: C::params_ik(), - legacy: { - #[allow(deprecated)] - LegacyConfig::default() - }, + legacy: { LegacyConfig::default() }, remote: (remote_dh, remote_id), _marker: std::marker::PhantomData, prologue: Vec::default(), @@ -241,7 +355,7 @@ where } /// Specialised implementation of `into_initiator` for the `IK` handshake where `R != ()`. - fn into_initiator(self, socket: S) -> Result, NoiseError> { + fn into_initiator(self, socket: S) -> Result, Error> { let session = self .params .into_builder( @@ -266,7 +380,7 @@ where /// libp2p_noise error type. #[derive(Debug, thiserror::Error)] #[non_exhaustive] -pub enum NoiseError { +pub enum Error { #[error(transparent)] Io(#[from] std::io::Error), #[error(transparent)] @@ -302,9 +416,9 @@ impl From for DecodeError { } } -impl From for NoiseError { +impl From for Error { fn from(e: quick_protobuf::Error) -> Self { - NoiseError::InvalidPayload(e.into()) + Error::InvalidPayload(e.into()) } } @@ -318,15 +432,16 @@ impl From for NoiseError { /// initiator -{id}-> responder /// initiator <-{id}- responder /// ``` + impl InboundUpgrade for NoiseConfig where NoiseConfig: UpgradeInfo, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Clone + Send + 'static, { - type Output = (RemoteIdentity, NoiseOutput); - type Error = NoiseError; - type Future = BoxFuture<'static, Result<(RemoteIdentity, NoiseOutput), NoiseError>>; + type Output = (RemoteIdentity, Output); + type Error = Error; + type Future = BoxFuture<'static, Result<(RemoteIdentity, Output), Error>>; fn upgrade_inbound(self, socket: T, _: Self::Info) -> Self::Future { async move { @@ -349,15 +464,16 @@ where /// initiator -{id}-> responder /// initiator <-{id}- responder /// ``` + impl OutboundUpgrade for NoiseConfig where NoiseConfig: UpgradeInfo, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Clone + Send + 'static, { - type Output = (RemoteIdentity, NoiseOutput); - type Error = NoiseError; - type Future = BoxFuture<'static, Result<(RemoteIdentity, NoiseOutput), NoiseError>>; + type Output = (RemoteIdentity, Output); + type Error = Error; + type Future = BoxFuture<'static, Result<(RemoteIdentity, Output), Error>>; fn upgrade_outbound(self, socket: T, _: Self::Info) -> Self::Future { async move { @@ -384,15 +500,16 @@ where /// initiator <-{id}- responder /// initiator -{id}-> responder /// ``` + impl InboundUpgrade for NoiseConfig where NoiseConfig: UpgradeInfo, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Clone + Send + 'static, { - type Output = (RemoteIdentity, NoiseOutput); - type Error = NoiseError; - type Future = BoxFuture<'static, Result<(RemoteIdentity, NoiseOutput), NoiseError>>; + type Output = (RemoteIdentity, Output); + type Error = Error; + type Future = BoxFuture<'static, Result<(RemoteIdentity, Output), Error>>; fn upgrade_inbound(self, socket: T, _: Self::Info) -> Self::Future { async move { @@ -420,15 +537,16 @@ where /// initiator <-{id}- responder /// initiator -{id}-> responder /// ``` + impl OutboundUpgrade for NoiseConfig where NoiseConfig: UpgradeInfo, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Clone + Send + 'static, { - type Output = (RemoteIdentity, NoiseOutput); - type Error = NoiseError; - type Future = BoxFuture<'static, Result<(RemoteIdentity, NoiseOutput), NoiseError>>; + type Output = (RemoteIdentity, Output); + type Error = Error; + type Future = BoxFuture<'static, Result<(RemoteIdentity, Output), Error>>; fn upgrade_outbound(self, socket: T, _: Self::Info) -> Self::Future { async move { @@ -455,15 +573,16 @@ where /// initiator -{id}-> responder /// initiator <-{id}- responder /// ``` + impl InboundUpgrade for NoiseConfig where NoiseConfig: UpgradeInfo, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Clone + Send + 'static, { - type Output = (RemoteIdentity, NoiseOutput); - type Error = NoiseError; - type Future = BoxFuture<'static, Result<(RemoteIdentity, NoiseOutput), NoiseError>>; + type Output = (RemoteIdentity, Output); + type Error = Error; + type Future = BoxFuture<'static, Result<(RemoteIdentity, Output), Error>>; fn upgrade_inbound(self, socket: T, _: Self::Info) -> Self::Future { async move { @@ -489,15 +608,16 @@ where /// initiator -{id}-> responder /// initiator <-{id}- responder /// ``` + impl OutboundUpgrade for NoiseConfig, identity::PublicKey)> where NoiseConfig, identity::PublicKey)>: UpgradeInfo, T: AsyncRead + AsyncWrite + Unpin + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Clone + Send + 'static, { - type Output = (RemoteIdentity, NoiseOutput); - type Error = NoiseError; - type Future = BoxFuture<'static, Result<(RemoteIdentity, NoiseOutput), NoiseError>>; + type Output = (RemoteIdentity, Output); + type Error = Error; + type Future = BoxFuture<'static, Result<(RemoteIdentity, Output), Error>>; fn upgrade_outbound(self, socket: T, _: Self::Info) -> Self::Future { async move { @@ -525,6 +645,9 @@ where /// for creating an [`authenticated`](libp2p_core::transport::upgrade::Authenticate) /// transport for use with a `Swarm`. #[derive(Clone)] +#[deprecated( + note = "Use `libp2p_noise::Config` instead. All other handshake patterns are deprecated and will be removed." +)] pub struct NoiseAuthenticated { config: NoiseConfig, } @@ -533,7 +656,8 @@ impl NoiseAuthenticated { /// Create a new [`NoiseAuthenticated`] for the `XX` handshake pattern using X25519 DH keys. /// /// For now, this is the only combination that is guaranteed to be compatible with other libp2p implementations. - pub fn xx(id_keys: &identity::Keypair) -> Result { + #[deprecated(note = "Use `libp2p_noise::Config::new` instead.")] + pub fn xx(id_keys: &identity::Keypair) -> Result { let dh_keys = Keypair::::new(); let noise_keys = dh_keys.into_authentic(id_keys)?; let config = NoiseConfig::xx(noise_keys); @@ -557,14 +681,14 @@ where impl InboundUpgrade for NoiseAuthenticated where NoiseConfig: UpgradeInfo - + InboundUpgrade, NoiseOutput), Error = NoiseError> + + InboundUpgrade, Output), Error = Error> + 'static, as InboundUpgrade>::Future: Send, T: AsyncRead + AsyncWrite + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Send + 'static, { - type Output = (PeerId, NoiseOutput); - type Error = NoiseError; + type Output = (PeerId, Output); + type Error = Error; type Future = Pin> + Send>>; fn upgrade_inbound(self, socket: T, info: Self::Info) -> Self::Future { @@ -573,7 +697,7 @@ where .upgrade_inbound(socket, info) .and_then(|(remote, io)| match remote { RemoteIdentity::IdentityKey(pk) => future::ok((pk.to_peer_id(), io)), - _ => future::err(NoiseError::AuthenticationFailed), + _ => future::err(Error::AuthenticationFailed), }), ) } @@ -582,14 +706,14 @@ where impl OutboundUpgrade for NoiseAuthenticated where NoiseConfig: UpgradeInfo - + OutboundUpgrade, NoiseOutput), Error = NoiseError> + + OutboundUpgrade, Output), Error = Error> + 'static, as OutboundUpgrade>::Future: Send, T: AsyncRead + AsyncWrite + Send + 'static, C: Protocol + AsRef<[u8]> + Zeroize + Send + 'static, { - type Output = (PeerId, NoiseOutput); - type Error = NoiseError; + type Output = (PeerId, Output); + type Error = Error; type Future = Pin> + Send>>; fn upgrade_outbound(self, socket: T, info: Self::Info) -> Self::Future { @@ -598,7 +722,7 @@ where .upgrade_outbound(socket, info) .and_then(|(remote, io)| match remote { RemoteIdentity::IdentityKey(pk) => future::ok((pk.to_peer_id(), io)), - _ => future::err(NoiseError::AuthenticationFailed), + _ => future::err(Error::AuthenticationFailed), }), ) } diff --git a/transports/noise/src/protocol.rs b/transports/noise/src/protocol.rs index db42b5888b3..c8d9da3ff56 100644 --- a/transports/noise/src/protocol.rs +++ b/transports/noise/src/protocol.rs @@ -22,7 +22,7 @@ pub(crate) mod x25519; pub(crate) mod x25519_spec; -use crate::NoiseError; +use crate::Error; use libp2p_identity as identity; use rand::SeedableRng; use zeroize::Zeroize; @@ -68,6 +68,9 @@ pub enum XX {} /// A Noise protocol over DH keys of type `C`. The choice of `C` determines the /// protocol parameters for each handshake pattern. +#[deprecated( + note = "This type will be made private in the future. Use `libp2p_noise::Config::new` instead to use the noise protocol." +)] pub trait Protocol { /// The protocol parameters for the IK handshake pattern. fn params_ik() -> ProtocolParams; @@ -77,7 +80,7 @@ pub trait Protocol { fn params_xx() -> ProtocolParams; /// Construct a DH public key from a byte slice. - fn public_from_bytes(s: &[u8]) -> Result, NoiseError>; + fn public_from_bytes(s: &[u8]) -> Result, Error>; /// Determines whether the authenticity of the given DH static public key /// and public identity key is linked, i.e. that proof of ownership of a @@ -103,7 +106,7 @@ pub trait Protocol { /// without a signature, otherwise a signature over the static DH public key /// must be given and is verified with the public identity key, establishing /// the authenticity of the static DH public key w.r.t. the public identity key. - #[allow(deprecated)] + fn verify(id_pk: &identity::PublicKey, dh_pk: &PublicKey, sig: &Option>) -> bool where C: AsRef<[u8]>, @@ -114,7 +117,7 @@ pub trait Protocol { .map_or(false, |s| id_pk.verify(dh_pk.as_ref(), s)) } - fn sign(id_keys: &identity::Keypair, dh_pk: &PublicKey) -> Result, NoiseError> + fn sign(id_keys: &identity::Keypair, dh_pk: &PublicKey) -> Result, Error> where C: AsRef<[u8]>, { @@ -175,10 +178,7 @@ impl Keypair { /// Turn this DH keypair into a [`AuthenticKeypair`], i.e. a DH keypair that /// is authentic w.r.t. the given identity keypair, by signing the DH public key. - pub fn into_authentic( - self, - id_keys: &identity::Keypair, - ) -> Result, NoiseError> + pub fn into_authentic(self, id_keys: &identity::Keypair) -> Result, Error> where T: AsRef<[u8]>, T: Protocol, diff --git a/transports/noise/src/protocol/x25519.rs b/transports/noise/src/protocol/x25519.rs index 9dcf5f8d73a..cc1586feb0d 100644 --- a/transports/noise/src/protocol/x25519.rs +++ b/transports/noise/src/protocol/x25519.rs @@ -23,9 +23,7 @@ //! **Note**: This set of protocols is not interoperable with other //! libp2p implementations. -#![allow(deprecated)] - -use crate::{NoiseConfig, NoiseError, Protocol, ProtocolParams}; +use crate::{Error, NoiseConfig, Protocol, ProtocolParams}; use curve25519_dalek::edwards::CompressedEdwardsY; use libp2p_core::UpgradeInfo; use libp2p_identity as identity; @@ -59,10 +57,6 @@ static PARAMS_XX: Lazy = Lazy::new(|| { /// A X25519 key. #[derive(Clone)] -#[deprecated( - since = "0.42.0", - note = "Will be removed because it is not compliant with the official libp2p specification. Use `X25519Spec` instead." -)] pub struct X25519([u8; 32]); impl AsRef<[u8]> for X25519 { @@ -122,9 +116,9 @@ impl Protocol for X25519 { PARAMS_XX.clone() } - fn public_from_bytes(bytes: &[u8]) -> Result, NoiseError> { + fn public_from_bytes(bytes: &[u8]) -> Result, Error> { if bytes.len() != 32 { - return Err(NoiseError::InvalidLength); + return Err(Error::InvalidLength); } let mut pk = [0u8; 32]; pk.copy_from_slice(bytes); diff --git a/transports/noise/src/protocol/x25519_spec.rs b/transports/noise/src/protocol/x25519_spec.rs index 0924bdd51e4..621532ad52d 100644 --- a/transports/noise/src/protocol/x25519_spec.rs +++ b/transports/noise/src/protocol/x25519_spec.rs @@ -22,7 +22,7 @@ //! //! [libp2p-noise-spec]: https://github.com/libp2p/specs/tree/master/noise -use crate::{NoiseConfig, NoiseError, Protocol, ProtocolParams}; +use crate::{Error, NoiseConfig, Protocol, ProtocolParams}; use libp2p_core::UpgradeInfo; use libp2p_identity as identity; use rand::Rng; @@ -94,6 +94,7 @@ impl UpgradeInfo for NoiseConfig { } /// **Note**: This is not currentlyy a standardised upgrade. + impl UpgradeInfo for NoiseConfig { type Info = &'static [u8]; type InfoIter = std::iter::Once; @@ -104,6 +105,7 @@ impl UpgradeInfo for NoiseConfig { } /// **Note**: This is not currently a standardised upgrade. + impl UpgradeInfo for NoiseConfig { type Info = &'static [u8]; type InfoIter = std::iter::Once; @@ -119,23 +121,20 @@ impl UpgradeInfo for NoiseConfig { /// interoperable with other libp2p implementations. impl Protocol for X25519Spec { fn params_ik() -> ProtocolParams { - #[allow(deprecated)] x25519::X25519::params_ik() } fn params_ix() -> ProtocolParams { - #[allow(deprecated)] x25519::X25519::params_ix() } fn params_xx() -> ProtocolParams { - #[allow(deprecated)] x25519::X25519::params_xx() } - fn public_from_bytes(bytes: &[u8]) -> Result, NoiseError> { + fn public_from_bytes(bytes: &[u8]) -> Result, Error> { if bytes.len() != 32 { - return Err(NoiseError::InvalidLength); + return Err(Error::InvalidLength); } let mut pk = [0u8; 32]; pk.copy_from_slice(bytes); @@ -152,10 +151,7 @@ impl Protocol for X25519Spec { }) } - fn sign( - id_keys: &identity::Keypair, - dh_pk: &PublicKey, - ) -> Result, NoiseError> { + fn sign(id_keys: &identity::Keypair, dh_pk: &PublicKey) -> Result, Error> { Ok(id_keys.sign(&[STATIC_KEY_DOMAIN.as_bytes(), dh_pk.as_ref()].concat())?) } } diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 2b71b115b99..9ddbca3eec8 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -19,17 +19,13 @@ // DEALINGS IN THE SOFTWARE. use async_io::Async; -use futures::{ - future::{self, Either}, - prelude::*, -}; +use futures::prelude::*; use libp2p_core::transport::Transport; -use libp2p_core::upgrade::{apply_inbound, apply_outbound, Negotiated}; +use libp2p_core::upgrade::Negotiated; use libp2p_core::{transport, upgrade}; use libp2p_identity as identity; -use libp2p_noise::{ - Keypair, NoiseAuthenticated, NoiseConfig, NoiseError, NoiseOutput, RemoteIdentity, X25519Spec, -}; +use libp2p_identity::PeerId; +use libp2p_noise as noise; use libp2p_tcp as tcp; use log::info; use quickcheck::*; @@ -40,7 +36,7 @@ fn core_upgrade_compat() { // Tests API compaibility with the libp2p-core upgrade API, // i.e. if it compiles, the "test" is considered a success. let id_keys = identity::Keypair::generate_ed25519(); - let noise = NoiseAuthenticated::xx(&id_keys).unwrap(); + let noise = noise::Config::new(&id_keys).unwrap(); let _ = tcp::async_io::Transport::default() .upgrade(upgrade::Version::V1) .authenticate(noise); @@ -57,140 +53,36 @@ fn xx() { let server_id_public = server_id.public(); let client_id_public = client_id.public(); - let server_dh = Keypair::::new() - .into_authentic(&server_id) - .unwrap(); let server_transport = tcp::async_io::Transport::default() .and_then(move |output, endpoint| { upgrade::apply( output, - NoiseConfig::xx(server_dh), + noise::Config::new(&server_id).unwrap(), endpoint, upgrade::Version::V1, ) }) - .and_then(move |out, _| expect_identity(out, &client_id_public)) - .boxed(); + .map(move |out, _| { + assert_eq!(out.0, client_id_public.to_peer_id()); - let client_dh = Keypair::::new() - .into_authentic(&client_id) - .unwrap(); - let client_transport = tcp::async_io::Transport::default() - .and_then(move |output, endpoint| { - upgrade::apply( - output, - NoiseConfig::xx(client_dh), - endpoint, - upgrade::Version::V1, - ) + out }) - .and_then(move |out, _| expect_identity(out, &server_id_public)) .boxed(); - run(server_transport, client_transport, messages); - true - } - QuickCheck::new() - .max_tests(30) - .quickcheck(prop as fn(Vec) -> bool) -} - -#[test] -fn ix() { - let _ = env_logger::try_init(); - fn prop(mut messages: Vec) -> bool { - messages.truncate(5); - let server_id = identity::Keypair::generate_ed25519(); - let client_id = identity::Keypair::generate_ed25519(); - - let server_id_public = server_id.public(); - let client_id_public = client_id.public(); - - let server_dh = Keypair::::new() - .into_authentic(&server_id) - .unwrap(); - let server_transport = tcp::async_io::Transport::default() - .and_then(move |output, endpoint| { - upgrade::apply( - output, - NoiseConfig::ix(server_dh), - endpoint, - upgrade::Version::V1, - ) - }) - .and_then(move |out, _| expect_identity(out, &client_id_public)) - .boxed(); - - let client_dh = Keypair::::new() - .into_authentic(&client_id) - .unwrap(); let client_transport = tcp::async_io::Transport::default() .and_then(move |output, endpoint| { upgrade::apply( output, - NoiseConfig::ix(client_dh), + noise::Config::new(&client_id).unwrap(), endpoint, upgrade::Version::V1, ) }) - .and_then(move |out, _| expect_identity(out, &server_id_public)) - .boxed(); - - run(server_transport, client_transport, messages); - true - } - QuickCheck::new() - .max_tests(30) - .quickcheck(prop as fn(Vec) -> bool) -} + .map(move |out, _| { + assert_eq!(out.0, server_id_public.to_peer_id()); -#[test] -fn ik_xx() { - let _ = env_logger::try_init(); - fn prop(mut messages: Vec) -> bool { - messages.truncate(5); - let server_id = identity::Keypair::generate_ed25519(); - let server_id_public = server_id.public(); - - let client_id = identity::Keypair::generate_ed25519(); - let client_id_public = client_id.public(); - - let server_dh = Keypair::::new() - .into_authentic(&server_id) - .unwrap(); - let server_dh_public = server_dh.public_dh_key().clone(); - let server_transport = tcp::async_io::Transport::default() - .and_then(move |output, endpoint| { - if endpoint.is_listener() { - Either::Left(apply_inbound(output, NoiseConfig::ik_listener(server_dh))) - } else { - Either::Right(apply_outbound( - output, - NoiseConfig::xx(server_dh), - upgrade::Version::V1, - )) - } + out }) - .and_then(move |out, _| expect_identity(out, &client_id_public)) - .boxed(); - - let client_dh = Keypair::::new() - .into_authentic(&client_id) - .unwrap(); - let server_id_public2 = server_id_public.clone(); - let client_transport = tcp::async_io::Transport::default() - .and_then(move |output, endpoint| { - if endpoint.is_dialer() { - Either::Left(apply_outbound( - output, - NoiseConfig::ik_dialer(client_dh, server_id_public, server_dh_public), - upgrade::Version::V1, - )) - } else { - Either::Right(apply_inbound(output, NoiseConfig::xx(client_dh))) - } - }) - .and_then(move |out, _| expect_identity(out, &server_id_public2)) .boxed(); run(server_transport, client_transport, messages); @@ -201,13 +93,10 @@ fn ik_xx() { .quickcheck(prop as fn(Vec) -> bool) } -type Output = (RemoteIdentity, NoiseOutput>>); +type Output = (PeerId, noise::Output>>); -fn run( - mut server: transport::Boxed>, - mut client: transport::Boxed>, - messages: I, -) where +fn run(mut server: transport::Boxed, mut client: transport::Boxed, messages: I) +where I: IntoIterator + Clone, { futures::executor::block_on(async { @@ -274,16 +163,6 @@ fn run( }) } -fn expect_identity( - output: Output, - pk: &identity::PublicKey, -) -> impl Future, NoiseError>> { - match output.0 { - RemoteIdentity::IdentityKey(ref k) if k == pk => future::ok(output), - _ => panic!("Unexpected remote identity"), - } -} - #[derive(Debug, Clone, PartialEq, Eq)] struct Message(Vec); diff --git a/transports/pnet/tests/smoke.rs b/transports/pnet/tests/smoke.rs index 7c8f571bb26..66fa01b7222 100644 --- a/transports/pnet/tests/smoke.rs +++ b/transports/pnet/tests/smoke.rs @@ -110,7 +110,7 @@ where let transport = transport .and_then(move |socket, _| pnet.handshake(socket)) .upgrade(Version::V1) - .authenticate(libp2p_noise::NoiseAuthenticated::xx(&identity).unwrap()) + .authenticate(libp2p_noise::Config::new(&identity).unwrap()) .multiplex(libp2p_yamux::YamuxConfig::default()) .boxed(); SwarmBuilder::with_tokio_executor( diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 2e8914140c4..0fe6a65c081 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -233,14 +233,7 @@ fn new_tcp_quic_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { let quic_transport = quic::async_std::Transport::new(config); let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default()) .upgrade(upgrade::Version::V1) - .authenticate( - noise::NoiseConfig::xx( - noise::Keypair::::new() - .into_authentic(&keypair) - .unwrap(), - ) - .into_authenticated(), - ) + .authenticate(noise::Config::new(&keypair).unwrap()) .multiplex(yamux::YamuxConfig::default()); let transport = OrTransport::new(quic_transport, tcp_transport) diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index f45d3004531..ae0379b2e03 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -19,7 +19,7 @@ futures-timer = "3" hex = "0.4" if-watch = "3.0" libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-noise = { version = "0.42.0", path = "../../transports/noise" } +libp2p-noise = { version = "0.42.2", path = "../../transports/noise" } libp2p-identity = { version = "0.1.0", path = "../../identity" } log = "0.4" sha2 = "0.10.6" diff --git a/transports/webrtc/src/tokio/error.rs b/transports/webrtc/src/tokio/error.rs index 4899a077b4b..1b274686ef3 100644 --- a/transports/webrtc/src/tokio/error.rs +++ b/transports/webrtc/src/tokio/error.rs @@ -29,7 +29,7 @@ pub enum Error { #[error("IO error")] Io(#[from] std::io::Error), #[error("failed to authenticate peer")] - Authentication(#[from] libp2p_noise::NoiseError), + Authentication(#[from] libp2p_noise::Error), // Authentication errors. #[error("invalid peer ID (expected {expected}, got {got})")] diff --git a/transports/webrtc/src/tokio/upgrade/noise.rs b/transports/webrtc/src/tokio/upgrade/noise.rs index fb95a0f4b46..34e3526a2fe 100644 --- a/transports/webrtc/src/tokio/upgrade/noise.rs +++ b/transports/webrtc/src/tokio/upgrade/noise.rs @@ -22,7 +22,7 @@ use futures::{AsyncRead, AsyncWrite, AsyncWriteExt}; use libp2p_core::{InboundUpgrade, OutboundUpgrade, UpgradeInfo}; use libp2p_identity as identity; use libp2p_identity::PeerId; -use libp2p_noise::{Keypair, NoiseConfig, X25519Spec}; +use libp2p_noise as noise; use crate::tokio::fingerprint::Fingerprint; use crate::tokio::Error; @@ -36,18 +36,13 @@ pub(crate) async fn inbound( where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { - let dh_keys = Keypair::::new() - .into_authentic(&id_keys) - .unwrap(); - let noise = NoiseConfig::xx(dh_keys) + let noise = noise::Config::new(&id_keys) + .unwrap() .with_prologue(noise_prologue(client_fingerprint, server_fingerprint)); let info = noise.protocol_info().next().unwrap(); // Note the roles are reversed because it allows the server (webrtc connection responder) to // send application data 0.5 RTT earlier. - let (peer_id, mut channel) = noise - .into_authenticated() - .upgrade_outbound(stream, info) - .await?; + let (peer_id, mut channel) = noise.upgrade_outbound(stream, info).await?; channel.close().await?; @@ -63,18 +58,13 @@ pub(crate) async fn outbound( where T: AsyncRead + AsyncWrite + Unpin + Send + 'static, { - let dh_keys = Keypair::::new() - .into_authentic(&id_keys) - .unwrap(); - let noise = NoiseConfig::xx(dh_keys) + let noise = noise::Config::new(&id_keys) + .unwrap() .with_prologue(noise_prologue(client_fingerprint, server_fingerprint)); let info = noise.protocol_info().next().unwrap(); // Note the roles are reversed because it allows the server (webrtc connection responder) to // send application data 0.5 RTT earlier. - let (peer_id, mut channel) = noise - .into_authenticated() - .upgrade_inbound(stream, info) - .await?; + let (peer_id, mut channel) = noise.upgrade_inbound(stream, info).await?; channel.close().await?; From e3a165093318417053699cbda5d2966d1f860aa1 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Fri, 28 Apr 2023 16:06:33 +0200 Subject: [PATCH 39/57] feat(identify): do not implicitly dial on push Previously, we would implicitly establish a connection when the user wanted to push identify information to a peer. I believe that this is the wrong behaviour. Instead, I am suggesting to log a message that we are skipping the push to this peer. Additionally, the way this is currently implemented does not make much sense. Dialing a peer takes time. In case we don't have a connection at all, it could be that we drop the push requests because there isn't an active handler and thus we would have unnecessarily established the connection. Instead of fixing this - which would require buffering the push messages - I think we should just remove the implicit dial. Pull-Request: #3843. --- Cargo.lock | 2 +- protocols/identify/CHANGELOG.md | 9 +++++++++ protocols/identify/Cargo.toml | 2 +- protocols/identify/src/behaviour.rs | 14 +++++++------- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ad9a1d5f15d..088b96b482d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2522,7 +2522,7 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.42.1" +version = "0.42.2" dependencies = [ "async-std", "asynchronous-codec", diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 278b793d58b..1869db55678 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,12 @@ +## 0.42.2 - unreleased + +- Do not implicitly dial a peer upon `identify::Behaviour::push`. + Previously, we would dial each peer in the provided list. + Now, we skip peers that we are not connected to. + See [PR 3843]. + +[PR 3843]: https://github.com/libp2p/rust-libp2p/pull/3843 + ## 0.42.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index bfe75da8133..fb186360ba9 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-identify" edition = "2021" rust-version = "1.62.0" description = "Nodes identifcation protocol for libp2p" -version = "0.42.1" +version = "0.42.2" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index ec1c7596de0..08d0681463a 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -25,9 +25,8 @@ use libp2p_identity::PeerId; use libp2p_identity::PublicKey; use libp2p_swarm::behaviour::{ConnectionClosed, ConnectionEstablished, DialFailure, FromSwarm}; use libp2p_swarm::{ - dial_opts::DialOpts, AddressScore, ConnectionDenied, ConnectionHandlerUpgrErr, DialError, - ExternalAddresses, ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters, - THandlerInEvent, ToSwarm, + AddressScore, ConnectionDenied, ConnectionHandlerUpgrErr, DialError, ExternalAddresses, + ListenAddresses, NetworkBehaviour, NotifyHandler, PollParameters, THandlerInEvent, ToSwarm, }; use libp2p_swarm::{ConnectionId, THandler, THandlerOutEvent}; use lru::LruCache; @@ -193,16 +192,17 @@ impl Behaviour { I: IntoIterator, { for p in peers { + if !self.connected.contains_key(&p) { + log::debug!("Not pushing to {p} because we are not connected"); + continue; + } + let request = Request { peer_id: p, protocol: Protocol::Push, }; if !self.requests.contains(&request) { self.requests.push(request); - - self.events.push_back(ToSwarm::Dial { - opts: DialOpts::peer_id(p).build(), - }); } } } From cfdf5c33453925b52be15ad8dfbabd9184ce8260 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 14:21:17 +0000 Subject: [PATCH 40/57] deps: bump clap from 4.2.4 to 4.2.5 Pull-Request: #3849. --- Cargo.lock | 24 ++++++++++++------------ examples/autonat/Cargo.toml | 2 +- examples/dcutr/Cargo.toml | 2 +- examples/file-sharing/Cargo.toml | 2 +- examples/relay-server/Cargo.toml | 2 +- misc/keygen/Cargo.toml | 2 +- protocols/dcutr/Cargo.toml | 2 +- protocols/perf/Cargo.toml | 2 +- 8 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 088b96b482d..156513b4779 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -499,7 +499,7 @@ name = "autonat-example" version = "0.1.0" dependencies = [ "async-std", - "clap 4.2.4", + "clap 4.2.5", "env_logger 0.10.0", "futures", "libp2p", @@ -781,9 +781,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.4" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62" +checksum = "8a1f23fa97e1d1641371b51f35535cb26959b8e27ab50d167a8b996b5bada819" dependencies = [ "clap_builder", "clap_derive", @@ -792,9 +792,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.4" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749" +checksum = "0fdc5d93c358224b4d6867ef1356d740de2303e9892edc06c5340daeccd96bab" dependencies = [ "anstream", "anstyle", @@ -1232,7 +1232,7 @@ dependencies = [ name = "dcutr" version = "0.1.0" dependencies = [ - "clap 4.2.4", + "clap 4.2.5", "env_logger 0.10.0", "futures", "futures-timer", @@ -1527,7 +1527,7 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "clap 4.2.4", + "clap 4.2.5", "either", "env_logger 0.10.0", "futures", @@ -2235,7 +2235,7 @@ name = "keygen" version = "0.1.0" dependencies = [ "base64 0.21.0", - "clap 4.2.4", + "clap 4.2.5", "libp2p-core", "libp2p-identity", "serde", @@ -2277,7 +2277,7 @@ dependencies = [ "async-std", "async-trait", "bytes", - "clap 4.2.4", + "clap 4.2.5", "either", "env_logger 0.10.0", "futures", @@ -2408,7 +2408,7 @@ version = "0.9.1" dependencies = [ "async-std", "asynchronous-codec", - "clap 4.2.4", + "clap 4.2.5", "either", "env_logger 0.10.0", "futures", @@ -2713,7 +2713,7 @@ version = "0.1.0" dependencies = [ "anyhow", "async-std", - "clap 4.2.4", + "clap 4.2.5", "env_logger 0.10.0", "futures", "instant", @@ -4177,7 +4177,7 @@ version = "0.1.0" dependencies = [ "async-std", "async-trait", - "clap 4.2.4", + "clap 4.2.5", "env_logger 0.10.0", "futures", "libp2p", diff --git a/examples/autonat/Cargo.toml b/examples/autonat/Cargo.toml index 199472d0cb9..fac3dc7ee9b 100644 --- a/examples/autonat/Cargo.toml +++ b/examples/autonat/Cargo.toml @@ -7,7 +7,7 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../../libp2p", features = ["async-std", "tcp", "noise", "yamux", "autonat", "identify", "macros"] } diff --git a/examples/dcutr/Cargo.toml b/examples/dcutr/Cargo.toml index 60509557539..cccddcb8263 100644 --- a/examples/dcutr/Cargo.toml +++ b/examples/dcutr/Cargo.toml @@ -6,7 +6,7 @@ publish = false license = "MIT" [dependencies] -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" futures-timer = "3.0" diff --git a/examples/file-sharing/Cargo.toml b/examples/file-sharing/Cargo.toml index 3a49e16b371..83d19448d0b 100644 --- a/examples/file-sharing/Cargo.toml +++ b/examples/file-sharing/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" [dependencies] async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } either = "1.8" env_logger = "0.10" futures = "0.3.28" diff --git a/examples/relay-server/Cargo.toml b/examples/relay-server/Cargo.toml index 4104c221015..379ebf2d03c 100644 --- a/examples/relay-server/Cargo.toml +++ b/examples/relay-server/Cargo.toml @@ -6,7 +6,7 @@ publish = false license = "MIT" [dependencies] -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } async-std = { version = "1.12", features = ["attributes"] } async-trait = "0.1" env_logger = "0.10.0" diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index cd861e1e222..18b4d8b0154 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -10,7 +10,7 @@ categories = ["network-programming", "asynchronous"] publish = false [dependencies] -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } zeroize = "1" serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.96" diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index 56854d6046e..93e17d5082a 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -27,7 +27,7 @@ void = "1" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } env_logger = "0.10.0" libp2p-dns = { path = "../../transports/dns", features = ["async-std"] } libp2p-identify = { path = "../../protocols/identify" } diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index d76024dfb37..c11b865a8e0 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] anyhow = "1" async-std = { version = "1.9.0", features = ["attributes"] } -clap = { version = "4.2.4", features = ["derive"] } +clap = { version = "4.2.5", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" instant = "0.1.11" From 193d2a1a6c366cee0c2f93ada3467ce3c660b29f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 14:36:12 +0000 Subject: [PATCH 41/57] deps: bump sha3 from 0.10.6 to 0.10.7 Pull-Request: #3799. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 156513b4779..327ed18486e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4563,9 +4563,9 @@ dependencies = [ [[package]] name = "sha3" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdf0c33fae925bdc080598b84bc15c55e7b9a4a43b3c704da051f977469691c9" +checksum = "54c2bb1a323307527314a36bfb73f24febb08ce2b8a554bf4ffd6f51ad15198c" dependencies = [ "digest 0.10.6", "keccak", From b1cdf8d4bbc994049880ca85535d1219297777dd Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 1 May 2023 04:25:52 +0200 Subject: [PATCH 42/57] feat(yamux): rename symbols to follow module-based naming convention Implements our naming convention for the `libp2p-yamux` crate. Related: #2217. Pull-Request: #3852. --- Cargo.lock | 2 +- examples/autonat/src/bin/autonat_client.rs | 2 +- examples/autonat/src/bin/autonat_server.rs | 2 +- examples/chat-example/src/main.rs | 2 +- examples/dcutr/src/main.rs | 2 +- .../distributed-key-value-store/src/main.rs | 2 +- examples/file-sharing/src/network.rs | 2 +- examples/identify/src/main.rs | 2 +- examples/ipfs-private/src/main.rs | 6 +- examples/metrics/src/main.rs | 2 +- examples/ping-example/src/main.rs | 2 +- examples/relay-server/src/main.rs | 2 +- examples/rendezvous/src/bin/rzv-discover.rs | 2 +- examples/rendezvous/src/bin/rzv-identify.rs | 2 +- examples/rendezvous/src/bin/rzv-register.rs | 2 +- examples/rendezvous/src/main.rs | 2 +- interop-tests/src/bin/ping.rs | 4 +- libp2p/Cargo.toml | 2 +- libp2p/src/lib.rs | 4 +- muxers/yamux/CHANGELOG.md | 8 ++ muxers/yamux/Cargo.toml | 2 +- muxers/yamux/src/lib.rs | 110 ++++++++++-------- muxers/yamux/tests/compliance.rs | 8 +- protocols/dcutr/tests/lib.rs | 2 +- protocols/kad/src/behaviour/test.rs | 2 +- protocols/perf/Cargo.toml | 2 +- protocols/perf/src/bin/perf-client.rs | 2 +- protocols/perf/src/bin/perf-server.rs | 2 +- protocols/relay/tests/lib.rs | 2 +- swarm-test/Cargo.toml | 2 +- swarm-test/src/lib.rs | 4 +- swarm/src/lib.rs | 2 +- transports/pnet/tests/smoke.rs | 2 +- transports/quic/tests/smoke.rs | 2 +- transports/tls/tests/smoke.rs | 2 +- 35 files changed, 108 insertions(+), 92 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 327ed18486e..890eb5583ac 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3078,7 +3078,7 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.43.0" +version = "0.43.1" dependencies = [ "async-std", "futures", diff --git a/examples/autonat/src/bin/autonat_client.rs b/examples/autonat/src/bin/autonat_client.rs index ff3e0805463..bc0c0521af8 100644 --- a/examples/autonat/src/bin/autonat_client.rs +++ b/examples/autonat/src/bin/autonat_client.rs @@ -65,7 +65,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&local_key)?) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); let behaviour = Behaviour::new(local_key.public()); diff --git a/examples/autonat/src/bin/autonat_server.rs b/examples/autonat/src/bin/autonat_server.rs index b6c51ba8b5e..7177a5bf840 100644 --- a/examples/autonat/src/bin/autonat_server.rs +++ b/examples/autonat/src/bin/autonat_server.rs @@ -54,7 +54,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&local_key)?) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); let behaviour = Behaviour::new(local_key.public()); diff --git a/examples/chat-example/src/main.rs b/examples/chat-example/src/main.rs index 0d1c68a9d3b..2c038724c37 100644 --- a/examples/chat-example/src/main.rs +++ b/examples/chat-example/src/main.rs @@ -78,7 +78,7 @@ async fn main() -> Result<(), Box> { let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)) .upgrade(upgrade::Version::V1Lazy) .authenticate(noise::Config::new(&id_keys).expect("signing libp2p-noise static keypair")) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .timeout(std::time::Duration::from_secs(20)) .boxed(); let quic_transport = quic::async_std::Transport::new(quic::Config::new(&id_keys)); diff --git a/examples/dcutr/src/main.rs b/examples/dcutr/src/main.rs index 62e28ca9c57..4dbee86fac3 100644 --- a/examples/dcutr/src/main.rs +++ b/examples/dcutr/src/main.rs @@ -100,7 +100,7 @@ fn main() -> Result<(), Box> { .authenticate( noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."), ) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); #[derive(NetworkBehaviour)] diff --git a/examples/distributed-key-value-store/src/main.rs b/examples/distributed-key-value-store/src/main.rs index 83adfa6b43c..952e55ba6e7 100644 --- a/examples/distributed-key-value-store/src/main.rs +++ b/examples/distributed-key-value-store/src/main.rs @@ -66,7 +66,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&local_key)?) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); // We create a custom network behaviour that combines Kademlia and mDNS. diff --git a/examples/file-sharing/src/network.rs b/examples/file-sharing/src/network.rs index 5eedd22d765..64fad09774e 100644 --- a/examples/file-sharing/src/network.rs +++ b/examples/file-sharing/src/network.rs @@ -50,7 +50,7 @@ pub(crate) async fn new( let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&id_keys)?) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); // Build the Swarm, connecting the lower layer transport logic with the diff --git a/examples/identify/src/main.rs b/examples/identify/src/main.rs index 1b900043108..a46fac7f368 100644 --- a/examples/identify/src/main.rs +++ b/examples/identify/src/main.rs @@ -54,7 +54,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&local_key).unwrap()) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); // Create a identify network behaviour. diff --git a/examples/ipfs-private/src/main.rs b/examples/ipfs-private/src/main.rs index 1af5bebb4b6..fd18581407b 100644 --- a/examples/ipfs-private/src/main.rs +++ b/examples/ipfs-private/src/main.rs @@ -41,9 +41,7 @@ use libp2p::{ noise, ping, pnet::{PnetConfig, PreSharedKey}, swarm::{NetworkBehaviour, SwarmBuilder, SwarmEvent}, - tcp, - yamux::YamuxConfig, - Multiaddr, PeerId, Transport, + tcp, yamux, Multiaddr, PeerId, Transport, }; use std::{env, error::Error, fs, path::Path, str::FromStr, time::Duration}; @@ -53,7 +51,7 @@ pub fn build_transport( psk: Option, ) -> transport::Boxed<(PeerId, StreamMuxerBox)> { let noise_config = noise::Config::new(&key_pair).unwrap(); - let yamux_config = YamuxConfig::default(); + let yamux_config = yamux::Config::default(); let base_transport = tcp::async_io::Transport::new(tcp::Config::default().nodelay(true)); let maybe_encrypted = match psk { diff --git a/examples/metrics/src/main.rs b/examples/metrics/src/main.rs index 7bbb533299c..2178de9802b 100644 --- a/examples/metrics/src/main.rs +++ b/examples/metrics/src/main.rs @@ -75,7 +75,7 @@ fn main() -> Result<(), Box> { tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&local_key)?) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(), Behaviour::new(local_pub_key), local_peer_id, diff --git a/examples/ping-example/src/main.rs b/examples/ping-example/src/main.rs index 34113e1d50d..ab67a8d2ba6 100644 --- a/examples/ping-example/src/main.rs +++ b/examples/ping-example/src/main.rs @@ -58,7 +58,7 @@ async fn main() -> Result<(), Box> { let transport = tcp::async_io::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&local_key)?) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); let mut swarm = diff --git a/examples/relay-server/src/main.rs b/examples/relay-server/src/main.rs index 1a6088b5563..416d4e7c111 100644 --- a/examples/relay-server/src/main.rs +++ b/examples/relay-server/src/main.rs @@ -53,7 +53,7 @@ fn main() -> Result<(), Box> { .authenticate( noise::Config::new(&local_key).expect("Signing libp2p-noise static DH keypair failed."), ) - .multiplex(libp2p::yamux::YamuxConfig::default()) + .multiplex(libp2p::yamux::Config::default()) .boxed(); let behaviour = Behaviour { diff --git a/examples/rendezvous/src/bin/rzv-discover.rs b/examples/rendezvous/src/bin/rzv-discover.rs index b1ac6d7220e..bd551c68f5a 100644 --- a/examples/rendezvous/src/bin/rzv-discover.rs +++ b/examples/rendezvous/src/bin/rzv-discover.rs @@ -45,7 +45,7 @@ async fn main() { tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&key_pair).unwrap()) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(), MyBehaviour { rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()), diff --git a/examples/rendezvous/src/bin/rzv-identify.rs b/examples/rendezvous/src/bin/rzv-identify.rs index 7cd28f73441..b970fc01a6e 100644 --- a/examples/rendezvous/src/bin/rzv-identify.rs +++ b/examples/rendezvous/src/bin/rzv-identify.rs @@ -41,7 +41,7 @@ async fn main() { tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&key_pair).unwrap()) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(), MyBehaviour { identify: identify::Behaviour::new(identify::Config::new( diff --git a/examples/rendezvous/src/bin/rzv-register.rs b/examples/rendezvous/src/bin/rzv-register.rs index 7edd7dc1fdb..40053aa96b9 100644 --- a/examples/rendezvous/src/bin/rzv-register.rs +++ b/examples/rendezvous/src/bin/rzv-register.rs @@ -41,7 +41,7 @@ async fn main() { tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&key_pair).unwrap()) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(), MyBehaviour { rendezvous: rendezvous::client::Behaviour::new(key_pair.clone()), diff --git a/examples/rendezvous/src/main.rs b/examples/rendezvous/src/main.rs index 929cdc097e2..7d6e5ad44a4 100644 --- a/examples/rendezvous/src/main.rs +++ b/examples/rendezvous/src/main.rs @@ -55,7 +55,7 @@ async fn main() { tcp::tokio::Transport::default() .upgrade(Version::V1Lazy) .authenticate(noise::Config::new(&key_pair).unwrap()) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(), MyBehaviour { identify: identify::Behaviour::new(identify::Config::new( diff --git a/interop-tests/src/bin/ping.rs b/interop-tests/src/bin/ping.rs index 7aacfa82a99..042be8b3eb8 100644 --- a/interop-tests/src/bin/ping.rs +++ b/interop-tests/src/bin/ping.rs @@ -181,9 +181,9 @@ async fn main() -> Result<()> { Ok(()) } -fn muxer_protocol_from_env() -> Result> { +fn muxer_protocol_from_env() -> Result> { Ok(match from_env("muxer")? { - Muxer::Yamux => Either::Left(yamux::YamuxConfig::default()), + Muxer::Yamux => Either::Left(yamux::Config::default()), Muxer::Mplex => Either::Right(mplex::MplexConfig::new()), }) } diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index dcdbb00f79d..f979366b71a 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -116,7 +116,7 @@ libp2p-rendezvous = { version = "0.12.0", path = "../protocols/rendezvous", opti libp2p-request-response = { version = "0.24.0", path = "../protocols/request-response", optional = true } libp2p-swarm = { version = "0.42.0", path = "../swarm" } libp2p-wasm-ext = { version = "0.39.0", path = "../transports/wasm-ext", optional = true } -libp2p-yamux = { version = "0.43.0", path = "../muxers/yamux", optional = true } +libp2p-yamux = { version = "0.43.1", path = "../muxers/yamux", optional = true } multiaddr = { version = "0.17.0" } pin-project = "1.0.0" diff --git a/libp2p/src/lib.rs b/libp2p/src/lib.rs index f2764e88ef9..fad08b0128c 100644 --- a/libp2p/src/lib.rs +++ b/libp2p/src/lib.rs @@ -233,7 +233,7 @@ pub async fn development_transport( .upgrade(core::upgrade::Version::V1) .authenticate(noise::Config::new(&keypair).unwrap()) .multiplex(core::upgrade::SelectUpgrade::new( - yamux::YamuxConfig::default(), + yamux::Config::default(), #[allow(deprecated)] mplex::MplexConfig::default(), )) @@ -290,7 +290,7 @@ pub fn tokio_development_transport( .upgrade(core::upgrade::Version::V1) .authenticate(noise::Config::new(&keypair).unwrap()) .multiplex(core::upgrade::SelectUpgrade::new( - yamux::YamuxConfig::default(), + yamux::Config::default(), #[allow(deprecated)] mplex::MplexConfig::default(), )) diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index 76a848c6302..6cd334b46a0 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,3 +1,11 @@ +## 0.43.1 - unreleased + +- Drop `Yamux` prefix from all types. + Users are encouraged to import the `yamux` module and refer to types via `yamux::Muxer`, `yamux::Config` etc. + See [PR XXXX]. + +[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX + ## 0.43.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index b820fbd5998..53004065ec7 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-yamux" edition = "2021" rust-version = "1.60.0" description = "Yamux multiplexing protocol for libp2p" -version = "0.43.0" +version = "0.43.1" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/muxers/yamux/src/lib.rs b/muxers/yamux/src/lib.rs index 42fb1621e56..197fefb69c7 100644 --- a/muxers/yamux/src/lib.rs +++ b/muxers/yamux/src/lib.rs @@ -40,8 +40,11 @@ use std::{ use thiserror::Error; use yamux::ConnectionError; +#[deprecated(note = "Import the `yamux` module instead and refer to this type as `yamux::Muxer`.")] +pub type Yamux = Muxer; + /// A Yamux connection. -pub struct Yamux { +pub struct Muxer { /// The [`futures::stream::Stream`] of incoming substreams. incoming: S, /// Handle to control the connection. @@ -62,13 +65,13 @@ pub struct Yamux { const MAX_BUFFERED_INBOUND_STREAMS: usize = 25; -impl fmt::Debug for Yamux { +impl fmt::Debug for Muxer { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str("Yamux") } } -impl Yamux> +impl Muxer> where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { @@ -77,7 +80,7 @@ where let conn = yamux::Connection::new(io, cfg, mode); let ctrl = conn.control(); - Yamux { + Self { incoming: Incoming { stream: yamux::into_stream(conn).err_into().boxed(), _marker: std::marker::PhantomData, @@ -89,7 +92,7 @@ where } } -impl Yamux> +impl Muxer> where C: AsyncRead + AsyncWrite + Unpin + 'static, { @@ -98,7 +101,7 @@ where let conn = yamux::Connection::new(io, cfg, mode); let ctrl = conn.control(); - Yamux { + Self { incoming: LocalIncoming { stream: yamux::into_stream(conn).err_into().boxed_local(), _marker: std::marker::PhantomData, @@ -110,14 +113,15 @@ where } } -pub type YamuxResult = Result; +#[deprecated(note = "Use `Result` instead.")] +pub type YamuxResult = Result; -impl StreamMuxer for Yamux +impl StreamMuxer for Muxer where - S: Stream> + Unpin, + S: Stream> + Unpin, { type Substream = yamux::Stream; - type Error = YamuxError; + type Error = Error; fn poll_inbound( mut self: Pin<&mut Self>, @@ -138,7 +142,7 @@ where ) -> Poll> { Pin::new(&mut self.control) .poll_open_stream(cx) - .map_err(YamuxError) + .map_err(Error) } fn poll( @@ -165,11 +169,8 @@ where Poll::Pending } - fn poll_close(mut self: Pin<&mut Self>, c: &mut Context<'_>) -> Poll> { - if let Poll::Ready(()) = Pin::new(&mut self.control) - .poll_close(c) - .map_err(YamuxError)? - { + fn poll_close(mut self: Pin<&mut Self>, c: &mut Context<'_>) -> Poll> { + if let Poll::Ready(()) = Pin::new(&mut self.control).poll_close(c).map_err(Error)? { return Poll::Ready(Ok(())); } @@ -184,24 +185,27 @@ where } } -impl Yamux +impl Muxer where - S: Stream> + Unpin, + S: Stream> + Unpin, { - fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll> { + fn poll_inner(&mut self, cx: &mut Context<'_>) -> Poll> { self.incoming.poll_next_unpin(cx).map(|maybe_stream| { let stream = maybe_stream .transpose()? - .ok_or(YamuxError(ConnectionError::Closed))?; + .ok_or(Error(ConnectionError::Closed))?; Ok(stream) }) } } +#[deprecated(note = "Import the `yamux` module and refer to this type as `yamux::Config` instead.")] +pub type YamuxConfig = Config; + /// The yamux configuration. #[derive(Debug, Clone)] -pub struct YamuxConfig { +pub struct Config { inner: yamux::Config, mode: Option, } @@ -246,11 +250,16 @@ impl WindowUpdateMode { } } +#[deprecated( + note = "Import the `yamux` module and refer to this type as `yamux::LocalConfig` instead." +)] +pub type YamuxLocalConfig = LocalConfig; + /// The yamux configuration for upgrading I/O resources which are ![`Send`]. #[derive(Clone)] -pub struct YamuxLocalConfig(YamuxConfig); +pub struct LocalConfig(Config); -impl YamuxConfig { +impl Config { /// Creates a new `YamuxConfig` in client mode, regardless of whether /// it will be used for an inbound or outbound upgrade. pub fn client() -> Self { @@ -294,24 +303,24 @@ impl YamuxConfig { self } - /// Converts the config into a [`YamuxLocalConfig`] for use with upgrades + /// Converts the config into a [`LocalConfig`] for use with upgrades /// of I/O streams that are ![`Send`]. - pub fn into_local(self) -> YamuxLocalConfig { - YamuxLocalConfig(self) + pub fn into_local(self) -> LocalConfig { + LocalConfig(self) } } -impl Default for YamuxConfig { +impl Default for Config { fn default() -> Self { let mut inner = yamux::Config::default(); // For conformity with mplex, read-after-close on a multiplexed // connection is never permitted and not configurable. inner.set_read_after_close(false); - YamuxConfig { inner, mode: None } + Config { inner, mode: None } } } -impl UpgradeInfo for YamuxConfig { +impl UpgradeInfo for Config { type Info = &'static [u8]; type InfoIter = iter::Once; @@ -320,7 +329,7 @@ impl UpgradeInfo for YamuxConfig { } } -impl UpgradeInfo for YamuxLocalConfig { +impl UpgradeInfo for LocalConfig { type Info = &'static [u8]; type InfoIter = iter::Once; @@ -329,71 +338,74 @@ impl UpgradeInfo for YamuxLocalConfig { } } -impl InboundUpgrade for YamuxConfig +impl InboundUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { - type Output = Yamux>; + type Output = Muxer>; type Error = io::Error; type Future = future::Ready>; fn upgrade_inbound(self, io: C, _: Self::Info) -> Self::Future { let mode = self.mode.unwrap_or(yamux::Mode::Server); - future::ready(Ok(Yamux::new(io, self.inner, mode))) + future::ready(Ok(Muxer::new(io, self.inner, mode))) } } -impl InboundUpgrade for YamuxLocalConfig +impl InboundUpgrade for LocalConfig where C: AsyncRead + AsyncWrite + Unpin + 'static, { - type Output = Yamux>; + type Output = Muxer>; type Error = io::Error; type Future = future::Ready>; fn upgrade_inbound(self, io: C, _: Self::Info) -> Self::Future { let cfg = self.0; let mode = cfg.mode.unwrap_or(yamux::Mode::Server); - future::ready(Ok(Yamux::local(io, cfg.inner, mode))) + future::ready(Ok(Muxer::local(io, cfg.inner, mode))) } } -impl OutboundUpgrade for YamuxConfig +impl OutboundUpgrade for Config where C: AsyncRead + AsyncWrite + Send + Unpin + 'static, { - type Output = Yamux>; + type Output = Muxer>; type Error = io::Error; type Future = future::Ready>; fn upgrade_outbound(self, io: C, _: Self::Info) -> Self::Future { let mode = self.mode.unwrap_or(yamux::Mode::Client); - future::ready(Ok(Yamux::new(io, self.inner, mode))) + future::ready(Ok(Muxer::new(io, self.inner, mode))) } } -impl OutboundUpgrade for YamuxLocalConfig +impl OutboundUpgrade for LocalConfig where C: AsyncRead + AsyncWrite + Unpin + 'static, { - type Output = Yamux>; + type Output = Muxer>; type Error = io::Error; type Future = future::Ready>; fn upgrade_outbound(self, io: C, _: Self::Info) -> Self::Future { let cfg = self.0; let mode = cfg.mode.unwrap_or(yamux::Mode::Client); - future::ready(Ok(Yamux::local(io, cfg.inner, mode))) + future::ready(Ok(Muxer::local(io, cfg.inner, mode))) } } +#[deprecated(note = "Import the `yamux` module and refer to this type as `yamux::Error` instead.")] +pub type YamuxError = Error; + /// The Yamux [`StreamMuxer`] error type. #[derive(Debug, Error)] #[error("yamux error: {0}")] -pub struct YamuxError(#[from] yamux::ConnectionError); +pub struct Error(#[from] yamux::ConnectionError); -impl From for io::Error { - fn from(err: YamuxError) -> Self { +impl From for io::Error { + fn from(err: Error) -> Self { match err.0 { yamux::ConnectionError::Io(e) => e, e => io::Error::new(io::ErrorKind::Other, e), @@ -403,7 +415,7 @@ impl From for io::Error { /// The [`futures::stream::Stream`] of incoming substreams. pub struct Incoming { - stream: BoxStream<'static, Result>, + stream: BoxStream<'static, Result>, _marker: std::marker::PhantomData, } @@ -415,7 +427,7 @@ impl fmt::Debug for Incoming { /// The [`futures::stream::Stream`] of incoming substreams (`!Send`). pub struct LocalIncoming { - stream: LocalBoxStream<'static, Result>, + stream: LocalBoxStream<'static, Result>, _marker: std::marker::PhantomData, } @@ -426,7 +438,7 @@ impl fmt::Debug for LocalIncoming { } impl Stream for Incoming { - type Item = Result; + type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.stream.as_mut().poll_next_unpin(cx) @@ -440,7 +452,7 @@ impl Stream for Incoming { impl Unpin for Incoming {} impl Stream for LocalIncoming { - type Item = Result; + type Item = Result; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { self.stream.as_mut().poll_next_unpin(cx) diff --git a/muxers/yamux/tests/compliance.rs b/muxers/yamux/tests/compliance.rs index ba5161dde0d..14d69952b0e 100644 --- a/muxers/yamux/tests/compliance.rs +++ b/muxers/yamux/tests/compliance.rs @@ -1,10 +1,9 @@ -use libp2p_yamux::YamuxConfig; +use libp2p_yamux::Config; #[async_std::test] async fn close_implies_flush() { let (alice, bob) = - libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::() - .await; + libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::().await; libp2p_muxer_test_harness::close_implies_flush(alice, bob).await; } @@ -12,8 +11,7 @@ async fn close_implies_flush() { #[async_std::test] async fn read_after_close() { let (alice, bob) = - libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::() - .await; + libp2p_muxer_test_harness::connected_muxers_on_memory_ring_buffer::().await; libp2p_muxer_test_harness::read_after_close(alice, bob).await; } diff --git a/protocols/dcutr/tests/lib.rs b/protocols/dcutr/tests/lib.rs index cf725f75797..ba190782b12 100644 --- a/protocols/dcutr/tests/lib.rs +++ b/protocols/dcutr/tests/lib.rs @@ -121,7 +121,7 @@ fn build_client() -> Swarm { .or_transport(libp2p_tcp::async_io::Transport::default()) .upgrade(Version::V1) .authenticate(PlainText2Config { local_public_key }) - .multiplex(libp2p_yamux::YamuxConfig::default()) + .multiplex(libp2p_yamux::Config::default()) .boxed(); SwarmBuilder::without_executor( diff --git a/protocols/kad/src/behaviour/test.rs b/protocols/kad/src/behaviour/test.rs index f361a31f756..3f03842aff5 100644 --- a/protocols/kad/src/behaviour/test.rs +++ b/protocols/kad/src/behaviour/test.rs @@ -60,7 +60,7 @@ fn build_node_with_config(cfg: KademliaConfig) -> (Multiaddr, TestSwarm) { let transport = MemoryTransport::default() .upgrade(upgrade::Version::V1) .authenticate(noise::Config::new(&local_key).unwrap()) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); let local_id = local_public_key.to_peer_id(); diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index c11b865a8e0..4609b076220 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -24,7 +24,7 @@ libp2p-noise = { version = "0.42.2", path = "../../transports/noise" } libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] } libp2p-swarm = { version = "0.42.1", path = "../../swarm", features = ["macros", "async-std"] } libp2p-tcp = { version = "0.39.0", path = "../../transports/tcp", features = ["async-io"] } -libp2p-yamux = { version = "0.43.0", path = "../../muxers/yamux" } +libp2p-yamux = { version = "0.43.1", path = "../../muxers/yamux" } log = "0.4" thiserror = "1.0" void = "1" diff --git a/protocols/perf/src/bin/perf-client.rs b/protocols/perf/src/bin/perf-client.rs index a1d809ac1cb..ddf3708ef5c 100644 --- a/protocols/perf/src/bin/perf-client.rs +++ b/protocols/perf/src/bin/perf-client.rs @@ -55,7 +55,7 @@ async fn main() -> Result<()> { libp2p_noise::Config::new(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), ) - .multiplex(libp2p_yamux::YamuxConfig::default()); + .multiplex(libp2p_yamux::Config::default()); let quic = { let mut config = libp2p_quic::Config::new(&local_key); diff --git a/protocols/perf/src/bin/perf-server.rs b/protocols/perf/src/bin/perf-server.rs index 8499ccc602b..9219ed85723 100644 --- a/protocols/perf/src/bin/perf-server.rs +++ b/protocols/perf/src/bin/perf-server.rs @@ -49,7 +49,7 @@ async fn main() { libp2p_noise::Config::new(&local_key) .expect("Signing libp2p-noise static DH keypair failed."), ) - .multiplex(libp2p_yamux::YamuxConfig::default()); + .multiplex(libp2p_yamux::Config::default()); let quic = { let mut config = libp2p_quic::Config::new(&local_key); diff --git a/protocols/relay/tests/lib.rs b/protocols/relay/tests/lib.rs index 92538549ba1..2103893ba12 100644 --- a/protocols/relay/tests/lib.rs +++ b/protocols/relay/tests/lib.rs @@ -357,7 +357,7 @@ where transport .upgrade(upgrade::Version::V1) .authenticate(PlainText2Config { local_public_key }) - .multiplex(libp2p_yamux::YamuxConfig::default()) + .multiplex(libp2p_yamux::Config::default()) .boxed() } diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index ff26f228e0e..9c922a1c2ed 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -18,7 +18,7 @@ libp2p-identity = { version = "0.1.1", path = "../identity" } libp2p-plaintext = { version = "0.39.1", path = "../transports/plaintext" } libp2p-swarm = { version = "0.42.0", path = "../swarm" } libp2p-tcp = { version = "0.39.0", path = "../transports/tcp", features = ["async-io"] } -libp2p-yamux = { version = "0.43.0", path = "../muxers/yamux" } +libp2p-yamux = { version = "0.43.1", path = "../muxers/yamux" } futures = "0.3.28" log = "0.4.17" rand = "0.8.5" diff --git a/swarm-test/src/lib.rs b/swarm-test/src/lib.rs index 94bad497e8f..f93a1efcfe8 100644 --- a/swarm-test/src/lib.rs +++ b/swarm-test/src/lib.rs @@ -32,7 +32,7 @@ use libp2p_swarm::{ dial_opts::DialOpts, AddressScore, NetworkBehaviour, Swarm, SwarmBuilder, SwarmEvent, THandlerErr, }; -use libp2p_yamux::YamuxConfig; +use libp2p_yamux as yamux; use std::fmt::Debug; use std::time::Duration; @@ -216,7 +216,7 @@ where .authenticate(PlainText2Config { local_public_key: identity.public(), }) - .multiplex(YamuxConfig::default()) + .multiplex(yamux::Config::default()) .timeout(Duration::from_secs(20)) .boxed(); diff --git a/swarm/src/lib.rs b/swarm/src/lib.rs index 3fba83cd44d..4ac5a59c089 100644 --- a/swarm/src/lib.rs +++ b/swarm/src/lib.rs @@ -2067,7 +2067,7 @@ mod tests { .authenticate(plaintext::PlainText2Config { local_public_key: local_public_key.clone(), }) - .multiplex(yamux::YamuxConfig::default()) + .multiplex(yamux::Config::default()) .boxed(); let behaviour = CallTraceBehaviour::new(MockBehaviour::new(handler_proto)); match ThreadPool::new().ok() { diff --git a/transports/pnet/tests/smoke.rs b/transports/pnet/tests/smoke.rs index 66fa01b7222..a7635c00ca3 100644 --- a/transports/pnet/tests/smoke.rs +++ b/transports/pnet/tests/smoke.rs @@ -111,7 +111,7 @@ where .and_then(move |socket, _| pnet.handshake(socket)) .upgrade(Version::V1) .authenticate(libp2p_noise::Config::new(&identity).unwrap()) - .multiplex(libp2p_yamux::YamuxConfig::default()) + .multiplex(libp2p_yamux::Config::default()) .boxed(); SwarmBuilder::with_tokio_executor( transport, diff --git a/transports/quic/tests/smoke.rs b/transports/quic/tests/smoke.rs index 0fe6a65c081..a576d3c9ef5 100644 --- a/transports/quic/tests/smoke.rs +++ b/transports/quic/tests/smoke.rs @@ -234,7 +234,7 @@ fn new_tcp_quic_transport() -> (PeerId, Boxed<(PeerId, StreamMuxerBox)>) { let tcp_transport = tcp::async_io::Transport::new(tcp::Config::default()) .upgrade(upgrade::Version::V1) .authenticate(noise::Config::new(&keypair).unwrap()) - .multiplex(yamux::YamuxConfig::default()); + .multiplex(yamux::Config::default()); let transport = OrTransport::new(quic_transport, tcp_transport) .map(|either_output, _| match either_output { diff --git a/transports/tls/tests/smoke.rs b/transports/tls/tests/smoke.rs index 9db82f0a693..17aa959c4b2 100644 --- a/transports/tls/tests/smoke.rs +++ b/transports/tls/tests/smoke.rs @@ -61,7 +61,7 @@ fn make_swarm() -> Swarm { let transport = MemoryTransport::default() .upgrade(Version::V1) .authenticate(libp2p_tls::Config::new(&identity).unwrap()) - .multiplex(libp2p_yamux::YamuxConfig::default()) + .multiplex(libp2p_yamux::Config::default()) .boxed(); SwarmBuilder::without_executor( From 2d9ae3800f39fcbbc55e5305b4e2a33ed76cbe5a Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 1 May 2023 04:56:32 +0200 Subject: [PATCH 43/57] chore: prepare patch releases on top of v0.51.3 Note that this does not release v0.51.4, i.e. there is no patch release of the meta crate `libp2p`. Pull-Request: #3854. --- core/CHANGELOG.md | 2 +- identity/CHANGELOG.md | 2 +- misc/allow-block-list/CHANGELOG.md | 2 +- muxers/yamux/CHANGELOG.md | 2 +- protocols/gossipsub/CHANGELOG.md | 2 +- protocols/identify/CHANGELOG.md | 2 +- protocols/kad/CHANGELOG.md | 2 +- protocols/request-response/CHANGELOG.md | 2 +- swarm/CHANGELOG.md | 2 +- transports/noise/CHANGELOG.md | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index 9cd4ca30de0..f2507ded5c9 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.39.2 - unreleased +## 0.39.2 - Deprecate `upgrade::from_fn` without replacement as it is not used within `rust-libp2p`. If you depend on it, we suggest you vendor it. diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 50876f4c156..0d2851ac6e2 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.1.2 - unreleased +## 0.1.2 - Add `impl From for PublicKey` so that `PublicKey::from(ed25519::PublicKey)` works. See [PR 3805]. diff --git a/misc/allow-block-list/CHANGELOG.md b/misc/allow-block-list/CHANGELOG.md index 52633fb6629..68566e5b57d 100644 --- a/misc/allow-block-list/CHANGELOG.md +++ b/misc/allow-block-list/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.1.1 - unreleased +## 0.1.1 - Correctly unblock and disallow peer in `unblock_peer` and `disallow_peer` functions. See [PR 3789]. diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index 6cd334b46a0..eb235887242 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.43.1 - unreleased +## 0.43.1 - Drop `Yamux` prefix from all types. Users are encouraged to import the `yamux` module and refer to types via `yamux::Muxer`, `yamux::Config` etc. diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index 8e292b87b05..c1e688c1200 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.44.4 - unreleased +## 0.44.4 - Deprecate `metrics`, `protocol`, `subscription_filter`, `time_cache` modules to make them private. See [PR 3777]. - Honor the `gossipsub::Config::support_floodsub` in all cases. diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 1869db55678..3915f92f88c 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.42.2 - unreleased +## 0.42.2 - Do not implicitly dial a peer upon `identify::Behaviour::push`. Previously, we would dial each peer in the provided list. diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index cb33d9d62ff..123acbf5ef8 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.43.3 - unreleased +## 0.43.3 - Preserve existing `KeepAlive::Until` timeout instead of continuously setting new `KeepAlive::Until(Instant::now() + self.config.idle_timeout)`. See [PR 3801]. diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index ac237dbdffd..ecb524d7c11 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.24.1 - unreleased +## 0.24.1 - Deprecate `handler`, `codec` modules to make them private. See [PR 3847]. diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 03d128d76b7..7198f898995 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.42.2 - unreleased +## 0.42.2 - Add `ConnectionEvent::{is_outbound,is_inbound}`. See [PR 3625]. diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index f9c51382a65..a2809467885 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.42.2 - unreleased +## 0.42.2 - Deprecate all noise handshakes apart from XX. This deprecates `NoiseConfig` and `NoiseAuthenticated` in favor of a new `libp2p_noise::Config` struct. From c8a064b74c337b3d2250f083fd7678cec53949cd Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Mon, 1 May 2023 04:22:39 -0400 Subject: [PATCH 44/57] chore(doc): Add missing PR to yamux CHANGELOG.md Add missing PR to yamux CHANGELOG.md Pull-Request: #3855. --- muxers/yamux/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index eb235887242..8308bd6cb4f 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -2,9 +2,9 @@ - Drop `Yamux` prefix from all types. Users are encouraged to import the `yamux` module and refer to types via `yamux::Muxer`, `yamux::Config` etc. - See [PR XXXX]. + See [PR 3852]. -[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX +[PR 3852]: https://github.com/libp2p/rust-libp2p/pull/3852 ## 0.43.0 From d1fadc592d676de1c7fc3363a063196780ae4386 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 1 May 2023 16:10:37 +0200 Subject: [PATCH 45/57] fix(identity): handle warnings related to feature flags Some of the feature-flags weren't set correctly and thus produced warnings for unused code. We can fix this by using absolute paths instead of imports and allow `dead_code` for the error constructor. It might be possible to write a correct `cfg` for this as well but I think it will be very verbose, hence I didn't bother. Pull-Request: #3859. --- identity/src/error.rs | 1 + identity/src/keypair.rs | 50 ++++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/identity/src/error.rs b/identity/src/error.rs index 79ef21d5c44..1ac945e71e9 100644 --- a/identity/src/error.rs +++ b/identity/src/error.rs @@ -166,6 +166,7 @@ pub struct OtherVariantError { } impl OtherVariantError { + #[allow(dead_code)] // This is used but the cfg is too complicated to write .. pub(crate) fn new(actual: KeyType) -> OtherVariantError { OtherVariantError { actual } } diff --git a/identity/src/keypair.rs b/identity/src/keypair.rs index 6b76f5638de..6f21125ff17 100644 --- a/identity/src/keypair.rs +++ b/identity/src/keypair.rs @@ -20,7 +20,7 @@ use crate::error::OtherVariantError; use crate::error::{DecodingError, SigningError}; -use crate::{proto, KeyType}; +use crate::proto; use quick_protobuf::{BytesReader, Writer}; use std::convert::TryFrom; @@ -322,11 +322,11 @@ impl TryInto for Keypair { match self { Keypair::Ed25519(inner) => Ok(inner), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - Keypair::Rsa(_) => Err(OtherVariantError::new(KeyType::RSA)), + Keypair::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)), #[cfg(feature = "secp256k1")] - Keypair::Secp256k1(_) => Err(OtherVariantError::new(KeyType::Secp256k1)), + Keypair::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)), #[cfg(feature = "ecdsa")] - Keypair::Ecdsa(_) => Err(OtherVariantError::new(KeyType::Ecdsa)), + Keypair::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)), } } } @@ -340,11 +340,11 @@ impl TryInto for Keypair { match self { Keypair::Ecdsa(inner) => Ok(inner), #[cfg(feature = "ed25519")] - Keypair::Ed25519(_) => Err(OtherVariantError::new(KeyType::Ed25519)), + Keypair::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - Keypair::Rsa(_) => Err(OtherVariantError::new(KeyType::RSA)), + Keypair::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)), #[cfg(feature = "secp256k1")] - Keypair::Secp256k1(_) => Err(OtherVariantError::new(KeyType::Secp256k1)), + Keypair::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)), } } } @@ -358,11 +358,11 @@ impl TryInto for Keypair { match self { Keypair::Secp256k1(inner) => Ok(inner), #[cfg(feature = "ed25519")] - Keypair::Ed25519(_) => Err(OtherVariantError::new(KeyType::Ed25519)), + Keypair::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - Keypair::Rsa(_) => Err(OtherVariantError::new(KeyType::RSA)), + Keypair::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)), #[cfg(feature = "ecdsa")] - Keypair::Ecdsa(_) => Err(OtherVariantError::new(KeyType::Ecdsa)), + Keypair::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)), } } } @@ -376,11 +376,11 @@ impl TryInto for Keypair { match self { Keypair::Rsa(inner) => Ok(inner), #[cfg(feature = "ed25519")] - Keypair::Ed25519(_) => Err(OtherVariantError::new(KeyType::Ed25519)), + Keypair::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)), #[cfg(feature = "secp256k1")] - Keypair::Secp256k1(_) => Err(OtherVariantError::new(KeyType::Secp256k1)), + Keypair::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)), #[cfg(feature = "ecdsa")] - Keypair::Ecdsa(_) => Err(OtherVariantError::new(KeyType::Ecdsa)), + Keypair::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)), } } } @@ -597,11 +597,11 @@ impl TryInto for PublicKey { match self { PublicKey::Ed25519(inner) => Ok(inner), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - PublicKey::Rsa(_) => Err(OtherVariantError::new(KeyType::RSA)), + PublicKey::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)), #[cfg(feature = "secp256k1")] - PublicKey::Secp256k1(_) => Err(OtherVariantError::new(KeyType::Secp256k1)), + PublicKey::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)), #[cfg(feature = "ecdsa")] - PublicKey::Ecdsa(_) => Err(OtherVariantError::new(KeyType::Ecdsa)), + PublicKey::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)), } } } @@ -615,11 +615,11 @@ impl TryInto for PublicKey { match self { PublicKey::Ecdsa(inner) => Ok(inner), #[cfg(feature = "ed25519")] - PublicKey::Ed25519(_) => Err(OtherVariantError::new(KeyType::Ed25519)), + PublicKey::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - PublicKey::Rsa(_) => Err(OtherVariantError::new(KeyType::RSA)), + PublicKey::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)), #[cfg(feature = "secp256k1")] - PublicKey::Secp256k1(_) => Err(OtherVariantError::new(KeyType::Secp256k1)), + PublicKey::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)), } } } @@ -633,11 +633,11 @@ impl TryInto for PublicKey { match self { PublicKey::Secp256k1(inner) => Ok(inner), #[cfg(feature = "ed25519")] - PublicKey::Ed25519(_) => Err(OtherVariantError::new(KeyType::Ed25519)), + PublicKey::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)), #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] - PublicKey::Rsa(_) => Err(OtherVariantError::new(KeyType::RSA)), + PublicKey::Rsa(_) => Err(OtherVariantError::new(crate::KeyType::RSA)), #[cfg(feature = "ecdsa")] - PublicKey::Ecdsa(_) => Err(OtherVariantError::new(KeyType::Ecdsa)), + PublicKey::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)), } } } @@ -651,11 +651,11 @@ impl TryInto for PublicKey { match self { PublicKey::Rsa(inner) => Ok(inner), #[cfg(feature = "ed25519")] - PublicKey::Ed25519(_) => Err(OtherVariantError::new(KeyType::Ed25519)), + PublicKey::Ed25519(_) => Err(OtherVariantError::new(crate::KeyType::Ed25519)), #[cfg(feature = "secp256k1")] - PublicKey::Secp256k1(_) => Err(OtherVariantError::new(KeyType::Secp256k1)), + PublicKey::Secp256k1(_) => Err(OtherVariantError::new(crate::KeyType::Secp256k1)), #[cfg(feature = "ecdsa")] - PublicKey::Ecdsa(_) => Err(OtherVariantError::new(KeyType::Ecdsa)), + PublicKey::Ecdsa(_) => Err(OtherVariantError::new(crate::KeyType::Ecdsa)), } } } From 996b5c8bd059e6753fae09f15561915cc5f20ce8 Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 2 May 2023 11:14:14 +0200 Subject: [PATCH 46/57] chore: leverage `cargo`'s workspace inheritance Previously, we would specify the version and path of our workspace dependencies in each of our crates. This is error prone as https://github.com/libp2p/rust-libp2p/pull/3658#discussion_r1153278072 for example shows. Problems like these happened in the past too. There is no need for us to ever depend on a earlier version than the most current one in our crates. It thus makes sense that we manage this version in a single place. Cargo supports a feature called "workspace inheritance" which allows us to share a dependency declaration across a workspace and inherit it with `{ workspace = true }`. We do this for all our workspace dependencies and for the MSRV. Resolves #3787. Pull-Request: #3715. --- .github/workflows/cache-factory.yml | 42 ++----------- .github/workflows/ci.yml | 61 +++++++++++------- Cargo.lock | 78 ++++++++++++------------ Cargo.toml | 44 +++++++++++++ core/CHANGELOG.md | 7 +++ core/Cargo.toml | 16 ++--- docs/release.md | 7 ++- identity/CHANGELOG.md | 7 +++ identity/Cargo.toml | 6 +- interop-tests/Cargo.toml | 4 +- libp2p/CHANGELOG.md | 7 +++ libp2p/Cargo.toml | 73 +++++++++++----------- misc/allow-block-list/CHANGELOG.md | 7 +++ misc/allow-block-list/Cargo.toml | 14 ++--- misc/connection-limits/CHANGELOG.md | 7 +++ misc/connection-limits/Cargo.toml | 20 +++--- misc/connection-limits/src/lib.rs | 2 +- misc/keygen/Cargo.toml | 4 +- misc/metrics/CHANGELOG.md | 7 +++ misc/metrics/Cargo.toml | 20 +++--- misc/multistream-select/CHANGELOG.md | 7 +++ misc/multistream-select/Cargo.toml | 18 +++--- misc/multistream-select/src/lib.rs | 9 +-- misc/quick-protobuf-codec/CHANGELOG.md | 7 +++ misc/quick-protobuf-codec/Cargo.toml | 4 +- misc/rw-stream-sink/CHANGELOG.md | 7 +++ misc/rw-stream-sink/Cargo.toml | 4 +- muxers/mplex/CHANGELOG.md | 7 +++ muxers/mplex/Cargo.toml | 16 ++--- muxers/test-harness/Cargo.toml | 2 +- muxers/yamux/CHANGELOG.md | 7 +++ muxers/yamux/Cargo.toml | 8 +-- protocols/autonat/CHANGELOG.md | 7 +++ protocols/autonat/Cargo.toml | 14 ++--- protocols/dcutr/CHANGELOG.md | 7 +++ protocols/dcutr/Cargo.toml | 32 +++++----- protocols/floodsub/CHANGELOG.md | 7 +++ protocols/floodsub/Cargo.toml | 12 ++-- protocols/gossipsub/CHANGELOG.md | 7 +++ protocols/gossipsub/Cargo.toml | 22 +++---- protocols/gossipsub/src/behaviour.rs | 2 +- protocols/gossipsub/src/protocol_priv.rs | 2 +- protocols/gossipsub/tests/smoke.rs | 2 +- protocols/identify/CHANGELOG.md | 7 +++ protocols/identify/Cargo.toml | 22 +++---- protocols/kad/CHANGELOG.md | 7 +++ protocols/kad/Cargo.toml | 14 ++--- protocols/mdns/CHANGELOG.md | 7 +++ protocols/mdns/Cargo.toml | 20 +++--- protocols/perf/CHANGELOG.md | 7 +++ protocols/perf/Cargo.toml | 22 +++---- protocols/ping/CHANGELOG.md | 7 +++ protocols/ping/Cargo.toml | 16 ++--- protocols/relay/CHANGELOG.md | 7 +++ protocols/relay/Cargo.toml | 22 +++---- protocols/rendezvous/CHANGELOG.md | 7 +++ protocols/rendezvous/Cargo.toml | 28 ++++----- protocols/request-response/CHANGELOG.md | 7 +++ protocols/request-response/Cargo.toml | 18 +++--- swarm-derive/CHANGELOG.md | 7 +++ swarm-derive/Cargo.toml | 4 +- swarm-test/CHANGELOG.md | 7 +++ swarm-test/Cargo.toml | 14 ++--- swarm/CHANGELOG.md | 7 +++ swarm/Cargo.toml | 28 ++++----- transports/deflate/CHANGELOG.md | 7 +++ transports/deflate/Cargo.toml | 10 +-- transports/dns/CHANGELOG.md | 7 +++ transports/dns/Cargo.toml | 8 +-- transports/noise/CHANGELOG.md | 7 +++ transports/noise/Cargo.toml | 12 ++-- transports/plaintext/CHANGELOG.md | 7 +++ transports/plaintext/Cargo.toml | 12 ++-- transports/pnet/CHANGELOG.md | 7 +++ transports/pnet/Cargo.toml | 20 +++--- transports/quic/CHANGELOG.md | 7 +++ transports/quic/Cargo.toml | 18 +++--- transports/tcp/CHANGELOG.md | 7 +++ transports/tcp/Cargo.toml | 8 +-- transports/tls/CHANGELOG.md | 7 +++ transports/tls/Cargo.toml | 16 ++--- transports/uds/CHANGELOG.md | 7 +++ transports/uds/Cargo.toml | 6 +- transports/wasm-ext/CHANGELOG.md | 7 +++ transports/wasm-ext/Cargo.toml | 6 +- transports/webrtc/CHANGELOG.md | 7 +++ transports/webrtc/Cargo.toml | 16 ++--- transports/websocket/CHANGELOG.md | 7 +++ transports/websocket/Cargo.toml | 14 ++--- 89 files changed, 726 insertions(+), 432 deletions(-) diff --git a/.github/workflows/cache-factory.yml b/.github/workflows/cache-factory.yml index 5d2a77791b7..2f4e807f7d9 100644 --- a/.github/workflows/cache-factory.yml +++ b/.github/workflows/cache-factory.yml @@ -1,5 +1,7 @@ -# This workflow _produces_ caches which are used to speed up pull request builds. -# The caches are split by Rust version (stable vs MSRV per crate) because those caches cannot share any artifacts. +# This workflow _produces_ a cache that is used to speed up pull request builds. +# +# Our CI runs a job per crate, meaning all jobs share compilation artifacts but never the full cache. +# Thus, we make a single cache here that is used by all jobs and the jobs only read from this cache. name: Cache factory @@ -13,42 +15,6 @@ concurrency: cancel-in-progress: true jobs: - gather_msrv_versions: - runs-on: ubuntu-latest - outputs: - versions: ${{ steps.find-rust-versions.outputs.versions }} - steps: - - uses: actions/checkout@v3 - - - id: find-rust-versions - run: | - RUST_VERSIONS=$(cargo metadata --format-version=1 --no-deps | jq -c '.packages | map(.rust_version) | unique | del(..|nulls)') - echo "versions=${RUST_VERSIONS}" >> $GITHUB_OUTPUT - - make_msrv_cache: - runs-on: ubuntu-latest - needs: gather_msrv_versions - strategy: - fail-fast: false - matrix: - rust: ${{ fromJSON(needs.gather_msrv_versions.outputs.versions) }} - steps: - - uses: actions/checkout@v3 - - - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust }} - - - uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1 - with: - shared-key: msrv-cache - - - name: Compile all crates which have MSRV ${{ matrix.rust }} - run: | - cargo metadata --format-version=1 --no-deps | \ - jq -r '.packages[] | select(.rust_version == "${{ matrix.rust }}") | "+\(.rust_version) build --all-features --package \(.name)"' | - xargs --verbose -L 1 cargo - make_stable_rust_cache: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3460d3ec148..f884617293f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,32 +32,10 @@ jobs: - name: Install Protoc run: sudo apt-get install -y protobuf-compiler - - uses: dtolnay/rust-toolchain@stable - - uses: actions/checkout@v3 - - name: Get MSRV for ${{ matrix.crate }} - id: parse-msrv - run: | - RUST_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[] | select(.name == "${{ matrix.crate }}") | .rust_version') - echo "version=${RUST_VERSION}" >> $GITHUB_OUTPUT - shell: bash - - - name: Install Rust ${{ steps.parse-msrv.outputs.version }} for MSRV check - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ steps.parse-msrv.outputs.version }} - - uses: r7kamura/rust-problem-matchers@d58b70c4a13c4866d96436315da451d8106f8f08 #v1.3.0 - - uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1 - with: - shared-key: msrv-cache - save-if: false - - - name: Check if ${{ matrix.crate }} compiles on MSRV (Rust ${{ steps.parse-msrv.outputs.version }}) - run: cargo +${{ steps.parse-msrv.outputs.version }} build --package ${{ matrix.crate }} --all-features - - uses: dtolnay/rust-toolchain@stable - uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1 @@ -90,6 +68,21 @@ jobs: cargo metadata --format-version=1 --no-deps | \ jq -e -r '.packages[] | select(.name == "${{ matrix.crate }}") | .dependencies | all(.name != "libp2p")' + - uses: taiki-e/cache-cargo-install-action@7dd0cff2732612ac642812bcec4ada5a279239ed # v1 + with: + tool: tomlq + + - name: Enforce version in `workspace.dependencies` matches latest version + if: matrix.crate != 'libp2p' + run: | + PACKAGE_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -e -r '.packages[] | select(.name == "${{ matrix.crate }}") | .version') + SPECIFIED_VERSION=$(tomlq 'workspace.dependencies.${{ matrix.crate }}.version' --file ./Cargo.toml) + + echo "Package version: $PACKAGE_VERSION"; + echo "Specified version: $SPECIFIED_VERSION"; + + test "$PACKAGE_VERSION" = "$SPECIFIED_VERSION" + cross: name: Compile on ${{ matrix.target }} strategy: @@ -122,6 +115,30 @@ jobs: - run: cargo check --package libp2p --all-features --target=${{ matrix.target }} + msrv: + name: Compile with MSRV + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Extract MSRV from workspace manifest + shell: bash + run: | + MSRV=$(grep -oP 'rust-version\s*=\s*"\K[^"]+' Cargo.toml) + echo "MSRV=$MSRV" >> $GITHUB_ENV + + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.MSRV }} + + - uses: r7kamura/rust-problem-matchers@d58b70c4a13c4866d96436315da451d8106f8f08 #v1.3.0 + + - uses: Swatinem/rust-cache@6fd3edff6979b79f87531400ad694fb7f2c84b1f # v2.2.1 + with: + save-if: ${{ github.ref == 'refs/heads/master' }} + + - run: cargo +$MSRV check --workspace --all-features + feature_matrix: # Test various feature combinations work correctly name: Compile with select features (${{ matrix.features }}) runs-on: ubuntu-latest diff --git a/Cargo.lock b/Cargo.lock index 890eb5583ac..a883c7e6b0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2272,7 +2272,7 @@ checksum = "7fc7aa29613bd6a620df431842069224d8bc9011086b1db4c0e0cd47fa03ec9a" [[package]] name = "libp2p" -version = "0.51.3" +version = "0.52.0" dependencies = [ "async-std", "async-trait", @@ -2323,7 +2323,7 @@ dependencies = [ [[package]] name = "libp2p-allow-block-list" -version = "0.1.1" +version = "0.2.0" dependencies = [ "async-std", "libp2p-core", @@ -2336,7 +2336,7 @@ dependencies = [ [[package]] name = "libp2p-autonat" -version = "0.10.2" +version = "0.11.0" dependencies = [ "async-std", "async-trait", @@ -2356,7 +2356,7 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" -version = "0.1.0" +version = "0.2.0" dependencies = [ "async-std", "libp2p-core", @@ -2373,7 +2373,7 @@ dependencies = [ [[package]] name = "libp2p-core" -version = "0.39.2" +version = "0.40.0" dependencies = [ "async-std", "either", @@ -2404,7 +2404,7 @@ dependencies = [ [[package]] name = "libp2p-dcutr" -version = "0.9.1" +version = "0.10.0" dependencies = [ "async-std", "asynchronous-codec", @@ -2436,19 +2436,21 @@ dependencies = [ [[package]] name = "libp2p-deflate" -version = "0.39.0" +version = "0.40.0" dependencies = [ + "async-std", "flate2", "futures", "futures_ringbuf", "libp2p-core", + "libp2p-tcp", "quickcheck-ext", "rand 0.8.5", ] [[package]] name = "libp2p-dns" -version = "0.39.0" +version = "0.40.0" dependencies = [ "async-std", "async-std-resolver", @@ -2465,7 +2467,7 @@ dependencies = [ [[package]] name = "libp2p-floodsub" -version = "0.42.1" +version = "0.43.0" dependencies = [ "asynchronous-codec", "cuckoofilter", @@ -2484,7 +2486,7 @@ dependencies = [ [[package]] name = "libp2p-gossipsub" -version = "0.44.4" +version = "0.45.0" dependencies = [ "async-std", "asynchronous-codec", @@ -2522,7 +2524,7 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.42.2" +version = "0.43.0" dependencies = [ "async-std", "asynchronous-codec", @@ -2548,7 +2550,7 @@ dependencies = [ [[package]] name = "libp2p-identity" -version = "0.1.2" +version = "0.2.0" dependencies = [ "asn1_der", "base64 0.21.0", @@ -2576,7 +2578,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.43.3" +version = "0.44.0" dependencies = [ "arrayvec", "asynchronous-codec", @@ -2607,7 +2609,7 @@ dependencies = [ [[package]] name = "libp2p-mdns" -version = "0.43.1" +version = "0.44.0" dependencies = [ "async-io", "async-std", @@ -2633,7 +2635,7 @@ dependencies = [ [[package]] name = "libp2p-metrics" -version = "0.12.0" +version = "0.13.0" dependencies = [ "libp2p-core", "libp2p-dcutr", @@ -2649,7 +2651,7 @@ dependencies = [ [[package]] name = "libp2p-mplex" -version = "0.39.0" +version = "0.40.0" dependencies = [ "async-std", "asynchronous-codec", @@ -2684,7 +2686,7 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.42.2" +version = "0.43.0" dependencies = [ "async-io", "bytes", @@ -2709,7 +2711,7 @@ dependencies = [ [[package]] name = "libp2p-perf" -version = "0.1.0" +version = "0.2.0" dependencies = [ "anyhow", "async-std", @@ -2734,7 +2736,7 @@ dependencies = [ [[package]] name = "libp2p-ping" -version = "0.42.0" +version = "0.43.0" dependencies = [ "async-std", "either", @@ -2754,7 +2756,7 @@ dependencies = [ [[package]] name = "libp2p-plaintext" -version = "0.39.1" +version = "0.40.0" dependencies = [ "asynchronous-codec", "bytes", @@ -2773,7 +2775,7 @@ dependencies = [ [[package]] name = "libp2p-pnet" -version = "0.22.3" +version = "0.23.0" dependencies = [ "futures", "libp2p-core", @@ -2794,7 +2796,7 @@ dependencies = [ [[package]] name = "libp2p-quic" -version = "0.7.0-alpha.3" +version = "0.8.0-alpha" dependencies = [ "async-std", "bytes", @@ -2821,7 +2823,7 @@ dependencies = [ [[package]] name = "libp2p-relay" -version = "0.15.2" +version = "0.16.0" dependencies = [ "asynchronous-codec", "bytes", @@ -2848,7 +2850,7 @@ dependencies = [ [[package]] name = "libp2p-rendezvous" -version = "0.12.1" +version = "0.13.0" dependencies = [ "async-trait", "asynchronous-codec", @@ -2878,7 +2880,7 @@ dependencies = [ [[package]] name = "libp2p-request-response" -version = "0.24.1" +version = "0.25.0" dependencies = [ "async-std", "async-trait", @@ -2898,7 +2900,7 @@ dependencies = [ [[package]] name = "libp2p-swarm" -version = "0.42.2" +version = "0.43.0" dependencies = [ "async-std", "either", @@ -2928,7 +2930,7 @@ dependencies = [ [[package]] name = "libp2p-swarm-derive" -version = "0.32.0" +version = "0.33.0" dependencies = [ "heck", "quote", @@ -2937,7 +2939,7 @@ dependencies = [ [[package]] name = "libp2p-swarm-test" -version = "0.1.0" +version = "0.2.0" dependencies = [ "async-trait", "futures", @@ -2954,7 +2956,7 @@ dependencies = [ [[package]] name = "libp2p-tcp" -version = "0.39.0" +version = "0.40.0" dependencies = [ "async-io", "async-std", @@ -2972,7 +2974,7 @@ dependencies = [ [[package]] name = "libp2p-tls" -version = "0.1.0" +version = "0.2.0" dependencies = [ "futures", "futures-rustls", @@ -2994,7 +2996,7 @@ dependencies = [ [[package]] name = "libp2p-uds" -version = "0.38.0" +version = "0.39.0" dependencies = [ "async-std", "futures", @@ -3006,7 +3008,7 @@ dependencies = [ [[package]] name = "libp2p-wasm-ext" -version = "0.39.0" +version = "0.40.0" dependencies = [ "futures", "js-sys", @@ -3018,7 +3020,7 @@ dependencies = [ [[package]] name = "libp2p-webrtc" -version = "0.4.0-alpha.4" +version = "0.5.0-alpha" dependencies = [ "anyhow", "async-trait", @@ -3056,7 +3058,7 @@ dependencies = [ [[package]] name = "libp2p-websocket" -version = "0.41.0" +version = "0.42.0" dependencies = [ "async-std", "either", @@ -3078,7 +3080,7 @@ dependencies = [ [[package]] name = "libp2p-yamux" -version = "0.43.1" +version = "0.44.0" dependencies = [ "async-std", "futures", @@ -3357,7 +3359,7 @@ dependencies = [ [[package]] name = "multistream-select" -version = "0.12.1" +version = "0.13.0" dependencies = [ "async-std", "bytes", @@ -3933,7 +3935,7 @@ dependencies = [ [[package]] name = "quick-protobuf-codec" -version = "0.1.0" +version = "0.2.0" dependencies = [ "asynchronous-codec", "bytes", @@ -4388,7 +4390,7 @@ dependencies = [ [[package]] name = "rw-stream-sink" -version = "0.3.0" +version = "0.4.0" dependencies = [ "async-std", "futures", diff --git a/Cargo.toml b/Cargo.toml index 280eb094675..8400238368d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,3 +55,47 @@ members = [ "transports/websocket", ] resolver = "2" + +[workspace.package] +rust-version = "1.65.0" + +[workspace.dependencies] +libp2p-allow-block-list = { version = "0.2.0", path = "misc/allow-block-list" } +libp2p-autonat = { version = "0.11.0", path = "protocols/autonat" } +libp2p-connection-limits = { version = "0.2.0", path = "misc/connection-limits" } +libp2p-core = { version = "0.40.0", path = "core" } +libp2p-dcutr = { version = "0.10.0", path = "protocols/dcutr" } +libp2p-deflate = { version = "0.40.0", path = "transports/deflate" } +libp2p-dns = { version = "0.40.0", path = "transports/dns" } +libp2p-floodsub = { version = "0.43.0", path = "protocols/floodsub" } +libp2p-gossipsub = { version = "0.45.0", path = "protocols/gossipsub" } +libp2p-identify = { version = "0.43.0", path = "protocols/identify" } +libp2p-identity = { version = "0.2.0", path = "identity" } +libp2p-kad = { version = "0.44.0", path = "protocols/kad" } +libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } +libp2p-metrics = { version = "0.13.0", path = "misc/metrics" } +libp2p-mplex = { version = "0.40.0", path = "muxers/mplex" } +libp2p-muxer-test-harness = { version = "0.1.0", path = "muxers/test-harness" } +libp2p-noise = { version = "0.43.0", path = "transports/noise" } +libp2p-perf = { version = "0.2.0", path = "protocols/perf" } +libp2p-ping = { version = "0.43.0", path = "protocols/ping" } +libp2p-plaintext = { version = "0.40.0", path = "transports/plaintext" } +libp2p-pnet = { version = "0.23.0", path = "transports/pnet" } +libp2p-quic = { version = "0.8.0-alpha", path = "transports/quic" } +libp2p-relay = { version = "0.16.0", path = "protocols/relay" } +libp2p-rendezvous = { version = "0.13.0", path = "protocols/rendezvous" } +libp2p-request-response = { version = "0.25.0", path = "protocols/request-response" } +libp2p-swarm = { version = "0.43.0", path = "swarm" } +libp2p-swarm-derive = { version = "0.33.0", path = "swarm-derive" } +libp2p-swarm-test = { version = "0.2.0", path = "swarm-test" } +libp2p-tcp = { version = "0.40.0", path = "transports/tcp" } +libp2p-tls = { version = "0.2.0", path = "transports/tls" } +libp2p-uds = { version = "0.39.0", path = "transports/uds" } +libp2p-wasm-ext = { version = "0.40.0", path = "transports/wasm-ext" } +libp2p-webrtc = { version = "0.5.0-alpha", path = "transports/webrtc" } +libp2p-websocket = { version = "0.42.0", path = "transports/websocket" } +libp2p-yamux = { version = "0.44.0", path = "muxers/yamux" } +multistream-select = { version = "0.13.0", path = "misc/multistream-select" } +quick-protobuf-codec = { version = "0.2.0", path = "misc/quick-protobuf-codec" } +quickcheck = { package = "quickcheck-ext", path = "misc/quickcheck-ext" } +rw-stream-sink = { version = "0.4.0", path = "misc/rw-stream-sink" } diff --git a/core/CHANGELOG.md b/core/CHANGELOG.md index f2507ded5c9..3f9854d89d6 100644 --- a/core/CHANGELOG.md +++ b/core/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.2 - Deprecate `upgrade::from_fn` without replacement as it is not used within `rust-libp2p`. diff --git a/core/Cargo.toml b/core/Cargo.toml index 60fa51c904b..6812e5f3b34 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-core" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Core traits and structs of libp2p" -version = "0.39.2" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,17 +16,17 @@ fnv = "1.0" futures = { version = "0.3.28", features = ["executor", "thread-pool"] } futures-timer = "3" instant = "0.1.11" -libp2p-identity = { version = "0.1", path = "../identity", features = ["peerid", "ed25519"] } +libp2p-identity = { workspace = true, features = ["peerid", "ed25519"] } log = "0.4" multiaddr = { version = "0.17.1" } multihash = { version = "0.17.0", default-features = false, features = ["std"] } -multistream-select = { version = "0.12.1", path = "../misc/multistream-select" } +multistream-select = { workspace = true } once_cell = "1.17.1" parking_lot = "0.12.0" pin-project = "1.0.0" quick-protobuf = "0.8" rand = "0.8" -rw-stream-sink = { version = "0.3.0", path = "../misc/rw-stream-sink" } +rw-stream-sink = { workspace = true } serde = { version = "1", optional = true, features = ["derive"] } smallvec = "1.6.1" thiserror = "1.0" @@ -35,10 +35,10 @@ void = "1" [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } -libp2p-mplex = { path = "../muxers/mplex" } -libp2p-noise = { path = "../transports/noise" } +libp2p-mplex = { workspace = true } +libp2p-noise = { workspace = true } multihash = { version = "0.17.0", default-features = false, features = ["arb"] } -quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } +quickcheck = { workspace = true } [features] secp256k1 = [ "libp2p-identity/secp256k1" ] diff --git a/docs/release.md b/docs/release.md index 1698c36be12..5b4d32aedaf 100644 --- a/docs/release.md +++ b/docs/release.md @@ -22,9 +22,10 @@ The next unreleased version is tagged with ` - unreleased`, for example: `0.17.0 In case there isn't a version with an ` - unreleased` postfix yet, add one for the next version. The next version number depends on the impact of your change (breaking vs non-breaking, see above). -If you are making a non-breaking change, please also bump the version number in the `Cargo.toml` manifest. -In case another crate _depends_ on the new features or APIs that you are adding, you may need to bump the dependency declaration in that `Cargo.toml` file as well. -Don't worry if you don't get this one right, we will flag it in the PR if necessary :) +If you are making a non-breaking change, please also bump the version number: + +- in the `Cargo.toml` manifest of the respective crate +- in the `[workspace.dependencies]` section of the workspace `Cargo.toml` manifest For breaking changes, a changelog entry itself is sufficient. Bumping the version in the `Cargo.toml` file would lead to many merge conflicts once we decide to merge them. diff --git a/identity/CHANGELOG.md b/identity/CHANGELOG.md index 0d2851ac6e2..c156928127a 100644 --- a/identity/CHANGELOG.md +++ b/identity/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.2 - Add `impl From for PublicKey` so that `PublicKey::from(ed25519::PublicKey)` works. diff --git a/identity/Cargo.toml b/identity/Cargo.toml index 99012eeab6f..a69c2c632dd 100644 --- a/identity/Cargo.toml +++ b/identity/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-identity" -version = "0.1.2" +version = "0.2.0" edition = "2021" description = "Data structures and algorithms for identifying peers in libp2p." -rust-version = "1.60.0" +rust-version = { workspace = true } license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking", "cryptography"] @@ -40,7 +40,7 @@ ed25519 = [ "dep:ed25519-dalek", "dep:rand", "dep:zeroize", "dep:quick-protobuf" peerid = [ "dep:multihash", "dep:multiaddr", "dep:bs58", "dep:rand", "dep:thiserror", "dep:sha2" ] [dev-dependencies] -quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } +quickcheck = { workspace = true } base64 = "0.21.0" serde_json = "1.0" rmp-serde = "1.0" diff --git a/interop-tests/Cargo.toml b/interop-tests/Cargo.toml index 32c815f89a8..22b825efc91 100644 --- a/interop-tests/Cargo.toml +++ b/interop-tests/Cargo.toml @@ -11,8 +11,8 @@ either = "1.8.0" env_logger = "0.10.0" futures = "0.3.28" libp2p = { path = "../libp2p", features = ["websocket", "yamux", "tcp", "tokio", "ping", "noise", "tls", "dns", "rsa", "macros"] } -libp2p-quic = { path = "../transports/quic", features = ["tokio"] } -libp2p-webrtc = { path = "../transports/webrtc", features = ["tokio"] } +libp2p-quic = { workspace = true, features = ["tokio"] } +libp2p-webrtc = { workspace = true, features = ["tokio"] } libp2p-mplex = { path = "../muxers/mplex" } log = "0.4" rand = "0.8.5" diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index a76b7b45ce7..5581fe7921d 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.52.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.51.3 - Deprecate the `mplex` feature. diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index f979366b71a..b4fa79d6343 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p" edition = "2021" rust-version = "1.65.0" description = "Peer-to-peer networking library" -version = "0.51.3" +version = "0.52.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -96,44 +96,45 @@ futures-timer = "3.0.2" # Explicit dependency to be used in `wasm-bindgen` featu getrandom = "0.2.3" # Explicit dependency to be used in `wasm-bindgen` feature instant = "0.1.11" # Explicit dependency to be used in `wasm-bindgen` feature -libp2p-allow-block-list = { version = "0.1.0", path = "../misc/allow-block-list" } -libp2p-autonat = { version = "0.10.0", path = "../protocols/autonat", optional = true } -libp2p-connection-limits = { version = "0.1.0", path = "../misc/connection-limits" } -libp2p-core = { version = "0.39.0", path = "../core" } -libp2p-dcutr = { version = "0.9.0", path = "../protocols/dcutr", optional = true } -libp2p-floodsub = { version = "0.42.0", path = "../protocols/floodsub", optional = true } -libp2p-identify = { version = "0.42.0", path = "../protocols/identify", optional = true } -libp2p-identity = { version = "0.1.0", path = "../identity" } -libp2p-kad = { version = "0.43.0", path = "../protocols/kad", optional = true } -libp2p-metrics = { version = "0.12.0", path = "../misc/metrics", optional = true } -libp2p-mplex = { version = "0.39.0", path = "../muxers/mplex", optional = true } -libp2p-noise = { version = "0.42.2", path = "../transports/noise", optional = true } -libp2p-ping = { version = "0.42.0", path = "../protocols/ping", optional = true } -libp2p-plaintext = { version = "0.39.0", path = "../transports/plaintext", optional = true } -libp2p-pnet = { version = "0.22.2", path = "../transports/pnet", optional = true } -libp2p-relay = { version = "0.15.0", path = "../protocols/relay", optional = true } -libp2p-rendezvous = { version = "0.12.0", path = "../protocols/rendezvous", optional = true } -libp2p-request-response = { version = "0.24.0", path = "../protocols/request-response", optional = true } -libp2p-swarm = { version = "0.42.0", path = "../swarm" } -libp2p-wasm-ext = { version = "0.39.0", path = "../transports/wasm-ext", optional = true } -libp2p-yamux = { version = "0.43.1", path = "../muxers/yamux", optional = true } +libp2p-allow-block-list = { workspace = true } +libp2p-autonat = { workspace = true, optional = true } +libp2p-connection-limits = { workspace = true } +libp2p-core = { workspace = true } +libp2p-dcutr = { workspace = true, optional = true } +libp2p-floodsub = { workspace = true, optional = true } +libp2p-identify = { workspace = true, optional = true } +libp2p-identity = { workspace = true } +libp2p-kad = { workspace = true, optional = true } +libp2p-metrics = { workspace = true, optional = true } +libp2p-mplex = { workspace = true, optional = true } +libp2p-noise = { workspace = true, optional = true } +libp2p-ping = { workspace = true, optional = true } +libp2p-plaintext = { workspace = true, optional = true } +libp2p-pnet = { workspace = true, optional = true } +libp2p-relay = { workspace = true, optional = true } +libp2p-rendezvous = { workspace = true, optional = true } +libp2p-request-response = { workspace = true, optional = true } +libp2p-swarm = { workspace = true } +libp2p-wasm-ext = { workspace = true, optional = true } +libp2p-yamux = { workspace = true, optional = true } + multiaddr = { version = "0.17.0" } pin-project = "1.0.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -libp2p-deflate = { version = "0.39.0", path = "../transports/deflate", optional = true } -libp2p-dns = { version = "0.39.0", path = "../transports/dns", optional = true } -libp2p-mdns = { version = "0.43.0", path = "../protocols/mdns", optional = true } -libp2p-perf = { version = "0.1.0", path = "../protocols/perf", optional = true } -libp2p-quic = { version = "0.7.0-alpha.3", path = "../transports/quic", optional = true } -libp2p-tcp = { version = "0.39.0", path = "../transports/tcp", optional = true } -libp2p-tls = { version = "0.1.0", path = "../transports/tls", optional = true } -libp2p-uds = { version = "0.38.0", path = "../transports/uds", optional = true } -libp2p-webrtc = { version = "0.4.0-alpha.3", path = "../transports/webrtc", optional = true } -libp2p-websocket = { version = "0.41.0", path = "../transports/websocket", optional = true } +libp2p-deflate = { workspace = true, optional = true } +libp2p-dns = { workspace = true, optional = true } +libp2p-mdns = { workspace = true, optional = true } +libp2p-perf = { workspace = true, optional = true } +libp2p-quic = { workspace = true, optional = true } +libp2p-tcp = { workspace = true, optional = true } +libp2p-tls = { workspace = true, optional = true } +libp2p-uds = { workspace = true, optional = true } +libp2p-webrtc = { workspace = true, optional = true } +libp2p-websocket = { workspace = true, optional = true } [target.'cfg(not(target_os = "unknown"))'.dependencies] -libp2p-gossipsub = { version = "0.44.0", path = "../protocols/gossipsub", optional = true } +libp2p-gossipsub = { workspace = true, optional = true } [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } @@ -143,9 +144,9 @@ env_logger = "0.10.0" clap = { version = "4.1.6", features = ["derive"] } tokio = { version = "1.15", features = ["io-util", "io-std", "macros", "rt", "rt-multi-thread"] } -libp2p-mplex = { path = "../muxers/mplex" } -libp2p-noise = { path = "../transports/noise" } -libp2p-tcp = { path = "../transports/tcp", features = ["tokio"] } +libp2p-mplex = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-tcp = { workspace = true, features = ["tokio"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/misc/allow-block-list/CHANGELOG.md b/misc/allow-block-list/CHANGELOG.md index 68566e5b57d..72eea3460df 100644 --- a/misc/allow-block-list/CHANGELOG.md +++ b/misc/allow-block-list/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.1 - Correctly unblock and disallow peer in `unblock_peer` and `disallow_peer` functions. diff --git a/misc/allow-block-list/Cargo.toml b/misc/allow-block-list/Cargo.toml index e65f93c53de..897087e3b0b 100644 --- a/misc/allow-block-list/Cargo.toml +++ b/misc/allow-block-list/Cargo.toml @@ -1,21 +1,21 @@ [package] name = "libp2p-allow-block-list" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Allow/block list connection management for libp2p." -version = "0.1.1" +version = "0.2.0" license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["peerid"] } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true, features = ["peerid"] } void = "1" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -libp2p-swarm-derive = { path = "../../swarm-derive" } -libp2p-swarm-test = { path = "../../swarm-test" } +libp2p-swarm-derive = { workspace = true } +libp2p-swarm-test = { workspace = true } diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index 951a5a3f138..b3a1028e768 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.0 - Initial release. diff --git a/misc/connection-limits/Cargo.toml b/misc/connection-limits/Cargo.toml index b1ea179f371..dfc5bdad5ab 100644 --- a/misc/connection-limits/Cargo.toml +++ b/misc/connection-limits/Cargo.toml @@ -1,25 +1,25 @@ [package] name = "libp2p-connection-limits" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Connection limits for libp2p." -version = "0.1.0" +version = "0.2.0" license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity", features = ["peerid"] } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true, features = ["peerid"] } void = "1" [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } -libp2p-identify = { path = "../../protocols/identify" } -libp2p-ping = { path = "../../protocols/ping" } -libp2p-swarm-derive = { path = "../../swarm-derive" } -libp2p-swarm-test = { path = "../../swarm-test" } -quickcheck-ext = { path = "../quickcheck-ext" } +libp2p-identify = { workspace = true } +libp2p-ping = { workspace = true } +libp2p-swarm-derive = { workspace = true } +libp2p-swarm-test = { workspace = true } +quickcheck = { workspace = true } rand = "0.8.5" diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 6161fca67bc..b781e83d92d 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -365,7 +365,7 @@ mod tests { use super::*; use libp2p_swarm::{dial_opts::DialOpts, DialError, ListenError, Swarm, SwarmEvent}; use libp2p_swarm_test::SwarmExt; - use quickcheck_ext::*; + use quickcheck::*; #[test] fn max_outgoing() { diff --git a/misc/keygen/Cargo.toml b/misc/keygen/Cargo.toml index 18b4d8b0154..236b4d616a6 100644 --- a/misc/keygen/Cargo.toml +++ b/misc/keygen/Cargo.toml @@ -14,6 +14,6 @@ clap = { version = "4.2.5", features = ["derive"] } zeroize = "1" serde = { version = "1.0.160", features = ["derive"] } serde_json = "1.0.96" -libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-core = { workspace = true } base64 = "0.21.0" -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { workspace = true } diff --git a/misc/metrics/CHANGELOG.md b/misc/metrics/CHANGELOG.md index 2d8c6160184..4c653ca0051 100644 --- a/misc/metrics/CHANGELOG.md +++ b/misc/metrics/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.13.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.12.0 - Update to `prometheus-client` `v0.19.0`. See [PR 3207]. diff --git a/misc/metrics/Cargo.toml b/misc/metrics/Cargo.toml index d1e44165125..05a5fa38371 100644 --- a/misc/metrics/Cargo.toml +++ b/misc/metrics/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-metrics" edition = "2021" rust-version = "1.65.0" description = "Metrics for libp2p" -version = "0.12.0" +version = "0.13.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -19,18 +19,18 @@ relay = ["libp2p-relay"] dcutr = ["libp2p-dcutr"] [dependencies] -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-dcutr = { version = "0.9.0", path = "../../protocols/dcutr", optional = true } -libp2p-identify = { version = "0.42.0", path = "../../protocols/identify", optional = true } -libp2p-kad = { version = "0.43.0", path = "../../protocols/kad", optional = true } -libp2p-ping = { version = "0.42.0", path = "../../protocols/ping", optional = true } -libp2p-relay = { version = "0.15.0", path = "../../protocols/relay", optional = true } -libp2p-swarm = { version = "0.42.0", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-dcutr = { workspace = true, optional = true } +libp2p-identify = { workspace = true, optional = true } +libp2p-kad = { workspace = true, optional = true } +libp2p-ping = { workspace = true, optional = true } +libp2p-relay = { workspace = true, optional = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } prometheus-client = "0.19.0" [target.'cfg(not(target_os = "unknown"))'.dependencies] -libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true } +libp2p-gossipsub = { workspace = true, optional = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/misc/multistream-select/CHANGELOG.md b/misc/multistream-select/CHANGELOG.md index 0a80762dd48..b893c5d19e3 100644 --- a/misc/multistream-select/CHANGELOG.md +++ b/misc/multistream-select/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.13.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.12.1 - Update `rust-version` to reflect the actual MSRV: 1.60.0. See [PR 3090]. diff --git a/misc/multistream-select/Cargo.toml b/misc/multistream-select/Cargo.toml index c364b33ebea..b8ebd0cab68 100644 --- a/misc/multistream-select/Cargo.toml +++ b/misc/multistream-select/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "multistream-select" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Multistream-select negotiation protocol for libp2p" -version = "0.12.1" +version = "0.13.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -21,14 +21,14 @@ unsigned-varint = "0.7" [dev-dependencies] async-std = "1.6.2" env_logger = "0.10" -libp2p-core = { path = "../../core" } -libp2p-mplex = { path = "../../muxers/mplex" } -libp2p-plaintext = { path = "../../transports/plaintext" } -libp2p-swarm = { path = "../../swarm", features = ["async-std"] } -libp2p-identity = { path = "../../identity", features = ["ed25519"] } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-core = { workspace = true } +libp2p-mplex = { workspace = true } +libp2p-plaintext = { workspace = true } +libp2p-swarm = { workspace = true, features = ["async-std"] } +libp2p-identity = { workspace = true, features = ["ed25519"] } +quickcheck = { workspace = true } rand = "0.8" -rw-stream-sink = { version = "0.3.0", path = "../../misc/rw-stream-sink" } +rw-stream-sink = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/misc/multistream-select/src/lib.rs b/misc/multistream-select/src/lib.rs index 0dbcf3cbe0b..b2393137386 100644 --- a/misc/multistream-select/src/lib.rs +++ b/misc/multistream-select/src/lib.rs @@ -101,12 +101,13 @@ pub use self::negotiated::{Negotiated, NegotiatedComplete, NegotiationError}; pub use self::protocol::ProtocolError; /// Supported multistream-select versions. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum Version { /// Version 1 of the multistream-select protocol. See [1] and [2]. /// /// [1]: https://github.com/libp2p/specs/blob/master/connections/README.md#protocol-negotiation /// [2]: https://github.com/multiformats/multistream-select + #[default] V1, /// A "lazy" variant of version 1 that is identical on the wire but whereby /// the dialer delays flushing protocol negotiation data in order to combine @@ -141,9 +142,3 @@ pub enum Version { // Draft: https://github.com/libp2p/specs/pull/95 // V2, } - -impl Default for Version { - fn default() -> Self { - Version::V1 - } -} diff --git a/misc/quick-protobuf-codec/CHANGELOG.md b/misc/quick-protobuf-codec/CHANGELOG.md index 228afd5490d..6591928f82d 100644 --- a/misc/quick-protobuf-codec/CHANGELOG.md +++ b/misc/quick-protobuf-codec/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.0 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/misc/quick-protobuf-codec/Cargo.toml b/misc/quick-protobuf-codec/Cargo.toml index 34eb7f43d3b..37cdd07f225 100644 --- a/misc/quick-protobuf-codec/Cargo.toml +++ b/misc/quick-protobuf-codec/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "quick-protobuf-codec" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Asynchronous de-/encoding of Protobuf structs using asynchronous-codec, unsigned-varint and quick-protobuf." -version = "0.1.0" +version = "0.2.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/misc/rw-stream-sink/CHANGELOG.md b/misc/rw-stream-sink/CHANGELOG.md index 24735707c05..89047a25849 100644 --- a/misc/rw-stream-sink/CHANGELOG.md +++ b/misc/rw-stream-sink/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.4.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.3.0 - Move from https://github.com/paritytech/rw-stream-sink/ to https://github.com/libp2p/rust-libp2p. See [Issue 2504]. diff --git a/misc/rw-stream-sink/Cargo.toml b/misc/rw-stream-sink/Cargo.toml index a32d365de12..85871d3671e 100644 --- a/misc/rw-stream-sink/Cargo.toml +++ b/misc/rw-stream-sink/Cargo.toml @@ -2,8 +2,8 @@ name = "rw-stream-sink" edition = "2021" description = "Adaptator between Stream/Sink and AsyncRead/AsyncWrite" -rust-version = "1.60.0" -version = "0.3.0" +rust-version = { workspace = true } +version = "0.4.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/muxers/mplex/CHANGELOG.md b/muxers/mplex/CHANGELOG.md index 67a2f68719e..1c28d2828ae 100644 --- a/muxers/mplex/CHANGELOG.md +++ b/muxers/mplex/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/muxers/mplex/Cargo.toml b/muxers/mplex/Cargo.toml index 1c0562803c7..c51e3956adc 100644 --- a/muxers/mplex/Cargo.toml +++ b/muxers/mplex/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-mplex" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Mplex multiplexing protocol for libp2p" -version = "0.39.0" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,8 +14,8 @@ categories = ["network-programming", "asynchronous"] bytes = "1" futures = "0.3.28" asynchronous-codec = "0.6" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" nohash-hasher = "0.2" parking_lot = "0.12" @@ -28,10 +28,10 @@ async-std = { version = "1.7.0", features = ["attributes"] } criterion = "0.4" env_logger = "0.10" futures = "0.3" -libp2p-muxer-test-harness = { path = "../test-harness" } -libp2p-plaintext = { path = "../../transports/plaintext" } -libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-muxer-test-harness = { workspace = true } +libp2p-plaintext = { workspace = true } +libp2p-tcp = { workspace = true, features = ["async-io"] } +quickcheck = { workspace = true } [[bench]] name = "split_send_size" diff --git a/muxers/test-harness/Cargo.toml b/muxers/test-harness/Cargo.toml index f19c6656d75..02e9bdd2372 100644 --- a/muxers/test-harness/Cargo.toml +++ b/muxers/test-harness/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -libp2p-core = { path = "../../core" } +libp2p-core = { workspace = true } futures = "0.3.28" log = "0.4" futures-timer = "3.0.2" diff --git a/muxers/yamux/CHANGELOG.md b/muxers/yamux/CHANGELOG.md index 8308bd6cb4f..4d0015aad4a 100644 --- a/muxers/yamux/CHANGELOG.md +++ b/muxers/yamux/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.44.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.43.1 - Drop `Yamux` prefix from all types. diff --git a/muxers/yamux/Cargo.toml b/muxers/yamux/Cargo.toml index 53004065ec7..7a024e3af3b 100644 --- a/muxers/yamux/Cargo.toml +++ b/muxers/yamux/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-yamux" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Yamux multiplexing protocol for libp2p" -version = "0.43.1" +version = "0.44.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,14 +12,14 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.28" -libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-core = { workspace = true } thiserror = "1.0" yamux = "0.10.0" log = "0.4" [dev-dependencies] async-std = { version = "1.7.0", features = ["attributes"] } -libp2p-muxer-test-harness = { path = "../test-harness" } +libp2p-muxer-test-harness = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/autonat/CHANGELOG.md b/protocols/autonat/CHANGELOG.md index b6956fc40f9..d7047e4b43b 100644 --- a/protocols/autonat/CHANGELOG.md +++ b/protocols/autonat/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.11.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.10.2 - Store server `PeerId`s in `HashSet` to avoid duplicates and lower memory consumption. diff --git a/protocols/autonat/Cargo.toml b/protocols/autonat/Cargo.toml index bf235d9dbe2..27cfcde0758 100644 --- a/protocols/autonat/Cargo.toml +++ b/protocols/autonat/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-autonat" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "NAT and firewall detection for libp2p" -version = "0.10.2" +version = "0.11.0" authors = ["David Craven ", "Elena Frank "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,10 +15,10 @@ async-trait = "0.1" futures = "0.3" futures-timer = "3.0" instant = "0.1" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-request-response = { version = "0.24.0", path = "../request-response" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-request-response = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" rand = "0.8" quick-protobuf = "0.8" @@ -26,7 +26,7 @@ quick-protobuf = "0.8" [dev-dependencies] async-std = { version = "1.10", features = ["attributes"] } env_logger = "0.10" -libp2p-swarm-test = { path = "../../swarm-test" } +libp2p-swarm-test = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/dcutr/CHANGELOG.md b/protocols/dcutr/CHANGELOG.md index b8c2ed5e3f7..cd3e34e2ad8 100644 --- a/protocols/dcutr/CHANGELOG.md +++ b/protocols/dcutr/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.10.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.9.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/protocols/dcutr/Cargo.toml b/protocols/dcutr/Cargo.toml index 93e17d5082a..227d8bd71fd 100644 --- a/protocols/dcutr/Cargo.toml +++ b/protocols/dcutr/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-dcutr" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Direct connection upgrade through relay" -version = "0.9.1" +version = "0.10.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,12 +16,12 @@ either = "1.6.0" futures = "0.3.28" futures-timer = "3.0" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" quick-protobuf = "0.8" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } thiserror = "1.0" void = "1" @@ -29,16 +29,16 @@ void = "1" async-std = { version = "1.12.0", features = ["attributes"] } clap = { version = "4.2.5", features = ["derive"] } env_logger = "0.10.0" -libp2p-dns = { path = "../../transports/dns", features = ["async-std"] } -libp2p-identify = { path = "../../protocols/identify" } -libp2p-noise = { path = "../../transports/noise" } -libp2p-ping = { path = "../../protocols/ping" } -libp2p-plaintext = { path = "../../transports/plaintext" } -libp2p-relay = { path = "../relay" } -libp2p-swarm = { path = "../../swarm", features = ["macros"] } -libp2p-swarm-test = { path = "../../swarm-test"} -libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] } -libp2p-yamux = { path = "../../muxers/yamux" } +libp2p-dns = { workspace = true, features = ["async-std"] } +libp2p-identify = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-ping = { workspace = true } +libp2p-plaintext = { workspace = true } +libp2p-relay = { workspace = true } +libp2p-swarm = { workspace = true, features = ["macros"] } +libp2p-swarm-test = { workspace = true } +libp2p-tcp = { workspace = true, features = ["async-io"] } +libp2p-yamux = { workspace = true } rand = "0.8" # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/protocols/floodsub/CHANGELOG.md b/protocols/floodsub/CHANGELOG.md index 1adba4d1d00..06059ff1dbb 100644 --- a/protocols/floodsub/CHANGELOG.md +++ b/protocols/floodsub/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.43.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.42.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/protocols/floodsub/Cargo.toml b/protocols/floodsub/Cargo.toml index 22f040e159e..00fa57c0272 100644 --- a/protocols/floodsub/Cargo.toml +++ b/protocols/floodsub/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-floodsub" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Floodsub protocol for libp2p" -version = "0.42.1" +version = "0.43.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,12 +15,12 @@ asynchronous-codec = "0.6" cuckoofilter = "0.5.0" fnv = "1.0" futures = "0.3.28" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" quick-protobuf = "0.8" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } rand = "0.8" smallvec = "1.6.1" thiserror = "1.0.40" diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index c1e688c1200..fbfb45ca5c7 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.45.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.44.4 - Deprecate `metrics`, `protocol`, `subscription_filter`, `time_cache` modules to make them private. See [PR 3777]. diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 39a5b3a2d7f..8ae5d0d5f87 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-gossipsub" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Gossipsub protocol for libp2p" -version = "0.44.4" +version = "0.45.0" authors = ["Age Manning "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,9 +12,9 @@ categories = ["network-programming", "asynchronous"] [dependencies] either = "1.5" -libp2p-swarm = { version = "0.42.2", path = "../../swarm" } -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.2", path = "../../identity" } +libp2p-swarm = { workspace = true } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } bytes = "1.4" byteorder = "1.3.4" fnv = "1.0.7" @@ -27,7 +27,7 @@ sha2 = "0.10.0" base64 = "0.21.0" smallvec = "1.6.1" quick-protobuf = "0.8" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } hex_fmt = "0.3.0" regex = "1.8.1" serde = { version = "1", optional = true, features = ["derive"] } @@ -42,11 +42,11 @@ prometheus-client = "0.19.0" async-std = { version = "1.6.3", features = ["unstable"] } env_logger = "0.10.0" hex = "0.4.2" -libp2p-core = { path = "../../core"} -libp2p-mplex = { path = "../../muxers/mplex"} -libp2p-noise = { path = "../../transports/noise"} -libp2p-swarm-test = { path = "../../swarm-test"} -quickcheck-ext = { path = "../../misc/quickcheck-ext" } +libp2p-core = { workspace = true } +libp2p-mplex = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-swarm-test = { workspace = true } +quickcheck = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 13ce3fcee35..542195617d2 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -3709,7 +3709,7 @@ mod local_test { use super::*; use crate::IdentTopic; use asynchronous_codec::Encoder; - use quickcheck_ext::*; + use quickcheck::*; fn empty_rpc() -> Rpc { Rpc { diff --git a/protocols/gossipsub/src/protocol_priv.rs b/protocols/gossipsub/src/protocol_priv.rs index 2145cd9dd4b..cde091c7b56 100644 --- a/protocols/gossipsub/src/protocol_priv.rs +++ b/protocols/gossipsub/src/protocol_priv.rs @@ -557,7 +557,7 @@ mod tests { use crate::IdentTopic as Topic; use crate::{Behaviour, ConfigBuilder}; use libp2p_core::identity::Keypair; - use quickcheck_ext::*; + use quickcheck::*; #[derive(Clone, Debug)] struct Message(RawMessage); diff --git a/protocols/gossipsub/tests/smoke.rs b/protocols/gossipsub/tests/smoke.rs index 4f63925af87..e4e4c90d768 100644 --- a/protocols/gossipsub/tests/smoke.rs +++ b/protocols/gossipsub/tests/smoke.rs @@ -26,7 +26,7 @@ use libp2p_gossipsub::{MessageAuthenticity, ValidationMode}; use libp2p_swarm::Swarm; use libp2p_swarm_test::SwarmExt as _; use log::debug; -use quickcheck_ext::{QuickCheck, TestResult}; +use quickcheck::{QuickCheck, TestResult}; use rand::{seq::SliceRandom, SeedableRng}; use std::{task::Poll, time::Duration}; diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index 3915f92f88c..aaf316869fe 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.43.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.42.2 - Do not implicitly dial a peer upon `identify::Behaviour::push`. diff --git a/protocols/identify/Cargo.toml b/protocols/identify/Cargo.toml index fb186360ba9..8f94ebc40b6 100644 --- a/protocols/identify/Cargo.toml +++ b/protocols/identify/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-identify" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Nodes identifcation protocol for libp2p" -version = "0.42.2" +version = "0.43.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,12 +14,12 @@ categories = ["network-programming", "asynchronous"] asynchronous-codec = "0.6" futures = "0.3.28" futures-timer = "3.0.2" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.2", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.1" lru = "0.10.0" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } quick-protobuf = "0.8" smallvec = "1.6.1" thiserror = "1.0" @@ -29,11 +29,11 @@ either = "1.8.0" [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } env_logger = "0.10" -libp2p-mplex = { path = "../../muxers/mplex" } -libp2p-yamux = { path = "../../muxers/yamux" } -libp2p-noise = { path = "../../transports/noise" } -libp2p-swarm = { path = "../../swarm", features = ["async-std"] } -libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] } +libp2p-mplex = { workspace = true } +libp2p-yamux = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-swarm = { workspace = true, features = ["async-std"] } +libp2p-tcp = { workspace = true, features = ["async-io"] } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 123acbf5ef8..525be910308 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.44.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.43.3 - Preserve existing `KeepAlive::Until` timeout instead of continuously setting new `KeepAlive::Until(Instant::now() + self.config.idle_timeout)`. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index c555bf8b768..561d6e4c424 100644 --- a/protocols/kad/Cargo.toml +++ b/protocols/kad/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-kad" edition = "2021" rust-version = "1.65.0" description = "Kademlia protocol for libp2p" -version = "0.43.3" +version = "0.44.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -18,10 +18,10 @@ fnv = "1.0" asynchronous-codec = "0.6" futures = "0.3.28" log = "0.4" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } quick-protobuf = "0.8" -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-identity = { workspace = true } rand = "0.8" sha2 = "0.10.0" smallvec = "1.6.1" @@ -36,9 +36,9 @@ thiserror = "1" [dev-dependencies] env_logger = "0.10.0" futures-timer = "3.0" -libp2p-noise = { path = "../../transports/noise" } -libp2p-yamux = { path = "../../muxers/yamux" } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-noise = { workspace = true } +libp2p-yamux = { workspace = true } +quickcheck = { workspace = true } [features] serde = ["dep:serde", "bytes/serde"] diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 5d3b4f79c55..7cc9ed0fb22 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.44.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.43.1 - Derive `Clone` for `mdns::Event`. See [PR 3606]. diff --git a/protocols/mdns/Cargo.toml b/protocols/mdns/Cargo.toml index 5f311f56bd5..942c2122a94 100644 --- a/protocols/mdns/Cargo.toml +++ b/protocols/mdns/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "libp2p-mdns" edition = "2021" -rust-version = "1.62.0" -version = "0.43.1" +rust-version = { workspace = true } +version = "0.44.0" description = "Implementation of the libp2p mDNS discovery method" authors = ["Parity Technologies "] license = "MIT" @@ -15,9 +15,9 @@ async-io = { version = "1.13.0", optional = true } data-encoding = "2.3.2" futures = "0.3.28" if-watch = "3.0.1" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.14" rand = "0.8.3" smallvec = "1.6.1" @@ -33,12 +33,12 @@ async-io = ["dep:async-io", "if-watch/smol"] [dev-dependencies] async-std = { version = "1.9.0", features = ["attributes"] } env_logger = "0.10.0" -libp2p-noise = { path = "../../transports/noise" } -libp2p-swarm = { path = "../../swarm", features = ["tokio", "async-std"] } -libp2p-tcp = { path = "../../transports/tcp", features = ["tokio", "async-io"] } -libp2p-yamux = { path = "../../muxers/yamux" } +libp2p-noise = { workspace = true } +libp2p-swarm = { workspace = true, features = ["tokio", "async-std"] } +libp2p-tcp = { workspace = true, features = ["tokio", "async-io"] } +libp2p-yamux = { workspace = true } tokio = { version = "1.28", default-features = false, features = ["macros", "rt", "rt-multi-thread", "time"] } -libp2p-swarm-test = { path = "../../swarm-test" } +libp2p-swarm-test = { workspace = true } [[test]] name = "use-async-std" diff --git a/protocols/perf/CHANGELOG.md b/protocols/perf/CHANGELOG.md index 951a5a3f138..b3a1028e768 100644 --- a/protocols/perf/CHANGELOG.md +++ b/protocols/perf/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.0 - Initial release. diff --git a/protocols/perf/Cargo.toml b/protocols/perf/Cargo.toml index 4609b076220..fc948401a91 100644 --- a/protocols/perf/Cargo.toml +++ b/protocols/perf/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-perf" edition = "2021" -rust-version = "1.64.0" +rust-version = { workspace = true } description = "libp2p perf protocol implementation" -version = "0.1.0" +version = "0.2.0" authors = ["Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,21 +17,21 @@ clap = { version = "4.2.5", features = ["derive"] } env_logger = "0.10.0" futures = "0.3.28" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-dns = { version = "0.39.0", path = "../../transports/dns", features = ["async-std"] } -libp2p-identity = { version = "0.1.0", path = "../../identity" } -libp2p-noise = { version = "0.42.2", path = "../../transports/noise" } -libp2p-quic = { version = "0.7.0-alpha.2", path = "../../transports/quic", features = ["async-std"] } -libp2p-swarm = { version = "0.42.1", path = "../../swarm", features = ["macros", "async-std"] } -libp2p-tcp = { version = "0.39.0", path = "../../transports/tcp", features = ["async-io"] } -libp2p-yamux = { version = "0.43.1", path = "../../muxers/yamux" } +libp2p-core = { workspace = true } +libp2p-dns = { workspace = true, features = ["async-std"] } +libp2p-identity = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-quic = { workspace = true, features = ["async-std"] } +libp2p-swarm = { workspace = true, features = ["macros", "async-std"] } +libp2p-tcp = { workspace = true, features = ["async-io"] } +libp2p-yamux = { workspace = true } log = "0.4" thiserror = "1.0" void = "1" [dev-dependencies] rand = "0.8" -libp2p-swarm-test = { path = "../../swarm-test"} +libp2p-swarm-test = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/ping/CHANGELOG.md b/protocols/ping/CHANGELOG.md index 550f9c630f6..06610c840ff 100644 --- a/protocols/ping/CHANGELOG.md +++ b/protocols/ping/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.43.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.42.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/protocols/ping/Cargo.toml b/protocols/ping/Cargo.toml index b917d467184..573a1170e86 100644 --- a/protocols/ping/Cargo.toml +++ b/protocols/ping/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-ping" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Ping protocol for libp2p" -version = "0.42.0" +version = "0.43.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -15,9 +15,9 @@ either = "1.8.0" futures = "0.3.28" futures-timer = "3.0.2" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.1" rand = "0.8" void = "1.0" @@ -25,9 +25,9 @@ void = "1.0" [dev-dependencies] async-std = "1.6.2" env_logger = "0.10.0" -libp2p-swarm = { path = "../../swarm", features = ["macros"] } -libp2p-swarm-test = { path = "../../swarm-test" } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-swarm = { workspace = true, features = ["macros"] } +libp2p-swarm-test = { workspace = true } +quickcheck = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 55b6ccf8152..f718fc5adf5 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.16.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.15.2 - Send correct `PeerId` in outbound STOP message to client. diff --git a/protocols/relay/Cargo.toml b/protocols/relay/Cargo.toml index 9bb92bb8961..f352358561b 100644 --- a/protocols/relay/Cargo.toml +++ b/protocols/relay/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-relay" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Communications relaying for libp2p" -version = "0.15.2" +version = "0.16.0" authors = ["Parity Technologies ", "Max Inden "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -17,12 +17,12 @@ either = "1.6.0" futures = "0.3.28" futures-timer = "3" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm", features = ["async-std"] } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true, features = ["async-std"] } +libp2p-identity = { workspace = true } log = "0.4" quick-protobuf = "0.8" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } rand = "0.8.4" static_assertions = "1" thiserror = "1.0" @@ -30,11 +30,11 @@ void = "1" [dev-dependencies] env_logger = "0.10.0" -libp2p-ping = { path = "../../protocols/ping" } -libp2p-plaintext = { path = "../../transports/plaintext" } -libp2p-swarm = { path = "../../swarm", features = ["macros"] } -libp2p-yamux = { path = "../../muxers/yamux" } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-ping = { workspace = true } +libp2p-plaintext = { workspace = true } +libp2p-swarm = { workspace = true, features = ["macros"] } +libp2p-yamux = { workspace = true } +quickcheck = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/rendezvous/CHANGELOG.md b/protocols/rendezvous/CHANGELOG.md index 202f225406c..8f2bd968e94 100644 --- a/protocols/rendezvous/CHANGELOG.md +++ b/protocols/rendezvous/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.13.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.12.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/protocols/rendezvous/Cargo.toml b/protocols/rendezvous/Cargo.toml index 45945837b91..ce5e9dfbeaf 100644 --- a/protocols/rendezvous/Cargo.toml +++ b/protocols/rendezvous/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-rendezvous" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Rendezvous protocol for libp2p" -version = "0.12.1" +version = "0.13.0" authors = ["The COMIT guys "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,12 +16,12 @@ bimap = "0.6.3" futures = { version = "0.3", default-features = false, features = ["std"] } futures-timer = "3.0.2" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" quick-protobuf = "0.8" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } rand = "0.8" thiserror = "1" void = "1" @@ -29,16 +29,16 @@ void = "1" [dev-dependencies] async-trait = "0.1" env_logger = "0.10.0" -libp2p-swarm = { path = "../../swarm", features = ["macros", "tokio"] } -libp2p-mplex = { path = "../../muxers/mplex" } -libp2p-noise = { path = "../../transports/noise" } -libp2p-ping = { path = "../ping" } -libp2p-identify = { path = "../identify" } -libp2p-yamux = { path = "../../muxers/yamux" } -libp2p-tcp = { path = "../../transports/tcp", features = ["tokio"] } +libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } +libp2p-mplex = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-ping = { workspace = true } +libp2p-identify = { workspace = true } +libp2p-yamux = { workspace = true } +libp2p-tcp = { workspace = true, features = ["tokio"] } rand = "0.8" tokio = { version = "1.28", features = [ "rt-multi-thread", "time", "macros", "sync", "process", "fs", "net" ] } -libp2p-swarm-test = { path = "../../swarm-test" } +libp2p-swarm-test = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index ecb524d7c11..0625006ef11 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.25.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.24.1 - Deprecate `handler`, `codec` modules to make them private. See [PR 3847]. diff --git a/protocols/request-response/Cargo.toml b/protocols/request-response/Cargo.toml index 75cbdc369fa..3bde34e2cc1 100644 --- a/protocols/request-response/Cargo.toml +++ b/protocols/request-response/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-request-response" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "Generic Request/Response Protocols" -version = "0.24.1" +version = "0.25.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,20 +14,20 @@ categories = ["network-programming", "asynchronous"] async-trait = "0.1" futures = "0.3.28" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-swarm = { version = "0.42.1", path = "../../swarm" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-identity = { workspace = true } rand = "0.8" smallvec = "1.6.1" [dev-dependencies] async-std = { version = "1.6.2", features = ["attributes"] } env_logger = "0.10.0" -libp2p-noise = { path = "../../transports/noise" } -libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] } -libp2p-yamux = { path = "../../muxers/yamux" } +libp2p-noise = { workspace = true } +libp2p-tcp = { workspace = true, features = ["async-io"] } +libp2p-yamux = { workspace = true } rand = "0.8" -libp2p-swarm-test = { path = "../../swarm-test" } +libp2p-swarm-test = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/swarm-derive/CHANGELOG.md b/swarm-derive/CHANGELOG.md index f13e4d39c95..9628e7ea777 100644 --- a/swarm-derive/CHANGELOG.md +++ b/swarm-derive/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.33.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.32.0 - Fix `NetworkBehaviour` Derive macro for generic types when `out_event` was not provided. Previously the enum generated diff --git a/swarm-derive/Cargo.toml b/swarm-derive/Cargo.toml index 31f70a01b5b..8d31a389ae5 100644 --- a/swarm-derive/Cargo.toml +++ b/swarm-derive/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-swarm-derive" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Procedural macros of libp2p-swarm" -version = "0.32.0" +version = "0.33.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/swarm-test/CHANGELOG.md b/swarm-test/CHANGELOG.md index 951a5a3f138..b3a1028e768 100644 --- a/swarm-test/CHANGELOG.md +++ b/swarm-test/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.0 - Initial release. diff --git a/swarm-test/Cargo.toml b/swarm-test/Cargo.toml index 9c922a1c2ed..2422618c190 100644 --- a/swarm-test/Cargo.toml +++ b/swarm-test/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-swarm-test" -version = "0.1.0" +version = "0.2.0" edition = "2021" rust-version = "1.65.0" license = "MIT" @@ -13,12 +13,12 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-trait = "0.1.68" -libp2p-core = { version = "0.39.1", path = "../core" } -libp2p-identity = { version = "0.1.1", path = "../identity" } -libp2p-plaintext = { version = "0.39.1", path = "../transports/plaintext" } -libp2p-swarm = { version = "0.42.0", path = "../swarm" } -libp2p-tcp = { version = "0.39.0", path = "../transports/tcp", features = ["async-io"] } -libp2p-yamux = { version = "0.43.1", path = "../muxers/yamux" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } +libp2p-plaintext = { workspace = true } +libp2p-swarm = { workspace = true } +libp2p-tcp = { workspace = true, features = ["async-io"] } +libp2p-yamux = { workspace = true } futures = "0.3.28" log = "0.4.17" rand = "0.8.5" diff --git a/swarm/CHANGELOG.md b/swarm/CHANGELOG.md index 7198f898995..3509d60e662 100644 --- a/swarm/CHANGELOG.md +++ b/swarm/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.43.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.42.2 - Add `ConnectionEvent::{is_outbound,is_inbound}`. See [PR 3625]. diff --git a/swarm/Cargo.toml b/swarm/Cargo.toml index 140d0a6d854..1d34dc03b13 100644 --- a/swarm/Cargo.toml +++ b/swarm/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-swarm" edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "The libp2p swarm" -version = "0.42.2" +version = "0.43.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,9 +16,9 @@ fnv = "1.0" futures = "0.3.28" futures-timer = "3.0.2" instant = "0.1.11" -libp2p-core = { version = "0.39.0", path = "../core" } -libp2p-identity = { version = "0.1.0", path = "../identity" } -libp2p-swarm-derive = { version = "0.32.0", path = "../swarm-derive", optional = true } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } +libp2p-swarm-derive = { workspace = true, optional = true } log = "0.4" rand = "0.8" smallvec = "1.6.1" @@ -41,15 +41,15 @@ async-std = { version = "1.6.2", features = ["attributes"] } either = "1.6.0" env_logger = "0.10" futures = "0.3.28" -libp2p-identify = { path = "../protocols/identify" } -libp2p-identity = { version = "0.1.0", path = "../identity", features = ["ed25519"] } -libp2p-kad = { path = "../protocols/kad" } -libp2p-ping = { path = "../protocols/ping" } -libp2p-plaintext = { path = "../transports/plaintext" } -libp2p-swarm-derive = { path = "../swarm-derive" } -libp2p-swarm-test = { path = "../swarm-test" } -libp2p-yamux = { path = "../muxers/yamux" } -quickcheck = { package = "quickcheck-ext", path = "../misc/quickcheck-ext" } +libp2p-identify = { workspace = true } +libp2p-identity = { workspace = true, features = ["ed25519"] } +libp2p-kad = { workspace = true } +libp2p-ping = { workspace = true } +libp2p-plaintext = { workspace = true } +libp2p-swarm-derive = { workspace = true } +libp2p-swarm-test = { workspace = true } +libp2p-yamux = { workspace = true } +quickcheck = { workspace = true } void = "1" [[test]] diff --git a/transports/deflate/CHANGELOG.md b/transports/deflate/CHANGELOG.md index e5946ef369b..2261d0aa92f 100644 --- a/transports/deflate/CHANGELOG.md +++ b/transports/deflate/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/transports/deflate/Cargo.toml b/transports/deflate/Cargo.toml index 32c64e65c27..3d46e77352f 100644 --- a/transports/deflate/Cargo.toml +++ b/transports/deflate/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-deflate" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Deflate encryption protocol for libp2p" -version = "0.39.0" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,11 +12,13 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.28" -libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-core = { workspace = true } flate2 = "1.0" [dev-dependencies] -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +async-std = "1.6.2" +libp2p-tcp = { workspace = true, features = ["async-io"] } +quickcheck = { workspace = true } rand = "0.8" futures_ringbuf = "0.3.1" diff --git a/transports/dns/CHANGELOG.md b/transports/dns/CHANGELOG.md index 13cddfc01d0..9511b6d8cdd 100644 --- a/transports/dns/CHANGELOG.md +++ b/transports/dns/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/transports/dns/Cargo.toml b/transports/dns/Cargo.toml index 5cd734d4525..c7d51db6083 100644 --- a/transports/dns/Cargo.toml +++ b/transports/dns/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-dns" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "DNS transport implementation for libp2p" -version = "0.39.0" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -11,8 +11,8 @@ keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] [dependencies] -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.1" futures = "0.3.28" async-std-resolver = { version = "0.22", optional = true } diff --git a/transports/noise/CHANGELOG.md b/transports/noise/CHANGELOG.md index a2809467885..3b3bce34dec 100644 --- a/transports/noise/CHANGELOG.md +++ b/transports/noise/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.42.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.42.2 - Deprecate all noise handshakes apart from XX. diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index b7da5a31090..97dca96f241 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-noise" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Cryptographic handshake protocol using the noise framework." -version = "0.42.2" +version = "0.43.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,8 +12,8 @@ repository = "https://github.com/libp2p/rust-libp2p" bytes = "1" curve25519-dalek = "3.0.0" futures = "0.3.28" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.2", path = "../../identity", features = ["ed25519"] } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true, features = ["ed25519"] } log = "0.4" quick-protobuf = "0.8" once_cell = "1.17.1" @@ -33,8 +33,8 @@ snow = { version = "0.9.2", features = ["default-resolver"], default-features = [dev-dependencies] async-io = "1.13.0" env_logger = "0.10.0" -libp2p-tcp = { path = "../tcp", features = ["async-io"] } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-tcp = { workspace = true, features = ["async-io"] } +quickcheck = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. # More information: https://docs.rs/about/builds#cross-compiling diff --git a/transports/plaintext/CHANGELOG.md b/transports/plaintext/CHANGELOG.md index b345894ffc9..5f04ca16cba 100644 --- a/transports/plaintext/CHANGELOG.md +++ b/transports/plaintext/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.1 - Migrate from `prost` to `quick-protobuf`. This removes `protoc` dependency. See [PR 3312]. diff --git a/transports/plaintext/Cargo.toml b/transports/plaintext/Cargo.toml index b8ccbcc2162..6946f22558e 100644 --- a/transports/plaintext/Cargo.toml +++ b/transports/plaintext/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-plaintext" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Plaintext encryption dummy protocol for libp2p" -version = "0.39.1" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,8 +14,8 @@ categories = ["network-programming", "asynchronous"] asynchronous-codec = "0.6" bytes = "1" futures = "0.3.28" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.2", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.8" quick-protobuf = "0.8" unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } @@ -23,8 +23,8 @@ void = "1.0.2" [dev-dependencies] env_logger = "0.10.0" -libp2p-identity = { path = "../../identity", features = ["ed25519"] } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-identity = { workspace = true, features = ["ed25519"] } +quickcheck = { workspace = true } rand = "0.8" futures_ringbuf = "0.3.1" diff --git a/transports/pnet/CHANGELOG.md b/transports/pnet/CHANGELOG.md index 7dc20176abc..9a4324f8371 100644 --- a/transports/pnet/CHANGELOG.md +++ b/transports/pnet/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.23.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.22.3 - Fix handshake over websocket. See [PR 3476] diff --git a/transports/pnet/Cargo.toml b/transports/pnet/Cargo.toml index 80f6c62df0b..3c834079e93 100644 --- a/transports/pnet/Cargo.toml +++ b/transports/pnet/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-pnet" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Private swarm support for libp2p" -version = "0.22.3" +version = "0.23.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -19,14 +19,14 @@ rand = "0.8" pin-project = "1.0.2" [dev-dependencies] -libp2p-core = { path = "../../core", features = ["rsa", "ecdsa", "secp256k1"] } -libp2p-identity = { path = "../../identity", features = ["ed25519"] } -libp2p-noise = { path = "../noise" } -libp2p-swarm = { path = "../../swarm", features = ["tokio"] } -libp2p-tcp = { path = "../tcp", features = ["tokio"] } -libp2p-websocket = { path = "../websocket" } -libp2p-yamux = { path = "../../muxers/yamux" } -quickcheck = { package = "quickcheck-ext", path = "../../misc/quickcheck-ext" } +libp2p-core = { workspace = true, features = ["rsa", "ecdsa", "secp256k1"] } +libp2p-identity = { workspace = true, features = ["ed25519"] } +libp2p-noise = { workspace = true } +libp2p-swarm = { workspace = true, features = ["tokio"] } +libp2p-tcp = { workspace = true, features = ["tokio"] } +libp2p-websocket = { workspace = true } +libp2p-yamux = { workspace = true } +quickcheck = { workspace = true } tokio = { version = "1.28.0", features = ["full"] } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/transports/quic/CHANGELOG.md b/transports/quic/CHANGELOG.md index 137f5494e4f..db50b7b8a31 100644 --- a/transports/quic/CHANGELOG.md +++ b/transports/quic/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.8.0-alpha - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.7.0-alpha.3 - Depend `libp2p-tls` `v0.1.0`. diff --git a/transports/quic/Cargo.toml b/transports/quic/Cargo.toml index 9bb54dddcb3..1b491ce0c37 100644 --- a/transports/quic/Cargo.toml +++ b/transports/quic/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-quic" -version = "0.7.0-alpha.3" +version = "0.8.0-alpha" authors = ["Parity Technologies "] edition = "2021" -rust-version = "1.62.0" +rust-version = { workspace = true } description = "TLS based QUIC transport implementation for libp2p" repository = "https://github.com/libp2p/rust-libp2p" license = "MIT" @@ -14,9 +14,9 @@ bytes = "1.4.0" futures = "0.3.28" futures-timer = "3.0.2" if-watch = "3.0.1" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-tls = { version = "0.1.0", path = "../tls" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-tls = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" parking_lot = "0.12.0" quinn-proto = { version = "0.9.3", default-features = false, features = ["tls-rustls"] } @@ -39,10 +39,10 @@ rustc-args = ["--cfg", "docsrs"] [dev-dependencies] async-std = { version = "1.12.0", features = ["attributes"] } env_logger = "0.10.0" -libp2p-muxer-test-harness = { path = "../../muxers/test-harness" } -libp2p-noise = { path = "../noise" } -libp2p-tcp = { path = "../tcp", features = ["async-io"] } -libp2p-yamux = { path = "../../muxers/yamux" } +libp2p-muxer-test-harness = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-tcp = { workspace = true, features = ["async-io"] } +libp2p-yamux = { workspace = true } quickcheck = "1" tokio = { version = "1.28.0", features = ["macros", "rt-multi-thread", "time"] } diff --git a/transports/tcp/CHANGELOG.md b/transports/tcp/CHANGELOG.md index 2acb0423bed..eeaedc0706d 100644 --- a/transports/tcp/CHANGELOG.md +++ b/transports/tcp/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/transports/tcp/Cargo.toml b/transports/tcp/Cargo.toml index 55507dd1dc4..b7bd9e8d5df 100644 --- a/transports/tcp/Cargo.toml +++ b/transports/tcp/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-tcp" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "TCP/IP transport protocol for libp2p" -version = "0.39.0" +version = "0.40.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,8 +16,8 @@ futures = "0.3.28" futures-timer = "3.0" if-watch = "3.0.1" libc = "0.2.142" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.11" socket2 = { version = "0.4.0", features = ["all"] } tokio = { version = "1.28.0", default-features = false, features = ["net"], optional = true } diff --git a/transports/tls/CHANGELOG.md b/transports/tls/CHANGELOG.md index 63f7afe5f6a..6e55e7f0864 100644 --- a/transports/tls/CHANGELOG.md +++ b/transports/tls/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.2.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.1.0 - Promote to `v0.1.0`. diff --git a/transports/tls/Cargo.toml b/transports/tls/Cargo.toml index 2a95d07aaba..f7cfc01444c 100644 --- a/transports/tls/Cargo.toml +++ b/transports/tls/Cargo.toml @@ -1,8 +1,8 @@ [package] name = "libp2p-tls" -version = "0.1.0" +version = "0.2.0" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "TLS configuration based on libp2p TLS specs." repository = "https://github.com/libp2p/rust-libp2p" license = "MIT" @@ -11,8 +11,8 @@ exclude = ["src/test_assets"] [dependencies] futures = { version = "0.3.28", default-features = false } futures-rustls = "0.22.2" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.2", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } rcgen = "0.10.0" ring = "0.16.20" thiserror = "1.0.40" @@ -29,10 +29,10 @@ features = ["dangerous_configuration"] # Must enable this to allow for custom ve [dev-dependencies] hex = "0.4.3" hex-literal = "0.4.1" -libp2p-core = { path = "../../core" } -libp2p-identity = { path = "../../identity", features = ["ed25519", "rsa", "secp256k1", "ecdsa"] } -libp2p-swarm = { path = "../../swarm" } -libp2p-yamux = { path = "../../muxers/yamux" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true, features = ["ed25519", "rsa", "secp256k1", "ecdsa"] } +libp2p-swarm = { workspace = true } +libp2p-yamux = { workspace = true } tokio = { version = "1.28.0", features = ["full"] } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/transports/uds/CHANGELOG.md b/transports/uds/CHANGELOG.md index df83cfc07c7..72858840fd1 100644 --- a/transports/uds/CHANGELOG.md +++ b/transports/uds/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.39.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.38.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/transports/uds/Cargo.toml b/transports/uds/Cargo.toml index 33fc9ed4337..ae5eb84e19e 100644 --- a/transports/uds/Cargo.toml +++ b/transports/uds/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-uds" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Unix domain sockets transport for libp2p" -version = "0.38.0" +version = "0.39.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] async-std = { version = "1.6.2", optional = true } -libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-core = { workspace = true } log = "0.4.1" futures = "0.3.28" tokio = { version = "1.28", default-features = false, features = ["net"], optional = true } diff --git a/transports/wasm-ext/CHANGELOG.md b/transports/wasm-ext/CHANGELOG.md index a720faac685..63fa731975e 100644 --- a/transports/wasm-ext/CHANGELOG.md +++ b/transports/wasm-ext/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.40.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.39.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/transports/wasm-ext/Cargo.toml b/transports/wasm-ext/Cargo.toml index 19a04bc1751..98fc25362c4 100644 --- a/transports/wasm-ext/Cargo.toml +++ b/transports/wasm-ext/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-wasm-ext" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "Allows passing in an external transport in a WASM environment" -version = "0.39.0" +version = "0.40.0" authors = ["Pierre Krieger "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -13,7 +13,7 @@ categories = ["network-programming", "asynchronous"] [dependencies] futures = "0.3.28" js-sys = "0.3.61" -libp2p-core = { version = "0.39.0", path = "../../core" } +libp2p-core = { workspace = true } parity-send-wrapper = "0.1.0" wasm-bindgen = "0.2.42" wasm-bindgen-futures = "0.4.34" diff --git a/transports/webrtc/CHANGELOG.md b/transports/webrtc/CHANGELOG.md index 1111606a3d1..c90bcc7446c 100644 --- a/transports/webrtc/CHANGELOG.md +++ b/transports/webrtc/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.5.0-alpha - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.4.0-alpha.4 - Make `Fingerprint` type public. See [PR 3648]. diff --git a/transports/webrtc/Cargo.toml b/transports/webrtc/Cargo.toml index ae0379b2e03..1019a49678f 100644 --- a/transports/webrtc/Cargo.toml +++ b/transports/webrtc/Cargo.toml @@ -1,12 +1,12 @@ [package] name = "libp2p-webrtc" -version = "0.4.0-alpha.4" +version = "0.5.0-alpha" authors = ["Parity Technologies "] description = "WebRTC transport for libp2p" repository = "https://github.com/libp2p/rust-libp2p" license = "MIT" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } keywords = ["peer-to-peer", "libp2p", "networking"] categories = ["network-programming", "asynchronous"] @@ -18,14 +18,14 @@ futures = "0.3" futures-timer = "3" hex = "0.4" if-watch = "3.0" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-noise = { version = "0.42.2", path = "../../transports/noise" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-noise = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4" sha2 = "0.10.6" multihash = { version = "0.17.0", default-features = false } quick-protobuf = "0.8" -quick-protobuf-codec = { version = "0.1", path = "../../misc/quick-protobuf-codec" } +quick-protobuf-codec = { workspace = true } rand = "0.8" rcgen = "0.9.3" serde = { version = "1.0", features = ["derive"] } @@ -44,8 +44,8 @@ pem = ["webrtc?/pem"] anyhow = "1.0" env_logger = "0.10" hex-literal = "0.4" -libp2p-swarm = { path = "../../swarm", features = ["macros", "tokio"] } -libp2p-ping = { path = "../../protocols/ping" } +libp2p-swarm = { workspace = true, features = ["macros", "tokio"] } +libp2p-ping = { workspace = true } tokio = { version = "1.28", features = ["full"] } unsigned-varint = { version = "0.7", features = ["asynchronous_codec"] } void = "1" diff --git a/transports/websocket/CHANGELOG.md b/transports/websocket/CHANGELOG.md index 8433db846be..b8e795fd8d3 100644 --- a/transports/websocket/CHANGELOG.md +++ b/transports/websocket/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.42.0 - unreleased + +- Raise MSRV to 1.65. + See [PR 3715]. + +[PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 + ## 0.41.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/transports/websocket/Cargo.toml b/transports/websocket/Cargo.toml index 11efd27d9cb..643bf15b15f 100644 --- a/transports/websocket/Cargo.toml +++ b/transports/websocket/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "libp2p-websocket" edition = "2021" -rust-version = "1.60.0" +rust-version = { workspace = true } description = "WebSocket transport for libp2p" -version = "0.41.0" +version = "0.42.0" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" @@ -14,19 +14,19 @@ categories = ["network-programming", "asynchronous"] futures-rustls = "0.22" either = "1.5.3" futures = "0.3.28" -libp2p-core = { version = "0.39.0", path = "../../core" } -libp2p-identity = { version = "0.1.0", path = "../../identity" } +libp2p-core = { workspace = true } +libp2p-identity = { workspace = true } log = "0.4.8" parking_lot = "0.12.0" quicksink = "0.1" -rw-stream-sink = { version = "0.3.0", path = "../../misc/rw-stream-sink" } +rw-stream-sink = { workspace = true } soketto = { version = "0.7.0", features = ["deflate"] } url = "2.1" webpki-roots = "0.23" [dev-dependencies] -libp2p-tcp = { path = "../tcp", features = ["async-io"] } -libp2p-dns = { path = "../dns", features = ["async-std"] } +libp2p-tcp = { workspace = true, features = ["async-io"] } +libp2p-dns = { workspace = true, features = ["async-std"] } async-std = { version = "1.6.5", features = ["attributes"] } rcgen = "0.9.3" From 02d87155a5a0b056217095de9fd2e28800e1b14d Mon Sep 17 00:00:00 2001 From: DrHuangMHT Date: Tue, 2 May 2023 19:13:41 +0800 Subject: [PATCH 47/57] feat(mdns): change `mdns::Event` to hold `Vec` In previous PR #3606 we've made `mdns::Event` `Clone`, but cloning single-use iterators doesn't sound right. Also you have to create an iterator from the actual data returned before putting it into events. So in this PR the iterators are replaced by `Vec`, as it's the type the data originally come from. Related #3612. Pull-Request: #3621. --- protocols/mdns/CHANGELOG.md | 5 ++ protocols/mdns/src/behaviour.rs | 72 +++------------------------ protocols/mdns/tests/use-async-std.rs | 20 ++++---- protocols/mdns/tests/use-tokio.rs | 16 +++--- 4 files changed, 29 insertions(+), 84 deletions(-) diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index 7cc9ed0fb22..c6c61c0c907 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -1,8 +1,12 @@ ## 0.44.0 - unreleased +- Change `mdns::Event` to hold `Vec` and remove `DiscoveredAddrsIter` and `ExpiredAddrsIter`. + See [PR 3621]. + - Raise MSRV to 1.65. See [PR 3715]. +[PR 3621]: https://github.com/libp2p/rust-libp2p/pull/3621 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 ## 0.43.1 @@ -10,6 +14,7 @@ - Derive `Clone` for `mdns::Event`. See [PR 3606]. [PR 3606]: https://github.com/libp2p/rust-libp2p/pull/3606 + ## 0.43.0 - Update to `libp2p-core` `v0.39.0`. diff --git a/protocols/mdns/src/behaviour.rs b/protocols/mdns/src/behaviour.rs index 92e38c04998..5186ce91cb7 100644 --- a/protocols/mdns/src/behaviour.rs +++ b/protocols/mdns/src/behaviour.rs @@ -285,7 +285,7 @@ where } } // Emit discovered event. - let mut discovered = SmallVec::<[(PeerId, Multiaddr); 4]>::new(); + let mut discovered = Vec::new(); for iface_state in self.iface_states.values_mut() { while let Poll::Ready((peer, addr, expiration)) = iface_state.poll(cx, &self.listen_addresses) @@ -304,15 +304,13 @@ where } } if !discovered.is_empty() { - let event = Event::Discovered(DiscoveredAddrsIter { - inner: discovered.into_iter(), - }); + let event = Event::Discovered(discovered); return Poll::Ready(ToSwarm::GenerateEvent(event)); } // Emit expired event. let now = Instant::now(); let mut closest_expiration = None; - let mut expired = SmallVec::<[(PeerId, Multiaddr); 4]>::new(); + let mut expired = Vec::new(); self.discovered_nodes.retain(|(peer, addr, expiration)| { if *expiration <= now { log::info!("expired: {} {}", peer, addr); @@ -323,9 +321,7 @@ where true }); if !expired.is_empty() { - let event = Event::Expired(ExpiredAddrsIter { - inner: expired.into_iter(), - }); + let event = Event::Expired(expired); return Poll::Ready(ToSwarm::GenerateEvent(event)); } if let Some(closest_expiration) = closest_expiration { @@ -342,67 +338,11 @@ where #[derive(Debug, Clone)] pub enum Event { /// Discovered nodes through mDNS. - Discovered(DiscoveredAddrsIter), + Discovered(Vec<(PeerId, Multiaddr)>), /// The given combinations of `PeerId` and `Multiaddr` have expired. /// /// Each discovered record has a time-to-live. When this TTL expires and the address hasn't /// been refreshed, we remove it from the list and emit it as an `Expired` event. - Expired(ExpiredAddrsIter), -} - -/// Iterator that produces the list of addresses that have been discovered. -#[derive(Clone)] -pub struct DiscoveredAddrsIter { - inner: smallvec::IntoIter<[(PeerId, Multiaddr); 4]>, -} - -impl Iterator for DiscoveredAddrsIter { - type Item = (PeerId, Multiaddr); - - #[inline] - fn next(&mut self) -> Option { - self.inner.next() - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - self.inner.size_hint() - } -} - -impl ExactSizeIterator for DiscoveredAddrsIter {} - -impl fmt::Debug for DiscoveredAddrsIter { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_struct("DiscoveredAddrsIter").finish() - } -} - -/// Iterator that produces the list of addresses that have expired. -#[derive(Clone)] -pub struct ExpiredAddrsIter { - inner: smallvec::IntoIter<[(PeerId, Multiaddr); 4]>, -} - -impl Iterator for ExpiredAddrsIter { - type Item = (PeerId, Multiaddr); - - #[inline] - fn next(&mut self) -> Option { - self.inner.next() - } - - #[inline] - fn size_hint(&self) -> (usize, Option) { - self.inner.size_hint() - } -} - -impl ExactSizeIterator for ExpiredAddrsIter {} - -impl fmt::Debug for ExpiredAddrsIter { - fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt.debug_struct("ExpiredAddrsIter").finish() - } + Expired(Vec<(PeerId, Multiaddr)>), } diff --git a/protocols/mdns/tests/use-async-std.rs b/protocols/mdns/tests/use-async-std.rs index 139fcca1d50..bfc3cd1201d 100644 --- a/protocols/mdns/tests/use-async-std.rs +++ b/protocols/mdns/tests/use-async-std.rs @@ -61,13 +61,13 @@ async fn test_expired_async_std() { loop { match futures::future::select(a.next_behaviour_event(), b.next_behaviour_event()).await { - Either::Left((Event::Expired(mut peers), _)) => { - if peers.any(|(p, _)| p == b_peer_id) { + Either::Left((Event::Expired(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == b_peer_id) { return; } } - Either::Right((Event::Expired(mut peers), _)) => { - if peers.any(|(p, _)| p == a_peer_id) { + Either::Right((Event::Expired(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == a_peer_id) { return; } } @@ -93,8 +93,8 @@ async fn test_no_expiration_on_close_async_std() { // 1. Connect via address from mDNS event loop { - if let Event::Discovered(mut peers) = a.next_behaviour_event().await { - if let Some((_, addr)) = peers.find(|(p, _)| p == &b_peer_id) { + if let Event::Discovered(peers) = a.next_behaviour_event().await { + if let Some((_, addr)) = peers.into_iter().find(|(p, _)| p == &b_peer_id) { a.dial_and_wait(addr).await; break; } @@ -130,13 +130,13 @@ async fn run_discovery_test(config: Config) { while !discovered_a && !discovered_b { match futures::future::select(a.next_behaviour_event(), b.next_behaviour_event()).await { - Either::Left((Event::Discovered(mut peers), _)) => { - if peers.any(|(p, _)| p == b_peer_id) { + Either::Left((Event::Discovered(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == b_peer_id) { discovered_b = true; } } - Either::Right((Event::Discovered(mut peers), _)) => { - if peers.any(|(p, _)| p == a_peer_id) { + Either::Right((Event::Discovered(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == a_peer_id) { discovered_a = true; } } diff --git a/protocols/mdns/tests/use-tokio.rs b/protocols/mdns/tests/use-tokio.rs index e18ae28fee7..229418437f4 100644 --- a/protocols/mdns/tests/use-tokio.rs +++ b/protocols/mdns/tests/use-tokio.rs @@ -59,13 +59,13 @@ async fn test_expired_tokio() { loop { match futures::future::select(a.next_behaviour_event(), b.next_behaviour_event()).await { - Either::Left((Event::Expired(mut peers), _)) => { - if peers.any(|(p, _)| p == b_peer_id) { + Either::Left((Event::Expired(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == b_peer_id) { return; } } - Either::Right((Event::Expired(mut peers), _)) => { - if peers.any(|(p, _)| p == a_peer_id) { + Either::Right((Event::Expired(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == a_peer_id) { return; } } @@ -86,13 +86,13 @@ async fn run_discovery_test(config: Config) { while !discovered_a && !discovered_b { match futures::future::select(a.next_behaviour_event(), b.next_behaviour_event()).await { - Either::Left((Event::Discovered(mut peers), _)) => { - if peers.any(|(p, _)| p == b_peer_id) { + Either::Left((Event::Discovered(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == b_peer_id) { discovered_b = true; } } - Either::Right((Event::Discovered(mut peers), _)) => { - if peers.any(|(p, _)| p == a_peer_id) { + Either::Right((Event::Discovered(peers), _)) => { + if peers.into_iter().any(|(p, _)| p == a_peer_id) { discovered_a = true; } } From 30d2c75206b805e0f1efdbd39fcc8917553b7bd6 Mon Sep 17 00:00:00 2001 From: Hannes <55623006+umgefahren@users.noreply.github.com> Date: Tue, 2 May 2023 13:32:28 +0200 Subject: [PATCH 48/57] chore(mdns): remove deprecated items Related: https://github.com/libp2p/rust-libp2p/issues/3647. Pull-Request: #3699. --- protocols/mdns/CHANGELOG.md | 2 ++ protocols/mdns/src/lib.rs | 19 ------------------- 2 files changed, 2 insertions(+), 19 deletions(-) diff --git a/protocols/mdns/CHANGELOG.md b/protocols/mdns/CHANGELOG.md index c6c61c0c907..661f9779943 100644 --- a/protocols/mdns/CHANGELOG.md +++ b/protocols/mdns/CHANGELOG.md @@ -5,9 +5,11 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Remove deprecated `Mdns` prefixed items. See [PR 3699]. [PR 3621]: https://github.com/libp2p/rust-libp2p/pull/3621 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3699]: https://github.com/libp2p/rust-libp2p/pull/3699 ## 0.43.1 diff --git a/protocols/mdns/src/lib.rs b/protocols/mdns/src/lib.rs index c303773a391..4823d740272 100644 --- a/protocols/mdns/src/lib.rs +++ b/protocols/mdns/src/lib.rs @@ -38,25 +38,6 @@ use std::net::{Ipv4Addr, Ipv6Addr}; use std::time::Duration; -#[deprecated( - since = "0.42.0", - note = "Use re-exports that omit `Mdns` prefix, i.e. `libp2p::mdns::Config`" -)] -pub type MdnsConfig = Config; - -#[deprecated( - since = "0.42.0", - note = "Use re-exports that omit `Mdns` prefix, i.e. `libp2p::mdns::Event`" -)] -pub type MdnsEvent = Event; - -#[deprecated( - since = "0.42.0", - note = "Use the async-io prefixed `Mdns`, i.e. `libp2p::mdns::async_io::Mdns`" -)] -#[cfg(feature = "async-io")] -pub type Mdns = async_io::Behaviour; - mod behaviour; pub use crate::behaviour::{Behaviour, Event}; From c728824440fa055e6ee025ab87621e08eade89de Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Tue, 2 May 2023 13:49:07 +0200 Subject: [PATCH 49/57] feat(relay): hide internals of `Connection` Relayed connections to other peers are created from streams to the relay itself. Internally, such a connection has different states. These however are not relevant to the user and should be encapsulated to allow for more backwards-compatible changes. The only interface exposed is `AsyncRead` and `AsyncWrite`. Resolves: #3255. Pull-Request: #3829. --- protocols/relay/CHANGELOG.md | 4 ++ protocols/relay/src/priv_client.rs | 78 ++++++++++++++-------- protocols/relay/src/priv_client/handler.rs | 13 ++-- 3 files changed, 59 insertions(+), 36 deletions(-) diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index f718fc5adf5..4b3b9778439 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -3,7 +3,11 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Hide internals of `Connection` and expose only `AsyncRead` and `AsyncWrite`. + See [PR 3829]. + [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3829]: https://github.com/libp2p/rust-libp2p/pull/3829 ## 0.15.2 diff --git a/protocols/relay/src/priv_client.rs b/protocols/relay/src/priv_client.rs index 2a24607a724..9f250adf8d8 100644 --- a/protocols/relay/src/priv_client.rs +++ b/protocols/relay/src/priv_client.rs @@ -45,7 +45,6 @@ use libp2p_swarm::{ }; use std::collections::{hash_map, HashMap, VecDeque}; use std::io::{Error, ErrorKind, IoSlice}; -use std::ops::DerefMut; use std::pin::Pin; use std::task::{Context, Poll}; use transport::Transport; @@ -387,32 +386,43 @@ impl NetworkBehaviour for Behaviour { } } -/// A [`NegotiatedSubstream`] acting as a [`Connection`]. -pub enum Connection { +/// Represents a connection to another peer via a relay. +/// +/// Internally, this uses a stream to the relay. +pub struct Connection { + state: ConnectionState, +} + +enum ConnectionState { InboundAccepting { - accept: BoxFuture<'static, Result>, + accept: BoxFuture<'static, Result>, }, Operational { read_buffer: Bytes, substream: NegotiatedSubstream, + /// "Drop notifier" pattern to signal to the transport that the connection has been dropped. + /// + /// This is flagged as "dead-code" by the compiler because we never read from it here. + /// However, it is actual use is to trigger the `Canceled` error in the `Transport` when this `Sender` is dropped. + #[allow(dead_code)] drop_notifier: oneshot::Sender, }, } -impl Unpin for Connection {} +impl Unpin for ConnectionState {} -impl Connection { +impl ConnectionState { pub(crate) fn new_inbound( circuit: inbound_stop::Circuit, drop_notifier: oneshot::Sender, ) -> Self { - Connection::InboundAccepting { + ConnectionState::InboundAccepting { accept: async { let (substream, read_buffer) = circuit .accept() .await .map_err(|e| Error::new(ErrorKind::Other, e))?; - Ok(Connection::Operational { + Ok(ConnectionState::Operational { read_buffer, substream, drop_notifier, @@ -427,7 +437,7 @@ impl Connection { read_buffer: Bytes, drop_notifier: oneshot::Sender, ) -> Self { - Connection::Operational { + ConnectionState::Operational { substream, read_buffer, drop_notifier, @@ -442,11 +452,13 @@ impl AsyncWrite for Connection { buf: &[u8], ) -> Poll> { loop { - match self.deref_mut() { - Connection::InboundAccepting { accept } => { - *self = ready!(accept.poll_unpin(cx))?; + match &mut self.state { + ConnectionState::InboundAccepting { accept } => { + *self = Connection { + state: ready!(accept.poll_unpin(cx))?, + }; } - Connection::Operational { substream, .. } => { + ConnectionState::Operational { substream, .. } => { return Pin::new(substream).poll_write(cx, buf); } } @@ -454,11 +466,13 @@ impl AsyncWrite for Connection { } fn poll_flush(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { loop { - match self.deref_mut() { - Connection::InboundAccepting { accept } => { - *self = ready!(accept.poll_unpin(cx))?; + match &mut self.state { + ConnectionState::InboundAccepting { accept } => { + *self = Connection { + state: ready!(accept.poll_unpin(cx))?, + }; } - Connection::Operational { substream, .. } => { + ConnectionState::Operational { substream, .. } => { return Pin::new(substream).poll_flush(cx); } } @@ -466,11 +480,13 @@ impl AsyncWrite for Connection { } fn poll_close(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll> { loop { - match self.deref_mut() { - Connection::InboundAccepting { accept } => { - *self = ready!(accept.poll_unpin(cx))?; + match &mut self.state { + ConnectionState::InboundAccepting { accept } => { + *self = Connection { + state: ready!(accept.poll_unpin(cx))?, + }; } - Connection::Operational { substream, .. } => { + ConnectionState::Operational { substream, .. } => { return Pin::new(substream).poll_close(cx); } } @@ -483,11 +499,13 @@ impl AsyncWrite for Connection { bufs: &[IoSlice], ) -> Poll> { loop { - match self.deref_mut() { - Connection::InboundAccepting { accept } => { - *self = ready!(accept.poll_unpin(cx))?; + match &mut self.state { + ConnectionState::InboundAccepting { accept } => { + *self = Connection { + state: ready!(accept.poll_unpin(cx))?, + }; } - Connection::Operational { substream, .. } => { + ConnectionState::Operational { substream, .. } => { return Pin::new(substream).poll_write_vectored(cx, bufs); } } @@ -502,11 +520,13 @@ impl AsyncRead for Connection { buf: &mut [u8], ) -> Poll> { loop { - match self.deref_mut() { - Connection::InboundAccepting { accept } => { - *self = ready!(accept.poll_unpin(cx))?; + match &mut self.state { + ConnectionState::InboundAccepting { accept } => { + *self = Connection { + state: ready!(accept.poll_unpin(cx))?, + }; } - Connection::Operational { + ConnectionState::Operational { read_buffer, substream, .. diff --git a/protocols/relay/src/priv_client/handler.rs b/protocols/relay/src/priv_client/handler.rs index 504fab590f8..290b72e94af 100644 --- a/protocols/relay/src/priv_client/handler.rs +++ b/protocols/relay/src/priv_client/handler.rs @@ -189,10 +189,11 @@ impl Handler { let (tx, rx) = oneshot::channel(); self.alive_lend_out_substreams.push(rx); - let connection = super::Connection::new_inbound(inbound_circuit, tx); + let connection = super::ConnectionState::new_inbound(inbound_circuit, tx); pending_msgs.push_back(transport::ToListenerMsg::IncomingRelayedConnection { - stream: connection, + // stream: connection, + stream: super::Connection { state: connection }, src_peer_id, relay_peer_id: self.remote_peer_id, relay_addr: self.remote_addr.clone(), @@ -271,11 +272,9 @@ impl Handler { OutboundOpenInfo::Connect { send_back }, ) => { let (tx, rx) = oneshot::channel(); - match send_back.send(Ok(super::Connection::new_outbound( - substream, - read_buffer, - tx, - ))) { + match send_back.send(Ok(super::Connection { + state: super::ConnectionState::new_outbound(substream, read_buffer, tx), + })) { Ok(()) => { self.alive_lend_out_substreams.push(rx); self.queued_events.push_back(ConnectionHandlerEvent::Custom( From 4ca888580c113916a36951106c4caaa13724f1ff Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Tue, 2 May 2023 13:15:22 +0100 Subject: [PATCH 50/57] refactor(noise): implement tests using `futures_ringbuf` Instead of creating a connection via a TCP transport, we can use the `futures_ringbuf` crate and run the noise encryption on an in-memory transport. This removes the dependency on the `libp2p_core::upgrade::apply` function and takes less code to implement. Related #3748. Pull-Request: #3773. --- Cargo.lock | 3 +- transports/noise/Cargo.toml | 3 +- transports/noise/src/lib.rs | 6 +- transports/noise/tests/smoke.rs | 166 +++++++++++--------------------- 4 files changed, 59 insertions(+), 119 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a883c7e6b0d..8766e028d2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2688,14 +2688,13 @@ dependencies = [ name = "libp2p-noise" version = "0.43.0" dependencies = [ - "async-io", "bytes", "curve25519-dalek 3.2.0", "env_logger 0.10.0", "futures", + "futures_ringbuf", "libp2p-core", "libp2p-identity", - "libp2p-tcp", "log", "once_cell", "quick-protobuf", diff --git a/transports/noise/Cargo.toml b/transports/noise/Cargo.toml index 97dca96f241..b44c07633c7 100644 --- a/transports/noise/Cargo.toml +++ b/transports/noise/Cargo.toml @@ -31,9 +31,8 @@ snow = { version = "0.9.2", features = ["ring-resolver"], default-features = fal snow = { version = "0.9.2", features = ["default-resolver"], default-features = false } [dev-dependencies] -async-io = "1.13.0" env_logger = "0.10.0" -libp2p-tcp = { workspace = true, features = ["async-io"] } +futures_ringbuf = "0.3.1" quickcheck = { workspace = true } # Passing arguments to the docsrs builder in order to properly document cfg's. diff --git a/transports/noise/src/lib.rs b/transports/noise/src/lib.rs index 1e5b0a437e1..4c296e9a111 100644 --- a/transports/noise/src/lib.rs +++ b/transports/noise/src/lib.rs @@ -39,14 +39,14 @@ //! Example: //! //! ``` -//! use libp2p_core::{identity, Transport, upgrade}; -//! use libp2p_tcp::TcpTransport; +//! use libp2p_core::{Transport, upgrade, transport::MemoryTransport}; //! use libp2p_noise as noise; +//! use libp2p_identity as identity; //! //! # fn main() { //! let id_keys = identity::Keypair::generate_ed25519(); //! let noise = noise::Config::new(&id_keys).unwrap(); -//! let builder = TcpTransport::default().upgrade(upgrade::Version::V1).authenticate(noise); +//! let builder = MemoryTransport::default().upgrade(upgrade::Version::V1).authenticate(noise); //! // let transport = builder.multiplex(...); //! # } //! ``` diff --git a/transports/noise/tests/smoke.rs b/transports/noise/tests/smoke.rs index 9ddbca3eec8..b7ce90267e1 100644 --- a/transports/noise/tests/smoke.rs +++ b/transports/noise/tests/smoke.rs @@ -18,18 +18,14 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use async_io::Async; use futures::prelude::*; -use libp2p_core::transport::Transport; -use libp2p_core::upgrade::Negotiated; -use libp2p_core::{transport, upgrade}; +use libp2p_core::transport::{MemoryTransport, Transport}; +use libp2p_core::{upgrade, InboundUpgrade, OutboundUpgrade}; use libp2p_identity as identity; -use libp2p_identity::PeerId; use libp2p_noise as noise; -use libp2p_tcp as tcp; use log::info; use quickcheck::*; -use std::{convert::TryInto, io, net::TcpStream}; +use std::{convert::TryInto, io}; #[allow(dead_code)] fn core_upgrade_compat() { @@ -37,7 +33,7 @@ fn core_upgrade_compat() { // i.e. if it compiles, the "test" is considered a success. let id_keys = identity::Keypair::generate_ed25519(); let noise = noise::Config::new(&id_keys).unwrap(); - let _ = tcp::async_io::Transport::default() + let _ = MemoryTransport::default() .upgrade(upgrade::Version::V1) .authenticate(noise); } @@ -50,42 +46,58 @@ fn xx() { let server_id = identity::Keypair::generate_ed25519(); let client_id = identity::Keypair::generate_ed25519(); - let server_id_public = server_id.public(); - let client_id_public = client_id.public(); - - let server_transport = tcp::async_io::Transport::default() - .and_then(move |output, endpoint| { - upgrade::apply( - output, - noise::Config::new(&server_id).unwrap(), - endpoint, - upgrade::Version::V1, - ) - }) - .map(move |out, _| { - assert_eq!(out.0, client_id_public.to_peer_id()); - - out - }) - .boxed(); - - let client_transport = tcp::async_io::Transport::default() - .and_then(move |output, endpoint| { - upgrade::apply( - output, - noise::Config::new(&client_id).unwrap(), - endpoint, - upgrade::Version::V1, - ) - }) - .map(move |out, _| { - assert_eq!(out.0, server_id_public.to_peer_id()); + let (client, server) = futures_ringbuf::Endpoint::pair(100, 100); + + futures::executor::block_on(async move { + let ( + (reported_client_id, mut client_session), + (reported_server_id, mut server_session), + ) = futures::future::try_join( + noise::Config::new(&server_id) + .unwrap() + .upgrade_inbound(server, b""), + noise::Config::new(&client_id) + .unwrap() + .upgrade_outbound(client, b""), + ) + .await + .unwrap(); - out - }) - .boxed(); + assert_eq!(reported_client_id, client_id.public().to_peer_id()); + assert_eq!(reported_server_id, server_id.public().to_peer_id()); + + let client_fut = async { + for m in &messages { + let n = (m.0.len() as u64).to_be_bytes(); + client_session.write_all(&n[..]).await.expect("len written"); + client_session.write_all(&m.0).await.expect("no error") + } + client_session.flush().await.expect("no error"); + }; + + let server_fut = async { + for m in &messages { + let len = { + let mut n = [0; 8]; + match server_session.read_exact(&mut n).await { + Ok(()) => u64::from_be_bytes(n), + Err(e) if e.kind() == io::ErrorKind::UnexpectedEof => 0, + Err(e) => panic!("error reading len: {e}"), + } + }; + info!("server: reading message ({} bytes)", len); + let mut server_buffer = vec![0; len.try_into().unwrap()]; + server_session + .read_exact(&mut server_buffer) + .await + .expect("no error"); + assert_eq!(server_buffer, m.0) + } + }; + + futures::future::join(client_fut, server_fut).await; + }); - run(server_transport, client_transport, messages); true } QuickCheck::new() @@ -93,76 +105,6 @@ fn xx() { .quickcheck(prop as fn(Vec) -> bool) } -type Output = (PeerId, noise::Output>>); - -fn run(mut server: transport::Boxed, mut client: transport::Boxed, messages: I) -where - I: IntoIterator + Clone, -{ - futures::executor::block_on(async { - server - .listen_on("/ip4/127.0.0.1/tcp/0".parse().unwrap()) - .unwrap(); - - let server_address = server - .next() - .await - .expect("some event") - .into_new_address() - .expect("listen address"); - - let outbound_msgs = messages.clone(); - let client_fut = async { - let mut client_session = client - .dial(server_address.clone()) - .unwrap() - .await - .map(|(_, session)| session) - .expect("no error"); - - for m in outbound_msgs { - let n = (m.0.len() as u64).to_be_bytes(); - client_session.write_all(&n[..]).await.expect("len written"); - client_session.write_all(&m.0).await.expect("no error") - } - client_session.flush().await.expect("no error"); - }; - - let server_fut = async { - let mut server_session = server - .next() - .await - .expect("some event") - .into_incoming() - .expect("listener upgrade") - .0 - .await - .map(|(_, session)| session) - .expect("no error"); - - for m in messages { - let len = { - let mut n = [0; 8]; - match server_session.read_exact(&mut n).await { - Ok(()) => u64::from_be_bytes(n), - Err(e) if e.kind() == io::ErrorKind::UnexpectedEof => 0, - Err(e) => panic!("error reading len: {e}"), - } - }; - info!("server: reading message ({} bytes)", len); - let mut server_buffer = vec![0; len.try_into().unwrap()]; - server_session - .read_exact(&mut server_buffer) - .await - .expect("no error"); - assert_eq!(server_buffer, m.0) - } - }; - - futures::future::join(server_fut, client_fut).await; - }) -} - #[derive(Debug, Clone, PartialEq, Eq)] struct Message(Vec); From 3e5f64345beaea3fe391442f4e090e289436304d Mon Sep 17 00:00:00 2001 From: Hannes <55623006+umgefahren@users.noreply.github.com> Date: Tue, 2 May 2023 15:15:34 +0200 Subject: [PATCH 51/57] chore(identify): remove deprecated items Related: https://github.com/libp2p/rust-libp2p/issues/3647. Pull-Request: #3698. --- protocols/identify/CHANGELOG.md | 2 ++ protocols/identify/src/lib.rs | 21 --------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index aaf316869fe..d05e63a5c4e 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -1,8 +1,10 @@ ## 0.43.0 - unreleased +- Remove deprecated `Identify` prefixed symbols. See [PR 3698]. - Raise MSRV to 1.65. See [PR 3715]. +[PR 3698]: https://github.com/libp2p/rust-libp2p/pull/3698 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 ## 0.42.2 diff --git a/protocols/identify/src/lib.rs b/protocols/identify/src/lib.rs index f7a4a1ecbd8..34928d5d7df 100644 --- a/protocols/identify/src/lib.rs +++ b/protocols/identify/src/lib.rs @@ -44,27 +44,6 @@ pub use self::behaviour::{Behaviour, Config, Event}; pub use self::protocol::{Info, UpgradeError, PROTOCOL_NAME, PUSH_PROTOCOL_NAME}; -#[deprecated( - since = "0.40.0", - note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p_identify::Config`" -)] -pub type IdentifyConfig = Config; - -#[deprecated( - since = "0.40.0", - note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p_identify::Event`" -)] -pub type IdentifyEvent = Event; - -#[deprecated(since = "0.40.0", note = "Use libp2p_identify::Behaviour instead.")] -pub type Identify = Behaviour; - -#[deprecated( - since = "0.40.0", - note = "Use re-exports that omit `Identify` prefix, i.e. `libp2p_identify::Info`" -)] -pub type IdentifyInfo = Info; - mod behaviour; mod handler; mod protocol; From cacfb5978116a5a46b1458f63e8c5291aaba3de0 Mon Sep 17 00:00:00 2001 From: Hannes <55623006+umgefahren@users.noreply.github.com> Date: Tue, 2 May 2023 15:30:04 +0200 Subject: [PATCH 52/57] chore(dcutr): remove deprecated items Removes deprecated items from `libp2p-dcutr`. Related https://github.com/libp2p/rust-libp2p/issues/3647 Pull-Request: #3700. --- libp2p/src/tutorials/hole_punching.rs | 4 ++-- protocols/dcutr/CHANGELOG.md | 2 ++ protocols/dcutr/src/lib.rs | 22 ---------------------- protocols/dcutr/src/protocol/inbound.rs | 3 --- protocols/dcutr/src/protocol/outbound.rs | 3 --- 5 files changed, 4 insertions(+), 30 deletions(-) diff --git a/libp2p/src/tutorials/hole_punching.rs b/libp2p/src/tutorials/hole_punching.rs index 10e2ec4c462..8c898f7f4f4 100644 --- a/libp2p/src/tutorials/hole_punching.rs +++ b/libp2p/src/tutorials/hole_punching.rs @@ -168,7 +168,7 @@ //! //! 2. The listening client initiating a direct connection upgrade for the new relayed connection. //! Reported by [`dcutr`](crate::dcutr) through -//! [`Event::RemoteInitiatedDirectConnectionUpgrade`](crate::dcutr::behaviour::Event::RemoteInitiatedDirectConnectionUpgrade). +//! [`Event::RemoteInitiatedDirectConnectionUpgrade`](crate::dcutr::Event::RemoteInitiatedDirectConnectionUpgrade). //! //! ``` ignore //! [2022-01-30T12:54:11Z INFO client] RemoteInitiatedDirectConnectionUpgrade { remote_peer_id: PeerId("12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X"), remote_relayed_addr: "/ip4/$RELAY_PEER_ID/tcp/4001/p2p/12D3KooWDpJ7As7BWAwRMfu1VU2WCqNjvq387JEYKDBj4kx6nXTN/p2p-circuit/p2p/12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X" } @@ -176,7 +176,7 @@ //! //! 3. The direct connection upgrade, also known as hole punch, succeeding. Reported by //! [`dcutr`](crate::dcutr) through -//! [`Event::RemoteInitiatedDirectConnectionUpgrade`](crate::dcutr::behaviour::Event::DirectConnectionUpgradeSucceeded). +//! [`Event::RemoteInitiatedDirectConnectionUpgrade`](crate::dcutr::Event::DirectConnectionUpgradeSucceeded). //! //! ``` ignore //! [2022-01-30T12:54:11Z INFO client] DirectConnectionUpgradeSucceeded { remote_peer_id: PeerId("12D3KooWPjceQrSwdWXPyLLeABRXmuqt69Rg3sBYbU1Nft9HyQ6X") } diff --git a/protocols/dcutr/CHANGELOG.md b/protocols/dcutr/CHANGELOG.md index cd3e34e2ad8..5fb84593488 100644 --- a/protocols/dcutr/CHANGELOG.md +++ b/protocols/dcutr/CHANGELOG.md @@ -2,8 +2,10 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Remove deprecated items. See [PR 3700]. [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3700]: https://github.com/libp2p/rust-libp2p/pull/3700 ## 0.9.1 diff --git a/protocols/dcutr/src/lib.rs b/protocols/dcutr/src/lib.rs index b35849319d2..6001c9144e7 100644 --- a/protocols/dcutr/src/lib.rs +++ b/protocols/dcutr/src/lib.rs @@ -43,25 +43,3 @@ pub mod inbound { pub mod outbound { pub use crate::protocol::outbound::UpgradeError; } - -#[deprecated( - since = "0.9.0", - note = "Use `libp2p_dcutr::inbound::UpgradeError` instead.`" -)] -pub type InboundUpgradeError = inbound::UpgradeError; - -#[deprecated( - since = "0.9.0", - note = "Use `libp2p_dcutr::outbound::UpgradeError` instead.`" -)] -pub type OutboundUpgradeError = outbound::UpgradeError; -pub mod behaviour { - #[deprecated(since = "0.9.0", note = "Use `libp2p_dcutr::Behaviour` instead.`")] - pub type Behaviour = crate::Behaviour; - - #[deprecated(since = "0.9.0", note = "Use `libp2p_dcutr::Event` instead.`")] - pub type Event = crate::Event; - - #[deprecated(since = "0.9.0", note = "Use `libp2p_dcutr::Error` instead.`")] - pub type UpgradeError = crate::Error; -} diff --git a/protocols/dcutr/src/protocol/inbound.rs b/protocols/dcutr/src/protocol/inbound.rs index fde42c6c924..df4c3c63d34 100644 --- a/protocols/dcutr/src/protocol/inbound.rs +++ b/protocols/dcutr/src/protocol/inbound.rs @@ -130,9 +130,6 @@ pub enum UpgradeError { StreamClosed, #[error("Expected at least one address in reservation.")] NoAddresses, - #[deprecated(since = "0.8.1", note = "Error is no longer constructed.")] - #[error("Invalid addresses.")] - InvalidAddrs, #[error("Failed to parse response type field.")] ParseTypeField, #[error("Unexpected message type 'connect'")] diff --git a/protocols/dcutr/src/protocol/outbound.rs b/protocols/dcutr/src/protocol/outbound.rs index 9bbb1eb89a8..29509b16c34 100644 --- a/protocols/dcutr/src/protocol/outbound.rs +++ b/protocols/dcutr/src/protocol/outbound.rs @@ -136,9 +136,6 @@ pub enum UpgradeError { NoAddresses, #[error("Invalid expiration timestamp in reservation.")] InvalidReservationExpiration, - #[deprecated(since = "0.8.1", note = "Error is no longer constructed.")] - #[error("Invalid addresses in reservation.")] - InvalidAddrs, #[error("Failed to parse response type field.")] ParseTypeField, #[error("Unexpected message type 'connect'")] From e135e550655bdbba9385a338b3a3007b67414db8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 13:58:44 +0000 Subject: [PATCH 53/57] deps: bump flate2 from 1.0.25 to 1.0.26 Pull-Request: #3857. --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8766e028d2e..a1ec08f9ff0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1537,9 +1537,9 @@ dependencies = [ [[package]] name = "flate2" -version = "1.0.25" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +checksum = "3b9429470923de8e8cbd4d2dc513535400b4b3fef0319fb5c4e1f520a7bef743" dependencies = [ "crc32fast", "libz-sys", @@ -3277,9 +3277,9 @@ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" dependencies = [ "adler", ] From 9fc2da01807caa7a20b64a1c73d4a2d396be5d26 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 2 May 2023 14:11:57 +0000 Subject: [PATCH 54/57] deps: bump anyhow from 1.0.70 to 1.0.71 Pull-Request: #3856. --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a1ec08f9ff0..3976577ecd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -175,9 +175,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] name = "arbitrary" From f858ec6237d8d6e0728791d7727ec707aae3b60a Mon Sep 17 00:00:00 2001 From: Bogdan <36648694+PopBogdan97@users.noreply.github.com> Date: Tue, 2 May 2023 16:24:56 +0200 Subject: [PATCH 55/57] feat(identify): immediately run identify protocol on new connections Previously, and for unknown legacy reasons, we waited for a configurable delay (default 500ms) upon new connections before we ran the identify protocol. This unnecessarily slows down applications that wait for the identify handshake to complete before performing further actions. Resolves #3485. Pull-Request: #3545. --- protocols/identify/CHANGELOG.md | 4 ++++ protocols/identify/src/behaviour.rs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/protocols/identify/CHANGELOG.md b/protocols/identify/CHANGELOG.md index d05e63a5c4e..69f26e447b8 100644 --- a/protocols/identify/CHANGELOG.md +++ b/protocols/identify/CHANGELOG.md @@ -4,8 +4,12 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Reduce the initial delay before running the identify protocol to 0 and make the option deprecated. + See [PR 3545]. + [PR 3698]: https://github.com/libp2p/rust-libp2p/pull/3698 [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3545]: https://github.com/libp2p/rust-libp2p/pull/3545 ## 0.42.2 diff --git a/protocols/identify/src/behaviour.rs b/protocols/identify/src/behaviour.rs index 08d0681463a..6dcea9c1df3 100644 --- a/protocols/identify/src/behaviour.rs +++ b/protocols/identify/src/behaviour.rs @@ -88,7 +88,10 @@ pub struct Config { /// The initial delay before the first identification request /// is sent to a remote on a newly established connection. /// - /// Defaults to 500ms. + /// Defaults to 0ms. + #[deprecated(note = "The `initial_delay` is no longer necessary and will be + completely removed since a remote should be able to instantly + answer to an identify request")] pub initial_delay: Duration, /// The interval at which identification requests are sent to /// the remote on established connections after the first request, @@ -117,12 +120,13 @@ pub struct Config { impl Config { /// Creates a new configuration for the identify [`Behaviour`] that /// advertises the given protocol version and public key. + #[allow(deprecated)] pub fn new(protocol_version: String, local_public_key: PublicKey) -> Self { Self { protocol_version, agent_version: format!("rust-libp2p/{}", env!("CARGO_PKG_VERSION")), local_public_key, - initial_delay: Duration::from_millis(500), + initial_delay: Duration::from_millis(0), interval: Duration::from_secs(5 * 60), push_listen_addr_updates: false, cache_size: 100, @@ -137,6 +141,10 @@ impl Config { /// Configures the initial delay before the first identification /// request is sent on a newly established connection to a peer. + #[deprecated(note = "The `initial_delay` is no longer necessary and will be + completely removed since a remote should be able to instantly + answer to an identify request thus also this setter will be removed")] + #[allow(deprecated)] pub fn with_initial_delay(mut self, d: Duration) -> Self { self.initial_delay = d; self @@ -239,6 +247,7 @@ impl NetworkBehaviour for Behaviour { type ConnectionHandler = Handler; type OutEvent = Event; + #[allow(deprecated)] fn handle_established_inbound_connection( &mut self, _: ConnectionId, @@ -257,6 +266,7 @@ impl NetworkBehaviour for Behaviour { )) } + #[allow(deprecated)] fn handle_established_outbound_connection( &mut self, _: ConnectionId, @@ -737,6 +747,7 @@ mod tests { let mut swarm1 = { let (pubkey, transport) = transport(); + #[allow(deprecated)] let protocol = Behaviour::new( Config::new("a".to_string(), pubkey.clone()) // `swarm1` will set `KeepAlive::No` once it identified `swarm2` and thus From 25d14349cc32f7a8e3feffb931ba2e84cccb0013 Mon Sep 17 00:00:00 2001 From: Hannes <55623006+umgefahren@users.noreply.github.com> Date: Tue, 2 May 2023 18:02:21 +0200 Subject: [PATCH 56/57] chore(gossipsub): remove deprecated items Removes deprecated items from gossipsub and make certain modules crate-private. Related https://github.com/libp2p/rust-libp2p/issues/3647. Pull-Request: #3862. --- Cargo.lock | 1 - protocols/gossipsub/CHANGELOG.md | 2 + protocols/gossipsub/Cargo.toml | 1 - protocols/gossipsub/src/behaviour.rs | 10 +- protocols/gossipsub/src/behaviour/tests.rs | 2 +- protocols/gossipsub/src/config.rs | 2 +- protocols/gossipsub/src/error.rs | 127 +++++++++++++--- protocols/gossipsub/src/error_priv.rs | 141 ------------------ protocols/gossipsub/src/handler.rs | 2 +- protocols/gossipsub/src/lib.rs | 104 ++----------- .../src/{metrics_priv.rs => metrics.rs} | 52 ++++--- protocols/gossipsub/src/peer_score.rs | 4 +- .../src/{protocol_priv.rs => protocol.rs} | 0 ..._filter_priv.rs => subscription_filter.rs} | 0 .../src/{time_cache_priv.rs => time_cache.rs} | 65 +++----- 15 files changed, 170 insertions(+), 343 deletions(-) delete mode 100644 protocols/gossipsub/src/error_priv.rs rename protocols/gossipsub/src/{metrics_priv.rs => metrics.rs} (92%) rename protocols/gossipsub/src/{protocol_priv.rs => protocol.rs} (100%) rename protocols/gossipsub/src/{subscription_filter_priv.rs => subscription_filter.rs} (100%) rename protocols/gossipsub/src/{time_cache_priv.rs => time_cache.rs} (74%) diff --git a/Cargo.lock b/Cargo.lock index 3976577ecd2..978a40d6140 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2516,7 +2516,6 @@ dependencies = [ "serde", "sha2 0.10.6", "smallvec", - "thiserror", "unsigned-varint", "void", "wasm-timer", diff --git a/protocols/gossipsub/CHANGELOG.md b/protocols/gossipsub/CHANGELOG.md index fbfb45ca5c7..b3885d66600 100644 --- a/protocols/gossipsub/CHANGELOG.md +++ b/protocols/gossipsub/CHANGELOG.md @@ -2,8 +2,10 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Remove deprecated items. See [PR 3862]. [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3862]: https://github.com/libp2p/rust-libp2p/pull/3862 ## 0.44.4 diff --git a/protocols/gossipsub/Cargo.toml b/protocols/gossipsub/Cargo.toml index 8ae5d0d5f87..a095256a788 100644 --- a/protocols/gossipsub/Cargo.toml +++ b/protocols/gossipsub/Cargo.toml @@ -31,7 +31,6 @@ quick-protobuf-codec = { workspace = true } hex_fmt = "0.3.0" regex = "1.8.1" serde = { version = "1", optional = true, features = ["derive"] } -thiserror = "1.0" wasm-timer = "0.2.5" instant = "0.1.11" void = "1.0.2" diff --git a/protocols/gossipsub/src/behaviour.rs b/protocols/gossipsub/src/behaviour.rs index 542195617d2..6a92210e725 100644 --- a/protocols/gossipsub/src/behaviour.rs +++ b/protocols/gossipsub/src/behaviour.rs @@ -50,11 +50,11 @@ use crate::config::{Config, ValidationMode}; use crate::gossip_promises::GossipPromises; use crate::handler::{Handler, HandlerEvent, HandlerIn}; use crate::mcache::MessageCache; -use crate::metrics_priv::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty}; +use crate::metrics::{Churn, Config as MetricsConfig, Inclusion, Metrics, Penalty}; use crate::peer_score::{PeerScore, PeerScoreParams, PeerScoreThresholds, RejectReason}; -use crate::protocol_priv::{ProtocolConfig, SIGNING_PREFIX}; -use crate::subscription_filter_priv::{AllowAllSubscriptionFilter, TopicSubscriptionFilter}; -use crate::time_cache_priv::{DuplicateCache, TimeCache}; +use crate::protocol::{ProtocolConfig, SIGNING_PREFIX}; +use crate::subscription_filter::{AllowAllSubscriptionFilter, TopicSubscriptionFilter}; +use crate::time_cache::{DuplicateCache, TimeCache}; use crate::topic::{Hasher, Topic, TopicHash}; use crate::transform::{DataTransform, IdentityTransform}; use crate::types::{ @@ -3824,7 +3824,7 @@ mod local_test { let mut length_codec = unsigned_varint::codec::UviBytes::default(); length_codec.set_max_len(max_transmit_size); let mut codec = - crate::protocol_priv::GossipsubCodec::new(length_codec, ValidationMode::Permissive); + crate::protocol::GossipsubCodec::new(length_codec, ValidationMode::Permissive); let rpc_proto = rpc.into_protobuf(); let fragmented_messages = gs diff --git a/protocols/gossipsub/src/behaviour/tests.rs b/protocols/gossipsub/src/behaviour/tests.rs index 9b662f765d5..8c6052bd6b6 100644 --- a/protocols/gossipsub/src/behaviour/tests.rs +++ b/protocols/gossipsub/src/behaviour/tests.rs @@ -21,7 +21,7 @@ // Collection of tests for the gossipsub network behaviour use super::*; -use crate::subscription_filter_priv::WhitelistSubscriptionFilter; +use crate::subscription_filter::WhitelistSubscriptionFilter; use crate::transform::{DataTransform, IdentityTransform}; use crate::types::FastMessageId; use crate::ValidationError; diff --git a/protocols/gossipsub/src/config.rs b/protocols/gossipsub/src/config.rs index 9fe5ee8cf5e..aa488b4ea29 100644 --- a/protocols/gossipsub/src/config.rs +++ b/protocols/gossipsub/src/config.rs @@ -884,7 +884,7 @@ impl std::fmt::Debug for Config { #[cfg(test)] mod test { use super::*; - use crate::protocol_priv::ProtocolConfig; + use crate::protocol::ProtocolConfig; use crate::topic::IdentityHash; use crate::types::PeerKind; use crate::Topic; diff --git a/protocols/gossipsub/src/error.rs b/protocols/gossipsub/src/error.rs index 61ef13bd248..1d8d6c052a8 100644 --- a/protocols/gossipsub/src/error.rs +++ b/protocols/gossipsub/src/error.rs @@ -1,4 +1,4 @@ -// Copyright 2023 Protocol Labs. +// Copyright 2020 Sigma Prime Pty Ltd. // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), @@ -18,26 +18,105 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -#[deprecated( - since = "0.44.0", - note = "Use `libp2p::gossipsub::PublishError` instead, as the `error` module will become crate-private in the future." -)] -pub type PublishError = crate::error_priv::PublishError; - -#[deprecated( - since = "0.44.0", - note = "Use `libp2p::gossipsub::SubscriptionError` instead, as the `error` module will become crate-private in the future." -)] -pub type SubscriptionError = crate::error_priv::SubscriptionError; - -#[deprecated(note = "This error will no longer be emitted")] -pub type GossipsubHandlerError = crate::error_priv::HandlerError; - -#[deprecated(note = "This error will no longer be emitted")] -pub type HandlerError = crate::error_priv::HandlerError; - -#[deprecated( - since = "0.44.0", - note = "Use `libp2p::gossipsub::ValidationError` instead, as the `error` module will become crate-private in the future." -)] -pub type ValidationError = crate::error_priv::ValidationError; +//! Error types that can result from gossipsub. + +use libp2p_core::identity::error::SigningError; + +/// Error associated with publishing a gossipsub message. +#[derive(Debug)] +pub enum PublishError { + /// This message has already been published. + Duplicate, + /// An error occurred whilst signing the message. + SigningError(SigningError), + /// There were no peers to send this message to. + InsufficientPeers, + /// The overall message was too large. This could be due to excessive topics or an excessive + /// message size. + MessageTooLarge, + /// The compression algorithm failed. + TransformFailed(std::io::Error), +} + +impl std::fmt::Display for PublishError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{self:?}") + } +} + +impl std::error::Error for PublishError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::SigningError(err) => Some(err), + Self::TransformFailed(err) => Some(err), + _ => None, + } + } +} + +/// Error associated with subscribing to a topic. +#[derive(Debug)] +pub enum SubscriptionError { + /// Couldn't publish our subscription + PublishError(PublishError), + /// We are not allowed to subscribe to this topic by the subscription filter + NotAllowed, +} + +impl std::fmt::Display for SubscriptionError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{self:?}") + } +} + +impl std::error::Error for SubscriptionError { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Self::PublishError(err) => Some(err), + _ => None, + } + } +} + +impl From for PublishError { + fn from(error: SigningError) -> Self { + PublishError::SigningError(error) + } +} + +#[derive(Debug, Clone, Copy)] +pub enum ValidationError { + /// The message has an invalid signature, + InvalidSignature, + /// The sequence number was empty, expected a value. + EmptySequenceNumber, + /// The sequence number was the incorrect size + InvalidSequenceNumber, + /// The PeerId was invalid + InvalidPeerId, + /// Signature existed when validation has been sent to + /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. + SignaturePresent, + /// Sequence number existed when validation has been sent to + /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. + SequenceNumberPresent, + /// Message source existed when validation has been sent to + /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. + MessageSourcePresent, + /// The data transformation failed. + TransformFailed, +} + +impl std::fmt::Display for ValidationError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "{self:?}") + } +} + +impl std::error::Error for ValidationError {} + +impl From for PublishError { + fn from(error: std::io::Error) -> PublishError { + PublishError::TransformFailed(error) + } +} diff --git a/protocols/gossipsub/src/error_priv.rs b/protocols/gossipsub/src/error_priv.rs deleted file mode 100644 index 04cc72028cd..00000000000 --- a/protocols/gossipsub/src/error_priv.rs +++ /dev/null @@ -1,141 +0,0 @@ -// Copyright 2020 Sigma Prime Pty Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -//! Error types that can result from gossipsub. - -use libp2p_core::identity::error::SigningError; -use libp2p_core::upgrade::ProtocolError; -use thiserror::Error; - -/// Error associated with publishing a gossipsub message. -#[derive(Debug)] -pub enum PublishError { - /// This message has already been published. - Duplicate, - /// An error occurred whilst signing the message. - SigningError(SigningError), - /// There were no peers to send this message to. - InsufficientPeers, - /// The overall message was too large. This could be due to excessive topics or an excessive - /// message size. - MessageTooLarge, - /// The compression algorithm failed. - TransformFailed(std::io::Error), -} - -impl std::fmt::Display for PublishError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{self:?}") - } -} - -impl std::error::Error for PublishError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::SigningError(err) => Some(err), - Self::TransformFailed(err) => Some(err), - _ => None, - } - } -} - -/// Error associated with subscribing to a topic. -#[derive(Debug)] -pub enum SubscriptionError { - /// Couldn't publish our subscription - PublishError(PublishError), - /// We are not allowed to subscribe to this topic by the subscription filter - NotAllowed, -} - -impl std::fmt::Display for SubscriptionError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{self:?}") - } -} - -impl std::error::Error for SubscriptionError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - match self { - Self::PublishError(err) => Some(err), - _ => None, - } - } -} - -impl From for PublishError { - fn from(error: SigningError) -> Self { - PublishError::SigningError(error) - } -} - -/// Errors that can occur in the protocols handler. -#[derive(Debug, Error)] -pub enum HandlerError { - #[error("The maximum number of inbound substreams created has been exceeded.")] - MaxInboundSubstreams, - #[error("The maximum number of outbound substreams created has been exceeded.")] - MaxOutboundSubstreams, - #[error("The message exceeds the maximum transmission size.")] - MaxTransmissionSize, - #[error("Protocol negotiation timeout.")] - NegotiationTimeout, - #[error("Protocol negotiation failed.")] - NegotiationProtocolError(ProtocolError), - #[error("Failed to encode or decode")] - Codec(#[from] quick_protobuf_codec::Error), -} - -#[derive(Debug, Clone, Copy)] -pub enum ValidationError { - /// The message has an invalid signature, - InvalidSignature, - /// The sequence number was empty, expected a value. - EmptySequenceNumber, - /// The sequence number was the incorrect size - InvalidSequenceNumber, - /// The PeerId was invalid - InvalidPeerId, - /// Signature existed when validation has been sent to - /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. - SignaturePresent, - /// Sequence number existed when validation has been sent to - /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. - SequenceNumberPresent, - /// Message source existed when validation has been sent to - /// [`crate::behaviour::MessageAuthenticity::Anonymous`]. - MessageSourcePresent, - /// The data transformation failed. - TransformFailed, -} - -impl std::fmt::Display for ValidationError { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{self:?}") - } -} - -impl std::error::Error for ValidationError {} - -impl From for PublishError { - fn from(error: std::io::Error) -> PublishError { - PublishError::TransformFailed(error) - } -} diff --git a/protocols/gossipsub/src/handler.rs b/protocols/gossipsub/src/handler.rs index 269bdcd404f..609bb81a306 100644 --- a/protocols/gossipsub/src/handler.rs +++ b/protocols/gossipsub/src/handler.rs @@ -18,7 +18,7 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -use crate::protocol_priv::{GossipsubCodec, ProtocolConfig}; +use crate::protocol::{GossipsubCodec, ProtocolConfig}; use crate::rpc_proto::proto; use crate::types::{PeerKind, RawMessage, Rpc}; use crate::ValidationError; diff --git a/protocols/gossipsub/src/lib.rs b/protocols/gossipsub/src/lib.rs index 556cb904fdd..fea17b67f6f 100644 --- a/protocols/gossipsub/src/lib.rs +++ b/protocols/gossipsub/src/lib.rs @@ -138,70 +138,32 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -pub mod error; - -mod metrics_priv; -#[deprecated( - note = "The `metrics` module will be made private in the future and should not be depended on." -)] -pub mod metrics { - pub use super::metrics_priv::*; -} - -mod protocol_priv; -#[deprecated( - note = "The `protocol` module will be made private in the future and should not be depended on." -)] -pub mod protocol { - pub use super::protocol_priv::*; -} - -mod subscription_filter_priv; -#[deprecated( - note = "The `subscription_filter` module will be made private in the future, import the types from the crate root instead." -)] -pub mod subscription_filter { - pub use super::subscription_filter_priv::*; - - pub mod regex { - pub use crate::subscription_filter_priv::RegexSubscriptionFilter; - } -} - -mod time_cache_priv; -#[deprecated( - note = "The `time_cache` module will be made private in the future and should not be depended on." -)] -pub mod time_cache { - pub use super::time_cache_priv::*; -} - mod backoff; mod behaviour; mod config; -mod error_priv; +mod error; mod gossip_promises; mod handler; mod mcache; +mod metrics; mod peer_score; +mod protocol; +mod rpc_proto; +mod subscription_filter; +mod time_cache; mod topic; mod transform; mod types; -mod rpc_proto; - -#[deprecated(note = "This error will no longer be emitted")] -pub type HandlerError = error_priv::HandlerError; - pub use self::behaviour::{Behaviour, Event, MessageAuthenticity}; pub use self::config::{Config, ConfigBuilder, ValidationMode, Version}; -pub use self::error_priv::{PublishError, SubscriptionError, ValidationError}; -pub use self::metrics_priv::Config as MetricsConfig; +pub use self::error::{PublishError, SubscriptionError, ValidationError}; +pub use self::metrics::Config as MetricsConfig; pub use self::peer_score::{ score_parameter_decay, score_parameter_decay_with_base, PeerScoreParams, PeerScoreThresholds, TopicScoreParams, }; -pub use self::subscription_filter_priv::{ +pub use self::subscription_filter::{ AllowAllSubscriptionFilter, CallbackSubscriptionFilter, CombinedSubscriptionFilters, MaxCountSubscriptionFilter, RegexSubscriptionFilter, TopicSubscriptionFilter, WhitelistSubscriptionFilter, @@ -210,53 +172,5 @@ pub use self::topic::{Hasher, Topic, TopicHash}; pub use self::transform::{DataTransform, IdentityTransform}; pub use self::types::{FastMessageId, Message, MessageAcceptance, MessageId, RawMessage, Rpc}; -#[deprecated( - since = "0.44.0", - note = "Use `Behaviour` instead of `Gossipsub` for Network Behaviour, i.e. `libp2p::gossipsub::Behaviour" -)] -pub type Gossipsub = Behaviour; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::Event" -)] -pub type GossipsubEvent = Event; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::Config" -)] -pub type GossipsubConfig = Config; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::Message" -)] -pub type GossipsubMessage = Message; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::Rpc" -)] -pub type GossipsubRpc = Rpc; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` infix, i.e. `libp2p::gossipsub::RawMessage" -)] -pub type RawGossipsubMessage = RawMessage; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::ConfigBuilder" -)] -pub type GossipsubConfigBuilder = ConfigBuilder; - -#[deprecated( - since = "0.44.0", - note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::Version" -)] -pub type GossipsubVersion = Version; - pub type IdentTopic = Topic; pub type Sha256Topic = Topic; diff --git a/protocols/gossipsub/src/metrics_priv.rs b/protocols/gossipsub/src/metrics.rs similarity index 92% rename from protocols/gossipsub/src/metrics_priv.rs rename to protocols/gossipsub/src/metrics.rs index 0eb62de7c16..e044ca67e71 100644 --- a/protocols/gossipsub/src/metrics_priv.rs +++ b/protocols/gossipsub/src/metrics.rs @@ -99,7 +99,7 @@ impl Default for Config { type EverSubscribed = bool; /// A collection of metrics used throughout the Gossipsub behaviour. -pub struct Metrics { +pub(crate) struct Metrics { /* Configuration parameters */ /// Maximum number of topics for which we store metrics. This helps keep the metrics bounded. max_topics: usize, @@ -177,7 +177,7 @@ pub struct Metrics { } impl Metrics { - pub fn new(registry: &mut Registry, config: Config) -> Self { + pub(crate) fn new(registry: &mut Registry, config: Config) -> Self { // Destructure the config to be sure everything is used. let Config { max_topics, @@ -356,7 +356,7 @@ impl Metrics { } /// Register how many peers do we known are subscribed to this topic. - pub fn set_topic_peers(&mut self, topic: &TopicHash, count: usize) { + pub(crate) fn set_topic_peers(&mut self, topic: &TopicHash, count: usize) { if self.register_topic(topic).is_ok() { self.topic_peers_count .get_or_create(topic) @@ -368,7 +368,7 @@ impl Metrics { /// Registers the subscription to a topic if the configured limits allow it. /// Sets the registered number of peers in the mesh to 0. - pub fn joined(&mut self, topic: &TopicHash) { + pub(crate) fn joined(&mut self, topic: &TopicHash) { if self.topic_info.contains_key(topic) || self.topic_info.len() < self.max_topics { self.topic_info.insert(topic.clone(), true); let was_subscribed = self.topic_subscription_status.get_or_create(topic).set(1); @@ -379,7 +379,7 @@ impl Metrics { /// Registers the unsubscription to a topic if the topic was previously allowed. /// Sets the registered number of peers in the mesh to 0. - pub fn left(&mut self, topic: &TopicHash) { + pub(crate) fn left(&mut self, topic: &TopicHash) { if self.topic_info.contains_key(topic) { // Depending on the configured topic bounds we could miss a mesh topic. // So, check first if the topic was previously allowed. @@ -390,7 +390,7 @@ impl Metrics { } /// Register the inclusion of peers in our mesh due to some reason. - pub fn peers_included(&mut self, topic: &TopicHash, reason: Inclusion, count: usize) { + pub(crate) fn peers_included(&mut self, topic: &TopicHash, reason: Inclusion, count: usize) { if self.register_topic(topic).is_ok() { self.mesh_peer_inclusion_events .get_or_create(&InclusionLabel { @@ -402,7 +402,7 @@ impl Metrics { } /// Register the removal of peers in our mesh due to some reason. - pub fn peers_removed(&mut self, topic: &TopicHash, reason: Churn, count: usize) { + pub(crate) fn peers_removed(&mut self, topic: &TopicHash, reason: Churn, count: usize) { if self.register_topic(topic).is_ok() { self.mesh_peer_churn_events .get_or_create(&ChurnLabel { @@ -414,7 +414,7 @@ impl Metrics { } /// Register the current number of peers in our mesh for this topic. - pub fn set_mesh_peers(&mut self, topic: &TopicHash, count: usize) { + pub(crate) fn set_mesh_peers(&mut self, topic: &TopicHash, count: usize) { if self.register_topic(topic).is_ok() { // Due to limits, this topic could have not been allowed, so we check. self.mesh_peer_counts.get_or_create(topic).set(count as i64); @@ -422,28 +422,28 @@ impl Metrics { } /// Register that an invalid message was received on a specific topic. - pub fn register_invalid_message(&mut self, topic: &TopicHash) { + pub(crate) fn register_invalid_message(&mut self, topic: &TopicHash) { if self.register_topic(topic).is_ok() { self.invalid_messages.get_or_create(topic).inc(); } } /// Register a score penalty. - pub fn register_score_penalty(&mut self, penalty: Penalty) { + pub(crate) fn register_score_penalty(&mut self, penalty: Penalty) { self.scoring_penalties .get_or_create(&PenaltyLabel { penalty }) .inc(); } /// Registers that a message was published on a specific topic. - pub fn register_published_message(&mut self, topic: &TopicHash) { + pub(crate) fn register_published_message(&mut self, topic: &TopicHash) { if self.register_topic(topic).is_ok() { self.topic_msg_published.get_or_create(topic).inc(); } } /// Register sending a message over a topic. - pub fn msg_sent(&mut self, topic: &TopicHash, bytes: usize) { + pub(crate) fn msg_sent(&mut self, topic: &TopicHash, bytes: usize) { if self.register_topic(topic).is_ok() { self.topic_msg_sent_counts.get_or_create(topic).inc(); self.topic_msg_sent_bytes @@ -453,14 +453,14 @@ impl Metrics { } /// Register that a message was received (and was not a duplicate). - pub fn msg_recvd(&mut self, topic: &TopicHash) { + pub(crate) fn msg_recvd(&mut self, topic: &TopicHash) { if self.register_topic(topic).is_ok() { self.topic_msg_recv_counts.get_or_create(topic).inc(); } } /// Register that a message was received (could have been a duplicate). - pub fn msg_recvd_unfiltered(&mut self, topic: &TopicHash, bytes: usize) { + pub(crate) fn msg_recvd_unfiltered(&mut self, topic: &TopicHash, bytes: usize) { if self.register_topic(topic).is_ok() { self.topic_msg_recv_counts_unfiltered .get_or_create(topic) @@ -471,7 +471,11 @@ impl Metrics { } } - pub fn register_msg_validation(&mut self, topic: &TopicHash, validation: &MessageAcceptance) { + pub(crate) fn register_msg_validation( + &mut self, + topic: &TopicHash, + validation: &MessageAcceptance, + ) { if self.register_topic(topic).is_ok() { match validation { MessageAcceptance::Accept => self.accepted_messages.get_or_create(topic).inc(), @@ -482,38 +486,38 @@ impl Metrics { } /// Register a memcache miss. - pub fn memcache_miss(&mut self) { + pub(crate) fn memcache_miss(&mut self) { self.memcache_misses.inc(); } /// Register sending an IWANT msg for this topic. - pub fn register_iwant(&mut self, topic: &TopicHash) { + pub(crate) fn register_iwant(&mut self, topic: &TopicHash) { if self.register_topic(topic).is_ok() { self.topic_iwant_msgs.get_or_create(topic).inc(); } } /// Observes a heartbeat duration. - pub fn observe_heartbeat_duration(&mut self, millis: u64) { + pub(crate) fn observe_heartbeat_duration(&mut self, millis: u64) { self.heartbeat_duration.observe(millis as f64); } /// Observe a score of a mesh peer. - pub fn observe_mesh_peers_score(&mut self, topic: &TopicHash, score: f64) { + pub(crate) fn observe_mesh_peers_score(&mut self, topic: &TopicHash, score: f64) { if self.register_topic(topic).is_ok() { self.score_per_mesh.get_or_create(topic).observe(score); } } /// Register a new peers connection based on its protocol. - pub fn peer_protocol_connected(&mut self, kind: PeerKind) { + pub(crate) fn peer_protocol_connected(&mut self, kind: PeerKind) { self.peers_per_protocol .get_or_create(&ProtocolLabel { protocol: kind }) .inc(); } /// Removes a peer from the counter based on its protocol when it disconnects. - pub fn peer_protocol_disconnected(&mut self, kind: PeerKind) { + pub(crate) fn peer_protocol_disconnected(&mut self, kind: PeerKind) { let metric = self .peers_per_protocol .get_or_create(&ProtocolLabel { protocol: kind }); @@ -526,7 +530,7 @@ impl Metrics { /// Reasons why a peer was included in the mesh. #[derive(PartialEq, Eq, Hash, EncodeLabelValue, Clone, Debug)] -pub enum Inclusion { +pub(crate) enum Inclusion { /// Peer was a fanaout peer. Fanout, /// Included from random selection. @@ -539,7 +543,7 @@ pub enum Inclusion { /// Reasons why a peer was removed from the mesh. #[derive(PartialEq, Eq, Hash, EncodeLabelValue, Clone, Debug)] -pub enum Churn { +pub(crate) enum Churn { /// Peer disconnected. Dc, /// Peer had a bad score. @@ -554,7 +558,7 @@ pub enum Churn { /// Kinds of reasons a peer's score has been penalized #[derive(PartialEq, Eq, Hash, EncodeLabelValue, Clone, Debug)] -pub enum Penalty { +pub(crate) enum Penalty { /// A peer grafted before waiting the back-off time. GraftBackoff, /// A Peer did not respond to an IWANT request in time. diff --git a/protocols/gossipsub/src/peer_score.rs b/protocols/gossipsub/src/peer_score.rs index 2f17b14b7a6..5d3f387a478 100644 --- a/protocols/gossipsub/src/peer_score.rs +++ b/protocols/gossipsub/src/peer_score.rs @@ -21,8 +21,8 @@ //! //! Manages and stores the Scoring logic of a particular peer on the gossipsub behaviour. -use crate::metrics_priv::{Metrics, Penalty}; -use crate::time_cache_priv::TimeCache; +use crate::metrics::{Metrics, Penalty}; +use crate::time_cache::TimeCache; use crate::{MessageId, TopicHash}; use libp2p_identity::PeerId; use log::{debug, trace, warn}; diff --git a/protocols/gossipsub/src/protocol_priv.rs b/protocols/gossipsub/src/protocol.rs similarity index 100% rename from protocols/gossipsub/src/protocol_priv.rs rename to protocols/gossipsub/src/protocol.rs diff --git a/protocols/gossipsub/src/subscription_filter_priv.rs b/protocols/gossipsub/src/subscription_filter.rs similarity index 100% rename from protocols/gossipsub/src/subscription_filter_priv.rs rename to protocols/gossipsub/src/subscription_filter.rs diff --git a/protocols/gossipsub/src/time_cache_priv.rs b/protocols/gossipsub/src/time_cache.rs similarity index 74% rename from protocols/gossipsub/src/time_cache_priv.rs rename to protocols/gossipsub/src/time_cache.rs index 864300b0bb4..46de2642fc4 100644 --- a/protocols/gossipsub/src/time_cache_priv.rs +++ b/protocols/gossipsub/src/time_cache.rs @@ -36,7 +36,7 @@ struct ExpiringElement { expires: Instant, } -pub struct TimeCache { +pub(crate) struct TimeCache { /// Mapping a key to its value together with its latest expire time (can be updated through /// reinserts). map: FnvHashMap>, @@ -46,42 +46,20 @@ pub struct TimeCache { ttl: Duration, } -pub struct OccupiedEntry<'a, K, V> { - expiration: Instant, +pub(crate) struct OccupiedEntry<'a, K, V> { entry: hash_map::OccupiedEntry<'a, K, ExpiringElement>, - list: &'a mut VecDeque>, } impl<'a, K, V> OccupiedEntry<'a, K, V> where K: Eq + std::hash::Hash + Clone, { - pub fn into_mut(self) -> &'a mut V { + pub(crate) fn into_mut(self) -> &'a mut V { &mut self.entry.into_mut().element } - - pub fn insert_without_updating_expiration(&mut self, value: V) -> V { - //keep old expiration, only replace value of element - ::std::mem::replace(&mut self.entry.get_mut().element, value) - } - - pub fn insert_and_update_expiration(&mut self, value: V) -> V { - //We push back an additional element, the first reference in the list will be ignored - // since we also updated the expires in the map, see below. - self.list.push_back(ExpiringElement { - element: self.entry.key().clone(), - expires: self.expiration, - }); - self.entry - .insert(ExpiringElement { - element: value, - expires: self.expiration, - }) - .element - } } -pub struct VacantEntry<'a, K, V> { +pub(crate) struct VacantEntry<'a, K, V> { expiration: Instant, entry: hash_map::VacantEntry<'a, K, ExpiringElement>, list: &'a mut VecDeque>, @@ -91,7 +69,7 @@ impl<'a, K, V> VacantEntry<'a, K, V> where K: Eq + std::hash::Hash + Clone, { - pub fn insert(self, value: V) -> &'a mut V { + pub(crate) fn insert(self, value: V) -> &'a mut V { self.list.push_back(ExpiringElement { element: self.entry.key().clone(), expires: self.expiration, @@ -106,7 +84,7 @@ where } } -pub enum Entry<'a, K: 'a, V: 'a> { +pub(crate) enum Entry<'a, K: 'a, V: 'a> { Occupied(OccupiedEntry<'a, K, V>), Vacant(VacantEntry<'a, K, V>), } @@ -115,7 +93,7 @@ impl<'a, K: 'a, V: 'a> Entry<'a, K, V> where K: Eq + std::hash::Hash + Clone, { - pub fn or_insert_with V>(self, default: F) -> &'a mut V { + pub(crate) fn or_insert_with V>(self, default: F) -> &'a mut V { match self { Entry::Occupied(entry) => entry.into_mut(), Entry::Vacant(entry) => entry.insert(default()), @@ -127,7 +105,7 @@ impl TimeCache where Key: Eq + std::hash::Hash + Clone, { - pub fn new(ttl: Duration) -> Self { + pub(crate) fn new(ttl: Duration) -> Self { TimeCache { map: FnvHashMap::default(), list: VecDeque::new(), @@ -149,15 +127,11 @@ where } } - pub fn entry(&mut self, key: Key) -> Entry { + pub(crate) fn entry(&mut self, key: Key) -> Entry { let now = Instant::now(); self.remove_expired_keys(now); match self.map.entry(key) { - Occupied(entry) => Entry::Occupied(OccupiedEntry { - expiration: now + self.ttl, - entry, - list: &mut self.list, - }), + Occupied(entry) => Entry::Occupied(OccupiedEntry { entry }), Vacant(entry) => Entry::Vacant(VacantEntry { expiration: now + self.ttl, entry, @@ -167,31 +141,28 @@ where } /// Empties the entire cache. - pub fn clear(&mut self) { + #[cfg(test)] + pub(crate) fn clear(&mut self) { self.map.clear(); self.list.clear(); } - pub fn contains_key(&self, key: &Key) -> bool { + pub(crate) fn contains_key(&self, key: &Key) -> bool { self.map.contains_key(key) } - pub fn get(&self, key: &Key) -> Option<&Value> { + pub(crate) fn get(&self, key: &Key) -> Option<&Value> { self.map.get(key).map(|e| &e.element) } - - pub fn get_mut(&mut self, key: &Key) -> Option<&mut Value> { - self.map.get_mut(key).map(|e| &mut e.element) - } } -pub struct DuplicateCache(TimeCache); +pub(crate) struct DuplicateCache(TimeCache); impl DuplicateCache where Key: Eq + std::hash::Hash + Clone, { - pub fn new(ttl: Duration) -> Self { + pub(crate) fn new(ttl: Duration) -> Self { Self(TimeCache::new(ttl)) } @@ -199,7 +170,7 @@ where // // If the key was not present this returns `true`. If the value was already present this // returns `false`. - pub fn insert(&mut self, key: Key) -> bool { + pub(crate) fn insert(&mut self, key: Key) -> bool { if let Entry::Vacant(entry) = self.0.entry(key) { entry.insert(()); true @@ -208,7 +179,7 @@ where } } - pub fn contains(&self, key: &Key) -> bool { + pub(crate) fn contains(&self, key: &Key) -> bool { self.0.contains_key(key) } } From 4bd4653fa9e083c8d76b9cfbef51748b620d38e6 Mon Sep 17 00:00:00 2001 From: Hannes <55623006+umgefahren@users.noreply.github.com> Date: Tue, 2 May 2023 18:17:15 +0200 Subject: [PATCH 57/57] chore(request-response): remove deprecated items Related: https://github.com/libp2p/rust-libp2p/issues/3647. Pull-Request: #3703. --- protocols/request-response/CHANGELOG.md | 2 + protocols/request-response/src/codec.rs | 80 +++++++ protocols/request-response/src/codec_priv.rs | 199 ------------------ .../src/{handler_priv.rs => handler.rs} | 27 +-- .../src/{handler_priv => handler}/protocol.rs | 2 +- protocols/request-response/src/lib.rs | 75 ++----- 6 files changed, 105 insertions(+), 280 deletions(-) create mode 100644 protocols/request-response/src/codec.rs delete mode 100644 protocols/request-response/src/codec_priv.rs rename protocols/request-response/src/{handler_priv.rs => handler.rs} (96%) rename protocols/request-response/src/{handler_priv => handler}/protocol.rs (99%) diff --git a/protocols/request-response/CHANGELOG.md b/protocols/request-response/CHANGELOG.md index 0625006ef11..bb57385c9c6 100644 --- a/protocols/request-response/CHANGELOG.md +++ b/protocols/request-response/CHANGELOG.md @@ -2,8 +2,10 @@ - Raise MSRV to 1.65. See [PR 3715]. +- Remove deprecated `RequestResponse` prefixed items. See [PR 3702]. [PR 3715]: https://github.com/libp2p/rust-libp2p/pull/3715 +[PR 3702]: https://github.com/libp2p/rust-libp2p/pull/3702 ## 0.24.1 diff --git a/protocols/request-response/src/codec.rs b/protocols/request-response/src/codec.rs new file mode 100644 index 00000000000..71cfb79a27a --- /dev/null +++ b/protocols/request-response/src/codec.rs @@ -0,0 +1,80 @@ +// Copyright 2020 Parity Technologies (UK) Ltd. +// +// Permission is hereby granted, free of charge, to any person obtaining a +// copy of this software and associated documentation files (the "Software"), +// to deal in the Software without restriction, including without limitation +// the rights to use, copy, modify, merge, publish, distribute, sublicense, +// and/or sell copies of the Software, and to permit persons to whom the +// Software is furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +// DEALINGS IN THE SOFTWARE. + +pub use libp2p_core::ProtocolName; + +use async_trait::async_trait; +use futures::prelude::*; +use std::io; + +/// A `Codec` defines the request and response types +/// for a request-response [`Behaviour`](crate::Behaviour) protocol or +/// protocol family and how they are encoded / decoded on an I/O stream. +#[async_trait] +pub trait Codec { + /// The type of protocol(s) or protocol versions being negotiated. + type Protocol: ProtocolName + Send + Clone; + /// The type of inbound and outbound requests. + type Request: Send; + /// The type of inbound and outbound responses. + type Response: Send; + + /// Reads a request from the given I/O stream according to the + /// negotiated protocol. + async fn read_request( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + ) -> io::Result + where + T: AsyncRead + Unpin + Send; + + /// Reads a response from the given I/O stream according to the + /// negotiated protocol. + async fn read_response( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + ) -> io::Result + where + T: AsyncRead + Unpin + Send; + + /// Writes a request to the given I/O stream according to the + /// negotiated protocol. + async fn write_request( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + req: Self::Request, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send; + + /// Writes a response to the given I/O stream according to the + /// negotiated protocol. + async fn write_response( + &mut self, + protocol: &Self::Protocol, + io: &mut T, + res: Self::Response, + ) -> io::Result<()> + where + T: AsyncWrite + Unpin + Send; +} diff --git a/protocols/request-response/src/codec_priv.rs b/protocols/request-response/src/codec_priv.rs deleted file mode 100644 index c5af967d0b9..00000000000 --- a/protocols/request-response/src/codec_priv.rs +++ /dev/null @@ -1,199 +0,0 @@ -// Copyright 2020 Parity Technologies (UK) Ltd. -// -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the "Software"), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -pub use libp2p_core::ProtocolName; - -use async_trait::async_trait; -use futures::prelude::*; -use std::io; - -/// A `RequestResponseCodec` defines the request and response types -/// for a request-response `Behaviour` protocol or -/// protocol family and how they are encoded / decoded on an I/O stream. -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Codec`" -)] -#[async_trait] -pub trait RequestResponseCodec { - /// The type of protocol(s) or protocol versions being negotiated. - type Protocol: ProtocolName + Send + Clone; - /// The type of inbound and outbound requests. - type Request: Send; - /// The type of inbound and outbound responses. - type Response: Send; - - /// Reads a request from the given I/O stream according to the - /// negotiated protocol. - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Reads a response from the given I/O stream according to the - /// negotiated protocol. - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Writes a request to the given I/O stream according to the - /// negotiated protocol. - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; - - /// Writes a response to the given I/O stream according to the - /// negotiated protocol. - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; -} - -/// A `Codec` defines the request and response types -/// for a request-response [`Behaviour`](crate::Behaviour) protocol or -/// protocol family and how they are encoded / decoded on an I/O stream. -#[async_trait] -pub trait Codec { - /// The type of protocol(s) or protocol versions being negotiated. - type Protocol: ProtocolName + Send + Clone; - /// The type of inbound and outbound requests. - type Request: Send; - /// The type of inbound and outbound responses. - type Response: Send; - - /// Reads a request from the given I/O stream according to the - /// negotiated protocol. - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Reads a response from the given I/O stream according to the - /// negotiated protocol. - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send; - - /// Writes a request to the given I/O stream according to the - /// negotiated protocol. - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; - - /// Writes a response to the given I/O stream according to the - /// negotiated protocol. - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send; -} - -#[allow(deprecated)] -#[async_trait] -impl Codec for U -where - U: RequestResponseCodec + Send, - U::Protocol: Sync, -{ - type Protocol = U::Protocol; - - type Request = U::Request; - - type Response = U::Response; - - async fn read_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send, - { - self.read_request(protocol, io).await - } - - async fn read_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - ) -> io::Result - where - T: AsyncRead + Unpin + Send, - { - self.read_response(protocol, io).await - } - - async fn write_request( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - req: Self::Request, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - { - self.write_request(protocol, io, req).await - } - - async fn write_response( - &mut self, - protocol: &Self::Protocol, - io: &mut T, - res: Self::Response, - ) -> io::Result<()> - where - T: AsyncWrite + Unpin + Send, - { - self.write_response(protocol, io, res).await - } -} diff --git a/protocols/request-response/src/handler_priv.rs b/protocols/request-response/src/handler.rs similarity index 96% rename from protocols/request-response/src/handler_priv.rs rename to protocols/request-response/src/handler.rs index 849c9e577fa..65aa1f842c5 100644 --- a/protocols/request-response/src/handler_priv.rs +++ b/protocols/request-response/src/handler.rs @@ -18,20 +18,21 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -mod protocol; +pub(crate) mod protocol; -use crate::codec_priv::Codec; +pub use protocol::ProtocolSupport; + +use crate::codec::Codec; +use crate::handler::protocol::{RequestProtocol, ResponseProtocol}; use crate::{RequestId, EMPTY_QUEUE_SHRINK_THRESHOLD}; +use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; +use instant::Instant; +use libp2p_core::upgrade::{NegotiationError, UpgradeError}; use libp2p_swarm::handler::{ ConnectionEvent, DialUpgradeError, FullyNegotiatedInbound, FullyNegotiatedOutbound, ListenUpgradeError, }; -pub use protocol::{ProtocolSupport, RequestProtocol, ResponseProtocol}; - -use futures::{channel::oneshot, future::BoxFuture, prelude::*, stream::FuturesUnordered}; -use instant::Instant; -use libp2p_core::upgrade::{NegotiationError, UpgradeError}; use libp2p_swarm::{ handler::{ConnectionHandler, ConnectionHandlerEvent, ConnectionHandlerUpgrErr, KeepAlive}, SubstreamProtocol, @@ -48,12 +49,6 @@ use std::{ time::Duration, }; -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Handler`" -)] -pub type RequestResponseHandler = Handler; - /// A connection handler for a request response [`Behaviour`](super::Behaviour) protocol. pub struct Handler where @@ -193,12 +188,6 @@ where } } -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`" -)] -pub type RequestResponseHandlerEvent = Event; - /// The events emitted by the [`Handler`]. pub enum Event where diff --git a/protocols/request-response/src/handler_priv/protocol.rs b/protocols/request-response/src/handler/protocol.rs similarity index 99% rename from protocols/request-response/src/handler_priv/protocol.rs rename to protocols/request-response/src/handler/protocol.rs index 3ee08c7f764..84ef365734f 100644 --- a/protocols/request-response/src/handler_priv/protocol.rs +++ b/protocols/request-response/src/handler/protocol.rs @@ -23,7 +23,7 @@ //! receives a request and sends a response, whereas the //! outbound upgrade send a request and receives a response. -use crate::codec_priv::Codec; +use crate::codec::Codec; use crate::RequestId; use futures::{channel::oneshot, future::BoxFuture, prelude::*}; diff --git a/protocols/request-response/src/lib.rs b/protocols/request-response/src/lib.rs index 723c11d831e..14854ddea77 100644 --- a/protocols/request-response/src/lib.rs +++ b/protocols/request-response/src/lib.rs @@ -58,31 +58,15 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] -mod codec_priv; -#[deprecated( - note = "The `codec` module will be made private in the future and should not be depended on." -)] -pub mod codec { - pub use super::codec_priv::*; -} - -mod handler_priv; -#[deprecated( - note = "The `handler` module will be made private in the future and should not be depended on." -)] -pub mod handler { - pub use super::handler_priv::*; -} +mod codec; +mod handler; -pub use codec_priv::{Codec, ProtocolName}; - -#[allow(deprecated)] -pub use codec_priv::RequestResponseCodec; - -pub use handler_priv::ProtocolSupport; +pub use codec::{Codec, ProtocolName}; +pub use handler::ProtocolSupport; +use crate::handler::protocol::RequestProtocol; use futures::channel::oneshot; -use handler_priv::{Handler, RequestProtocol}; +use handler::Handler; use libp2p_core::{ConnectedPoint, Endpoint, Multiaddr}; use libp2p_identity::PeerId; use libp2p_swarm::{ @@ -100,37 +84,6 @@ use std::{ time::Duration, }; -#[deprecated( - since = "0.24.0", - note = "Use libp2p::request_response::Behaviour instead." -)] -pub type RequestResponse = Behaviour; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Config`" -)] -pub type RequestResponseConfig = Config; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Event`" -)] -pub type RequestResponseEvent = Event; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::Message`" -)] -pub type RequestResponseMessage = - Message; - -#[deprecated( - since = "0.24.0", - note = "Use re-exports that omit `RequestResponse` prefix, i.e. `libp2p::request_response::handler::Event`" -)] -pub type HandlerEvent = handler_priv::Event; - /// An inbound request or response. #[derive(Debug)] pub enum Message { @@ -815,7 +768,7 @@ where event: THandlerOutEvent, ) { match event { - handler_priv::Event::Response { + handler::Event::Response { request_id, response, } => { @@ -832,7 +785,7 @@ where self.pending_events .push_back(ToSwarm::GenerateEvent(Event::Message { peer, message })); } - handler_priv::Event::Request { + handler::Event::Request { request_id, request, sender, @@ -863,7 +816,7 @@ where } } } - handler_priv::Event::ResponseSent(request_id) => { + handler::Event::ResponseSent(request_id) => { let removed = self.remove_pending_outbound_response(&peer, connection, request_id); debug_assert!( removed, @@ -876,7 +829,7 @@ where request_id, })); } - handler_priv::Event::ResponseOmission(request_id) => { + handler::Event::ResponseOmission(request_id) => { let removed = self.remove_pending_outbound_response(&peer, connection, request_id); debug_assert!( removed, @@ -890,7 +843,7 @@ where error: InboundFailure::ResponseOmission, })); } - handler_priv::Event::OutboundTimeout(request_id) => { + handler::Event::OutboundTimeout(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( removed, @@ -904,7 +857,7 @@ where error: OutboundFailure::Timeout, })); } - handler_priv::Event::InboundTimeout(request_id) => { + handler::Event::InboundTimeout(request_id) => { // Note: `Event::InboundTimeout` is emitted both for timing // out to receive the request and for timing out sending the response. In the former // case the request is never added to `pending_outbound_responses` and thus one can @@ -918,7 +871,7 @@ where error: InboundFailure::Timeout, })); } - handler_priv::Event::OutboundUnsupportedProtocols(request_id) => { + handler::Event::OutboundUnsupportedProtocols(request_id) => { let removed = self.remove_pending_inbound_response(&peer, connection, &request_id); debug_assert!( removed, @@ -932,7 +885,7 @@ where error: OutboundFailure::UnsupportedProtocols, })); } - handler_priv::Event::InboundUnsupportedProtocols(request_id) => { + handler::Event::InboundUnsupportedProtocols(request_id) => { // Note: No need to call `self.remove_pending_outbound_response`, // `Event::Request` was never emitted for this request and // thus request was never added to `pending_outbound_responses`.