pub struct TcpIPv4Handler { /* private fields */ }Expand description
Implements a minimalist TCP over IPv4 listener.
Forwards incoming TCP segments to the appropriate connection object, based on the associated
tuple, or attempts to establish new connections (when receiving SYN segments). Aside from
constructors, the handler operation is based on three methods:
receive_packetexamines an incoming IPv4 packet. It checks whether the destination address is correct, the attempts examine the inner TCP segment, making sure the destination port number is also correct. Then, it steers valid segments towards exiting connections, creates new connections for incomingSYNsegments, and enqueuesRSTreplies in response to any segments which cannot be associated with a connection (except otherRSTsegments). On success, also describes any internal status changes triggered by the reception of the packet.write_next_packetwrites the next IPv4 packet (if available) that would be sent by the handler itself (right now it can only mean an enqueuedRST), or one of the existing connections. On success, also describes any internal status changes triggered as the packet gets transmitted.next_segment_statusdescribes whether the handler can send a packet immediately, or after some retransmission timeout associated with a connection fires, or if there’s nothing to send for the moment. This is used to determine whether it’s appropriate to callwrite_next_packet.
Implementations§
Source§impl TcpIPv4Handler
impl TcpIPv4Handler
Sourcepub fn new(
local_ipv4_addr: Ipv4Addr,
local_port: u16,
max_connections: NonZeroUsize,
max_pending_resets: NonZeroUsize,
) -> Self
pub fn new( local_ipv4_addr: Ipv4Addr, local_port: u16, max_connections: NonZeroUsize, max_pending_resets: NonZeroUsize, ) -> Self
Creates a new TcpIPv4Handler.
The handler acts as if bound to local_addr:local_port, and will accept at most
max_connections concurrent connections. RST segments generated by unexpected incoming
segments are placed in a queue which is at most max_pending_resets long.
Sourcepub fn set_local_ipv4_addr(&mut self, ipv4_addr: Ipv4Addr)
pub fn set_local_ipv4_addr(&mut self, ipv4_addr: Ipv4Addr)
Setter for the local IPv4 address of this TCP handler.
Sourcepub fn local_ipv4_addr(&self) -> Ipv4Addr
pub fn local_ipv4_addr(&self) -> Ipv4Addr
Returns the local IPv4 address of this TCP handler.
Sourcepub fn local_port(&self) -> u16
pub fn local_port(&self) -> u16
Returns the local port of this TCP handler.
Sourcepub fn max_connections(&self) -> NonZeroUsize
pub fn max_connections(&self) -> NonZeroUsize
Returns the max connections of this TCP handler.
Sourcepub fn max_pending_resets(&self) -> NonZeroUsize
pub fn max_pending_resets(&self) -> NonZeroUsize
Returns the max pending resets of this TCP handler.
Sourcepub fn receive_packet<T: NetworkBytes + Debug, F: FnOnce(Request) -> Response>(
&mut self,
packet: &IPv4Packet<'_, T>,
callback: F,
) -> Result<RecvEvent, RecvError>
pub fn receive_packet<T: NetworkBytes + Debug, F: FnOnce(Request) -> Response>( &mut self, packet: &IPv4Packet<'_, T>, callback: F, ) -> Result<RecvEvent, RecvError>
Contains logic for handling incoming segments.
Any changes to the state of the handler are communicated through an Ok(RecvEvent).
Sourcepub fn write_next_packet(
&mut self,
buf: &mut [u8],
) -> Result<(Option<NonZeroUsize>, WriteEvent), WriteNextError>
pub fn write_next_packet( &mut self, buf: &mut [u8], ) -> Result<(Option<NonZeroUsize>, WriteEvent), WriteNextError>
Attempts to write one packet, from either the RST queue or one of the existing endpoints,
to buf.
On success, the function returns a pair containing an Option<NonZeroUsize> and a
WriteEvent. The options represents how many bytes have been written to buf, or
that no packet can be send presently (when equal to None). The WriteEvent describes
whether any noteworthy state changes are associated with the write.
Sourcepub fn next_segment_status(&self) -> NextSegmentStatus
pub fn next_segment_status(&self) -> NextSegmentStatus
Describes the status of the next segment to be sent by the handler.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TcpIPv4Handler
impl RefUnwindSafe for TcpIPv4Handler
impl Send for TcpIPv4Handler
impl Sync for TcpIPv4Handler
impl Unpin for TcpIPv4Handler
impl UnwindSafe for TcpIPv4Handler
Blanket Implementations§
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
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.