pub struct ConnectionTracker { /* private fields */ }Expand description
Tracks TCP connections between guest and proxy tasks.
Each guest TCP connection maps to a smoltcp socket and a pair of channels connecting it to a tokio proxy task. The tracker handles:
- Socket creation — on SYN detection, before smoltcp processes the frame.
- Data relay — shuttles bytes between smoltcp sockets and channels.
- Lifecycle detection — identifies newly-established connections for proxy spawning.
- Cleanup — removes closed sockets from the socket set.
Implementations§
Source§impl ConnectionTracker
impl ConnectionTracker
Sourcepub fn new(max_connections: Option<usize>) -> Self
pub fn new(max_connections: Option<usize>) -> Self
Create a new tracker with the given connection limit.
Sourcepub fn has_socket_for(&self, src: &SocketAddr, dst: &SocketAddr) -> bool
pub fn has_socket_for(&self, src: &SocketAddr, dst: &SocketAddr) -> bool
Returns true if a tracked socket already exists for this exact
connection (same source AND destination). O(1) via HashSet lookup.
Sourcepub fn create_tcp_socket(
&mut self,
src: SocketAddr,
dst: SocketAddr,
sockets: &mut SocketSet<'_>,
) -> bool
pub fn create_tcp_socket( &mut self, src: SocketAddr, dst: SocketAddr, sockets: &mut SocketSet<'_>, ) -> bool
Create a smoltcp TCP socket for an incoming SYN and register it.
The socket is put into LISTEN state on the destination IP + port so smoltcp will complete the three-way handshake when it processes the SYN frame. Binding to the specific destination IP (not just port) prevents socket dispatch ambiguity when multiple connections target different IPs on the same port.
Returns false if at max_connections limit.
Sourcepub fn relay_data(&mut self, sockets: &mut SocketSet<'_>)
pub fn relay_data(&mut self, sockets: &mut SocketSet<'_>)
Relay data between smoltcp sockets and proxy task channels.
For each connection with a spawned proxy:
- Reads data from the smoltcp socket and sends it to the proxy channel.
- Receives data from the proxy channel and writes it to the smoltcp socket.
Sourcepub fn take_new_connections(
&mut self,
sockets: &mut SocketSet<'_>,
) -> Vec<NewConnection>
pub fn take_new_connections( &mut self, sockets: &mut SocketSet<'_>, ) -> Vec<NewConnection>
Collect newly-established connections that need proxy tasks.
Returns a list of NewConnection structs containing the channel ends
for the proxy task. The poll loop is responsible for spawning the task.
Sourcepub fn cleanup_closed(&mut self, sockets: &mut SocketSet<'_>)
pub fn cleanup_closed(&mut self, sockets: &mut SocketSet<'_>)
Remove closed connections and their sockets.
Only removes sockets in the Closed state. Sockets in TimeWait
are left for smoltcp to handle naturally (2*MSL timer), preventing
delayed duplicate segments from being accepted by a reused port.