comments remove

This commit is contained in:
2026-03-20 15:05:22 +07:00
parent bc8662034f
commit ea3492c6a7
19 changed files with 43 additions and 149 deletions
+1 -9
View File
@@ -64,7 +64,7 @@ impl Connection {
pub fn new_raw(inbound: OwnedReadHalf, outbound: OwnedWriteHalf) -> Self {
Self {
addr: "0.0.0.0:0".parse().unwrap(), // заглушка, если адрес не важен
addr: "0.0.0.0:0".parse().unwrap(),
inbound,
outbound,
read_buf: BytesMut::with_capacity(BUF_SIZE),
@@ -105,7 +105,6 @@ pub struct ClientHandler {
pub muxer: Muxer,
}
// Внутри connection.rs или где у тебя ClientHandler
impl ClientHandler {
pub async fn connect(
remote_proxy_addr: &str,
@@ -118,7 +117,6 @@ impl ClientHandler {
let mut conn = Connection::new_raw(inbound, outbound);
// TLS Handshake
let ch = conn
.codec
.make_client_handshake(&BrowserProfile::CHROME_131, "google.com")
@@ -177,7 +175,6 @@ impl ClientHandler {
let mut buf = [0u8; 1024];
loop {
// Просто ждем, пока клиент не разорвет TCP-соединение
if self
.conn
.inbound
@@ -198,17 +195,14 @@ impl TunnelHandler for ClientHandler {
async fn run(mut self) -> Result<(), String> {
info!("Starting SOCKS multiplexed handling");
// 1. Приветствие (Handshake)
self.conn.read_socks_request().await?;
self.conn
.send_socks_reply(SocksReply::HandshakeSelect { method: 0x00 })
.await?;
// 2. Получаем основной запрос (Connect или UDP Associate)
let req = self.conn.read_socks_request().await?;
match req {
// Ветка TCP CONNECT
SocksRequest::Connect {
command: 0x01,
target,
@@ -253,13 +247,11 @@ impl TunnelHandler for ClientHandler {
Ok(())
}
// Ветка UDP ASSOCIATE
SocksRequest::Connect { command: 0x03, .. } => {
info!("Handling UDP Associate request");
self.handle_udp_associate().await
}
// Всё остальное (BIND и т.д.)
_ => Err("Unsupported SOCKS command".into()),
}
}
+3 -5
View File
@@ -35,7 +35,6 @@ impl StreamHandler {
let target_str = String::from_utf8_lossy(&payload).to_string();
let muxer = self.muxer.clone();
// Канал для передачи данных из мультиплексора в мост (bridge)
let (v_tx, v_rx) = tokio::sync::mpsc::channel(512);
muxer.register_stream(stream_id, v_tx).await;
@@ -43,7 +42,6 @@ impl StreamHandler {
let start = std::time::Instant::now();
info!(stream_id, target = %target_str, "Attempting remote connection");
// Обертываем коннект в таймаут, чтобы не плодить зомби-таски
let connect_timeout = tokio::time::timeout(
std::time::Duration::from_secs(5),
tokio::net::TcpStream::connect(&target_str),
@@ -62,7 +60,7 @@ impl StreamHandler {
let mut reply_buf = BytesMut::with_capacity(10);
let reply = SocksReply::ConnectResult {
reply_code: 0x00, // Success
reply_code: 0x00,
atyp: 0x01,
addr: [0, 0, 0, 0],
port: 0,
@@ -78,11 +76,11 @@ impl StreamHandler {
}
Ok(Err(e)) => {
error!(stream_id, target = %target_str, error = %e, "TCP connection failed");
Self::send_error_reply(&muxer, stream_id, 0x01).await; // 0x01 = General failure
Self::send_error_reply(&muxer, stream_id, 0x01).await;
}
Err(_) => {
error!(stream_id, target = %target_str, "Connection timed out (DNS/TCP)");
Self::send_error_reply(&muxer, stream_id, 0x04).await; // 0x04 = Host unreachable
Self::send_error_reply(&muxer, stream_id, 0x04).await;
}
}
});