Skip to content

Commit 44f7aa1

Browse files
committed
feat: Implement Quic-v1 transport
Notes: - This is only compatible with v1 so likelihood of connecting to go-libp2p and go-ipfs/kubo peers via quic will unlikely to work until draft-29 is supported in rust-libp2p (see libp2p/rust-libp2p#3133) - DCuTR will not work with quic-v1 at this time so unless port mapping/UPNP is used (coming later), we wont be able to utilize quic-v1 with hole punching, but should work fine with relay (see libp2p/rust-libp2p#2883) Closes #10
1 parent ec14bb4 commit 44f7aa1

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/p2p/transport.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ use libp2p::dns::TokioDnsConfig;
77
use libp2p::identity;
88
use libp2p::mplex::MplexConfig;
99
use libp2p::noise::{self, NoiseConfig};
10+
use libp2p::quic::tokio::Transport as TokioQuicTransport;
11+
use libp2p::quic::Config as QuicConfig;
1012
use libp2p::relay::v2::client::transport::ClientTransport;
11-
use libp2p::tcp::{Config as GenTcpConfig, tokio::Transport as TokioTcpTransport};
13+
use libp2p::swarm::derive_prelude::EitherOutput;
14+
use libp2p::tcp::{tokio::Transport as TokioTcpTransport, Config as GenTcpConfig};
1215
use libp2p::yamux::YamuxConfig;
1316
use libp2p::{PeerId, Transport};
1417
use std::io::{self, Error, ErrorKind};
@@ -65,6 +68,10 @@ pub fn build_transport(
6568
.nodelay(no_delay)
6669
.port_reuse(port_reuse);
6770

71+
let mut quic_config = QuicConfig::new(&keypair);
72+
quic_config.handshake_timeout = Duration::from_secs(1);
73+
let quic_transport = TokioQuicTransport::new(quic_config);
74+
6875
let tcp_transport = TokioTcpTransport::new(tcp_config.clone());
6976
let ws_transport = libp2p::websocket::WsConfig::new(TokioTcpTransport::new(tcp_config));
7077

@@ -100,5 +107,12 @@ pub fn build_transport(
100107
.boxed(),
101108
};
102109

110+
let transport = OrTransport::new(quic_transport, transport)
111+
.map(|either_output, _| match either_output {
112+
EitherOutput::First((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
113+
EitherOutput::Second((peer_id, muxer)) => (peer_id, StreamMuxerBox::new(muxer)),
114+
})
115+
.boxed();
116+
103117
Ok(transport)
104118
}

0 commit comments

Comments
 (0)