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

feat: WebTransport on top QUIC transport #5564

Draft
wants to merge 16 commits into
base: master
Choose a base branch
from
Draft
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
73 changes: 60 additions & 13 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion libp2p/src/builder/phase/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ macro_rules! impl_quic_builder {
.transport
.or_transport(
libp2p_quic::$quic::Transport::new(constructor(
libp2p_quic::Config::new(&self.keypair),
libp2p_quic::Config::new(&self.keypair, None),
))
.map(|(peer_id, muxer), _| {
(peer_id, libp2p_core::muxing::StreamMuxerBox::new(muxer))
Expand Down
7 changes: 7 additions & 0 deletions transports/quic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ if-watch = "3.2.0"
libp2p-core = { workspace = true }
libp2p-tls = { workspace = true }
libp2p-identity = { workspace = true }
libp2p-noise = { workspace = true }
parking_lot = "0.12.3"
quinn = { version = "0.11.2", default-features = false, features = ["rustls", "futures-io"] }
rand = "0.8.5"
Expand All @@ -26,6 +27,12 @@ tokio = { workspace = true, default-features = false, features = ["net", "rt", "
tracing = { workspace = true }
socket2 = "0.5.7"
ring = { workspace = true }
sha2 = "0.10.8"
time = "0.3"
http = "1.1.0"
h3 = { git = "https://github.com/hyperium/h3" }
h3-quinn = { git = "https://github.com/hyperium/h3" }
h3-webtransport = { git = "https://github.com/hyperium/h3" }

[features]
tokio = ["dep:tokio", "if-watch/tokio", "quinn/runtime-tokio"]
Expand Down
37 changes: 32 additions & 5 deletions transports/quic/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

use std::{sync::Arc, time::Duration};

use quinn::{
crypto::rustls::{QuicClientConfig, QuicServerConfig},
MtuDiscoveryConfig, VarInt,
};
use std::{sync::Arc, time::Duration};

use libp2p_core::multihash::Multihash;

use crate::webtransport;
use crate::webtransport::Certificate;

/// Config for the transport.
#[derive(Clone)]
Expand Down Expand Up @@ -69,18 +75,33 @@ pub struct Config {

/// Parameters governing MTU discovery. See [`MtuDiscoveryConfig`] for details.
mtu_discovery_config: Option<MtuDiscoveryConfig>,

webtransport_certhashes: Vec<Multihash<64>>,
}

impl Config {
/// Creates a new configuration object with default values.
pub fn new(keypair: &libp2p_identity::Keypair) -> Self {
pub fn new(keypair: &libp2p_identity::Keypair, webtransport_cert: Option<Certificate>) -> Self {
let client_tls_config = Arc::new(
QuicClientConfig::try_from(libp2p_tls::make_client_config(keypair, None).unwrap())
.unwrap(),
);
let server_tls_config = Arc::new(
QuicServerConfig::try_from(libp2p_tls::make_server_config(keypair).unwrap()).unwrap(),
);
let server_config = match &webtransport_cert {
None => libp2p_tls::make_server_config(keypair).unwrap(),
Some(c) => libp2p_tls::make_webtransport_server_config(
&c.cert,
&c.private_key,
webtransport::alpn_protocols(),
)
.unwrap(),
};
let server_tls_config = Arc::new(QuicServerConfig::try_from(server_config).unwrap());

let webtransport_certhashes: Vec<Multihash<64>> = match webtransport_cert {
Some(c) => vec![c.cert_hash()],
None => vec![],
};

Self {
client_tls_config,
server_tls_config,
Expand All @@ -95,6 +116,7 @@ impl Config {
max_stream_data: 10_000_000,
keypair: keypair.clone(),
mtu_discovery_config: Some(Default::default()),
webtransport_certhashes,
}
}

Expand All @@ -119,6 +141,8 @@ pub(crate) struct QuinnConfig {
pub(crate) client_config: quinn::ClientConfig,
pub(crate) server_config: quinn::ServerConfig,
pub(crate) endpoint_config: quinn::EndpointConfig,
pub(crate) keypair: libp2p_identity::Keypair,
pub(crate) webtransport_certhashes: Vec<Multihash<64>>,
}

impl From<Config> for QuinnConfig {
Expand All @@ -135,6 +159,7 @@ impl From<Config> for QuinnConfig {
handshake_timeout: _,
keypair,
mtu_discovery_config,
webtransport_certhashes,
} = config;
let mut transport = quinn::TransportConfig::default();
// Disable uni-directional streams.
Expand Down Expand Up @@ -176,6 +201,8 @@ impl From<Config> for QuinnConfig {
client_config,
server_config,
endpoint_config,
keypair,
webtransport_certhashes,
}
}
}
Loading
Loading