This commit is contained in:
2026-03-08 17:07:15 +07:00
parent 676683d29c
commit 2069f1a62c
9 changed files with 179 additions and 95 deletions
+1 -1
View File
@@ -66,6 +66,6 @@ pub async fn run_proxy_bridge<R, W>(
data: Bytes::new(),
})
.await;
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
muxer.remove_stream(stream_id).await;
}
+3 -1
View File
@@ -6,7 +6,7 @@ use tokio::{
net::tcp::{OwnedReadHalf, OwnedWriteHalf},
sync::mpsc::Receiver,
};
use tracing::error;
use tracing::{debug, error};
use crate::{
protocol::{codec::codec::Codec, errors::ErrorAction},
@@ -75,6 +75,7 @@ impl TunnelEngine {
break;
}
// Иначе — это реальная проблема (кривой TLS и т.д.)
error!(error = ?e, "Codec inbound failed");
return Err(format!("Codec error: {:?}", e));
}
}
@@ -98,6 +99,7 @@ impl TunnelEngine {
error!(stream_id = msg.stream_id, error = %e, "Failed to write encrypted data to network");
e.to_string()
})?;
debug!(stream_id = msg.stream_id, "Outbound packet sent");
Ok(())
}
Err(e) => {
-1
View File
@@ -93,6 +93,5 @@ impl StreamHandler {
async fn on_close(&self, stream_id: u32) {
self.muxer.dispatch_to_local(stream_id, Bytes::new()).await;
self.muxer.remove_stream(stream_id).await;
}
}
+28 -9
View File
@@ -5,7 +5,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use std::sync::Arc;
use tokio::sync::mpsc::Sender;
use tokio::sync::RwLock;
use tracing::error;
use tracing::{debug, error};
pub struct IdGenerator {
counter: AtomicU32,
@@ -53,15 +53,16 @@ impl Muxer {
pub async fn register_stream(&self, stream_id: u32, tx: Sender<Bytes>) {
let mut lock = self.streams.write().await;
lock.insert(stream_id, tx);
// ДОБАВЬ ЭТО:
tracing::debug!(
stream_id,
total_active = lock.len(),
"STREAMS_MAP_UPDATE: Registered new stream"
"MUXER: [REGISTER] Stream added"
);
}
pub async fn remove_stream(&self, stream_id: u32) {
self.streams.write().await.remove(&stream_id);
let mut lock = self.streams.write().await;
lock.remove(&stream_id); // Просто удаляем, если есть
}
pub async fn send_control(
@@ -80,17 +81,35 @@ impl Muxer {
.map_err(|e| e.to_string())
}
/// Отправляет входящие данные конкретному локальному обработчику
pub async fn dispatch_to_local(&self, stream_id: u32, data: Bytes) {
// Асинхронный лок сам умеет корректно работать с .await
let tx = self.streams.read().await.get(&stream_id).cloned();
let tx = {
let lock = self.streams.read().await;
lock.get(&stream_id).cloned()
};
if let Some(tx) = tx {
if tx.send(data).await.is_err() {
if data.is_empty() {
tracing::debug!(stream_id, "MUXER: [EOF] Forwarding EOF to local handler");
} else {
tracing::trace!(
stream_id,
len = data.len(),
"MUXER: [DISPATCH] Sending data"
);
}
if let Err(_e) = tx.send(data).await {
tracing::debug!(
stream_id,
"MUXER: [WARN] Local channel closed, dropping packet"
);
self.remove_stream(stream_id).await;
}
} else {
error!(stream_id, "MUXER: Received data for UNKNOWN stream_id");
tracing::trace!(
stream_id,
"MUXER: [IGNORE] Packet for already closed stream"
);
}
}
}