pub trait NetworkProtocolHandler: Sync + Send {
fn read(
&self,
io: &dyn NetworkContext,
peer: &PeerId,
packet_id: u8,
data: &[u8]
);
fn connected(&self, io: &dyn NetworkContext, peer: &PeerId);
fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId);
fn initialize(&self, _io: &dyn NetworkContext) { ... }
fn timeout(&self, _io: &dyn NetworkContext, _timer: TimerToken) { ... }
}
Expand description
Network IO protocol handler. This needs to be implemented for each new subprotocol.
All the handler function are called from within IO event loop.
Message
is the type for message data.
Required methods
Called when new network packet received.
fn connected(&self, io: &dyn NetworkContext, peer: &PeerId)
fn connected(&self, io: &dyn NetworkContext, peer: &PeerId)
Called when new peer is connected. Only called when peer supports the same protocol.
fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId)
fn disconnected(&self, io: &dyn NetworkContext, peer: &PeerId)
Called when a previously connected peer disconnects.
Provided methods
fn initialize(&self, _io: &dyn NetworkContext)
fn initialize(&self, _io: &dyn NetworkContext)
Initialize the handler
fn timeout(&self, _io: &dyn NetworkContext, _timer: TimerToken)
fn timeout(&self, _io: &dyn NetworkContext, _timer: TimerToken)
Timer function called after a timeout created with NetworkContext::timeout
.