fix proxy not disconnecting propperly
This commit is contained in:
parent
449ce0c0ba
commit
949c347569
3 changed files with 26 additions and 18 deletions
|
|
@ -76,12 +76,12 @@ async fn main() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
data = conn.recv() => {
|
data = conn.recv() => {
|
||||||
let Some(data) = data else {
|
let Some(data) = data else {
|
||||||
break;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = stream.send_buffer(&data[..]).await{
|
if let Err(e) = stream.send_buffer(&data[..]).await{
|
||||||
error!("error sending data to backend: {}", e);
|
error!("error sending data to backend: {}", e);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data = stream.read_buffer() => {
|
data = stream.read_buffer() => {
|
||||||
|
|
@ -89,7 +89,7 @@ async fn main() {
|
||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("error reveiving data from backend: {}", e);
|
error!("error reveiving data from backend: {}", e);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -78,12 +78,12 @@ async fn main() {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
data = conn.recv() => {
|
data = conn.recv() => {
|
||||||
let Some(data) = data else {
|
let Some(data) = data else {
|
||||||
break;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = stream.send_buffer(&data[..]).await{
|
if let Err(e) = stream.send_buffer(&data[..]).await{
|
||||||
error!("error sending data to backend: {}", e);
|
error!("error sending data to backend: {}", e);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data = stream.read_buffer() => {
|
data = stream.read_buffer() => {
|
||||||
|
|
@ -91,7 +91,7 @@ async fn main() {
|
||||||
Ok(d) => d,
|
Ok(d) => d,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("error reveiving data from backend: {}", e);
|
error!("error reveiving data from backend: {}", e);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -91,6 +91,21 @@ impl<E: CryptoHandlerConnectionInstance> InternalConnection<E> {
|
||||||
async fn send_raw_packet(&self, prudp_packet: &PRUDPV1Packet) {
|
async fn send_raw_packet(&self, prudp_packet: &PRUDPV1Packet) {
|
||||||
send_raw_prudp_to_sockaddr(&self.socket, self.socket_addr, prudp_packet).await;
|
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 {
|
pub struct ExternalConnection {
|
||||||
|
|
@ -172,6 +187,8 @@ pub(super) trait AnyInternalConnection:
|
||||||
async fn close_connection(&mut self);
|
async fn close_connection(&mut self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<T: CryptoHandlerConnectionInstance> AnyInternalConnection for InternalConnection<T> {
|
impl<T: CryptoHandlerConnectionInstance> AnyInternalConnection for InternalConnection<T> {
|
||||||
async fn send_data_packet(&mut self, data: Vec<u8>) {
|
async fn send_data_packet(&mut self, data: Vec<u8>) {
|
||||||
|
|
@ -202,6 +219,7 @@ impl<T: CryptoHandlerConnectionInstance> AnyInternalConnection for InternalConne
|
||||||
self.unacknowleged_packets.push((Instant::now(), packet));
|
self.unacknowleged_packets.push((Instant::now(), packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async fn close_connection(&mut self) {
|
async fn close_connection(&mut self) {
|
||||||
// jon confirmed that this should be a safe way to dc a client
|
// jon confirmed that this should be a safe way to dc a client
|
||||||
|
|
||||||
|
|
@ -228,18 +246,7 @@ impl<T: CryptoHandlerConnectionInstance> AnyInternalConnection for InternalConne
|
||||||
|
|
||||||
self.send_raw_packet(&packet).await;
|
self.send_raw_packet(&packet).await;
|
||||||
|
|
||||||
let Some(conns) = self.connections.upgrade() else {
|
self.delete_connection().await;
|
||||||
// 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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -583,6 +590,7 @@ impl<T: CryptoHandler> InternalSocket<T> {
|
||||||
self.send_packet_unbuffered(address, &response).await;
|
self.send_packet_unbuffered(address, &response).await;
|
||||||
self.send_packet_unbuffered(address, &response).await;
|
self.send_packet_unbuffered(address, &response).await;
|
||||||
|
|
||||||
|
conn.delete_connection().await;
|
||||||
//self.internal_connections.lock().await;
|
//self.internal_connections.lock().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue