TcpLayer

Struct TcpLayer 

Source
pub struct TcpLayer {
    port_map: RwLock<BTreeMap<u16, Vec<Weak<TcpSocket>>>>,
    stats: RwLock<NetworkLayerStats>,
    self_weak: Weak<TcpLayer>,
}
Expand description

TCP layer

Manages TCP port bindings and routes packets to sockets.

Fields§

§port_map: RwLock<BTreeMap<u16, Vec<Weak<TcpSocket>>>>

Port-to-socket mapping for receiving packets

§stats: RwLock<NetworkLayerStats>

Statistics

§self_weak: Weak<TcpLayer>

Implementations§

Source§

impl TcpLayer

Source

pub fn new() -> Arc<Self>

Create a new TCP layer

Source

pub fn init(network_manager: &NetworkManager)

Initialize and register the TCP layer with NetworkManager

Registers with NetworkManager and registers itself with Ipv4Layer for protocol number 6 (TCP).

§Panics

Panics if Ipv4Layer is not registered (must be initialized first).

Source

pub fn create_socket(&self) -> Arc<TcpSocket>

Source

pub fn register_port(&self, port: u16, socket: Weak<TcpSocket>)

Register a socket for a specific port

Source

pub fn unregister_socket(&self, port: u16, socket: &Weak<TcpSocket>)

Unregister a specific socket from a port

Only removes the given socket from the port’s socket list. The port entry itself is removed only when no sockets remain.

Source

pub fn find_socket( &self, port: u16, src_ip: Ipv4Address, src_port: u16, ) -> Option<Arc<TcpSocket>>

Find socket for a destination port

Source

pub fn find_listening_socket(&self, port: u16) -> Option<Arc<TcpSocket>>

Source

pub fn receive_segment( &self, src_ip: Ipv4Address, header: TcpHeader, data: &[u8], )

Process incoming TCP segment

Source§

impl TcpLayer

Source

pub fn receive_packet( &self, src_ip: Ipv4Address, _dst_ip: Ipv4Address, packet: &[u8], ) -> Result<(), SocketError>

Receive a TCP segment with IPv4 addressing information

Trait Implementations§

Source§

impl NetworkLayer for TcpLayer

Source§

fn register_protocol(&self, _proto_num: u16, _handler: Arc<dyn NetworkLayer>)

Register a protocol handler for this layer Read more
Source§

fn send( &self, _packet: &[u8], _context: &LayerContext, _next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Send a packet through this layer Read more
Source§

fn receive( &self, packet: &[u8], context: Option<&LayerContext>, ) -> Result<(), SocketError>

Receive and process a packet at this layer Read more
Source§

fn name(&self) -> &'static str

Get layer name for debugging
Source§

fn stats(&self) -> NetworkLayerStats

Get layer statistics
Source§

fn as_any(&self) -> &dyn Any

Cast to Any for safe downcasting
Source§

fn configure( &self, config: &SocketConfig, next_layers: &[Arc<dyn NetworkLayer>], ) -> Result<(), SocketError>

Configure this layer with socket-specific parameters Read more

Auto Trait Implementations§

§

impl !Freeze for TcpLayer

§

impl !RefUnwindSafe for TcpLayer

§

impl Send for TcpLayer

§

impl Sync for TcpLayer

§

impl Unpin for TcpLayer

§

impl !UnwindSafe for TcpLayer

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.