mirror of
https://github.com/dndx/phantun.git
synced 2025-11-26 22:55:34 +08:00
Preventing resource exhaustion and reconnection
This commit is contained in:
@@ -312,6 +312,10 @@ async fn main() -> io::Result<()> {
|
||||
res = tcp_sock.recv(&mut buf_tcp) => {
|
||||
match res {
|
||||
Some(size) => {
|
||||
if size == 0 {
|
||||
debug!("Received EOF from {addr}, closing connection {sock_index}");
|
||||
break;
|
||||
}
|
||||
let udp_sock_index = udp_sock_index.fetch_add(1, Ordering::Relaxed) % udp_socks_amount;
|
||||
let udp_sock = udp_socks[udp_sock_index].clone();
|
||||
if let Some(ref enc) = *encryption {
|
||||
@@ -359,6 +363,10 @@ async fn main() -> io::Result<()> {
|
||||
res = udp_sock.recv(&mut buf_udp) => {
|
||||
match res {
|
||||
Ok(size) => {
|
||||
if size == 0 {
|
||||
debug!("Zero-sized data are not supported, discarding received data from {addr}");
|
||||
continue;
|
||||
}
|
||||
let tcp_sock_index = tcp_sock_index.fetch_add(1, Ordering::Relaxed) % tcp_socks_amount;
|
||||
let tcp_sock = tcp_socks[tcp_sock_index].clone();
|
||||
if let Some(ref enc) = *encryption {
|
||||
|
||||
@@ -273,6 +273,10 @@ async fn main() -> io::Result<()> {
|
||||
res = udp_sock.recv(&mut buf_udp) => {
|
||||
match res {
|
||||
Ok(size) => {
|
||||
if size == 0 {
|
||||
debug!("Zero-sized data are not supported, discarding received data from {local_addr}");
|
||||
continue;
|
||||
}
|
||||
if let Some(ref enc) = *encryption {
|
||||
enc.encrypt(&mut buf_udp[..size]);
|
||||
}
|
||||
@@ -311,6 +315,10 @@ async fn main() -> io::Result<()> {
|
||||
res = tcp_sock.recv(&mut buf_tcp) => {
|
||||
match res {
|
||||
Some(size) => {
|
||||
if size == 0 {
|
||||
debug!("Received EOF from {local_addr}, closing connection");
|
||||
break;
|
||||
}
|
||||
udp_sock_index = (udp_sock_index + 1) % udp_socks_amount;
|
||||
let udp_sock = udp_socks[udp_sock_index].clone();
|
||||
if let Some(ref enc) = *encryption {
|
||||
|
||||
Reference in New Issue
Block a user