pub trait ProtocolStack: Send + Sync {
// Required methods
fn domain(&self) -> SocketDomain;
fn create_socket(
&self,
socket_type: SocketType,
protocol: SocketProtocol,
) -> Result<Arc<dyn SocketObject>, SocketError>;
fn process_incoming_packet(
&self,
packet: &DevicePacket,
) -> Result<(), SocketError>;
fn send_packet(&self, packet: DevicePacket) -> Result<(), SocketError>;
fn statistics(&self) -> ProtocolStackStats;
fn name(&self) -> &'static str;
fn supports(
&self,
socket_type: SocketType,
protocol: SocketProtocol,
) -> bool;
}Expand description
Protocol stack trait for network protocols
This trait defines the interface for protocol stack implementations. ABI modules can implement this to provide TCP/IP, UDP, or other protocol support.
§Example: TCP/IP Stack
ⓘ
struct TcpIpStack {
// TCP/IP implementation details
}
impl ProtocolStack for TcpIpStack {
fn domain(&self) -> SocketDomain {
SocketDomain::Inet
}
fn create_socket(&self, socket_type: SocketType, protocol: SocketProtocol)
-> Result<Arc<dyn SocketObject>, SocketError> {
match (socket_type, protocol) {
(SocketType::Stream, SocketProtocol::Tcp) => {
Ok(Arc::new(TcpSocket::new(self.clone())))
}
(SocketType::Datagram, SocketProtocol::Udp) => {
Ok(Arc::new(UdpSocket::new(self.clone())))
}
_ => Err(SocketError::NotSupported),
}
}
fn process_incoming_packet(&self, packet: &DevicePacket) -> Result<(), SocketError> {
// Parse IP header, route to appropriate socket
// ...
Ok(())
}
}Required Methods§
Sourcefn domain(&self) -> SocketDomain
fn domain(&self) -> SocketDomain
Get the protocol stack domain
Returns which address family this stack handles (Inet, Inet6, etc.)
Sourcefn create_socket(
&self,
socket_type: SocketType,
protocol: SocketProtocol,
) -> Result<Arc<dyn SocketObject>, SocketError>
fn create_socket( &self, socket_type: SocketType, protocol: SocketProtocol, ) -> Result<Arc<dyn SocketObject>, SocketError>
Sourcefn process_incoming_packet(
&self,
packet: &DevicePacket,
) -> Result<(), SocketError>
fn process_incoming_packet( &self, packet: &DevicePacket, ) -> Result<(), SocketError>
Sourcefn send_packet(&self, packet: DevicePacket) -> Result<(), SocketError>
fn send_packet(&self, packet: DevicePacket) -> Result<(), SocketError>
Sourcefn statistics(&self) -> ProtocolStackStats
fn statistics(&self) -> ProtocolStackStats
Get protocol stack statistics
Sourcefn supports(&self, socket_type: SocketType, protocol: SocketProtocol) -> bool
fn supports(&self, socket_type: SocketType, protocol: SocketProtocol) -> bool
Check if the protocol stack supports a specific socket type and protocol