chore: prioritize http3-quinn over http3-s2n when both features are enabled (avoid compile error)

This commit is contained in:
Jun Kurihara 2023-12-09 00:17:59 +09:00
commit f7142828ac
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
6 changed files with 14 additions and 17 deletions

View file

@ -15,9 +15,6 @@ use crate::{
use hot_reload::{ReloaderReceiver, ReloaderService}; use hot_reload::{ReloaderReceiver, ReloaderService};
use rpxy_lib::entrypoint; use rpxy_lib::entrypoint;
#[cfg(all(feature = "http3-quinn", feature = "http3-s2n"))]
compile_error!("feature \"http3-quinn\" and feature \"http3-s2n\" cannot be enabled at the same time");
fn main() { fn main() {
init_logger(); init_logger();

View file

@ -22,7 +22,7 @@ pub struct ServerCrypto {
// For Quic/HTTP3, only servers with no client authentication // For Quic/HTTP3, only servers with no client authentication
#[cfg(feature = "http3-quinn")] #[cfg(feature = "http3-quinn")]
pub inner_global_no_client_auth: Arc<ServerConfig>, pub inner_global_no_client_auth: Arc<ServerConfig>,
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
pub inner_global_no_client_auth: s2n_quic_rustls::Server, pub inner_global_no_client_auth: s2n_quic_rustls::Server,
// For TLS over TCP/HTTP2 and 1.1, map of SNI to server_crypto for all given servers // For TLS over TCP/HTTP2 and 1.1, map of SNI to server_crypto for all given servers
pub inner_local_map: Arc<SniServerCryptoMap>, pub inner_local_map: Arc<SniServerCryptoMap>,
@ -74,7 +74,7 @@ impl TryInto<Arc<ServerCrypto>> for &ServerCryptoBase {
Ok(Arc::new(ServerCrypto { Ok(Arc::new(ServerCrypto {
#[cfg(feature = "http3-quinn")] #[cfg(feature = "http3-quinn")]
inner_global_no_client_auth: Arc::new(server_crypto_global), inner_global_no_client_auth: Arc::new(server_crypto_global),
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
inner_global_no_client_auth: server_crypto_global, inner_global_no_client_auth: server_crypto_global,
inner_local_map: Arc::new(server_crypto_local_map), inner_local_map: Arc::new(server_crypto_local_map),
})) }))
@ -200,7 +200,7 @@ impl ServerCryptoBase {
Ok(server_crypto_global) Ok(server_crypto_global)
} }
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
fn build_server_crypto_global(&self) -> Result<s2n_quic_rustls::Server, ReloaderError<ServerCryptoBase>> { fn build_server_crypto_global(&self) -> Result<s2n_quic_rustls::Server, ReloaderError<ServerCryptoBase>> {
let mut resolver_global = s2n_quic_rustls::rustls::server::ResolvesServerCertUsingSni::new(); let mut resolver_global = s2n_quic_rustls::rustls::server::ResolvesServerCertUsingSni::new();
@ -241,7 +241,7 @@ impl ServerCryptoBase {
} }
} }
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
/// This is workaround for the version difference between rustls and s2n-quic-rustls /// This is workaround for the version difference between rustls and s2n-quic-rustls
fn parse_server_certs_and_keys_s2n( fn parse_server_certs_and_keys_s2n(
certs_and_keys: &CertsAndKeys, certs_and_keys: &CertsAndKeys,

View file

@ -44,13 +44,13 @@ pub enum RpxyError {
#[error("Quinn connection error: {0}")] #[error("Quinn connection error: {0}")]
QuinnConnectionFailed(#[from] quinn::ConnectionError), QuinnConnectionFailed(#[from] quinn::ConnectionError),
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
#[error("s2n-quic validation error: {0}")] #[error("s2n-quic validation error: {0}")]
S2nQuicValidationError(#[from] s2n_quic_core::transport::parameters::ValidationError), S2nQuicValidationError(#[from] s2n_quic_core::transport::parameters::ValidationError),
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
#[error("s2n-quic connection error: {0}")] #[error("s2n-quic connection error: {0}")]
S2nQuicConnectionError(#[from] s2n_quic_core::connection::Error), S2nQuicConnectionError(#[from] s2n_quic_core::connection::Error),
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
#[error("s2n-quic start error: {0}")] #[error("s2n-quic start error: {0}")]
S2nQuicStartError(#[from] s2n_quic::provider::StartError), S2nQuicStartError(#[from] s2n_quic::provider::StartError),

View file

@ -27,9 +27,6 @@ pub mod reexports {
pub use rustls::{Certificate, PrivateKey}; pub use rustls::{Certificate, PrivateKey};
} }
#[cfg(all(feature = "http3-quinn", feature = "http3-s2n"))]
compile_error!("feature \"http3-quinn\" and feature \"http3-s2n\" cannot be enabled at the same time");
/// Entrypoint that creates and spawns tasks of reverse proxy services /// Entrypoint that creates and spawns tasks of reverse proxy services
pub async fn entrypoint<T>( pub async fn entrypoint<T>(
proxy_config: &ProxyConfig, proxy_config: &ProxyConfig,
@ -40,6 +37,9 @@ pub async fn entrypoint<T>(
where where
T: CryptoSource + Clone + Send + Sync + 'static, T: CryptoSource + Clone + Send + Sync + 'static,
{ {
#[cfg(all(feature = "http3-quinn", feature = "http3-s2n"))]
warn!("Both \"http3-quinn\" and \"http3-s2n\" features are enabled. \"http3-quinn\" will be used");
// For initial message logging // For initial message logging
if proxy_config.listen_sockets.iter().any(|addr| addr.is_ipv6()) { if proxy_config.listen_sockets.iter().any(|addr| addr.is_ipv6()) {
info!("Listen both IPv4 and IPv6") info!("Listen both IPv4 and IPv6")

View file

@ -2,7 +2,7 @@ mod proxy_h3;
mod proxy_main; mod proxy_main;
#[cfg(feature = "http3-quinn")] #[cfg(feature = "http3-quinn")]
mod proxy_quic_quinn; mod proxy_quic_quinn;
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
mod proxy_quic_s2n; mod proxy_quic_s2n;
mod socket; mod socket;

View file

@ -15,7 +15,7 @@ use tokio::time::timeout;
#[cfg(feature = "http3-quinn")] #[cfg(feature = "http3-quinn")]
use h3::{quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestStream}; use h3::{quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestStream};
#[cfg(feature = "http3-s2n")] #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))]
use s2n_quic_h3::h3::{self, quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestStream}; use s2n_quic_h3::h3::{self, quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestStream};
impl<U, T> Proxy<U, T> impl<U, T> Proxy<U, T>