#peer-to-peer #libp2p #networking #discovery #discv5


Implementation of the p2p discv5 discovery protocol

23 releases

new 0.1.0-beta.10 Sep 16, 2021
0.1.0-beta.8 Jul 21, 2021
0.1.0-beta.3 Feb 3, 2021
0.1.0-beta.2 Nov 23, 2020
0.1.0-alpha.7 Jul 21, 2020

#48 in Network programming

Download history 593/week @ 2021-06-01 364/week @ 2021-06-08 571/week @ 2021-06-15 152/week @ 2021-06-22 290/week @ 2021-06-29 870/week @ 2021-07-06 801/week @ 2021-07-13 570/week @ 2021-07-20 937/week @ 2021-07-27 975/week @ 2021-08-03 416/week @ 2021-08-10 1067/week @ 2021-08-17 1402/week @ 2021-08-24 1176/week @ 2021-08-31 1054/week @ 2021-09-07 710/week @ 2021-09-14

3,432 downloads per month
Used in discv5-cli

MIT license

10K SLoC


Build Status Doc Status Crates Status

Documentation at docs.rs


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 Node 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


A simple example of creating this service is as follows:

   use discv5::{enr, enr::{CombinedKey, NodeId}, TokioExecutor, Discv5, Discv5ConfigBuilder};
   use std::net::SocketAddr;

   // listening address and port
   let listen_addr = "".parse::<SocketAddr>().unwrap();

   // construct a local ENR
   let enr_key = CombinedKey::generate_secp256k1();
   let enr = enr::EnrBuilder::new("v4").build(&enr_key).unwrap();

   // build the tokio executor
   let mut runtime = tokio::runtime::Builder::new_multi_thread()

   // default configuration
   let config = Discv5ConfigBuilder::new().build();

   // construct the discv5 server
   let mut discv5 = Discv5::new(enr, enr_key, config).unwrap();

   // In order to bootstrap the routing table an external ENR should be added
   // This can be done via add_enr. I.e.:
   // discv5.add_enr(<ENR>)

   // start the discv5 server

   // run a find_node query
   runtime.block_on(async {
      let found_nodes = discv5.find_node(NodeId::random()).await.unwrap();
      println!("Found nodes: {:?}", found_nodes);


~276K SLoC