pub struct ConstrainedEngine { /* private fields */ }Expand description
The constrained protocol engine
Manages multiple connections and provides a simple API for sending/receiving data.
Implementations§
Source§impl ConstrainedEngine
impl ConstrainedEngine
Sourcepub fn new(config: EngineConfig) -> Self
pub fn new(config: EngineConfig) -> Self
Create a new constrained protocol engine
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
Create with default configuration
Sourcepub fn connection_count(&self) -> usize
pub fn connection_count(&self) -> usize
Number of active connections
Sourcepub fn can_accept_connection(&self) -> bool
pub fn can_accept_connection(&self) -> bool
Check if we can accept more connections
Sourcepub fn connect(
&mut self,
remote_addr: SocketAddr,
) -> Result<(ConnectionId, Vec<u8>), ConstrainedError>
pub fn connect( &mut self, remote_addr: SocketAddr, ) -> Result<(ConnectionId, Vec<u8>), ConstrainedError>
Initiate a connection to a remote address
Returns the connection ID and a SYN packet to transmit.
Sourcepub fn process_incoming(
&mut self,
remote_addr: SocketAddr,
data: &[u8],
) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
pub fn process_incoming( &mut self, remote_addr: SocketAddr, data: &[u8], ) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
Process an incoming packet
Returns any response packets that need to be transmitted.
Sourcepub fn send(
&mut self,
connection_id: ConnectionId,
data: &[u8],
) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
pub fn send( &mut self, connection_id: ConnectionId, data: &[u8], ) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
Send data on a connection
Sourcepub fn recv(&mut self, connection_id: ConnectionId) -> Option<Vec<u8>>
pub fn recv(&mut self, connection_id: ConnectionId) -> Option<Vec<u8>>
Receive data from a connection
Sourcepub fn close(
&mut self,
connection_id: ConnectionId,
) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
pub fn close( &mut self, connection_id: ConnectionId, ) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
Close a connection gracefully
Sourcepub fn reset(
&mut self,
connection_id: ConnectionId,
) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
pub fn reset( &mut self, connection_id: ConnectionId, ) -> Result<Vec<(SocketAddr, Vec<u8>)>, ConstrainedError>
Reset a connection immediately
Sourcepub fn poll(&mut self) -> Vec<(SocketAddr, Vec<u8>)>
pub fn poll(&mut self) -> Vec<(SocketAddr, Vec<u8>)>
Poll the engine for maintenance tasks
This should be called periodically. Returns packets that need to be transmitted.
Sourcepub fn next_event(&mut self) -> Option<EngineEvent>
pub fn next_event(&mut self) -> Option<EngineEvent>
Get next pending event
Sourcepub fn has_connection(&self, connection_id: ConnectionId) -> bool
pub fn has_connection(&self, connection_id: ConnectionId) -> bool
Check if a connection exists
Sourcepub fn connection_for_addr(&self, addr: &SocketAddr) -> Option<ConnectionId>
pub fn connection_for_addr(&self, addr: &SocketAddr) -> Option<ConnectionId>
Get connection by remote address
Sourcepub fn active_connections(&self) -> Vec<ConnectionId>
pub fn active_connections(&self) -> Vec<ConnectionId>
Get list of active connection IDs
Sourcepub fn connection_state(
&self,
connection_id: ConnectionId,
) -> Option<ConnectionState>
pub fn connection_state( &self, connection_id: ConnectionId, ) -> Option<ConnectionState>
Get the state of a specific connection