Skip to content

Commit

Permalink
Update 'enr' dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
morph-dev committed Nov 30, 2023
1 parent e64446b commit d308467
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 60 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ categories = ["network-programming", "asynchronous"]
exclude = [".gitignore", ".github/*"]

[dependencies]
enr = { version = "0.9", features = ["k256", "ed25519"] }
enr = { version = "0.10", features = ["k256", "ed25519"] }
tokio = { version = "1", features = ["net", "sync", "macros", "rt"] }
libp2p = { version = "0.52", features = ["ed25519", "secp256k1"], optional = true }
zeroize = { version = "1", features = ["zeroize_derive"] }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ A simple example of creating this service is as follows:

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

// build the tokio executor
let mut runtime = tokio::runtime::Builder::new_multi_thread()
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ fn main() {

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

// build the tokio executor
let runtime = tokio::runtime::Builder::new_multi_thread()
Expand Down
2 changes: 1 addition & 1 deletion examples/find_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async fn main() {
};

let enr = {
let mut builder = enr::EnrBuilder::new("v4");
let mut builder = enr::Enr::builder();
if let Some(ip4) = args.enr_ip4 {
// if the given address is the UNSPECIFIED address we want to advertise localhost
if ip4.is_unspecified() {
Expand Down
2 changes: 1 addition & 1 deletion examples/request_enr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async fn main() {
// generate a new enr key
let enr_key = CombinedKey::generate_secp256k1();
// construct a local ENR
let enr = enr::EnrBuilder::new("v4").build(&enr_key).unwrap();
let enr = enr::Enr::empty(&enr_key).unwrap();

// default discv5 configuration
let config = ConfigBuilder::new(listen_config).build();
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ async fn main() {

// construct a local ENR
let enr = {
let mut builder = enr::EnrBuilder::new("v4");
let mut builder = enr::Enr::builder();
// if an IP was specified, use it
if let Some(external_address) = address {
builder.ip4(external_address);
Expand Down
36 changes: 10 additions & 26 deletions src/discv5/test.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![cfg(test)]

use crate::{socket::ListenConfig, Discv5, *};
use enr::{k256, CombinedKey, Enr, EnrBuilder, EnrKey, NodeId};
use enr::{k256, CombinedKey, Enr, EnrKey, NodeId};
use rand_core::{RngCore, SeedableRng};
use std::{
collections::HashMap,
Expand All @@ -28,11 +28,7 @@ async fn build_nodes(n: usize, base_port: u16) -> Vec<Discv5> {
let listen_config = ListenConfig::Ipv4 { ip, port };
let config = ConfigBuilder::new(listen_config).build();

let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(port)
.build(&enr_key)
.unwrap();
let enr = Enr::builder().ip4(ip).udp4(port).build(&enr_key).unwrap();
// transport for building a swarm
let mut discv5 = Discv5::new(enr, enr_key, config).unwrap();
discv5.start().await.unwrap();
Expand All @@ -52,11 +48,7 @@ async fn build_nodes_from_keypairs(keys: Vec<CombinedKey>, base_port: u16) -> Ve
let listen_config = ListenConfig::Ipv4 { ip, port };
let config = ConfigBuilder::new(listen_config).build();

let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(port)
.build(&enr_key)
.unwrap();
let enr = Enr::builder().ip4(ip).udp4(port).build(&enr_key).unwrap();

let mut discv5 = Discv5::new(enr, enr_key, config).unwrap();
discv5.start().await.unwrap();
Expand All @@ -77,7 +69,7 @@ async fn build_nodes_from_keypairs_ipv6(keys: Vec<CombinedKey>, base_port: u16)
};
let config = ConfigBuilder::new(listen_config).build();

let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip6(Ipv6Addr::LOCALHOST)
.udp6(port)
.build(&enr_key)
Expand Down Expand Up @@ -108,7 +100,7 @@ async fn build_nodes_from_keypairs_dual_stack(
};
let config = ConfigBuilder::new(listen_config).build();

let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip4(Ipv4Addr::LOCALHOST)
.udp4(ipv4_port)
.ip6(Ipv6Addr::LOCALHOST)
Expand Down Expand Up @@ -744,11 +736,7 @@ async fn test_table_limits() {
let mut keypairs = generate_deterministic_keypair(12, 9487);
let ip: Ipv4Addr = "127.0.0.1".parse().unwrap();
let enr_key: CombinedKey = keypairs.remove(0);
let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(9050)
.build(&enr_key)
.unwrap();
let enr = Enr::builder().ip4(ip).udp4(9050).build(&enr_key).unwrap();
let listen_config = ListenConfig::Ipv4 {
ip: enr.ip4().unwrap(),
port: enr.udp4().unwrap(),
Expand All @@ -763,7 +751,7 @@ async fn test_table_limits() {
.map(|i| {
let ip: Ipv4Addr = Ipv4Addr::new(192, 168, 1, i as u8);
let enr_key: CombinedKey = keypairs.remove(0);
EnrBuilder::new("v4")
Enr::builder()
.ip4(ip)
.udp4(9050 + i as u16)
.build(&enr_key)
Expand All @@ -782,19 +770,15 @@ async fn test_table_limits() {
async fn test_bucket_limits() {
let enr_key = CombinedKey::generate_secp256k1();
let ip: Ipv4Addr = "127.0.0.1".parse().unwrap();
let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(9500)
.build(&enr_key)
.unwrap();
let enr = Enr::builder().ip4(ip).udp4(9500).build(&enr_key).unwrap();
let bucket_limit: usize = 2;
// Generate `bucket_limit + 1` keypairs that go in `enr` node's 256th bucket.
let keys = {
let mut keys = Vec::new();
for _ in 0..bucket_limit + 1 {
loop {
let key = CombinedKey::generate_secp256k1();
let enr_new = EnrBuilder::new("v4").build(&key).unwrap();
let enr_new = Enr::empty(&key).unwrap();
let node_key: Key<NodeId> = enr.node_id().into();
let distance = node_key.log2_distance(&enr_new.node_id().into()).unwrap();
if distance == 256 {
Expand All @@ -810,7 +794,7 @@ async fn test_bucket_limits() {
.map(|i| {
let kp = &keys[i - 1];
let ip: Ipv4Addr = Ipv4Addr::new(192, 168, 1, i as u8);
EnrBuilder::new("v4")
Enr::builder()
.ip4(ip)
.udp4(9500 + i as u16)
.build(kp)
Expand Down
6 changes: 3 additions & 3 deletions src/handler/crypto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ mod tests {
use crate::packet::DefaultProtocolId;

use super::*;
use enr::{CombinedKey, EnrBuilder, EnrKey};
use enr::{CombinedKey, Enr, EnrKey};
use std::convert::TryInto;

fn hex_decode(x: &'static str) -> Vec<u8> {
Expand Down Expand Up @@ -341,12 +341,12 @@ mod tests {
let node1_key = CombinedKey::generate_secp256k1();
let node2_key = CombinedKey::generate_secp256k1();

let node1_enr = EnrBuilder::new("v4")
let node1_enr = Enr::builder()
.ip("127.0.0.1".parse().unwrap())
.udp4(9000)
.build(&node1_key)
.unwrap();
let node2_enr = EnrBuilder::new("v4")
let node2_enr = Enr::builder()
.ip("127.0.0.1".parse().unwrap())
.udp4(9000)
.build(&node2_key)
Expand Down
23 changes: 9 additions & 14 deletions src/handler/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::{
RequestError::SelfRequest,
};
use active_requests::ActiveRequests;
use enr::EnrBuilder;
use std::time::Duration;
use tokio::time::sleep;

Expand Down Expand Up @@ -108,12 +107,12 @@ async fn simple_session_message() {
let key1 = CombinedKey::generate_secp256k1();
let key2 = CombinedKey::generate_secp256k1();

let sender_enr = EnrBuilder::new("v4")
let sender_enr = Enr::builder()
.ip4(ip)
.udp4(sender_port)
.build(&key1)
.unwrap();
let receiver_enr = EnrBuilder::new("v4")
let receiver_enr = Enr::builder()
.ip4(ip)
.udp4(receiver_port)
.build(&key2)
Expand Down Expand Up @@ -195,13 +194,13 @@ async fn multiple_messages() {
let key1 = CombinedKey::generate_secp256k1();
let key2 = CombinedKey::generate_secp256k1();

let sender_enr = EnrBuilder::new("v4")
let sender_enr = Enr::builder()
.ip4(ip)
.udp4(sender_port)
.build(&key1)
.unwrap();

let receiver_enr = EnrBuilder::new("v4")
let receiver_enr = Enr::builder()
.ip4(ip)
.udp4(receiver_port)
.build(&key2)
Expand Down Expand Up @@ -345,11 +344,7 @@ async fn test_active_requests_insert() {

let key = CombinedKey::generate_secp256k1();

let enr = EnrBuilder::new("v4")
.ip4(ip)
.udp4(port)
.build(&key)
.unwrap();
let enr = Enr::builder().ip4(ip).udp4(port).build(&key).unwrap();
let node_id = enr.node_id();

let contact: NodeContact = enr.into();
Expand All @@ -374,7 +369,7 @@ async fn test_self_request_ipv4() {
init();

let key = CombinedKey::generate_secp256k1();
let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip4(Ipv4Addr::LOCALHOST)
.udp4(5004)
.build(&key)
Expand Down Expand Up @@ -414,7 +409,7 @@ async fn test_self_request_ipv6() {
init();

let key = CombinedKey::generate_secp256k1();
let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip6(Ipv6Addr::LOCALHOST)
.udp6(5005)
.build(&key)
Expand Down Expand Up @@ -451,7 +446,7 @@ async fn test_self_request_ipv6() {
async fn remove_one_time_session() {
let config = ConfigBuilder::new(ListenConfig::default()).build();
let key = CombinedKey::generate_secp256k1();
let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip4(Ipv4Addr::LOCALHOST)
.udp4(9000)
.build(&key)
Expand All @@ -460,7 +455,7 @@ async fn remove_one_time_session() {

let enr = {
let key = CombinedKey::generate_secp256k1();
EnrBuilder::new("v4")
Enr::builder()
.ip4(Ipv4Addr::LOCALHOST)
.udp4(9000)
.build(&key)
Expand Down
2 changes: 1 addition & 1 deletion src/ipmode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ mod tests {

fn test(&self) {
let test_enr = {
let builder = &mut enr::EnrBuilder::new("v4");
let builder = &mut enr::Enr::builder();
if let Some(ip4) = self.enr_ip4 {
builder.ip4(ip4).udp4(IP4_TEST_PORT);
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
//!
//! // construct a local ENR
//! let enr_key = CombinedKey::generate_secp256k1();
//! let enr = enr::EnrBuilder::new("v4").build(&enr_key).unwrap();
//! let enr = enr::Enr::empty(&enr_key).unwrap();
//!
//! // build the tokio executor
//! let mut runtime = tokio::runtime::Builder::new_multi_thread()
Expand Down
7 changes: 3 additions & 4 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,6 @@ impl Message {
#[cfg(test)]
mod tests {
use super::*;
use enr::EnrBuilder;
use std::net::Ipv4Addr;

#[test]
Expand Down Expand Up @@ -733,17 +732,17 @@ mod tests {
#[test]
fn encode_decode_nodes_response() {
let key = CombinedKey::generate_secp256k1();
let enr1 = EnrBuilder::new("v4")
let enr1 = Enr::builder()
.ip4("127.0.0.1".parse().unwrap())
.udp4(500)
.build(&key)
.unwrap();
let enr2 = EnrBuilder::new("v4")
let enr2 = Enr::builder()
.ip4("10.0.0.1".parse().unwrap())
.tcp4(8080)
.build(&key)
.unwrap();
let enr3 = EnrBuilder::new("v4")
let enr3 = Enr::builder()
.ip("10.4.5.6".parse().unwrap())
.build(&key)
.unwrap();
Expand Down
10 changes: 5 additions & 5 deletions src/service/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
socket::ListenConfig,
ConfigBuilder, Enr,
};
use enr::{CombinedKey, EnrBuilder};
use enr::CombinedKey;
use parking_lot::RwLock;
use std::{collections::HashMap, sync::Arc, time::Duration};
use tokio::sync::{mpsc, oneshot};
Expand Down Expand Up @@ -106,14 +106,14 @@ async fn test_updating_connection_on_ping() {
init();
let enr_key1 = CombinedKey::generate_secp256k1();
let ip = "127.0.0.1".parse().unwrap();
let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip4(ip)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key1)
.unwrap();
let ip2 = "127.0.0.1".parse().unwrap();
let enr_key2 = CombinedKey::generate_secp256k1();
let enr2 = EnrBuilder::new("v4")
let enr2 = Enr::builder()
.ip4(ip2)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key2)
Expand Down Expand Up @@ -174,15 +174,15 @@ async fn test_connection_direction_on_inject_session_established() {

let enr_key1 = CombinedKey::generate_secp256k1();
let ip = std::net::Ipv4Addr::LOCALHOST;
let enr = EnrBuilder::new("v4")
let enr = Enr::builder()
.ip4(ip)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key1)
.unwrap();

let enr_key2 = CombinedKey::generate_secp256k1();
let ip2 = std::net::Ipv4Addr::LOCALHOST;
let enr2 = EnrBuilder::new("v4")
let enr2 = Enr::builder()
.ip4(ip2)
.udp4(DEFAULT_UDP_PORT)
.build(&enr_key2)
Expand Down

0 comments on commit d308467

Please sign in to comment.