From 8ff2cf3a37ffdc425a8582934abeb7867d7753c6 Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Mon, 31 Jul 2023 09:58:20 -0400 Subject: [PATCH 1/4] fix(relay): export `RateLimiter` type The `rate-limiter` module was not made publicly available. This change exports the `RateLimiter` trait defined within that module which allows users to define their own rate limiters. To make common usecases easy, we also provide a set of constructor functions for common rate limiters. Resolves #3741. Pull-Request: #3742. --- protocols/relay/CHANGELOG.md | 4 +++ protocols/relay/src/behaviour.rs | 34 +++++++++++++++++++ protocols/relay/src/behaviour/rate_limiter.rs | 12 +++---- protocols/relay/src/lib.rs | 2 +- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/protocols/relay/CHANGELOG.md b/protocols/relay/CHANGELOG.md index 1f8d57058bd..46e27bc7bf9 100644 --- a/protocols/relay/CHANGELOG.md +++ b/protocols/relay/CHANGELOG.md @@ -1,8 +1,12 @@ ## 0.16.1 - unreleased +- Export `RateLimiter` type. + See [PR 3742]. + - Add functions to access data within `Limit`. See [PR 4162]. +[PR 3742]: https://github.com/libp2p/rust-libp2p/pull/3742 [PR 4162]: https://github.com/libp2p/rust-libp2p/pull/4162 ## 0.16.0 diff --git a/protocols/relay/src/behaviour.rs b/protocols/relay/src/behaviour.rs index eb2f662581f..8fcfa103c4f 100644 --- a/protocols/relay/src/behaviour.rs +++ b/protocols/relay/src/behaviour.rs @@ -61,6 +61,40 @@ pub struct Config { pub circuit_src_rate_limiters: Vec>, } +impl Config { + pub fn reservation_rate_per_peer(mut self, limit: NonZeroU32, interval: Duration) -> Self { + self.reservation_rate_limiters + .push(rate_limiter::new_per_peer( + rate_limiter::GenericRateLimiterConfig { limit, interval }, + )); + self + } + + pub fn circuit_src_per_peer(mut self, limit: NonZeroU32, interval: Duration) -> Self { + self.circuit_src_rate_limiters + .push(rate_limiter::new_per_peer( + rate_limiter::GenericRateLimiterConfig { limit, interval }, + )); + self + } + + pub fn reservation_rate_per_ip(mut self, limit: NonZeroU32, interval: Duration) -> Self { + self.reservation_rate_limiters + .push(rate_limiter::new_per_ip( + rate_limiter::GenericRateLimiterConfig { limit, interval }, + )); + self + } + + pub fn circuit_src_per_ip(mut self, limit: NonZeroU32, interval: Duration) -> Self { + self.circuit_src_rate_limiters + .push(rate_limiter::new_per_ip( + rate_limiter::GenericRateLimiterConfig { limit, interval }, + )); + self + } +} + impl std::fmt::Debug for Config { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Config") diff --git a/protocols/relay/src/behaviour/rate_limiter.rs b/protocols/relay/src/behaviour/rate_limiter.rs index 31223c309f2..a4a127e1253 100644 --- a/protocols/relay/src/behaviour/rate_limiter.rs +++ b/protocols/relay/src/behaviour/rate_limiter.rs @@ -30,10 +30,10 @@ use std::time::Duration; /// Allows rate limiting access to some resource based on the [`PeerId`] and /// [`Multiaddr`] of a remote peer. -/// -/// See [`new_per_peer`] and [`new_per_ip`] for precast implementations. Use -/// [`GenericRateLimiter`] to build your own, e.g. based on the autonomous system -/// number of a peers IP address. +// +// See [`new_per_peer`] and [`new_per_ip`] for precast implementations. Use +// [`GenericRateLimiter`] to build your own, e.g. based on the autonomous system +// number of a peers IP address. pub trait RateLimiter: Send { fn try_next(&mut self, peer: PeerId, addr: &Multiaddr, now: Instant) -> bool; } @@ -80,9 +80,9 @@ pub(crate) struct GenericRateLimiter { /// 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. + // 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. + // The interval at which a single token is added to the bucket. pub(crate) interval: Duration, } diff --git a/protocols/relay/src/lib.rs b/protocols/relay/src/lib.rs index b411c650aeb..39ccd539838 100644 --- a/protocols/relay/src/lib.rs +++ b/protocols/relay/src/lib.rs @@ -39,7 +39,7 @@ mod proto { }; } -pub use behaviour::{Behaviour, CircuitId, Config, Event}; +pub use behaviour::{rate_limiter::RateLimiter, Behaviour, CircuitId, Config, Event}; pub use protocol::{HOP_PROTOCOL_NAME, STOP_PROTOCOL_NAME}; /// Types related to the relay protocol inbound. From 23d7d1a247eb3e5b9a40582f18cdb1a036b51d00 Mon Sep 17 00:00:00 2001 From: arsenron <33022971+arsenron@users.noreply.github.com> Date: Mon, 31 Jul 2023 17:23:45 +0300 Subject: [PATCH 2/4] feat(kad): implement common traits on `RoutingUpdate` A few weeks ago when I was debugging my wrong setup with kademlia, I could not conveniently debug `RoutingUpdate` after adding an address to the DHT. It would be nice to have a few derivable traits on a public enum. Pull-Request: #4270. --- Cargo.lock | 2 +- Cargo.toml | 2 +- protocols/kad/CHANGELOG.md | 9 ++++++++- protocols/kad/Cargo.toml | 2 +- protocols/kad/src/behaviour.rs | 1 + 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdddd50c952..57bca1723d4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2812,7 +2812,7 @@ dependencies = [ [[package]] name = "libp2p-kad" -version = "0.44.3" +version = "0.44.4" dependencies = [ "arrayvec", "async-std", diff --git a/Cargo.toml b/Cargo.toml index fa8c70eb4ea..0a23bc54815 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ 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.2" } -libp2p-kad = { version = "0.44.3", path = "protocols/kad" } +libp2p-kad = { version = "0.44.4", path = "protocols/kad" } libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" } libp2p-metrics = { version = "0.13.1", path = "misc/metrics" } libp2p-mplex = { version = "0.40.0", path = "muxers/mplex" } diff --git a/protocols/kad/CHANGELOG.md b/protocols/kad/CHANGELOG.md index 5389bda4592..c729e5ea0f9 100644 --- a/protocols/kad/CHANGELOG.md +++ b/protocols/kad/CHANGELOG.md @@ -1,4 +1,11 @@ -## 0.44.3 - unreleased +## 0.44.4 - unreleased + +- Implement common traits on `RoutingUpdate`. + See [PR 4270]. + +[PR 4270]: https://github.com/libp2p/rust-libp2p/pull/4270 + +## 0.44.3 - Prevent simultaneous dials to peers. See [PR 4224]. diff --git a/protocols/kad/Cargo.toml b/protocols/kad/Cargo.toml index 52a5ba4e188..80e8946f871 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.44.3" +version = "0.44.4" authors = ["Parity Technologies "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/protocols/kad/src/behaviour.rs b/protocols/kad/src/behaviour.rs index e3651fa2b3d..c0a11a100ec 100644 --- a/protocols/kad/src/behaviour.rs +++ b/protocols/kad/src/behaviour.rs @@ -3289,6 +3289,7 @@ impl fmt::Display for NoKnownPeers { impl std::error::Error for NoKnownPeers {} /// The possible outcomes of [`Kademlia::add_address`]. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum RoutingUpdate { /// The given peer and address has been added to the routing /// table. From d20dec05bed4db7dd7d08ce1e7d6b3c12b384dbc Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Mon, 31 Jul 2023 20:31:43 +0200 Subject: [PATCH 3/4] chore(ci): bump `cargo semver-checks` to `0.22.1` Pull-Request: #4227. --- .github/actions/cargo-semver-checks/action.yml | 2 +- .github/workflows/ci.yml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/actions/cargo-semver-checks/action.yml b/.github/actions/cargo-semver-checks/action.yml index 79151e6e98c..e9e6844f49c 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.20.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.22.1/cargo-semver-checks-x86_64-unknown-linux-gnu.tar.gz | tar -xz -C ~/.cargo/bin shell: bash - name: Get released version diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 89b756d1d72..14cd04f4299 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,9 +58,9 @@ jobs: echo "code=${RESPONSE_CODE}" >> $GITHUB_OUTPUT - uses: ./.github/actions/cargo-semver-checks - if: steps.check-released.outputs.code == 200 # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped. + if: steps.check-released.outputs.code == 200 && !contains(fromJSON('["libp2p-swarm-derive"]'), env.CRATE) # Workaround until https://github.com/obi1kenobi/cargo-semver-check/issues/146 is shipped. with: - crate: env.CRATE + crate: ${{ env.CRATE }} - name: Enforce no dependency on meta crate run: | From c86b665a653626f5eca30c4f8811a2a08c3fbb20 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 31 Jul 2023 22:17:36 +0200 Subject: [PATCH 4/4] chore(roadmap): move QUIC quinn to done Done with https://github.com/libp2p/rust-libp2p/pull/3454. Pull-Request: #4277. --- ROADMAP.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index a148de5794e..fc0ad003f49 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -8,14 +8,6 @@ This is a living document. Input is always welcome e.g. via GitHub issues or pul This is the roadmap of the Rust implementation of libp2p. See also the [general libp2p project roadmap](https://github.com/libp2p/specs/blob/master/ROADMAP.md). -## QUIC - evaluate and move to quinn - -| Category | Status | Target Completion | Tracking | Dependencies | Dependents | -|--------------|--------|-------------------|---------------------------------------------------|--------------|------------| -| Connectivity | todo | Q3/2023 | https://github.com/libp2p/rust-libp2p/issues/2883 | | | - -We added alpha support for QUIC in Q4/2022 wrapping `quinn-proto`. Evaluate using `quinn` directly, replacing the wrapper. - ## Attempt to switch from webrtc-rs to str0m | Category | Status | Target Completion | Tracking | Dependencies | Dependents | @@ -180,3 +172,11 @@ QUIC](https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol). Kademlia client mode will enhance routing table health and thus have a positive impact on all Kademlia operations. + +## QUIC - evaluate and move to quinn + +| Category | Status | Target Completion | Tracking | Dependencies | Dependents | +|--------------|--------|-------------------|---------------------------------------------------|--------------|------------| +| Connectivity | done | Q3/2023 | https://github.com/libp2p/rust-libp2p/issues/2883 | | | + +We added alpha support for QUIC in Q4/2022 wrapping `quinn-proto`. Evaluate using `quinn` directly, replacing the wrapper.