Skip to content

Commit

Permalink
udp数据注释
Browse files Browse the repository at this point in the history
  • Loading branch information
w273732573 committed Oct 29, 2023
1 parent b885895 commit 83f2e8f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion config/reverse.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 10 additions & 2 deletions src/reverse/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl StreamConfig {
}
}

/// stream的绑定,按bind_mode区分出udp或者是tcp,返回相应的列表
pub async fn bind(&mut self) -> ProxyResult<(Vec<TcpListener>, Vec<StreamUdp>)> {
let mut listeners = vec![];
let mut udp_listeners = vec![];
Expand All @@ -75,7 +76,7 @@ impl StreamConfig {
data: Arc<Mutex<StreamConfig>>,
local_addr: SocketAddr,
mut inbound: T,
addr: SocketAddr,
_addr: SocketAddr,
) -> ProxyResult<()>
where
T: AsyncRead + AsyncWrite + Unpin + std::marker::Send + 'static,
Expand Down Expand Up @@ -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<u8>, SocketAddr)>,
/// 将发送器传达给每个子协程
pub sender: Sender<(Vec<u8>, SocketAddr)>,

/// 接收的缓存数据,无法保证全部直接进行发送完毕
pub cache_data: LinkedList<(Vec<u8>, SocketAddr)>,
/// 发送的缓存数据,无法保证全部直接进行发送完毕
pub send_cache_data: LinkedList<(Vec<u8>, SocketAddr)>,
/// 每个地址绑定的对象,包含Sender,最后操作时间,超时时间
remote_sockets: HashMap<SocketAddr, InnerUdp>,
}

Expand Down

0 comments on commit 83f2e8f

Please sign in to comment.