Preventing resource exhaustion and reconnection

This commit is contained in:
Saber Haj Rabiee
2022-12-20 06:53:26 -08:00
parent f68f153eb9
commit 1040b3dec9
3 changed files with 47 additions and 17 deletions

View File

@@ -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 {

View File

@@ -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 {