tests for http3

This commit is contained in:
Jun Kurihara 2022-07-04 23:15:25 +09:00
commit 9d4cf08fba
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
11 changed files with 317 additions and 34 deletions

View file

@ -1,5 +1,7 @@
use super::proxy_main::{LocalExecutor, Proxy};
use crate::{constants::CERTS_WATCH_DELAY_SECS, error::*, log::*};
#[cfg(feature = "h3")]
use futures::StreamExt;
use futures::{future::FutureExt, join, select};
use hyper::{client::connect::Connect, server::conn::Http};
use std::{sync::Arc, time::Duration};
@ -9,11 +11,7 @@ impl<T> Proxy<T>
where
T: Connect + Clone + Sync + Send + 'static,
{
pub async fn start_with_tls(
self,
listener: TcpListener,
server: Http<LocalExecutor>,
) -> Result<()> {
pub async fn start_with_tls(self, server: Http<LocalExecutor>) -> Result<()> {
let cert_service = async {
info!("Start cert watch service for {}", self.listening_on);
loop {
@ -28,10 +26,17 @@ where
}
};
// TCP Listener Service, i.e., http/2 and http/1.1
let listener_service = async {
let tcp_listener = TcpListener::bind(&self.listening_on).await?;
info!(
"Start TCP proxy serving with HTTPS request for configured host names: {:?}",
tcp_listener.local_addr()?
);
loop {
select! {
tcp_cnx = listener.accept().fuse() => {
tcp_cnx = tcp_listener.accept().fuse() => {
if tcp_cnx.is_err() {
continue;
}
@ -81,6 +86,44 @@ where
Ok(()) as Result<()>
};
join!(listener_service, cert_service).0
/////////////////////// TODO:!!!!!
#[cfg(feature = "h3")]
let listener_service_h3 = async {
// TODO: とりあえずデフォルトのserver_cryptoが必要になりそう
let backend_serve = self.backends.apps.get("localhost").unwrap();
let server_crypto = backend_serve.get_tls_server_config().unwrap();
let server_config_h3 = quinn::ServerConfig::with_crypto(Arc::new(server_crypto));
let (endpoint, mut incoming) =
quinn::Endpoint::server(server_config_h3, self.listening_on).unwrap();
debug!("HTTP/3 UDP listening on {}", endpoint.local_addr().unwrap());
while let Some(mut conn) = incoming.next().await {
debug!("HTTP/3 connection incoming");
let hsd = conn.handshake_data().await;
let hsd_downcast = hsd
.unwrap()
.downcast::<quinn::crypto::rustls::HandshakeData>()
.unwrap();
debug!("HTTP/3 SNI: {:?}", hsd_downcast.server_name);
// TODO: ServerConfig::set_server_configでSNIに応じて再セット
let fut = self.clone().client_serve_h3(conn);
self.globals.runtime_handle.spawn(async {
if let Err(e) = fut.await {
error!("connection failed: {reason}", reason = e.to_string())
}
});
}
};
#[cfg(not(feature = "h3"))]
{
join!(listener_service, cert_service).0
}
#[cfg(feature = "h3")]
{
join!(listener_service, cert_service, listener_service_h3).0
}
}
}