Skip to content

Commit

Permalink
Merge branch 'master' into feat/connection-limit-change
Browse files Browse the repository at this point in the history
  • Loading branch information
dariusc93 committed Dec 2, 2023
2 parents 4192b6d + 4f0013c commit 46b6060
Show file tree
Hide file tree
Showing 28 changed files with 130 additions and 62 deletions.
15 changes: 7 additions & 8 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ rust-version = "1.73.0"
[workspace.dependencies]
asynchronous-codec = { version = "0.7.0" }
futures-bounded = { version = "0.2.3", path = "misc/futures-bounded" }
libp2p = { version = "0.53.0", path = "libp2p" }
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" }
Expand All @@ -83,7 +83,7 @@ libp2p-floodsub = { version = "0.44.0", path = "protocols/floodsub" }
libp2p-gossipsub = { version = "0.46.1", path = "protocols/gossipsub" }
libp2p-identify = { version = "0.44.1", path = "protocols/identify" }
libp2p-identity = { version = "0.2.8" }
libp2p-kad = { version = "0.45.2", path = "protocols/kad" }
libp2p-kad = { version = "0.45.3", path = "protocols/kad" }
libp2p-mdns = { version = "0.45.1", path = "protocols/mdns" }
libp2p-memory-connection-limits = { version = "0.2.0", path = "misc/memory-connection-limits" }
libp2p-metrics = { version = "0.14.1", path = "misc/metrics" }
Expand All @@ -94,11 +94,11 @@ libp2p-perf = { version = "0.3.0", path = "protocols/perf" }
libp2p-ping = { version = "0.44.0", path = "protocols/ping" }
libp2p-plaintext = { version = "0.41.0", path = "transports/plaintext" }
libp2p-pnet = { version = "0.24.0", path = "transports/pnet" }
libp2p-quic = { version = "0.10.1", path = "transports/quic" }
libp2p-quic = { version = "0.10.2", path = "transports/quic" }
libp2p-relay = { version = "0.17.1", path = "protocols/relay" }
libp2p-rendezvous = { version = "0.14.0", path = "protocols/rendezvous" }
libp2p-request-response = { version = "0.26.0", path = "protocols/request-response" }
libp2p-server = { version = "0.12.4", path = "misc/server" }
libp2p-request-response = { version = "0.26.1", path = "protocols/request-response" }
libp2p-server = { version = "0.12.5", path = "misc/server" }
libp2p-swarm = { version = "0.44.0", path = "swarm" }
libp2p-swarm-derive = { version = "=0.34.0", path = "swarm-derive" } # `libp2p-swarm-derive` may not be compatible with different `libp2p-swarm` non-breaking releases. E.g. `libp2p-swarm` might introduce a new enum variant `FromSwarm` (which is `#[non-exhaustive]`) in a non-breaking release. Older versions of `libp2p-swarm-derive` would not forward this enum variant within the `NetworkBehaviour` hierarchy. Thus the version pinning is required.
libp2p-swarm-test = { version = "0.3.0", path = "swarm-test" }
Expand All @@ -107,7 +107,7 @@ libp2p-tls = { version = "0.3.0", path = "transports/tls" }
libp2p-uds = { version = "0.40.0", path = "transports/uds" }
libp2p-upnp = { version = "0.2.0", path = "protocols/upnp" }
libp2p-webrtc = { version = "0.7.0-alpha", path = "transports/webrtc" }
libp2p-webrtc-utils = { version = "0.1.0", path = "misc/webrtc-utils" }
libp2p-webrtc-utils = { version = "0.2.0", path = "misc/webrtc-utils" }
libp2p-webrtc-websys = { version = "0.3.0-alpha", path = "transports/webrtc-websys" }
libp2p-websocket = { version = "0.43.0", path = "transports/websocket" }
libp2p-websocket-websys = { version = "0.3.1", path = "transports/websocket-websys" }
Expand Down
5 changes: 5 additions & 0 deletions core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.41.2

- Implement `std::fmt::Display` on `ListenerId`.
See [PR 4936](https://github.com/libp2p/rust-libp2p/pull/4936).

## 0.41.1

- Implement `{In,Out}boundConnectionUpgrade` for `SelectUpgrade`.
Expand Down
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-core"
edition = "2021"
rust-version = { workspace = true }
description = "Core traits and structs of libp2p"
version = "0.41.1"
version = "0.41.2"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
6 changes: 6 additions & 0 deletions core/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ impl ListenerId {
}
}

