diff --git a/prudpv1/src/executables/proxy_insecure.rs b/prudpv1/src/executables/proxy_insecure.rs index b33e069..cbfacec 100644 --- a/prudpv1/src/executables/proxy_insecure.rs +++ b/prudpv1/src/executables/proxy_insecure.rs @@ -76,12 +76,12 @@ async fn main() { tokio::select! { data = conn.recv() => { let Some(data) = data else { - break; + return; }; if let Err(e) = stream.send_buffer(&data[..]).await{ error!("error sending data to backend: {}", e); - break; + return; } }, data = stream.read_buffer() => { @@ -89,7 +89,7 @@ async fn main() { Ok(d) => d, Err(e) => { error!("error reveiving data from backend: {}", e); - break; + return; } }; diff --git a/prudpv1/src/executables/proxy_secure.rs b/prudpv1/src/executables/proxy_secure.rs index 91a66fa..b25a03a 100644 --- a/prudpv1/src/executables/proxy_secure.rs +++ b/prudpv1/src/executables/proxy_secure.rs @@ -78,12 +78,12 @@ async fn main() { tokio::select! { data = conn.recv() => { let Some(data) = data else { - break; + return; }; if let Err(e) = stream.send_buffer(&data[..]).await{ error!("error sending data to backend: {}", e); - break; + return; } }, data = stream.read_buffer() => { @@ -91,7 +91,7 @@ async fn main() { Ok(d) => d, Err(e) => { error!("error reveiving data from backend: {}", e); - break; + return; } }; diff --git a/prudpv1/src/prudp/socket.rs b/prudpv1/src/prudp/socket.rs index 9307007..6467d8f 100644 --- a/prudpv1/src/prudp/socket.rs +++ b/prudpv1/src/prudp/socket.rs @@ -91,6 +91,21 @@ impl InternalConnection { async fn send_raw_packet(&self, prudp_packet: &PRUDPV1Packet) { send_raw_prudp_to_sockaddr(&self.socket, self.socket_addr, prudp_packet).await; } + + async fn delete_connection(&self){ + let Some(conns) = self.connections.upgrade() else { + // this is fine as it implies the server has already quit, thus meaning that we dont + // have to remove ourselves from the server + return; + }; + + let mut conns = conns.lock().await; + + conns.remove(&self.socket_addr); + + // the connection will now drop as soon as we leave this due to no longer having a permanent + // reference + } } pub struct ExternalConnection { @@ -172,6 +187,8 @@ pub(super) trait AnyInternalConnection: async fn close_connection(&mut self); } + + #[async_trait] impl AnyInternalConnection for InternalConnection { async fn send_data_packet(&mut self, data: Vec) { @@ -202,6 +219,7 @@ impl AnyInternalConnection for InternalConne self.unacknowleged_packets.push((Instant::now(), packet)); } + async fn close_connection(&mut self) { // jon confirmed that this should be a safe way to dc a client @@ -228,18 +246,7 @@ impl AnyInternalConnection for InternalConne self.send_raw_packet(&packet).await; - let Some(conns) = self.connections.upgrade() else { - // this is fine as it implies the server has already quit, thus meaning that we dont - // have to remove ourselves from the server - return; - }; - - let mut conns = conns.lock().await; - - conns.remove(&self.socket_addr); - - // the connection will now drop as soon as we leave this due to no longer having a permanent - // reference + self.delete_connection().await; } } @@ -583,6 +590,7 @@ impl InternalSocket { self.send_packet_unbuffered(address, &response).await; self.send_packet_unbuffered(address, &response).await; + conn.delete_connection().await; //self.internal_connections.lock().await; } }