Module discv5::handler

source ·
Expand description

Session and packet handling for the Discv5 Discovery service.

The Handler is responsible for establishing and maintaining sessions with connected/discovered nodes. Each node, identified by it’s NodeId is associated with a Session. This service drives the handshakes for establishing the sessions and associated logic for sending/requesting initial connections/ENR’s to/from unknown peers.

The Handler also manages the timeouts for each request and reports back RPC failures, and received messages. Messages are encrypted and decrypted using the associated Session for each node.

An ongoing established connection is abstractly represented by a Session. A node that provides an ENR with an IP address/port that doesn’t match the source, is considered invalid. A node that doesn’t know their external contactable addresses should set their ENR IP field to None.

The Handler also routinely checks the timeouts for banned nodes and removes them from the banned list once their ban expires.

§Usage

Interacting with a handler is done via channels. A Handler is spawned using the Handler::spawn function. This returns an exit channel, a sending and receiving channel respectively. If the exit channel is dropped or fired, the handler task gets shutdown.

Requests from the application layer can be made via the receive channel using a HandlerIn. Responses from the application layer can be made via the receive channel using a HandlerIn. Messages from a node on the network come by Socket and get the form of a HandlerOut and can be forwarded to the application layer via the send channel.

Structs§

  • A Challenge (WHOAREYOU) object used to handle and send WHOAREYOU requests.
  • Process to handle handshakes and sessions established from raw RPC communications between nodes.
  • A representation of an unsigned contactable node.
  • This type relaxes the requirement of having an ENR to connect to a node, to allow for unsigned connection types, such as multiaddrs.
  • A reference for the application layer to send back when the handler requests any known ENR for the NodeContact.

Enums§