remove useless is_in_heartbeat in udpgw

This commit is contained in:
ssrlive 2024-11-02 17:16:54 +08:00
parent 53f60ffda6
commit e8143a691b
2 changed files with 1 additions and 16 deletions

View file

@ -506,9 +506,6 @@ async fn handle_udp_gateway_session(
} }
} }
None => { 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?; 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 { if let Err(e) = handle_proxy_session(&mut tcp_server_stream, proxy_handler).await {
return Err(format!("udpgw connection error: {}", e).into()); return Err(format!("udpgw connection error: {}", e).into());

View file

@ -13,7 +13,7 @@ use tokio::{
pub(crate) const UDPGW_LENGTH_FIELD_SIZE: usize = std::mem::size_of::<u16>(); pub(crate) const UDPGW_LENGTH_FIELD_SIZE: usize = std::mem::size_of::<u16>();
pub(crate) const UDPGW_MAX_CONNECTIONS: usize = 5; 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)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct UdpFlag(pub u8); pub struct UdpFlag(pub u8);
@ -410,7 +410,6 @@ pub(crate) struct UdpGwClient {
keepalive_time: Duration, keepalive_time: Duration,
udpgw_server: SocketAddr, udpgw_server: SocketAddr,
server_connections: Mutex<VecDeque<UdpGwClientStream>>, server_connections: Mutex<VecDeque<UdpGwClientStream>>,
is_in_heartbeat: std::sync::atomic::AtomicBool,
} }
impl UdpGwClient { impl UdpGwClient {
@ -423,7 +422,6 @@ impl UdpGwClient {
udpgw_server, udpgw_server,
keepalive_time, keepalive_time,
server_connections, server_connections,
is_in_heartbeat: std::sync::atomic::AtomicBool::new(false),
} }
} }
@ -435,10 +433,6 @@ impl UdpGwClient {
self.udp_timeout 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<UdpGwClientStream> { pub(crate) async fn pop_server_connection_from_queue(&self) -> Option<UdpGwClientStream> {
self.server_connections.lock().await.pop_front() self.server_connections.lock().await.pop_front()
} }
@ -461,16 +455,10 @@ impl UdpGwClient {
self.udpgw_server 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. /// 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<()> { pub(crate) async fn heartbeat_task(&self) -> std::io::Result<()> {
loop { loop {
self.is_in_heartbeat.store(false, Relaxed);
sleep(self.keepalive_time).await; sleep(self.keepalive_time).await;
self.is_in_heartbeat.store(true, Relaxed);
let mut streams = Vec::new(); let mut streams = Vec::new();
while let Some(stream) = self.pop_server_connection_from_queue().await { while let Some(stream) = self.pop_server_connection_from_queue().await {