Skip to content

Commit a9f1e99

Browse files
refactor for removing Discv5 prefix (#206)
* goodbye prefix * adjust docs
1 parent 3135833 commit a9f1e99

File tree

18 files changed

+124
-134
lines changed

18 files changed

+124
-134
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ Status]][Crates Link]
1919
This is a rust implementation of the [Discovery v5](https://github.com/ethereum/devp2p/blob/master/discv5/discv5.md)
2020
peer discovery protocol.
2121

22-
Discovery v5 is a protocol designed for encrypted peer discovery (and topic advertisement tba). Each peer/node
23-
on the network is identified via it's `ENR` ([Ethereum Node
24-
Record](https://eips.ethereum.org/EIPS/eip-778)), which is essentially a signed key-value store
25-
containing the node's public key and optionally IP address and port.
22+
Discovery v5 is a protocol designed for encrypted peer discovery. Each peer/node on the network is
23+
identified via it's `ENR` ([Ethereum Node Record](https://eips.ethereum.org/EIPS/eip-778)), which
24+
is essentially a signed key-value store containing the node's public key and optionally IP address
25+
and port.
2626

2727
Discv5 employs a kademlia-like routing table to store and manage discovered peers and topics. The
2828
protocol allows for external IP discovery in NAT environments through regular PING/PONG's with
@@ -37,7 +37,7 @@ For a simple CLI discovery service see [discv5-cli](https://github.com/AgeMannin
3737
A simple example of creating this service is as follows:
3838

3939
```rust
40-
use discv5::{enr, enr::{CombinedKey, NodeId}, TokioExecutor, Discv5, Discv5ConfigBuilder};
40+
use discv5::{enr, enr::{CombinedKey, NodeId}, TokioExecutor, Discv5, ConfigBuilder};
4141
use discv5::socket::ListenConfig;
4242
use std::net::SocketAddr;
4343

@@ -59,7 +59,7 @@ A simple example of creating this service is as follows:
5959
};
6060

6161
// default configuration
62-
let config = Discv5ConfigBuilder::new(listen_config).build();
62+
let config = ConfigBuilder::new(listen_config).build();
6363

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

examples/custom_executor.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
//! $ cargo run --example custom_executor <BASE64ENR>
1010
//! ```
1111
12-
use discv5::{enr, enr::CombinedKey, Discv5, Discv5ConfigBuilder, Discv5Event, ListenConfig};
12+
use discv5::{enr, enr::CombinedKey, ConfigBuilder, Discv5, Event, ListenConfig};
1313
use std::net::Ipv4Addr;
1414

1515
fn main() {
@@ -39,7 +39,7 @@ fn main() {
3939
.unwrap();
4040

4141
// default configuration - uses the current executor
42-
let config = Discv5ConfigBuilder::new(listen_config).build();
42+
let config = ConfigBuilder::new(listen_config).build();
4343

4444
// construct the discv5 server
4545
let mut discv5: Discv5 = Discv5::new(enr, enr_key, config).unwrap();
@@ -72,10 +72,10 @@ fn main() {
7272

7373
loop {
7474
match event_stream.recv().await {
75-
Some(Discv5Event::SocketUpdated(addr)) => {
75+
Some(Event::SocketUpdated(addr)) => {
7676
println!("Nodes ENR socket address has been updated to: {addr:?}");
7777
}
78-
Some(Discv5Event::Discovered(enr)) => {
78+
Some(Event::Discovered(enr)) => {
7979
println!("A peer has been discovered: {}", enr.node_id());
8080
}
8181
_ => {}

examples/find_nodes.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use clap::Parser;
1919
use discv5::{
2020
enr,
2121
enr::{k256, CombinedKey},
22-
Discv5, Discv5ConfigBuilder, Discv5Event, ListenConfig,
22+
ConfigBuilder, Discv5, Event, ListenConfig,
2323
};
2424
use std::{
2525
net::{IpAddr, Ipv4Addr, Ipv6Addr},
@@ -120,10 +120,10 @@ async fn main() {
120120
};
121121

122122
// default configuration with packet filtering
123-
// let config = Discv5ConfigBuilder::new(listen_config).enable_packet_filter().build();
123+
// let config = ConfigBuilder::new(listen_config).enable_packet_filter().build();
124124

125125
// default configuration without packet filtering
126-
let config = Discv5ConfigBuilder::new(listen_config).build();
126+
let config = ConfigBuilder::new(listen_config).build();
127127

128128
info!("Node Id: {}", enr.node_id());
129129
if args.enr_ip6.is_some() || args.enr_ip4.is_some() {
@@ -192,12 +192,12 @@ async fn main() {
192192
continue;
193193
}
194194
match discv5_ev {
195-
Discv5Event::Discovered(enr) => info!("Enr discovered {}", enr),
196-
Discv5Event::EnrAdded { enr, replaced: _ } => info!("Enr added {}", enr),
197-
Discv5Event::NodeInserted { node_id, replaced: _ } => info!("Node inserted {}", node_id),
198-
Discv5Event::SessionEstablished(enr, _) => info!("Session established {}", enr),
199-
Discv5Event::SocketUpdated(addr) => info!("Socket updated {}", addr),
200-
Discv5Event::TalkRequest(_) => info!("Talk request received"),
195+
Event::Discovered(enr) => info!("Enr discovered {}", enr),
196+
Event::EnrAdded { enr, replaced: _ } => info!("Enr added {}", enr),
197+
Event::NodeInserted { node_id, replaced: _ } => info!("Node inserted {}", node_id),
198+
Event::SessionEstablished(enr, _) => info!("Session established {}", enr),
199+
Event::SocketUpdated(addr) => info!("Socket updated {}", addr),
200+
Event::TalkRequest(_) => info!("Talk request received"),
201201
};
202202
}
203203
}

examples/request_enr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//!
1414
//! This requires the "libp2p" feature.
1515
#[cfg(feature = "libp2p")]
16-
use discv5::Discv5ConfigBuilder;
16+
use discv5::ConfigBuilder;
1717
#[cfg(feature = "libp2p")]
1818
use discv5::ListenConfig;
1919
#[cfg(feature = "libp2p")]
@@ -46,7 +46,7 @@ async fn main() {
4646
let enr = enr::EnrBuilder::new("v4").build(&enr_key).unwrap();
4747

4848
// default discv5 configuration
49-
let config = Discv5ConfigBuilder::new(listen_config).build();
49+
let config = ConfigBuilder::new(listen_config).build();
5050

5151
let multiaddr = std::env::args()
5252
.nth(1)

examples/simple_server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! $ cargo run --example simple_server -- <ENR-IP> <ENR-PORT> <BASE64ENR>
1111
//! ```
1212
13-
use discv5::{enr, enr::CombinedKey, Discv5, Discv5ConfigBuilder, Discv5Event, ListenConfig};
13+
use discv5::{enr, enr::CombinedKey, ConfigBuilder, Discv5, Event, ListenConfig};
1414
use std::net::Ipv4Addr;
1515

1616
#[tokio::main]
@@ -72,7 +72,7 @@ async fn main() {
7272
}
7373

7474
// default configuration
75-
let config = Discv5ConfigBuilder::new(listen_config).build();
75+
let config = ConfigBuilder::new(listen_config).build();
7676

7777
// construct the discv5 server
7878
let mut discv5: Discv5 = Discv5::new(enr, enr_key, config).unwrap();
@@ -104,10 +104,10 @@ async fn main() {
104104

105105
loop {
106106
match event_stream.recv().await {
107-
Some(Discv5Event::SocketUpdated(addr)) => {
107+
Some(Event::SocketUpdated(addr)) => {
108108
println!("Nodes ENR socket address has been updated to: {addr:?}");
109109
}
110-
Some(Discv5Event::Discovered(enr)) => {
110+
Some(Event::Discovered(enr)) => {
111111
println!("A peer has been discovered: {}", enr.node_id());
112112
}
113113
_ => {}

src/config.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::time::Duration;
77

88
/// Configuration parameters that define the performance of the discovery network.
99
#[derive(Clone)]
10-
pub struct Discv5Config {
10+
pub struct Config {
1111
/// Whether to enable the incoming packet filter. Default: false.
1212
pub enable_packet_filter: bool,
1313

@@ -101,11 +101,11 @@ pub struct Discv5Config {
101101
}
102102

103103
#[derive(Debug)]
104-
pub struct Discv5ConfigBuilder {
105-
config: Discv5Config,
104+
pub struct ConfigBuilder {
105+
config: Config,
106106
}
107107

108-
impl Discv5ConfigBuilder {
108+
impl ConfigBuilder {
109109
pub fn new(listen_config: ListenConfig) -> Self {
110110
// This is only applicable if enable_packet_filter is set.
111111
let filter_rate_limiter = Some(
@@ -118,7 +118,7 @@ impl Discv5ConfigBuilder {
118118
);
119119

120120
// set default values
121-
let config = Discv5Config {
121+
let config = Config {
122122
enable_packet_filter: false,
123123
request_timeout: Duration::from_secs(1),
124124
vote_duration: Duration::from_secs(30),
@@ -145,7 +145,7 @@ impl Discv5ConfigBuilder {
145145
listen_config,
146146
};
147147

148-
Discv5ConfigBuilder { config }
148+
ConfigBuilder { config }
149149
}
150150

151151
/// Whether to enable the incoming packet filter.
@@ -302,7 +302,7 @@ impl Discv5ConfigBuilder {
302302
self
303303
}
304304

305-
pub fn build(&mut self) -> Discv5Config {
305+
pub fn build(&mut self) -> Config {
306306
// If an executor is not provided, assume a current tokio runtime is running.
307307
if self.config.executor.is_none() {
308308
self.config.executor = Some(Box::<crate::executor::TokioExecutor>::default());
@@ -314,9 +314,9 @@ impl Discv5ConfigBuilder {
314314
}
315315
}
316316

317-
impl std::fmt::Debug for Discv5Config {
317+
impl std::fmt::Debug for Config {
318318
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
319-
f.debug_struct("Discv5Config")
319+
f.debug_struct("Config")
320320
.field("filter_enabled", &self.enable_packet_filter)
321321
.field("request_timeout", &self.request_timeout)
322322
.field("vote_duration", &self.vote_duration)

src/discv5.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
//!
33
//! This provides the main struct for running and interfacing with a discovery v5 server.
44
//!
5-
//! A [`Discv5`] struct needs to be created either with an [`crate::executor::Executor`] specified in the
6-
//! [`Discv5Config`] via the [`crate::Discv5ConfigBuilder`] or in the presence of a tokio runtime that has
7-
//! timing and io enabled.
5+
//! A [`Discv5`] struct needs to be created either with an [`crate::executor::Executor`] specified
6+
//! in the [`Config`] via the [`crate::ConfigBuilder`] or in the presence of a tokio runtime that
7+
//! has timing and io enabled.
88
//!
99
//! Once a [`Discv5`] struct has been created the service is started by running the [`Discv5::start`]
1010
//! functions with a UDP socket. This will start a discv5 server in the background listening on the
@@ -13,15 +13,15 @@
1313
//! The server can be shutdown using the [`Discv5::shutdown`] function.
1414
1515
use crate::{
16-
error::{Discv5Error, QueryError, RequestError},
16+
error::{Error, QueryError, RequestError},
1717
kbucket::{
1818
self, ConnectionDirection, ConnectionState, FailureReason, InsertResult, KBucketsTable,
1919
NodeStatus, UpdateResult,
2020
},
2121
node_info::NodeContact,
2222
packet::ProtocolIdentity,
2323
service::{QueryKind, Service, ServiceRequest, TalkRequest},
24-
DefaultProtocolId, Discv5Config, Enr, IpMode,
24+
Config, DefaultProtocolId, Enr, IpMode,
2525
};
2626
use enr::{CombinedKey, EnrError, EnrKey, NodeId};
2727
use parking_lot::RwLock;
@@ -53,7 +53,7 @@ mod test;
5353

5454
/// Events that can be produced by the `Discv5` event stream.
5555
#[derive(Debug)]
56-
pub enum Discv5Event {
56+
pub enum Event {
5757
/// A node has been discovered from a FINDNODES request.
5858
///
5959
/// The ENR of the node is returned. Various properties can be derived from the ENR.
@@ -81,7 +81,7 @@ pub struct Discv5<P = DefaultProtocolId>
8181
where
8282
P: ProtocolIdentity,
8383
{
84-
config: Discv5Config,
84+
config: Config,
8585
/// The channel to make requests from the main service.
8686
service_channel: Option<mpsc::Sender<ServiceRequest>>,
8787
/// The exit channel to shutdown the underlying service.
@@ -102,7 +102,7 @@ impl<P: ProtocolIdentity> Discv5<P> {
102102
pub fn new(
103103
local_enr: Enr,
104104
enr_key: CombinedKey,
105-
mut config: Discv5Config,
105+
mut config: Config,
106106
) -> Result<Self, &'static str> {
107107
// ensure the keypair matches the one that signed the enr.
108108
if local_enr.public_key() != enr_key.public() {
@@ -154,10 +154,10 @@ impl<P: ProtocolIdentity> Discv5<P> {
154154
}
155155

156156
/// Starts the required tasks and begins listening on a given UDP SocketAddr.
157-
pub async fn start(&mut self) -> Result<(), Discv5Error> {
157+
pub async fn start(&mut self) -> Result<(), Error> {
158158
if self.service_channel.is_some() {
159159
warn!("Service is already started");
160-
return Err(Discv5Error::ServiceAlreadyStarted);
160+
return Err(Error::ServiceAlreadyStarted);
161161
}
162162

163163
// create the main service
@@ -670,7 +670,7 @@ impl<P: ProtocolIdentity> Discv5<P> {
670670
/// Creates an event stream channel which can be polled to receive Discv5 events.
671671
pub fn event_stream(
672672
&self,
673-
) -> impl Future<Output = Result<mpsc::Receiver<Discv5Event>, Discv5Error>> + 'static {
673+
) -> impl Future<Output = Result<mpsc::Receiver<Event>, Error>> + 'static {
674674
let channel = self.clone_channel();
675675

676676
async move {
@@ -682,20 +682,18 @@ impl<P: ProtocolIdentity> Discv5<P> {
682682
channel
683683
.send(event)
684684
.await
685-
.map_err(|_| Discv5Error::ServiceChannelClosed)?;
685+
.map_err(|_| Error::ServiceChannelClosed)?;
686686

687-
callback_recv
688-
.await
689-
.map_err(|_| Discv5Error::ServiceChannelClosed)
687+
callback_recv.await.map_err(|_| Error::ServiceChannelClosed)
690688
}
691689
}
692690

693691
/// Internal helper function to send events to the Service.
694-
fn clone_channel(&self) -> Result<mpsc::Sender<ServiceRequest>, Discv5Error> {
692+
fn clone_channel(&self) -> Result<mpsc::Sender<ServiceRequest>, Error> {
695693
if let Some(channel) = self.service_channel.as_ref() {
696694
Ok(channel.clone())
697695
} else {
698-
Err(Discv5Error::ServiceNotStarted)
696+
Err(Error::ServiceNotStarted)
699697
}
700698
}
701699
}

src/discv5/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async fn build_nodes(n: usize, base_port: u16) -> Vec<Discv5> {
2626
for port in base_port..base_port + n as u16 {
2727
let enr_key = CombinedKey::generate_secp256k1();
2828
let listen_config = ListenConfig::Ipv4 { ip, port };
29-
let config = Discv5ConfigBuilder::new(listen_config).build();
29+
let config = ConfigBuilder::new(listen_config).build();
3030

3131
let enr = EnrBuilder::new("v4")
3232
.ip4(ip)
@@ -50,7 +50,7 @@ async fn build_nodes_from_keypairs(keys: Vec<CombinedKey>, base_port: u16) -> Ve
5050
let port = base_port + i as u16;
5151

5252
let listen_config = ListenConfig::Ipv4 { ip, port };
53-
let config = Discv5ConfigBuilder::new(listen_config).build();
53+
let config = ConfigBuilder::new(listen_config).build();
5454

5555
let enr = EnrBuilder::new("v4")
5656
.ip4(ip)
@@ -75,7 +75,7 @@ async fn build_nodes_from_keypairs_ipv6(keys: Vec<CombinedKey>, base_port: u16)
7575
ip: Ipv6Addr::LOCALHOST,
7676
port,
7777
};
78-
let config = Discv5ConfigBuilder::new(listen_config).build();
78+
let config = ConfigBuilder::new(listen_config).build();
7979

8080
let enr = EnrBuilder::new("v4")
8181
.ip6(Ipv6Addr::LOCALHOST)
@@ -106,7 +106,7 @@ async fn build_nodes_from_keypairs_dual_stack(
106106
ipv6: Ipv6Addr::LOCALHOST,
107107
ipv6_port,
108108
};
109-
let config = Discv5ConfigBuilder::new(listen_config).build();
109+
let config = ConfigBuilder::new(listen_config).build();
110110

111111
let enr = EnrBuilder::new("v4")
112112
.ip4(Ipv4Addr::LOCALHOST)
@@ -753,7 +753,7 @@ async fn test_table_limits() {
753753
ip: enr.ip4().unwrap(),
754754
port: enr.udp4().unwrap(),
755755
};
756-
let config = Discv5ConfigBuilder::new(listen_config).ip_limit().build();
756+
let config = ConfigBuilder::new(listen_config).ip_limit().build();
757757

758758
// let socket_addr = enr.udp_socket().unwrap();
759759
let discv5: Discv5 = Discv5::new(enr, enr_key, config).unwrap();
@@ -822,7 +822,7 @@ async fn test_bucket_limits() {
822822
ip: enr.ip4().unwrap(),
823823
port: enr.udp4().unwrap(),
824824
};
825-
let config = Discv5ConfigBuilder::new(listen_config).ip_limit().build();
825+
let config = ConfigBuilder::new(listen_config).ip_limit().build();
826826

827827
let discv5: Discv5 = Discv5::new(enr, enr_key, config).unwrap();
828828
for enr in enrs {

0 commit comments

Comments
 (0)