Fix CPU spikes due to always-writable event and improve half-open connection handling

This commit is contained in:
B. Blechschmidt 2023-04-04 00:18:50 +02:00
parent 0be39345a8
commit 10a674d1c9
3 changed files with 143 additions and 59 deletions

View file

@ -1,7 +1,7 @@
use crate::error::Error;
use crate::tun2proxy::{
Connection, ConnectionManager, DestinationHost, IncomingDataEvent, IncomingDirection,
OutgoingDataEvent, OutgoingDirection, TcpProxy,
Connection, ConnectionManager, DestinationHost, Direction, IncomingDataEvent,
IncomingDirection, OutgoingDataEvent, OutgoingDirection, TcpProxy,
};
use crate::Credentials;
use smoltcp::wire::IpProtocol;
@ -368,6 +368,21 @@ impl TcpProxy for SocksConnection {
fn connection_established(&self) -> bool {
self.state == SocksState::Established
}
fn have_data(&mut self, dir: Direction) -> bool {
match dir {
Direction::Incoming(incoming) => match incoming {
IncomingDirection::FromServer => self.server_inbuf.len() > 0,
IncomingDirection::FromClient => {
self.client_inbuf.len() > 0 || self.data_buf.len() > 0
}
},
Direction::Outgoing(outgoing) => match outgoing {
OutgoingDirection::ToServer => self.server_outbuf.len() > 0,
OutgoingDirection::ToClient => self.client_outbuf.len() > 0,
},
}
}
}
pub struct SocksManager {