diff --git a/Cargo.toml b/Cargo.toml index 9fb44ecc..390bf101 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,6 +96,8 @@ mime = "0.3" percent-encoding = "2.1" http = "0.2.9" h2 = "0.3.19" +h3-quinn = "0.0.3" +h3 = "0.0.2" # log = "0.4" slog = "2" diff --git a/g3bench/Cargo.toml b/g3bench/Cargo.toml index b75783ff..4da76e41 100644 --- a/g3bench/Cargo.toml +++ b/g3bench/Cargo.toml @@ -18,8 +18,8 @@ tokio = { workspace = true, features = ["rt", "net", "macros"] } http.workspace = true url.workspace = true h2.workspace = true -h3 = "0.0.2" -h3-quinn = "0.0.3" +h3.workspace = true +h3-quinn.workspace = true bytes.workspace = true futures-util.workspace = true tokio-openssl.workspace = true diff --git a/g3bench/src/target/h3/opts.rs b/g3bench/src/target/h3/opts.rs index 6fc1382e..ad4387c6 100644 --- a/g3bench/src/target/h3/opts.rs +++ b/g3bench/src/target/h3/opts.rs @@ -29,7 +29,7 @@ use http::{HeaderValue, Method, StatusCode}; use url::Url; use g3_types::collection::{SelectiveVec, WeightedValue}; -use g3_types::net::{HttpAuth, RustlsClientConfigBuilder, UpstreamAddr}; +use g3_types::net::{AlpnProtocol, HttpAuth, RustlsClientConfigBuilder, UpstreamAddr}; use super::{H3PreRequest, HttpRuntimeStats, ProcArgs}; use crate::target::{AppendRustlsArgs, RustlsTlsClientArgs}; @@ -68,6 +68,7 @@ impl BenchH3Args { let tls = RustlsTlsClientArgs { config: Some(RustlsClientConfigBuilder::default()), + alpn_protocol: Some(AlpnProtocol::Http3), ..Default::default() }; @@ -114,7 +115,7 @@ impl BenchH3Args { }; let mut transport = TransportConfig::default(); transport.max_concurrent_bidi_streams(VarInt::from_u32(0)); - transport.max_concurrent_uni_streams(VarInt::from_u32(0)); + // transport.max_concurrent_uni_streams(VarInt::from_u32(0)); // TODO add more transport settings let mut client_config = ClientConfig::new(tls_client.driver.clone()); client_config.transport_config(Arc::new(transport)); diff --git a/g3bench/src/target/h3/task.rs b/g3bench/src/target/h3/task.rs index 0069bd90..e966cc64 100644 --- a/g3bench/src/target/h3/task.rs +++ b/g3bench/src/target/h3/task.rs @@ -129,7 +129,7 @@ impl H3TaskContext { let mut send_stream = send_req .send_request(req) .await - .map_err(|e| anyhow!("failed to send request header: {e:?}"))?; + .map_err(|e| anyhow!("failed to send request header: {e}"))?; send_stream.finish().await?; let send_hdr_time = time_started.elapsed(); if let Some(r) = &mut self.histogram_recorder { diff --git a/g3bench/src/target/openssl.rs b/g3bench/src/target/openssl.rs index 476626ea..52e1ec7e 100644 --- a/g3bench/src/target/openssl.rs +++ b/g3bench/src/target/openssl.rs @@ -189,7 +189,7 @@ impl OpensslTlsClientArgs { let tls_client = if let Some(p) = self.alpn_protocol { tls_config .build_with_alpn_protocols(Some(vec![p])) - .context("failed to build tls client with alpn protocol {p}")? + .context(format!("failed to build tls client with alpn protocol {p}"))? } else { tls_config.build().context("failed to build tls client")? }; diff --git a/g3bench/src/target/rustls.rs b/g3bench/src/target/rustls.rs index 94a414fc..91c80fdc 100644 --- a/g3bench/src/target/rustls.rs +++ b/g3bench/src/target/rustls.rs @@ -22,7 +22,9 @@ use anyhow::{anyhow, Context}; use clap::{value_parser, Arg, ArgAction, ArgMatches, Command, ValueHint}; use rustls::{Certificate, PrivateKey}; -use g3_types::net::{RustlsCertificatePair, RustlsClientConfig, RustlsClientConfigBuilder}; +use g3_types::net::{ + AlpnProtocol, RustlsCertificatePair, RustlsClientConfig, RustlsClientConfigBuilder, +}; const TLS_ARG_CA_CERT: &str = "tls-ca-cert"; const TLS_ARG_CERT: &str = "tls-cert"; @@ -52,6 +54,7 @@ pub(crate) struct RustlsTlsClientArgs { pub(crate) tls_name: Option, pub(crate) cert_pair: RustlsCertificatePair, pub(crate) no_verify: bool, + pub(crate) alpn_protocol: Option, } impl RustlsTlsClientArgs { @@ -137,7 +140,13 @@ impl RustlsTlsClientArgs { } tls_config.check().context("invalid tls config")?; - let tls_client = tls_config.build().context("failed to build tls client")?; + let tls_client = if let Some(p) = self.alpn_protocol { + tls_config + .build_with_alpn_protocols(Some(vec![p])) + .context(format!("failed to build tls client with alpn protocol {p}"))? + } else { + tls_config.build().context("failed to build tls client")? + }; self.client = Some(tls_client); Ok(()) } diff --git a/lib/g3-dpi/src/protocol/mod.rs b/lib/g3-dpi/src/protocol/mod.rs index b9305682..306534a2 100644 --- a/lib/g3-dpi/src/protocol/mod.rs +++ b/lib/g3-dpi/src/protocol/mod.rs @@ -101,9 +101,10 @@ impl FromStr for MaybeProtocol { impl From for MaybeProtocol { fn from(p: AlpnProtocol) -> Self { match p { - AlpnProtocol::Http10 | AlpnProtocol::Http11 | AlpnProtocol::Http2 => { - MaybeProtocol::Http - } + AlpnProtocol::Http10 + | AlpnProtocol::Http11 + | AlpnProtocol::Http2 + | AlpnProtocol::Http3 => MaybeProtocol::Http, } } } @@ -117,6 +118,7 @@ pub enum Protocol { TlsTlcp, Http1, Http2, + Http3, Smtp, SshLegacy, Ssh, @@ -142,6 +144,7 @@ impl Protocol { Protocol::TlsTlcp => "tls_tlcp", Protocol::Http1 => "http_1", Protocol::Http2 => "http_2", + Protocol::Http3 => "http_3", Protocol::Smtp => "smtp", Protocol::SshLegacy => "ssh_legacy", Protocol::Ssh => "ssh", @@ -164,6 +167,7 @@ impl From for Protocol { match p { AlpnProtocol::Http10 | AlpnProtocol::Http11 => Protocol::Http1, AlpnProtocol::Http2 => Protocol::Http2, + AlpnProtocol::Http3 => Protocol::Http3, } } } diff --git a/lib/g3-types/src/net/tls/alpn.rs b/lib/g3-types/src/net/tls/alpn.rs index 74ee240b..656d07d4 100644 --- a/lib/g3-types/src/net/tls/alpn.rs +++ b/lib/g3-types/src/net/tls/alpn.rs @@ -14,19 +14,38 @@ * limitations under the License. */ +use std::fmt; + #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum AlpnProtocol { Http10, Http11, Http2, + Http3, +} + +impl fmt::Display for AlpnProtocol { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.as_str()) + } } impl AlpnProtocol { + pub fn as_str(&self) -> &str { + match self { + Self::Http10 => "http/1.0", + Self::Http11 => "http/1.1", + Self::Http2 => "h2", + Self::Http3 => "h3", + } + } + pub fn wired_identification_sequence(&self) -> &'static [u8] { match self { Self::Http10 => b"\x08http/1.0", Self::Http11 => b"\x08http/1.1", Self::Http2 => b"\x02h2", + Self::Http3 => b"\x02h3", } } @@ -45,6 +64,7 @@ impl AlpnProtocol { b"http/1.0" => Some(AlpnProtocol::Http10), b"http/1.1" => Some(AlpnProtocol::Http11), b"h2" => Some(AlpnProtocol::Http2), + b"h3" => Some(AlpnProtocol::Http3), _ => None, } }