This commit is contained in:
Jun Kurihara 2022-07-22 22:28:26 +09:00
commit 45895ca7bc
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
12 changed files with 36 additions and 151 deletions

View file

@ -11,9 +11,7 @@ where
T: Connect + Clone + Sync + Send + 'static,
{
pub(super) fn connection_serve_h3(&self, conn: quinn::Connecting, tls_server_name: &[u8]) {
let fut = self
.clone()
.handle_connection_h3(conn, tls_server_name.to_vec());
let fut = self.clone().handle_connection_h3(conn, tls_server_name.to_vec());
self.globals.runtime_handle.spawn(async move {
// Timeout is based on underlying quic
if let Err(e) = fut.await {
@ -22,18 +20,12 @@ where
});
}
async fn handle_connection_h3(
self,
conn: quinn::Connecting,
tls_server_name: ServerNameLC,
) -> Result<()> {
async fn handle_connection_h3(self, conn: quinn::Connecting, tls_server_name: ServerNameLC) -> Result<()> {
let client_addr = conn.remote_address();
match conn.await {
Ok(new_conn) => {
let mut h3_conn =
h3::server::Connection::<_, bytes::Bytes>::new(h3_quinn::Connection::new(new_conn))
.await?;
let mut h3_conn = h3::server::Connection::<_, bytes::Bytes>::new(h3_quinn::Connection::new(new_conn)).await?;
info!(
"QUIC/HTTP3 connection established from {:?} {:?}",
client_addr, tls_server_name
@ -113,9 +105,7 @@ where
return Err(anyhow!("Exceeds max request body size for HTTP/3"));
}
// create stream body to save memory, shallow copy (increment of ref-count) to Bytes using copy_to_bytes
sender
.send_data(body.copy_to_bytes(body.remaining()))
.await?;
sender.send_data(body.copy_to_bytes(body.remaining())).await?;
}
// trailers: use inner for work around. (directly get trailer)

View file

@ -1,7 +1,5 @@
// use super::proxy_handler::handle_request;
use crate::{
backend::ServerNameLC, error::*, globals::Globals, log::*, msg_handler::HttpMessageHandler,
};
use crate::{backend::ServerNameLC, error::*, globals::Globals, log::*, msg_handler::HttpMessageHandler};
use hyper::{client::connect::Connect, server::conn::Http, service::service_fn, Body, Request};
use std::{net::SocketAddr, sync::Arc};
use tokio::{
@ -95,9 +93,7 @@ where
let tcp_listener = TcpListener::bind(&self.listening_on).await?;
info!("Start TCP proxy serving with HTTP request for configured host names");
while let Ok((stream, _client_addr)) = tcp_listener.accept().await {
self
.clone()
.client_serve(stream, server.clone(), _client_addr, None);
self.clone().client_serve(stream, server.clone(), _client_addr, None);
}
Ok(()) as Result<()>
};

View file

@ -20,12 +20,7 @@ where
async fn cert_service(&self, server_crypto_tx: watch::Sender<Option<Arc<ServerConfig>>>) {
info!("Start cert watch service");
loop {
if let Ok(server_crypto) = self
.globals
.backends
.generate_server_crypto_with_cert_resolver()
.await
{
if let Ok(server_crypto) = self.globals.backends.generate_server_crypto_with_cert_resolver().await {
if let Err(_e) = server_crypto_tx.send(Some(Arc::new(server_crypto))) {
error!("Failed to populate server crypto");
break;
@ -82,10 +77,7 @@ where
}
#[cfg(feature = "h3")]
async fn listener_service_h3(
&self,
mut server_crypto_rx: watch::Receiver<Option<Arc<ServerConfig>>>,
) -> Result<()> {
async fn listener_service_h3(&self, mut server_crypto_rx: watch::Receiver<Option<Arc<ServerConfig>>>) -> Result<()> {
let mut transport_config_quic = quinn::TransportConfig::default();
transport_config_quic
.max_concurrent_bidi_streams(self.globals.h3_max_concurrent_bidistream)