impl std::fmt::Display for ListenerId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.0)
}
}

/// Event produced by [`Transport`]s.
pub enum TransportEvent<TUpgr, TErr> {
/// A new address is being listened on.
Expand Down
5 changes: 5 additions & 0 deletions libp2p/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.53.2

- Allow `SwarmBuilder::with_bandwidth_metrics` after `SwarmBuilder::with_websocket`.
See [PR 4937](https://github.com/libp2p/rust-libp2p/pull/4937).

## 0.53.1

- Allow `SwarmBuilder::with_quic_config` to be called without `with_tcp` first.
Expand Down
2 changes: 1 addition & 1 deletion libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p"
edition = "2021"
rust-version = { workspace = true }
description = "Peer-to-peer networking library"
version = "0.53.1"
version = "0.53.2"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
19 changes: 18 additions & 1 deletion libp2p/src/builder/phase/relay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,28 @@ impl<Provider, T> SwarmBuilder<Provider, RelayPhase<T>> {
}

// Shortcuts
#[cfg(feature = "metrics")]
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, RelayPhase<T>> {
pub fn with_bandwidth_metrics(
self,
registry: &mut libp2p_metrics::Registry,
) -> SwarmBuilder<
Provider,
BehaviourPhase<impl AuthenticatedMultiplexedTransport, NoRelayBehaviour>,
> {
self.without_relay()
.without_bandwidth_logging()
.with_bandwidth_metrics(registry)
}
}
impl<Provider, T: AuthenticatedMultiplexedTransport> SwarmBuilder<Provider, RelayPhase<T>> {
pub fn with_behaviour<B, R: TryIntoBehaviour<B>>(
self,
constructor: impl FnOnce(&libp2p_identity::Keypair) -> R,
) -> Result<SwarmBuilder<Provider, SwarmPhase<T, B>>, R::Error> {
self.without_relay().with_behaviour(constructor)
self.without_relay()
.without_bandwidth_logging()
.without_bandwidth_metrics()
.with_behaviour(constructor)
}
}
37 changes: 16 additions & 21 deletions misc/connection-limits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,17 @@ impl Behaviour {
pub fn limits_mut(&mut self) -> &mut ConnectionLimits {
&mut self.limits
}
}

fn check_limit(
&mut self,
limit: Option<u32>,
current: usize,
kind: Kind,
) -> Result<(), ConnectionDenied> {
let limit = limit.unwrap_or(u32::MAX);
let current = current as u32;
fn check_limit(limit: Option<u32>, current: usize, kind: Kind) -> Result<(), ConnectionDenied> {
let limit = limit.unwrap_or(u32::MAX);
let current = current as u32;

if current >= limit {
return Err(ConnectionDenied::new(Exceeded { limit, kind }));
}

Ok(())
if current >= limit {
return Err(ConnectionDenied::new(Exceeded { limit, kind }));
}

Ok(())
}

/// A connection limit has been exceeded.
Expand Down Expand Up @@ -215,7 +210,7 @@ impl NetworkBehaviour for Behaviour {
_: &Multiaddr,
_: &Multiaddr,
) -> Result<(), ConnectionDenied> {
self.check_limit(
check_limit(
self.limits.max_pending_incoming,
self.pending_inbound_connections.len(),
Kind::PendingIncoming,
Expand All @@ -235,20 +230,20 @@ impl NetworkBehaviour for Behaviour {
) -> Result<THandler<Self>, ConnectionDenied> {
self.pending_inbound_connections.remove(&connection_id);

self.check_limit(
check_limit(
self.limits.max_established_incoming,
self.established_inbound_connections.len(),
Kind::EstablishedIncoming,
)?;
self.check_limit(
check_limit(
self.limits.max_established_per_peer,
self.established_per_peer
.get(&peer)
.map(|connections| connections.len())
.unwrap_or(0),
Kind::EstablishedPerPeer,
)?;
self.check_limit(
check_limit(
self.limits.max_established_total,
self.established_inbound_connections.len()
+ self.established_outbound_connections.len(),
Expand All @@ -265,7 +260,7 @@ impl NetworkBehaviour for Behaviour {
_: &[Multiaddr],
_: Endpoint,
) -> Result<Vec<Multiaddr>, ConnectionDenied> {
self.check_limit(
check_limit(
self.limits.max_pending_outgoing,
self.pending_outbound_connections.len(),
Kind::PendingOutgoing,
Expand All @@ -285,20 +280,20 @@ impl NetworkBehaviour for Behaviour {
) -> Result<THandler<Self>, ConnectionDenied> {
self.pending_outbound_connections.remove(&connection_id);

self.check_limit(
check_limit(
self.limits.max_established_outgoing,
self.established_outbound_connections.len(),
Kind::EstablishedOutgoing,
)?;
self.check_limit(
check_limit(
self.limits.max_established_per_peer,
self.established_per_peer
.get(&peer)
.map(|connections| connections.len())
.unwrap_or(0),
Kind::EstablishedPerPeer,
)?;
self.check_limit(
check_limit(
self.limits.max_established_total,
self.established_inbound_connections.len()
+ self.established_outbound_connections.len(),
Expand Down
7 changes: 7 additions & 0 deletions misc/server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.12.5

### Added

- Add `/wss` support.
See [PR 4937](https://github.com/libp2p/rust-libp2p/pull/4937).

## 0.12.4

### Added
Expand Down
4 changes: 2 additions & 2 deletions misc/server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libp2p-server"
version = "0.12.4"
version = "0.12.5"
authors = ["Max Inden <[email protected]>"]
edition = "2021"
repository = "https://github.com/libp2p/rust-libp2p"
Expand All @@ -16,7 +16,7 @@ clap = { version = "4.4.10", features = ["derive"] }
futures = "0.3"
futures-timer = "3"
hyper = { version = "0.14", features = ["server", "tcp", "http1"] }
libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic"] }
libp2p = { workspace = true, features = ["autonat", "dns", "tokio", "noise", "tcp", "yamux", "identify", "kad", "ping", "relay", "metrics", "rsa", "macros", "quic", "websocket"] }
prometheus-client = { workspace = true }
serde = "1.0.193"
serde_derive = "1.0.125"
Expand Down
2 changes: 2 additions & 0 deletions misc/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
)?
.with_quic()
.with_dns()?
.with_websocket(noise::Config::new, yamux::Config::default)
.await?
.with_bandwidth_metrics(&mut metric_registry)
.with_behaviour(|key| {
behaviour::Behaviour::new(key.public(), opt.enable_kademlia, opt.enable_autonat)
Expand Down
5 changes: 5 additions & 0 deletions misc/webrtc-utils/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.2.0

- Update to latest version of `libp2p-noise`.
See [PR 4968](https://github.com/libp2p/rust-libp2p/pull/4968).

## 0.1.0

- Initial release.
Expand Down
2 changes: 1 addition & 1 deletion misc/webrtc-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license = "MIT"
name = "libp2p-webrtc-utils"
repository = "https://github.com/libp2p/rust-libp2p"
rust-version = { workspace = true }
version = "0.1.0"
version = "0.2.0"
publish = true

[dependencies]
Expand Down
6 changes: 4 additions & 2 deletions misc/webrtc-utils/src/noise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ use libp2p_noise as noise;

use crate::fingerprint::Fingerprint;

pub use noise::Error;

pub async fn inbound<T>(
id_keys: identity::Keypair,
stream: T,
client_fingerprint: Fingerprint,
server_fingerprint: Fingerprint,
) -> Result<PeerId, libp2p_noise::Error>
) -> Result<PeerId, Error>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
Expand All @@ -54,7 +56,7 @@ pub async fn outbound<T>(
stream: T,
server_fingerprint: Fingerprint,
client_fingerprint: Fingerprint,
) -> Result<PeerId, libp2p_noise::Error>
) -> Result<PeerId, Error>
where
T: AsyncRead + AsyncWrite + Unpin + Send + 'static,
{
Expand Down
5 changes: 5 additions & 0 deletions protocols/kad/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.45.3

- The progress of the close query iterator shall be decided by ANY of the new peers.
See [PR 4932](https://github.com/libp2p/rust-libp2p/pull/4932).

## 0.45.2

- Ensure `Multiaddr` handled and returned by `Behaviour` are `/p2p` terminated.
Expand Down
2 changes: 1 addition & 1 deletion protocols/kad/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "libp2p-kad"
edition = "2021"
rust-version = { workspace = true }
description = "Kademlia protocol for libp2p"
version = "0.45.2"
version = "0.45.3"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
Loading

0 comments on commit 46b6060

Please sign in to comment.