diff --git a/src/lib.rs b/src/lib.rs index 41b901a..1aa64ca 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -506,9 +506,6 @@ async fn handle_udp_gateway_session( } } None => { - if !udpgw_client.is_in_heartbeat_progress() && udpgw_client.is_full().await { - return Err("max udpgw connection limit reached".into()); - } let mut tcp_server_stream = create_tcp_stream(&socket_queue, proxy_server_addr).await?; if let Err(e) = handle_proxy_session(&mut tcp_server_stream, proxy_handler).await { return Err(format!("udpgw connection error: {}", e).into()); diff --git a/src/udpgw.rs b/src/udpgw.rs index 9a2f5eb..be791f8 100644 --- a/src/udpgw.rs +++ b/src/udpgw.rs @@ -13,7 +13,7 @@ use tokio::{ pub(crate) const UDPGW_LENGTH_FIELD_SIZE: usize = std::mem::size_of::(); pub(crate) const UDPGW_MAX_CONNECTIONS: usize = 5; -pub(crate) const UDPGW_KEEPALIVE_TIME: tokio::time::Duration = std::time::Duration::from_secs(10); +pub(crate) const UDPGW_KEEPALIVE_TIME: tokio::time::Duration = std::time::Duration::from_secs(30); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct UdpFlag(pub u8); @@ -410,7 +410,6 @@ pub(crate) struct UdpGwClient { keepalive_time: Duration, udpgw_server: SocketAddr, server_connections: Mutex>, - is_in_heartbeat: std::sync::atomic::AtomicBool, } impl UdpGwClient { @@ -423,7 +422,6 @@ impl UdpGwClient { udpgw_server, keepalive_time, server_connections, - is_in_heartbeat: std::sync::atomic::AtomicBool::new(false), } } @@ -435,10 +433,6 @@ impl UdpGwClient { self.udp_timeout } - pub(crate) async fn is_full(&self) -> bool { - self.server_connections.lock().await.len() >= self.max_connections - } - pub(crate) async fn pop_server_connection_from_queue(&self) -> Option { self.server_connections.lock().await.pop_front() } @@ -461,16 +455,10 @@ impl UdpGwClient { self.udpgw_server } - pub(crate) fn is_in_heartbeat_progress(&self) -> bool { - self.is_in_heartbeat.load(Relaxed) - } - /// Heartbeat task asynchronous function to periodically check and maintain the active state of the server connection. pub(crate) async fn heartbeat_task(&self) -> std::io::Result<()> { loop { - self.is_in_heartbeat.store(false, Relaxed); sleep(self.keepalive_time).await; - self.is_in_heartbeat.store(true, Relaxed); let mut streams = Vec::new(); while let Some(stream) = self.pop_server_connection_from_queue().await {