discv5
Overview
This is a rust implementation of the Discovery v5 peer discovery protocol.
Discovery v5 is a protocol designed for encrypted peer discovery and topic advertisement. Each peer/node on the network is identified via it's 'ENR' (Ethereum Name Record), which is essentially a signed key-value store containing the node's public key and optionally IP address and port.
Discv5 employs a kademlia-like routing table to store and manage discovered peers and topics. The protocol allows for external IP discovery in NAT environments through regular PING/PONG's with discovered nodes. Nodes return the external IP address that they have received and a simple majority is chosen as our external IP address. If an external IP address is updated, this is produced as an event to notify the swarm (if one is used for this behaviour).
For a simple CLI discovery service see discv5-cli
Usage
The Discv5
service implements Stream
which emits Discv5Event
events. Running a
discv5 service is as simple as initialising a Discv5
struct and driving the stream.
A simple example of creating this service is as follows:
use ;
use Ipv4Addr;
use ;
use *;
async
To see a usage in a runtime environment, see the find_nodes
example in /examples
.
Implementation Notes
This protocol is split into three main sections/layers:
- Transport - The transport for this protocol is currently fixed to UDP and is realised by the
[
Discv5Service
] struct. It encodes/decodes [Packet
]'s to and from the specified UDP socket. - Session - The protocol's communication is encrypted with
AES_GCM
. All node communication undergoes a handshake, which results in a [Session
]. [Session
]'s are established when needed and get dropped after a timeout. This section manages the creation and maintenance of sessions between nodes. It is realised by the [SessionService
] struct. - Behaviour - This section contains the protocol-level logic. In particular it manages the
routing table of known ENR's, topic registration/advertisement and performs various queries
such as peer discovery. This section is realised by the [
Discv5
] struct.
Note - Currently only secp256k1
keys are supported.