From c2bf189af9589c1ee99781975f482bb386ac4da1 Mon Sep 17 00:00:00 2001 From: Darius Date: Tue, 14 Nov 2023 10:15:57 -0500 Subject: [PATCH 01/10] chore: Add function to mutate connection limit --- Cargo.lock | 2 +- misc/connection-limits/CHANGELOG.md | 7 +++++++ misc/connection-limits/Cargo.toml | 2 +- misc/connection-limits/src/lib.rs | 4 ++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 842b7ebb462..15034c5801d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2450,7 +2450,7 @@ dependencies = [ [[package]] name = "libp2p-connection-limits" -version = "0.3.0" +version = "0.3.1" dependencies = [ "async-std", "libp2p-core", diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index a5b68a6f51b..7d11c4d61cf 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.3.1 +- Adds `Behaviour::limits_mut`. + + See [PR XXXX]. + +[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX + ## 0.3.0 diff --git a/misc/connection-limits/Cargo.toml b/misc/connection-limits/Cargo.toml index 2aa26ad44f1..8ecb0005cb1 100644 --- a/misc/connection-limits/Cargo.toml +++ b/misc/connection-limits/Cargo.toml @@ -3,7 +3,7 @@ name = "libp2p-connection-limits" edition = "2021" rust-version = { workspace = true } description = "Connection limits for libp2p." -version = "0.3.0" +version = "0.3.1" license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" keywords = ["peer-to-peer", "libp2p", "networking"] diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index af76e9a57d9..4d40a1a16cc 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -80,6 +80,10 @@ impl Behaviour { } } + pub fn limits_mut(&mut self) -> &mut ConnectionLimits { + &mut self.limits + } + fn check_limit( &mut self, limit: Option, From 44d43c292ed938b97098d077f5d0d57673697207 Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 29 Nov 2023 21:11:05 -0500 Subject: [PATCH 02/10] chore: Add getters/setter functions to `ConnectionLimits` --- misc/connection-limits/src/lib.rs | 57 +++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 4d40a1a16cc..f27ec57ad8a 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -80,6 +80,7 @@ impl Behaviour { } } + /// Returns a mutable reference to [`ConnectionLimits`]. pub fn limits_mut(&mut self) -> &mut ConnectionLimits { &mut self.limits } @@ -204,6 +205,62 @@ impl ConnectionLimits { } } +impl ConnectionLimits { + pub fn max_pending_incoming(&self) -> Option { + self.max_pending_incoming + } + + pub fn max_pending_outgoing(&self) -> Option { + self.max_pending_outgoing + } + + pub fn max_established_incoming(&self) -> Option { + self.max_established_incoming + } + + pub fn max_established_outgoing(&self) -> Option { + self.max_established_outgoing + } + + pub fn max_established(&self) -> Option { + self.max_established_total + } + + pub fn max_established_per_peer(&self) -> Option { + self.max_established_per_peer + } + + pub fn set_max_pending_incoming(&mut self, limit: Option) -> &mut Self { + self.max_pending_incoming = limit; + self + } + + pub fn set_max_pending_outgoing(&mut self, limit: Option) -> &mut Self { + self.max_pending_outgoing = limit; + self + } + + pub fn set_max_established_incoming(&mut self, limit: Option) -> &mut Self { + self.max_established_incoming = limit; + self + } + + pub fn set_max_established_outgoing(&mut self, limit: Option) -> &mut Self { + self.max_established_outgoing = limit; + self + } + + pub fn set_max_established(&mut self, limit: Option) -> &mut Self { + self.max_established_total = limit; + self + } + + pub fn set_max_established_per_peer(&mut self, limit: Option) -> &mut Self { + self.max_established_per_peer = limit; + self + } +} + impl NetworkBehaviour for Behaviour { type ConnectionHandler = dummy::ConnectionHandler; type ToSwarm = Void; From 978e4270c8d03171edcd269ce043d8ec19599723 Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 29 Nov 2023 21:11:47 -0500 Subject: [PATCH 03/10] chore: Remove setter functions --- misc/connection-limits/src/lib.rs | 30 ------------------------------ 1 file changed, 30 deletions(-) diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index f27ec57ad8a..b63d97596a3 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -229,36 +229,6 @@ impl ConnectionLimits { pub fn max_established_per_peer(&self) -> Option { self.max_established_per_peer } - - pub fn set_max_pending_incoming(&mut self, limit: Option) -> &mut Self { - self.max_pending_incoming = limit; - self - } - - pub fn set_max_pending_outgoing(&mut self, limit: Option) -> &mut Self { - self.max_pending_outgoing = limit; - self - } - - pub fn set_max_established_incoming(&mut self, limit: Option) -> &mut Self { - self.max_established_incoming = limit; - self - } - - pub fn set_max_established_outgoing(&mut self, limit: Option) -> &mut Self { - self.max_established_outgoing = limit; - self - } - - pub fn set_max_established(&mut self, limit: Option) -> &mut Self { - self.max_established_total = limit; - self - } - - pub fn set_max_established_per_peer(&mut self, limit: Option) -> &mut Self { - self.max_established_per_peer = limit; - self - } } impl NetworkBehaviour for Behaviour { From 3592cf032d812d3306f04766c22e890b508ad16e Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 29 Nov 2023 21:13:24 -0500 Subject: [PATCH 04/10] chore: Remove getter function --- misc/connection-limits/src/lib.rs | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index b63d97596a3..ad475bf72cf 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -205,32 +205,6 @@ impl ConnectionLimits { } } -impl ConnectionLimits { - pub fn max_pending_incoming(&self) -> Option { - self.max_pending_incoming - } - - pub fn max_pending_outgoing(&self) -> Option { - self.max_pending_outgoing - } - - pub fn max_established_incoming(&self) -> Option { - self.max_established_incoming - } - - pub fn max_established_outgoing(&self) -> Option { - self.max_established_outgoing - } - - pub fn max_established(&self) -> Option { - self.max_established_total - } - - pub fn max_established_per_peer(&self) -> Option { - self.max_established_per_peer - } -} - impl NetworkBehaviour for Behaviour { type ConnectionHandler = dummy::ConnectionHandler; type ToSwarm = Void; From 9f20352f8febe68db83bf2c53e3fc03193f67d39 Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 29 Nov 2023 21:14:59 -0500 Subject: [PATCH 05/10] chore: Update CHANGELOG --- misc/connection-limits/CHANGELOG.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index 7d11c4d61cf..cb686cdb7e8 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,9 +1,7 @@ -## 0.3.1 -- Adds `Behaviour::limits_mut`. +## 0.3.1 - unreleased - See [PR XXXX]. - -[PR XXXX]: https://github.com/libp2p/rust-libp2p/pull/XXXX +- Add function to mutate `ConnectionLimits`. + See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). ## 0.3.0 From c68704b5af5607c6190addf2f3acb5c8dd21f51e Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 29 Nov 2023 21:19:50 -0500 Subject: [PATCH 06/10] chore: Update changelog --- misc/connection-limits/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index cb686cdb7e8..1347d354431 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.3.1 - unreleased - Add function to mutate `ConnectionLimits`. - See [PR XXXX](https://github.com/libp2p/rust-libp2p/pull/XXXX). + See [PR 4964](https://github.com/libp2p/rust-libp2p/pull/4964). ## 0.3.0 From 6d4e1dd794aadee36cffa6663edc00d351d558dd Mon Sep 17 00:00:00 2001 From: Darius Date: Wed, 29 Nov 2023 21:55:49 -0500 Subject: [PATCH 07/10] chore: Bump version --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 346b316d4dc..9c4d7911387 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,7 +75,7 @@ futures-bounded = { version = "0.2.3", path = "misc/futures-bounded" } libp2p = { version = "0.53.0", path = "libp2p" } libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" } libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" } -libp2p-connection-limits = { version = "0.3.0", path = "misc/connection-limits" } +libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" } libp2p-core = { version = "0.41.1", path = "core" } libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.41.1", path = "transports/dns" } From 3fb51026418fb37b9f36504c41f055f0cad69fba Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Fri, 1 Dec 2023 01:56:18 -0500 Subject: [PATCH 08/10] Update misc/connection-limits/CHANGELOG.md Co-authored-by: Thomas Eizinger --- misc/connection-limits/CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/misc/connection-limits/CHANGELOG.md b/misc/connection-limits/CHANGELOG.md index 1347d354431..4654281a83e 100644 --- a/misc/connection-limits/CHANGELOG.md +++ b/misc/connection-limits/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.3.1 - unreleased +## 0.3.1 - Add function to mutate `ConnectionLimits`. See [PR 4964](https://github.com/libp2p/rust-libp2p/pull/4964). From 9345fb5ae19a26e893bea0363131f0eff2dd7017 Mon Sep 17 00:00:00 2001 From: Darius Clark Date: Sun, 3 Dec 2023 20:06:54 -0500 Subject: [PATCH 09/10] Update Cargo.toml Co-authored-by: Thomas Eizinger --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5d47746de81..db5e0013b32 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ libp2p = { version = "0.53.2", path = "libp2p" } libp2p-allow-block-list = { version = "0.3.0", path = "misc/allow-block-list" } libp2p-autonat = { version = "0.12.0", path = "protocols/autonat" } libp2p-connection-limits = { version = "0.3.1", path = "misc/connection-limits" } -libp2p-core = { version = "0.41.1", path = "core" } +libp2p-core = { version = "0.41.2", path = "core" } libp2p-dcutr = { version = "0.11.0", path = "protocols/dcutr" } libp2p-dns = { version = "0.41.1", path = "transports/dns" } libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" } From d90ca1458568690fcf25ccad3dac438b5e3a0cfd Mon Sep 17 00:00:00 2001 From: Darius Date: Sun, 3 Dec 2023 20:28:54 -0500 Subject: [PATCH 10/10] chore: Add minor note to limits_mut --- misc/connection-limits/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/misc/connection-limits/src/lib.rs b/misc/connection-limits/src/lib.rs index 7d8afcaacbd..dbe68a8ad11 100644 --- a/misc/connection-limits/src/lib.rs +++ b/misc/connection-limits/src/lib.rs @@ -81,6 +81,7 @@ impl Behaviour { } /// Returns a mutable reference to [`ConnectionLimits`]. + /// > **Note**: A new limit will not be enforced against existing connections. pub fn limits_mut(&mut self) -> &mut ConnectionLimits { &mut self.limits }