From 83f2e8f36f24db39bc90c1a231123885c21468bb Mon Sep 17 00:00:00 2001 From: ticbh Date: Sun, 29 Oct 2023 11:10:46 +0800 Subject: [PATCH] =?UTF-8?q?udp=E6=95=B0=E6=8D=AE=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/reverse.toml | 2 +- src/reverse/stream.rs | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/config/reverse.toml b/config/reverse.toml index 1874698..e908e91 100644 --- a/config/reverse.toml +++ b/config/reverse.toml @@ -73,7 +73,7 @@ server_name = "server" bind_addr = "0.0.0.0:84" bind_mode = "udp" server_name = "udp" -timeout = 5 +timeout = 500 # [[http.server]] # bind_addr = "0.0.0.0:81" diff --git a/src/reverse/stream.rs b/src/reverse/stream.rs index b4ed15f..82649e3 100644 --- a/src/reverse/stream.rs +++ b/src/reverse/stream.rs @@ -50,6 +50,7 @@ impl StreamConfig { } } + /// stream的绑定,按bind_mode区分出udp或者是tcp,返回相应的列表 pub async fn bind(&mut self) -> ProxyResult<(Vec, Vec)> { let mut listeners = vec![]; let mut udp_listeners = vec![]; @@ -75,7 +76,7 @@ impl StreamConfig { data: Arc>, local_addr: SocketAddr, mut inbound: T, - addr: SocketAddr, + _addr: SocketAddr, ) -> ProxyResult<()> where T: AsyncRead + AsyncWrite + Unpin + std::marker::Send + 'static, @@ -105,17 +106,24 @@ impl InnerUdp { } } +/// Udp转发的处理结构,缓存一些数值以做中转 pub struct StreamUdp { + /// 读的缓冲类,避免每次都释放 pub buf: BinaryMut, + /// 核心的udp绑定端口 pub socket: UdpSocket, pub server: ServerConfig, - // 如果接收该数据大小为0,那么则代表通知数据关闭 + /// 如果接收该数据大小为0,那么则代表通知数据关闭 pub receiver: Receiver<(Vec, SocketAddr)>, + /// 将发送器传达给每个子协程 pub sender: Sender<(Vec, SocketAddr)>, + /// 接收的缓存数据,无法保证全部直接进行发送完毕 pub cache_data: LinkedList<(Vec, SocketAddr)>, + /// 发送的缓存数据,无法保证全部直接进行发送完毕 pub send_cache_data: LinkedList<(Vec, SocketAddr)>, + /// 每个地址绑定的对象,包含Sender,最后操作时间,超时时间 remote_sockets: HashMap, }