proto: upgrade to Quinn 0.9

This commit is contained in:
Dirkjan Ochtman 2022-11-04 23:11:47 +01:00 committed by Benjamin Fry
parent 11d5398634
commit da6bdca577
4 changed files with 107 additions and 75 deletions

130
Cargo.lock generated
View File

@ -273,12 +273,6 @@ version = "3.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "bytes"
version = "1.2.1"
@ -591,15 +585,6 @@ dependencies = [
"slab",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "getrandom"
version = "0.2.7"
@ -871,7 +856,7 @@ dependencies = [
"libc",
"log",
"wasi",
"windows-sys",
"windows-sys 0.36.1",
]
[[package]]
@ -1028,7 +1013,7 @@ dependencies = [
"libc",
"redox_syscall",
"smallvec",
"windows-sys",
"windows-sys 0.36.1",
]
[[package]]
@ -1116,16 +1101,15 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quinn"
version = "0.8.5"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b435e71d9bfa0d8889927231970c51fb89c58fa63bffcab117c9c7a41e5ef8f"
checksum = "6a5f2962a2f18666b1b690cbc33f528b4fcdfc6e51a84b47c7fb19b6a9fab753"
dependencies = [
"bytes",
"futures-channel",
"futures-util",
"fxhash",
"pin-project-lite",
"quinn-proto",
"quinn-udp",
"rustc-hash",
"rustls",
"thiserror",
"tokio",
@ -1135,17 +1119,16 @@ dependencies = [
[[package]]
name = "quinn-proto"
version = "0.8.4"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fce546b9688f767a57530652488420d419a8b1f44a478b451c3d1ab6d992a55"
checksum = "e1268269057c3f78dab82fe8d8b7834e656710cff55b97dbc890a67dcc113b2e"
dependencies = [
"bytes",
"fxhash",
"rand",
"ring",
"rustc-hash",
"rustls",
"rustls-native-certs",
"rustls-pemfile 0.2.1",
"slab",
"thiserror",
"tinyvec",
@ -1155,16 +1138,15 @@ dependencies = [
[[package]]
name = "quinn-udp"
version = "0.1.3"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f832d8958db3e84d2ec93b5eb2272b45aa23cf7f8fe6e79f578896f4e6c231b"
checksum = "47085d44ed35b0f4499a88e47d689a411d483845966124e187a8f3cbb39eeebb"
dependencies = [
"futures-util",
"libc",
"quinn-proto",
"socket2",
"tokio",
"tracing",
"windows-sys 0.42.0",
]
[[package]]
@ -1306,6 +1288,12 @@ version = "0.1.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342"
[[package]]
name = "rustc-hash"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustls"
version = "0.20.6"
@ -1325,20 +1313,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0167bac7a9f490495f3c33013e7722b53cb087ecbe082fb0c6387c96f634ea50"
dependencies = [
"openssl-probe",
"rustls-pemfile 1.0.1",
"rustls-pemfile",
"schannel",
"security-framework",
]
[[package]]
name = "rustls-pemfile"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5eebeaeb360c87bfb72e84abdb3447159c0eaececf1bef2aecd65a8be949d1c9"
dependencies = [
"base64",
]
[[package]]
name = "rustls-pemfile"
version = "1.0.1"
@ -1355,7 +1334,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d6731146462ea25d9244b2ed5fd1d716d25c52e4d54aa4fb0f3c4e9854dbe2"
dependencies = [
"lazy_static",
"windows-sys",
"windows-sys 0.36.1",
]
[[package]]
@ -1842,7 +1821,7 @@ dependencies = [
"rand",
"ring",
"rustls",
"rustls-pemfile 1.0.1",
"rustls-pemfile",
"serde",
"smallvec",
"socket2",
@ -2193,43 +2172,100 @@ version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
dependencies = [
"windows_aarch64_msvc",
"windows_i686_gnu",
"windows_i686_msvc",
"windows_x86_64_gnu",
"windows_x86_64_msvc",
"windows_aarch64_msvc 0.36.1",
"windows_i686_gnu 0.36.1",
"windows_i686_msvc 0.36.1",
"windows_x86_64_gnu 0.36.1",
"windows_x86_64_msvc 0.36.1",
]
[[package]]
name = "windows-sys"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
dependencies = [
"windows_aarch64_gnullvm",
"windows_aarch64_msvc 0.42.0",
"windows_i686_gnu 0.42.0",
"windows_i686_msvc 0.42.0",
"windows_x86_64_gnu 0.42.0",
"windows_x86_64_gnullvm",
"windows_x86_64_msvc 0.42.0",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
[[package]]
name = "windows_aarch64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
[[package]]
name = "windows_aarch64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
[[package]]
name = "windows_i686_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
[[package]]
name = "windows_i686_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
[[package]]
name = "windows_i686_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
[[package]]
name = "windows_i686_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
[[package]]
name = "windows_x86_64_gnu"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
[[package]]
name = "windows_x86_64_gnu"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
[[package]]
name = "windows_x86_64_msvc"
version = "0.36.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
[[package]]
name = "windows_x86_64_msvc"
version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]]
name = "winreg"
version = "0.7.0"

View File

@ -88,7 +88,7 @@ js-sys = { version = "0.3.44", optional = true }
lazy_static = "1.2.0"
native-tls = { version = "0.2", optional = true }
openssl = { version = "0.10", features = ["v102", "v110"], optional = true }
quinn = { version = "0.8.2", optional = true }
quinn = { version = "0.9", optional = true }
rand = "0.8"
ring = { version = "0.16", optional = true, features = ["std"] }
rustls = { version = "0.20.0", optional = true }

View File

@ -15,7 +15,7 @@ use std::{
};
use futures_util::{future::FutureExt, stream::Stream};
use quinn::{ClientConfig, Connection, Endpoint, NewConnection, OpenBi, TransportConfig, VarInt};
use quinn::{ClientConfig, Connection, Endpoint, TransportConfig, VarInt};
use rustls::{version::TLS13, ClientConfig as TlsClientConfig};
use crate::{
@ -52,8 +52,11 @@ impl QuicClientStream {
QuicClientStreamBuilder::default()
}
async fn inner_send(stream: OpenBi, message: DnsRequest) -> Result<DnsResponse, ProtoError> {
let (send_stream, recv_stream) = stream.await?;
async fn inner_send(
connection: Connection,
message: DnsRequest,
) -> Result<DnsResponse, ProtoError> {
let (send_stream, recv_stream) = connection.open_bi().await?;
// RFC: The mapping specified here requires that the client selects a separate
// QUIC stream for each query. The server then uses the same stream to provide all the response messages for that query.
@ -115,9 +118,7 @@ impl DnsRequestSender for QuicClientStream {
panic!("can not send messages after stream is shutdown")
}
let connection = self.quic_connection.open_bi();
Box::pin(Self::inner_send(connection, message)).into()
Box::pin(Self::inner_send(self.quic_connection.clone(), message)).into()
}
fn shutdown(&mut self) {
@ -189,7 +190,7 @@ impl QuicClientStreamBuilder {
let socket = socket.into_std()?;
let endpoint_config = quic_config::endpoint();
let (mut endpoint, _incoming) = Endpoint::new(endpoint_config, None, socket)?;
let mut endpoint = Endpoint::new(endpoint_config, None, socket, quinn::TokioRuntime)?;
// ensure the ALPN protocol is set correctly
let mut crypto_config = self.crypto_config;
@ -199,14 +200,14 @@ impl QuicClientStreamBuilder {
let early_data_enabled = crypto_config.enable_early_data;
let mut client_config = ClientConfig::new(Arc::new(crypto_config));
client_config.transport = self.transport_config;
client_config.transport_config(self.transport_config.clone());
endpoint.set_default_client_config(client_config);
let connecting = endpoint.connect(name_server, &dns_name)?;
// TODO: for Client/Dynamic update, don't use RTT, for queries, do use it.
let connection = if early_data_enabled {
let quic_connection = if early_data_enabled {
match connecting.into_0rtt() {
Ok((new_connection, _)) => new_connection,
Err(connecting) => connecting.await?,
@ -214,10 +215,6 @@ impl QuicClientStreamBuilder {
} else {
connecting.await?
};
let NewConnection {
connection: quic_connection,
..
} = connection;
Ok(QuicClientStream {
quic_connection,

View File

@ -7,8 +7,7 @@
use std::{io, net::SocketAddr, sync::Arc};
use futures_util::StreamExt;
use quinn::{Endpoint, Incoming, IncomingBiStreams, ServerConfig};
use quinn::{Connection, Endpoint, ServerConfig};
use rustls::{server::ServerConfig as TlsServerConfig, version::TLS13, Certificate, PrivateKey};
use crate::{error::ProtoError, udp::UdpSocket};
@ -21,7 +20,6 @@ use super::{
/// A DNS-over-QUIC Server, see QuicClientStream for the client counterpart
pub struct QuicServer {
endpoint: Endpoint,
incoming: Incoming,
}
impl QuicServer {
@ -58,9 +56,14 @@ impl QuicServer {
let socket = socket.into_std()?;
let endpoint_config = quic_config::endpoint();
let (endpoint, incoming) = Endpoint::new(endpoint_config, Some(server_config), socket)?;
let endpoint = Endpoint::new(
endpoint_config,
Some(server_config),
socket,
quinn::TokioRuntime,
)?;
Ok(Self { endpoint, incoming })
Ok(Self { endpoint })
}
/// Get the next incoming stream
@ -69,18 +72,14 @@ impl QuicServer {
///
/// A remote connection that could have many potential bi-directional streams and the remote socket address
pub async fn next(&mut self) -> Result<Option<(QuicStreams, SocketAddr)>, ProtoError> {
let connecting = match self.incoming.next().await {
let connecting = match self.endpoint.accept().await {
Some(conn) => conn,
None => return Ok(None),
};
let remote_addr = connecting.remote_address();
let conn = connecting.await?;
let streams = QuicStreams {
incoming_bi_streams: conn.bi_streams,
};
Ok(Some((streams, remote_addr)))
let connection = connecting.await?;
Ok(Some((QuicStreams { connection }, remote_addr)))
}
/// Returns the address this server is listening on
@ -94,13 +93,13 @@ impl QuicServer {
/// A stream of bi-directional QUIC streams
pub struct QuicStreams {
incoming_bi_streams: IncomingBiStreams,
connection: Connection,
}
impl QuicStreams {
/// Get the next bi directional stream from the client
pub async fn next(&mut self) -> Option<Result<QuicStream, ProtoError>> {
match self.incoming_bi_streams.next().await? {
match self.connection.accept_bi().await {
Ok((send_stream, receive_stream)) => {
Some(Ok(QuicStream::new(send_stream, receive_stream)))
}