Skip to content

Commit

Permalink
impl(http-inbound): entrypoint peek
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed Sep 18, 2024
1 parent 9475ed0 commit 2f6d0ac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
30 changes: 23 additions & 7 deletions boltconn/src/proxy/http_inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion boltconn/src/proxy/mixed_inbound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,14 @@ impl MixedInbound {
.await?
}
_ => {
// Unknown, drop
HttpInbound::serve_legacy_connection(
self_port,
socks_stream,
http_auth,
src_addr,
dispatcher,
)
.await?
}
}
Ok(())
Expand Down

0 comments on commit 2f6d0ac

Please sign in to comment.