Skip to content

Commit

Permalink
Merge pull request #2075 from subspace/make-quic-default-protocol
Browse files Browse the repository at this point in the history
Adjust QUIC usage in subspace-networking crate
  • Loading branch information
shamil-gadelshin authored Oct 9, 2023
2 parents fdddc4a + f407113 commit d64a311
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 47 deletions.
23 changes: 0 additions & 23 deletions Cargo.lock

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

5 changes: 1 addition & 4 deletions crates/subspace-networking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,13 @@ features = [
"noise",
"ping",
"plaintext",
"quic",
"request-response",
"serde",
"tcp",
"tokio",
"websocket",
"yamux",
]
[dependencies.libp2p-quic]
version = "0.8.0-alpha"
features = ["tokio"]

# Remove after this patch goes to the release branch
[dependencies.libp2p-kad]
Expand Down
32 changes: 12 additions & 20 deletions crates/subspace-networking/src/constructor/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use libp2p::core::muxing::StreamMuxerBox;
use libp2p::core::transport::{Boxed, ListenerId, TransportError, TransportEvent};
use libp2p::core::Transport;
use libp2p::dns::TokioDnsConfig;
use libp2p::quic::tokio::Transport as QuicTransport;
use libp2p::quic::Config as QuicConfig;
use libp2p::tcp::tokio::Transport as TokioTcpTransport;
use libp2p::tcp::Config as GenTcpConfig;
use libp2p::websocket::WsConfig;
use libp2p::yamux::Config as YamuxConfig;
use libp2p::{core, identity, noise, PeerId};
use libp2p_quic::tokio::Transport as QuicTransport;
use libp2p_quic::Config as QuicConfig;
use parking_lot::Mutex;
use std::io;
use std::pin::Pin;
Expand All @@ -29,28 +28,21 @@ pub(super) fn build_transport(
timeout: Duration,
yamux_config: YamuxConfig,
) -> Result<Boxed<(PeerId, StreamMuxerBox)>, CreationError> {
let wrapped_tcp_ws = {
let wrapped_tcp = {
let tcp_config = GenTcpConfig::default().nodelay(true);
let wrapped_tcp = CustomTransportWrapper::new(
TokioTcpTransport::new(tcp_config.clone()),
allow_non_global_addresses_in_dht,
temporary_bans.clone(),
);

let wrapped_ws = WsConfig::new(CustomTransportWrapper::new(
TokioTcpTransport::new(tcp_config),
CustomTransportWrapper::new(
TokioTcpTransport::new(tcp_config.clone()),
allow_non_global_addresses_in_dht,
temporary_bans.clone(),
));

wrapped_tcp.or_transport(wrapped_ws)
)
};

let tcp_ws_upgraded = {
let tcp_upgraded = {
let noise =
noise::Config::new(keypair).expect("Signing libp2p-noise static DH keypair failed.");

wrapped_tcp_ws
wrapped_tcp
.upgrade(core::upgrade::Version::V1Lazy)
.authenticate(noise)
.multiplex(yamux_config)
Expand All @@ -64,16 +56,16 @@ pub(super) fn build_transport(
let wrapped_quic =
CustomTransportWrapper::new(quic, allow_non_global_addresses_in_dht, temporary_bans);

let tcp_ws_quic = tcp_ws_upgraded
.or_transport(wrapped_quic)
let quic_tcp = wrapped_quic
.or_transport(tcp_upgraded)
.map(|either, _| match either {
Either::Left((peer_id, muxer)) => (peer_id, muxer),
Either::Right((peer_id, muxer)) => (peer_id, muxer),
});

let dns_wrapped_upgraded_tcp_ws_quic = TokioDnsConfig::system(tcp_ws_quic)?;
let dns_wrapped_upgraded_quic_tcp = TokioDnsConfig::system(quic_tcp)?;

Ok(dns_wrapped_upgraded_tcp_ws_quic.boxed())
Ok(dns_wrapped_upgraded_quic_tcp.boxed())
}

#[derive(Debug, Clone)]
Expand Down

0 comments on commit d64a311

Please sign in to comment.