Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add SwarmBuilder::with_quic_config for TcpPhase #4821

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

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

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.1 - unreleased

- Allow `SwarmBuilder::with_quic_config` to be called without `with_tcp` first.
See [PR 4821](https://github.com/libp2p/rust-libp2p/pull/4821).

## 0.53.0

- Raise MSRV to 1.73.
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.0"
version = "0.53.1"
authors = ["Parity Technologies <admin@parity.io>"]
license = "MIT"
repository = "https://github.com/libp2p/rust-libp2p"
Expand Down
132 changes: 130 additions & 2 deletions libp2p/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,13 @@ mod tests {
use libp2p_swarm::{NetworkBehaviour, Swarm};

#[test]
#[cfg(all(feature = "tokio", feature = "tcp", feature = "tls", feature = "noise"))]
#[cfg(all(
feature = "tokio",
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
))]
fn tcp() {
let _ = SwarmBuilder::with_new_identity()
.with_tokio()
Expand All @@ -96,7 +102,8 @@ mod tests {
feature = "async-std",
feature = "tcp",
feature = "tls",
feature = "noise"
feature = "noise",
feature = "yamux",
))]
fn async_std_tcp() {
let _ = SwarmBuilder::with_new_identity()
Expand All @@ -112,6 +119,50 @@ mod tests {
.build();
}

#[test]
#[cfg(all(feature = "tokio", feature = "quic"))]
thomaseizinger marked this conversation as resolved.
Show resolved Hide resolved
fn quic() {
let _ = SwarmBuilder::with_new_identity()
.with_tokio()
.with_quic()
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(feature = "async-std", feature = "quic"))]
fn async_std_quic() {
let _ = SwarmBuilder::with_new_identity()
.with_async_std()
.with_quic()
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(feature = "tokio", feature = "quic"))]
fn quic_config() {
let _ = SwarmBuilder::with_new_identity()
.with_tokio()
.with_quic_config(|config| config)
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(feature = "async-std", feature = "quic"))]
fn async_std_quic_config() {
let _ = SwarmBuilder::with_new_identity()
.with_async_std()
.with_quic_config(|config| config)
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(feature = "tokio", feature = "tcp", feature = "tls", feature = "yamux"))]
fn tcp_yamux_mplex() {
Expand Down Expand Up @@ -162,6 +213,7 @@ mod tests {
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "quic"
))]
fn tcp_quic() {
Expand All @@ -179,12 +231,85 @@ mod tests {
.build();
}

#[test]
#[cfg(all(
feature = "async-std",
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "quic"
))]
fn async_std_tcp_quic() {
let _ = SwarmBuilder::with_new_identity()
.with_async_std()
.with_tcp(
Default::default(),
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)
.unwrap()
.with_quic()
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(
feature = "tokio",
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "quic"
))]
fn tcp_quic_config() {
let _ = SwarmBuilder::with_new_identity()
.with_tokio()
.with_tcp(
Default::default(),
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)
.unwrap()
.with_quic_config(|config| config)
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(
feature = "async-std",
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "quic"
))]
fn async_std_tcp_quic_config() {
let _ = SwarmBuilder::with_new_identity()
.with_async_std()
.with_tcp(
Default::default(),
(libp2p_tls::Config::new, libp2p_noise::Config::new),
libp2p_yamux::Config::default,
)
.unwrap()
.with_quic_config(|config| config)
.with_behaviour(|_| libp2p_swarm::dummy::Behaviour)
.unwrap()
.build();
}

#[test]
#[cfg(all(
feature = "tokio",
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "relay"
))]
fn tcp_relay() {
Expand Down Expand Up @@ -219,6 +344,7 @@ mod tests {
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "dns"
))]
async fn tcp_dns() {
Expand Down Expand Up @@ -266,6 +392,7 @@ mod tests {
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "dns",
feature = "websocket",
))]
Expand Down Expand Up @@ -295,6 +422,7 @@ mod tests {
feature = "tcp",
feature = "tls",
feature = "noise",
feature = "yamux",
feature = "quic",
feature = "dns",
feature = "relay",
Expand Down
24 changes: 24 additions & 0 deletions libp2p/src/builder/phase/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ impl SwarmBuilder<super::provider::Tokio, TcpPhase> {
self.without_tcp().with_quic()
}
}
#[cfg(all(not(target_arch = "wasm32"), feature = "quic", feature = "async-std"))]
impl SwarmBuilder<super::provider::AsyncStd, TcpPhase> {
pub fn with_quic_config(
self,
constructor: impl FnOnce(libp2p_quic::Config) -> libp2p_quic::Config,
) -> SwarmBuilder<
super::provider::AsyncStd,
OtherTransportPhase<impl AuthenticatedMultiplexedTransport>,
> {
self.without_tcp().with_quic_config(constructor)
}
}
#[cfg(all(not(target_arch = "wasm32"), feature = "quic", feature = "tokio"))]
impl SwarmBuilder<super::provider::Tokio, TcpPhase> {
pub fn with_quic_config(
self,
constructor: impl FnOnce(libp2p_quic::Config) -> libp2p_quic::Config,
) -> SwarmBuilder<
super::provider::Tokio,
OtherTransportPhase<impl AuthenticatedMultiplexedTransport>,
> {
self.without_tcp().with_quic_config(constructor)
}
}
impl<Provider> SwarmBuilder<Provider, TcpPhase> {
pub fn with_other_transport<
Muxer: libp2p_core::muxing::StreamMuxer + Send + 'static,
Expand Down