implement native-tls client

This commit is contained in:
Jun Kurihara 2023-11-29 17:24:07 +09:00
commit 48a84a77cb
No known key found for this signature in database
GPG key ID: 48ADFD173ED22B03
12 changed files with 90 additions and 69 deletions

View file

@ -9,6 +9,7 @@ use crate::{
use bytes::{Buf, Bytes};
use http::{Request, Response};
use http_body_util::BodyExt;
use hyper_util::client::legacy::connect::Connect;
use std::{net::SocketAddr, time::Duration};
use tokio::time::timeout;
@ -17,12 +18,9 @@ use h3::{quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestSt
#[cfg(feature = "http3-s2n")]
use s2n_quic_h3::h3::{self, quic::BidiStream, quic::Connection as ConnectionQuic, server::RequestStream};
// use futures::Stream;
// use hyper_util::client::legacy::connect::Connect;
impl<U> Proxy<U>
impl<U, T> Proxy<U, T>
where
// T: Connect + Clone + Sync + Send + 'static,
T: Connect + Clone + Sync + Send + 'static,
U: CryptoSource + Clone + Sync + Send + 'static,
{
pub(super) async fn h3_serve_connection<C>(

View file

@ -19,23 +19,22 @@ use hyper::{
rt::{Read, Write},
service::service_fn,
};
use hyper_util::{rt::TokioIo, server::conn::auto::Builder as ConnectionBuilder};
use hyper_util::{client::legacy::connect::Connect, rt::TokioIo, server::conn::auto::Builder as ConnectionBuilder};
use std::{net::SocketAddr, sync::Arc, time::Duration};
use tokio::time::timeout;
/// Wrapper function to handle request for HTTP/1.1 and HTTP/2
/// HTTP/3 is handled in proxy_h3.rs which directly calls the message handler
async fn serve_request<U>(
async fn serve_request<U, T>(
req: Request<Incoming>,
// handler: Arc<HttpMessageHandler<T, U>>,
handler: Arc<HttpMessageHandler<U>>,
handler: Arc<HttpMessageHandler<U, T>>,
client_addr: SocketAddr,
listen_addr: SocketAddr,
tls_enabled: bool,
tls_server_name: Option<ServerName>,
) -> RpxyResult<Response<IncomingOr<BoxBody>>>
where
// T: Connect + Clone + Sync + Send + 'static,
T: Send + Sync + Connect + Clone,
U: CryptoSource + Clone,
{
handler
@ -51,9 +50,9 @@ where
#[derive(Clone)]
/// Proxy main object responsible to serve requests received from clients at the given socket address.
pub(crate) struct Proxy<U, E = LocalExecutor>
pub(crate) struct Proxy<U, T, E = LocalExecutor>
where
// T: Connect + Clone + Sync + Send + 'static,
T: Send + Sync + Connect + Clone + 'static,
U: CryptoSource + Clone + Sync + Send + 'static,
{
/// global context shared among async tasks
@ -65,12 +64,12 @@ where
/// hyper connection builder serving http request
pub connection_builder: Arc<ConnectionBuilder<E>>,
/// message handler serving incoming http request
pub message_handler: Arc<HttpMessageHandler<U>>,
pub message_handler: Arc<HttpMessageHandler<U, T>>,
}
impl<U> Proxy<U>
impl<U, T> Proxy<U, T>
where
// T: Connect + Clone + Sync + Send + 'static,
T: Send + Sync + Connect + Clone + 'static,
U: CryptoSource + Clone + Sync + Send + 'static,
{
/// Serves requests from clients

View file

@ -6,14 +6,14 @@ use crate::{
log::*,
name_exp::ByteName,
};
// use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::Connect;
use quinn::{crypto::rustls::HandshakeData, Endpoint, ServerConfig as QuicServerConfig, TransportConfig};
use rustls::ServerConfig;
use std::sync::Arc;
impl<U> Proxy<U>
impl<U, T> Proxy<U, T>
where
// T: Connect + Clone + Sync + Send + 'static,
T: Send + Sync + Connect + Clone + 'static,
U: CryptoSource + Clone + Sync + Send + 'static,
{
pub(super) async fn h3_listener_service(&self) -> RpxyResult<()> {

View file

@ -1,18 +1,20 @@
use super::proxy_main::Proxy;
use crate::{
crypto::CryptoSource,
crypto::{ServerCrypto, ServerCryptoBase},
error::*,
log::*,
name_exp::ByteName,
};
use anyhow::anyhow;
use hot_reload::ReloaderReceiver;
use std::sync::Arc;
// use hyper_util::client::legacy::connect::Connect;
use hyper_util::client::legacy::connect::Connect;
use s2n_quic::provider;
use std::sync::Arc;
impl<U> Proxy<U>
impl<U, T> Proxy<U, T>
where
// T: Connect + Clone + Sync + Send + 'static,
T: Connect + Clone + Sync + Send + 'static,
U: CryptoSource + Clone + Sync + Send + 'static,
{
/// Start UDP proxy serving with HTTP/3 request for configured host names