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.

Called when new peer is connected. Only called when peer supports the same protocol.

Called when a previously connected peer disconnects.

Provided methods

Initialize the handler

Timer function called after a timeout created with NetworkContext::timeout.

Implementors