Skip to content

Commit

Permalink
feat: memory based connection limits
Browse files Browse the repository at this point in the history
Implements memory-based connection limits where the user can specify an absolute or a relative limit of the process' memory usage in relation to the available system memory.

Related: #4252.

Pull-Request: #4281.
  • Loading branch information
hanabi1224 authored Aug 8, 2023
1 parent 188b70e commit b5d9932
Show file tree
Hide file tree
Showing 11 changed files with 633 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ members = [
"misc/allow-block-list",
"misc/connection-limits",
"misc/keygen",
"misc/memory-connection-limits",
"misc/metrics",
"misc/multistream-select",
"misc/quick-protobuf-codec",
Expand Down Expand Up @@ -75,6 +76,7 @@ libp2p-identify = { version = "0.43.0", path = "protocols/identify" }
libp2p-identity = { version = "0.2.2" }
libp2p-kad = { version = "0.44.4", path = "protocols/kad" }
libp2p-mdns = { version = "0.44.0", path = "protocols/mdns" }
libp2p-memory-connection-limits = { version = "0.1.0", path = "misc/memory-connection-limits" }
libp2p-metrics = { version = "0.13.1", path = "misc/metrics" }
libp2p-mplex = { version = "0.40.0", path = "muxers/mplex" }
libp2p-muxer-test-harness = { path = "muxers/test-harness" }
Expand Down
4 changes: 4 additions & 0 deletions libp2p/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
- Add `json` feature which exposes `request_response::json`.
See [PR 4188].

- Add `libp2p-memory-connection-limits` providing memory usage based connection limit configurations.
See [PR 4281].

[PR 4188]: https://github.com/libp2p/rust-libp2p/pull/4188
[PR 4217]: https://github.com/libp2p/rust-libp2p/pull/4217
[PR 4281]: https://github.com/libp2p/rust-libp2p/pull/4281

## 0.52.1

Expand Down
3 changes: 3 additions & 0 deletions libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ full = [
"kad",
"macros",
"mdns",
"memory-connection-limits",
"metrics",
"noise",
"ping",
Expand Down Expand Up @@ -65,6 +66,7 @@ json = ["libp2p-request-response?/json"]
kad = ["dep:libp2p-kad", "libp2p-metrics?/kad"]
macros = ["libp2p-swarm/macros"]
mdns = ["dep:libp2p-mdns"]
memory-connection-limits = ["dep:libp2p-memory-connection-limits"]
metrics = ["dep:libp2p-metrics"]
noise = ["dep:libp2p-noise"]
ping = ["dep:libp2p-ping", "libp2p-metrics?/ping"]
Expand Down Expand Up @@ -124,6 +126,7 @@ pin-project = "1.0.0"
libp2p-deflate = { workspace = true, optional = true }
libp2p-dns = { workspace = true, optional = true }
libp2p-mdns = { workspace = true, optional = true }
libp2p-memory-connection-limits = { workspace = true, optional = true }
libp2p-tcp = { workspace = true, optional = true }
libp2p-tls = { workspace = true, optional = true }
libp2p-uds = { workspace = true, optional = true }
Expand Down
5 changes: 5 additions & 0 deletions libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ pub use libp2p_kad as kad;
#[cfg_attr(docsrs, doc(cfg(feature = "mdns")))]
#[doc(inline)]
pub use libp2p_mdns as mdns;
#[cfg(feature = "memory-connection-limits")]
#[cfg(not(target_arch = "wasm32"))]
#[cfg_attr(docsrs, doc(cfg(feature = "memory-connection-limits")))]
#[doc(inline)]
pub use libp2p_memory_connection_limits as memory_connection_limits;
#[cfg(feature = "metrics")]
#[doc(inline)]
pub use libp2p_metrics as metrics;
Expand Down
3 changes: 3 additions & 0 deletions misc/memory-connection-limits/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0 - unreleased

- Initial release.
26 changes: 26 additions & 0 deletions misc/memory-connection-limits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[package]
name = "libp2p-memory-connection-limits"
edition = "2021"
rust-version = { workspace = true }
description = "Memory usage based connection limits for libp2p."
version = "0.1.0"
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
keywords = ["peer-to-peer", "libp2p", "networking"]
categories = ["network-programming", "asynchronous"]

[dependencies]
memory-stats = { version = "1", features = ["always_use_statm"] }
libp2p-core = { workspace = true }
libp2p-swarm = { workspace = true }
libp2p-identity = { workspace = true, features = ["peerid"] }
log = "0.4"
sysinfo = "0.29"
void = "1"

[dev-dependencies]
async-std = { version = "1.12.0", features = ["attributes"] }
libp2p-identify = { workspace = true }
libp2p-swarm-derive = { path = "../../swarm-derive" }
libp2p-swarm-test = { path = "../../swarm-test" }
rand = "0.8.5"
Loading

0 comments on commit b5d9932

Please sign in to comment.