From 2f6173f6907e340c73a56621af9059cb670ff6df Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 27 Nov 2023 21:01:52 +0100 Subject: [PATCH 1/2] feat(server): support websocket --- Cargo.lock | 4 ++-- Cargo.toml | 4 ++-- libp2p/CHANGELOG.md | 5 +++++ libp2p/Cargo.toml | 2 +- libp2p/src/builder/phase/relay.rs | 19 ++++++++++++++++++- misc/server/CHANGELOG.md | 7 +++++++ misc/server/Cargo.toml | 4 ++-- misc/server/src/main.rs | 2 ++ 8 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 168ffb2034c..2523deb41b8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2423,7 +2423,7 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" [[package]] name = "libp2p" -version = "0.53.1" +version = "0.53.2" dependencies = [ "async-std", "async-trait", @@ -3087,7 +3087,7 @@ dependencies = [ [[package]] name = "libp2p-server" -version = "0.12.4" +version = "0.12.5" dependencies = [ "base64 0.21.5", "clap", diff --git a/Cargo.toml b/Cargo.toml index 1dce34011c8..7d9b28fc33a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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.0", path = "misc/connection-limits" } @@ -98,7 +98,7 @@ libp2p-quic = { version = "0.10.1", 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-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" } diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index bb6d8211bd5..1e61dab81c9 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.53.2 + +- Allow `SwarmBuilder::with_bandwidth_metrics` after `SwarmBuilder::with_websocket`. + See [PR XXX](https://github.com/libp2p/rust-libp2p/pull/XXX). + ## 0.53.1 - Allow `SwarmBuilder::with_quic_config` to be called without `with_tcp` first. diff --git a/libp2p/Cargo.toml b/libp2p/Cargo.toml index 6ced40e1dfe..9dc9667be10 100644 --- a/libp2p/Cargo.toml +++ b/libp2p/Cargo.toml @@ -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 "] license = "MIT" repository = "https://github.com/libp2p/rust-libp2p" diff --git a/libp2p/src/builder/phase/relay.rs b/libp2p/src/builder/phase/relay.rs index 2d47810ca9e..f8305f9d246 100644 --- a/libp2p/src/builder/phase/relay.rs +++ b/libp2p/src/builder/phase/relay.rs @@ -116,11 +116,28 @@ impl SwarmBuilder> { } // Shortcuts +#[cfg(feature = "metrics")] +impl SwarmBuilder> { + pub fn with_bandwidth_metrics( + self, + registry: &mut libp2p_metrics::Registry, + ) -> SwarmBuilder< + Provider, + BehaviourPhase, + > { + self.without_relay() + .without_bandwidth_logging() + .with_bandwidth_metrics(registry) + } +} impl SwarmBuilder> { pub fn with_behaviour>( self, constructor: impl FnOnce(&libp2p_identity::Keypair) -> R, ) -> Result>, R::Error> { - self.without_relay().with_behaviour(constructor) + self.without_relay() + .without_bandwidth_logging() + .without_bandwidth_metrics() + .with_behaviour(constructor) } } diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index d476a8722eb..dd9fdf3678f 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -1,3 +1,10 @@ +## 0.12.5 + +### Added + +- Add `/wss` support. + See [PR XXX](https://github.com/libp2p/rust-libp2p/pull/XXX). + ## 0.12.4 ### Added diff --git a/misc/server/Cargo.toml b/misc/server/Cargo.toml index 9cc77b09d18..99fc7aafe69 100644 --- a/misc/server/Cargo.toml +++ b/misc/server/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "libp2p-server" -version = "0.12.4" +version = "0.12.5" authors = ["Max Inden "] edition = "2021" repository = "https://github.com/libp2p/rust-libp2p" @@ -16,7 +16,7 @@ clap = { version = "4.4.8", 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" diff --git a/misc/server/src/main.rs b/misc/server/src/main.rs index 2349ebf6485..16e6530e946 100644 --- a/misc/server/src/main.rs +++ b/misc/server/src/main.rs @@ -82,6 +82,8 @@ async fn main() -> Result<(), Box> { )? .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) From 6092c8e64bb6a3caa83a228c9e8d0a12887bc9e1 Mon Sep 17 00:00:00 2001 From: Max Inden Date: Mon, 27 Nov 2023 21:04:57 +0100 Subject: [PATCH 2/2] Update changelogs --- libp2p/CHANGELOG.md | 2 +- misc/server/CHANGELOG.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libp2p/CHANGELOG.md b/libp2p/CHANGELOG.md index 1e61dab81c9..80b32c35643 100644 --- a/libp2p/CHANGELOG.md +++ b/libp2p/CHANGELOG.md @@ -1,7 +1,7 @@ ## 0.53.2 - Allow `SwarmBuilder::with_bandwidth_metrics` after `SwarmBuilder::with_websocket`. - See [PR XXX](https://github.com/libp2p/rust-libp2p/pull/XXX). + See [PR 4937](https://github.com/libp2p/rust-libp2p/pull/4937). ## 0.53.1 diff --git a/misc/server/CHANGELOG.md b/misc/server/CHANGELOG.md index dd9fdf3678f..e4c5dd4a103 100644 --- a/misc/server/CHANGELOG.md +++ b/misc/server/CHANGELOG.md @@ -3,7 +3,7 @@ ### Added - Add `/wss` support. - See [PR XXX](https://github.com/libp2p/rust-libp2p/pull/XXX). + See [PR 4937](https://github.com/libp2p/rust-libp2p/pull/4937). ## 0.12.4