Trait ethcore_network::NetworkProtocolHandler
[−]
[src]
pub trait NetworkProtocolHandler: Sync + Send { fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8]); fn connected(&self, io: &NetworkContext, peer: &PeerId); fn disconnected(&self, io: &NetworkContext, peer: &PeerId); fn initialize(&self, _io: &NetworkContext) { ... } fn timeout(&self, _io: &NetworkContext, _timer: TimerToken) { ... } }
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
fn read(&self, io: &NetworkContext, peer: &PeerId, packet_id: u8, data: &[u8])
Called when new network packet received.
fn connected(&self, io: &NetworkContext, peer: &PeerId)
Called when new peer is connected. Only called when peer supports the same protocol.
fn disconnected(&self, io: &NetworkContext, peer: &PeerId)
Called when a previously connected peer disconnects.
Provided Methods
fn initialize(&self, _io: &NetworkContext)
Initialize the handler
fn timeout(&self, _io: &NetworkContext, _timer: TimerToken)
Timer function called after a timeout created with NetworkContext::timeout
.