diff --git a/rpxy-bin/src/main.rs b/rpxy-bin/src/main.rs index f04a6f1..9aeb971 100644 --- a/rpxy-bin/src/main.rs +++ b/rpxy-bin/src/main.rs @@ -15,9 +15,6 @@ use crate::{ use hot_reload::{ReloaderReceiver, ReloaderService}; 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() { init_logger(); @@ -29,8 +26,8 @@ fn main() { runtime.block_on(async { // Initially load options let Ok(parsed_opts) = parse_opts() else { - error!("Invalid toml file"); - std::process::exit(1); + error!("Invalid toml file"); + std::process::exit(1); }; if !parsed_opts.watch { diff --git a/rpxy-lib/src/crypto/service.rs b/rpxy-lib/src/crypto/service.rs index 0736b0e..8eda27a 100644 --- a/rpxy-lib/src/crypto/service.rs +++ b/rpxy-lib/src/crypto/service.rs @@ -22,7 +22,7 @@ pub struct ServerCrypto { // For Quic/HTTP3, only servers with no client authentication #[cfg(feature = "http3-quinn")] pub inner_global_no_client_auth: Arc, - #[cfg(feature = "http3-s2n")] + #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))] 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 pub inner_local_map: Arc, @@ -74,7 +74,7 @@ impl TryInto> for &ServerCryptoBase { Ok(Arc::new(ServerCrypto { #[cfg(feature = "http3-quinn")] 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_local_map: Arc::new(server_crypto_local_map), })) @@ -200,7 +200,7 @@ impl ServerCryptoBase { Ok(server_crypto_global) } - #[cfg(feature = "http3-s2n")] + #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))] fn build_server_crypto_global(&self) -> Result> { 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 fn parse_server_certs_and_keys_s2n( certs_and_keys: &CertsAndKeys, diff --git a/rpxy-lib/src/error.rs b/rpxy-lib/src/error.rs index a19ca2c..843845d 100644 --- a/rpxy-lib/src/error.rs +++ b/rpxy-lib/src/error.rs @@ -44,13 +44,13 @@ pub enum RpxyError { #[error("Quinn connection error: {0}")] QuinnConnectionFailed(#[from] quinn::ConnectionError), - #[cfg(feature = "http3-s2n")] + #[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))] #[error("s2n-quic validation error: {0}")] 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}")] 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}")] S2nQuicStartError(#[from] s2n_quic::provider::StartError), diff --git a/rpxy-lib/src/lib.rs b/rpxy-lib/src/lib.rs index da2cabc..4f66634 100644 --- a/rpxy-lib/src/lib.rs +++ b/rpxy-lib/src/lib.rs @@ -27,9 +27,6 @@ pub mod reexports { 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 pub async fn entrypoint( proxy_config: &ProxyConfig, @@ -40,6 +37,9 @@ pub async fn entrypoint( where 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 if proxy_config.listen_sockets.iter().any(|addr| addr.is_ipv6()) { info!("Listen both IPv4 and IPv6") diff --git a/rpxy-lib/src/proxy/mod.rs b/rpxy-lib/src/proxy/mod.rs index e4ac6f7..389df43 100644 --- a/rpxy-lib/src/proxy/mod.rs +++ b/rpxy-lib/src/proxy/mod.rs @@ -2,7 +2,7 @@ mod proxy_h3; mod proxy_main; #[cfg(feature = "http3-quinn")] mod proxy_quic_quinn; -#[cfg(feature = "http3-s2n")] +#[cfg(all(feature = "http3-s2n", not(feature = "http3-quinn")))] mod proxy_quic_s2n; mod socket; diff --git a/rpxy-lib/src/proxy/proxy_h3.rs b/rpxy-lib/src/proxy/proxy_h3.rs index 813eaa8..8abb710 100644 --- a/rpxy-lib/src/proxy/proxy_h3.rs +++ b/rpxy-lib/src/proxy/proxy_h3.rs @@ -15,7 +15,7 @@ use tokio::time::timeout; #[cfg(feature = "http3-quinn")] 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}; impl Proxy