pub struct TcpConnectionTracker { /* 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 TcpConnectionTracker
impl TcpConnectionTracker
Sourcepub fn new(max_tcp_connections: Option<NonZeroUsize>) -> Self
pub fn new(max_tcp_connections: Option<NonZeroUsize>) -> 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_tcp_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 trace_stats(&self, sockets: &SocketSet<'_>)
pub fn trace_stats(&self, sockets: &SocketSet<'_>)
Record bounded-cardinality diagnostics once per maintenance interval.
Sourcepub fn cleanup_closed(&mut self, sockets: &mut SocketSet<'_>)
pub fn cleanup_closed(&mut self, sockets: &mut SocketSet<'_>)
Remove closed connections and their sockets.
Idle listeners represent failed/reset SYNs: this tracker never owns persistent listening sockets. Closed sockets with a remote endpoint still owe the guest an RST and must survive until smoltcp emits it. TIME_WAIT remains intact to reject delayed duplicate segments.
Auto Trait Implementations§
impl Freeze for TcpConnectionTracker
impl RefUnwindSafe for TcpConnectionTracker
impl Send for TcpConnectionTracker
impl Sync for TcpConnectionTracker
impl Unpin for TcpConnectionTracker
impl UnsafeUnpin for TcpConnectionTracker
impl UnwindSafe for TcpConnectionTracker
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more