mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-28 10:11:19 +00:00
core: Add a total established connection limit (#2137)
Co-authored-by: Max Inden <mail@max-inden.de>
This commit is contained in:
parent
99c7078bcf
commit
76f1fcbee3
@ -1,5 +1,7 @@
|
||||
# 0.30.0 [unreleased]
|
||||
|
||||
- Add `ConnectionLimit::with_max_established` (see [PR 2137]).
|
||||
|
||||
- Add `Keypair::to_protobuf_encoding` (see [PR 2142]).
|
||||
|
||||
- Change `PublicKey::into_protobuf_encoding` to `PublicKey::to_protobuf_encoding` (see [PR 2145]).
|
||||
@ -12,6 +14,7 @@
|
||||
|
||||
[PR 2145]: https://github.com/libp2p/rust-libp2p/pull/2145
|
||||
[PR 2142]: https://github.com/libp2p/rust-libp2p/pull/2142
|
||||
[PR 2137]: https://github.com/libp2p/rust-libp2p/pull/2137/
|
||||
|
||||
# 0.29.0 [2021-07-12]
|
||||
|
||||
|
@ -987,6 +987,9 @@ impl ConnectionCounters {
|
||||
fn check_max_established(&self, endpoint: &ConnectedPoint)
|
||||
-> Result<(), ConnectionLimit>
|
||||
{
|
||||
// Check total connection limit.
|
||||
Self::check(self.num_established(), self.limits.max_established_total)?;
|
||||
// Check incoming/outgoing connection limits
|
||||
match endpoint {
|
||||
ConnectedPoint::Dialer { .. } =>
|
||||
Self::check(self.established_outgoing, self.limits.max_established_outgoing),
|
||||
@ -1031,6 +1034,7 @@ pub struct ConnectionLimits {
|
||||
max_established_incoming: Option<u32>,
|
||||
max_established_outgoing: Option<u32>,
|
||||
max_established_per_peer: Option<u32>,
|
||||
max_established_total: Option<u32>,
|
||||
}
|
||||
|
||||
impl ConnectionLimits {
|
||||
@ -1058,6 +1062,17 @@ impl ConnectionLimits {
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures the maximum number of concurrent established connections (both
|
||||
/// inbound and outbound).
|
||||
///
|
||||
/// Note: This should be used in conjunction with
|
||||
/// [`ConnectionLimits::with_max_established_incoming`] to prevent possible
|
||||
/// eclipse attacks (all connections being inbound).
|
||||
pub fn with_max_established(mut self, limit: Option<u32>) -> Self {
|
||||
self.max_established_total = limit;
|
||||
self
|
||||
}
|
||||
|
||||
/// Configures the maximum number of concurrent established connections per peer,
|
||||
/// regardless of direction (incoming or outgoing).
|
||||
pub fn with_max_established_per_peer(mut self, limit: Option<u32>) -> Self {
|
||||
|
Loading…
x
Reference in New Issue
Block a user