From 2f6d0acdf67742c0f6f1a113e18910584681e502 Mon Sep 17 00:00:00 2001 From: XOR-op <17672363+XOR-op@users.noreply.github.com> Date: Wed, 18 Sep 2024 00:29:18 -0400 Subject: [PATCH] impl(http-inbound): entrypoint peek --- boltconn/src/proxy/http_inbound.rs | 30 ++++++++++++++++++++++------- boltconn/src/proxy/mixed_inbound.rs | 9 ++++++++- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/boltconn/src/proxy/http_inbound.rs b/boltconn/src/proxy/http_inbound.rs index 2872513..96db2a4 100644 --- a/boltconn/src/proxy/http_inbound.rs +++ b/boltconn/src/proxy/http_inbound.rs @@ -44,18 +44,34 @@ impl HttpInbound { pub async fn run(self) { tracing::info!("[HTTP] Listen proxy at {}, running...", self.sock_addr); + const C_ASCII: u8 = b"C"[0]; loop { match self.server.accept().await { Ok((socket, addr)) => { let disp = self.dispatcher.clone(); let auth = self.auth.clone(); - tokio::spawn(Self::serve_connection( - self.sock_addr.port(), - socket, - auth, - addr, - disp, - )); + let mut first_char = [0u8; 1]; + let _ = socket.peek(&mut first_char).await; + match first_char[0] { + C_ASCII => { + tokio::spawn(Self::serve_connection( + self.sock_addr.port(), + socket, + auth, + addr, + disp, + )); + } + _ => { + tokio::spawn(Self::serve_legacy_connection( + self.sock_addr.port(), + socket, + auth, + addr, + disp, + )); + } + } } Err(err) => { tracing::error!("HTTP inbound failed to accept: {}", err); diff --git a/boltconn/src/proxy/mixed_inbound.rs b/boltconn/src/proxy/mixed_inbound.rs index e89e4b7..0708fe9 100644 --- a/boltconn/src/proxy/mixed_inbound.rs +++ b/boltconn/src/proxy/mixed_inbound.rs @@ -93,7 +93,14 @@ impl MixedInbound { .await? } _ => { - // Unknown, drop + HttpInbound::serve_legacy_connection( + self_port, + socks_stream, + http_auth, + src_addr, + dispatcher, + ) + .await? } } Ok(())