Skip to content

Commit

Permalink
feat(server): support websocket
Browse files Browse the repository at this point in the history
Pull-Request: #4937.
  • Loading branch information
mxinden authored Dec 1, 2023
1 parent a83c30a commit 4f0013c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

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

4 changes: 2 additions & 2 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.0", path = "misc/connection-limits" }
Expand All @@ -98,7 +98,7 @@ 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.1", 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" }
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)
}
}
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

0 comments on commit 4f0013c

Please sign in to comment.