From d308467290f5f7fd83b131631a948ed87aed28eb Mon Sep 17 00:00:00 2001 From: morph <82043364+morph-dev@users.noreply.github.com> Date: Thu, 30 Nov 2023 23:39:58 +0200 Subject: [PATCH] Update 'enr' dependency --- Cargo.toml | 2 +- README.md | 2 +- examples/custom_executor.rs | 2 +- examples/find_nodes.rs | 2 +- examples/request_enr.rs | 2 +- examples/simple_server.rs | 2 +- src/discv5/test.rs | 36 ++++++++++-------------------------- src/handler/crypto/mod.rs | 6 +++--- src/handler/tests.rs | 23 +++++++++-------------- src/ipmode.rs | 2 +- src/lib.rs | 2 +- src/rpc.rs | 7 +++---- src/service/test.rs | 10 +++++----- 13 files changed, 38 insertions(+), 60 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9bc784f93..b733a4a96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] } diff --git a/README.md b/README.md index c9ca44d23..3ce88a19d 100644 --- a/README.md +++ b/README.md @@ -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() diff --git a/examples/custom_executor.rs b/examples/custom_executor.rs index 1d97d3561..a184fbf6e 100644 --- a/examples/custom_executor.rs +++ b/examples/custom_executor.rs @@ -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() diff --git a/examples/find_nodes.rs b/examples/find_nodes.rs index 112cba319..012256816 100644 --- a/examples/find_nodes.rs +++ b/examples/find_nodes.rs @@ -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() { diff --git a/examples/request_enr.rs b/examples/request_enr.rs index e6986f1b3..d3daac640 100644 --- a/examples/request_enr.rs +++ b/examples/request_enr.rs @@ -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(); diff --git a/examples/simple_server.rs b/examples/simple_server.rs index 41a925e57..2cc453281 100644 --- a/examples/simple_server.rs +++ b/examples/simple_server.rs @@ -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); diff --git a/src/discv5/test.rs b/src/discv5/test.rs index 07d3a9c47..47ecad9b8 100644 --- a/src/discv5/test.rs +++ b/src/discv5/test.rs @@ -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, @@ -28,11 +28,7 @@ async fn build_nodes(n: usize, base_port: u16) -> Vec { 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(); @@ -52,11 +48,7 @@ async fn build_nodes_from_keypairs(keys: Vec, 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(); @@ -77,7 +69,7 @@ async fn build_nodes_from_keypairs_ipv6(keys: Vec, 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) @@ -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) @@ -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(), @@ -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) @@ -782,11 +770,7 @@ 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 = { @@ -794,7 +778,7 @@ async fn test_bucket_limits() { 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 = enr.node_id().into(); let distance = node_key.log2_distance(&enr_new.node_id().into()).unwrap(); if distance == 256 { @@ -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) diff --git a/src/handler/crypto/mod.rs b/src/handler/crypto/mod.rs index c96d7afdc..6b609d3a8 100644 --- a/src/handler/crypto/mod.rs +++ b/src/handler/crypto/mod.rs @@ -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 { @@ -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) diff --git a/src/handler/tests.rs b/src/handler/tests.rs index 1b155a5f5..187ed5aba 100644 --- a/src/handler/tests.rs +++ b/src/handler/tests.rs @@ -17,7 +17,6 @@ use crate::{ RequestError::SelfRequest, }; use active_requests::ActiveRequests; -use enr::EnrBuilder; use std::time::Duration; use tokio::time::sleep; @@ -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) @@ -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) @@ -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(); @@ -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) @@ -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) @@ -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) @@ -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) diff --git a/src/ipmode.rs b/src/ipmode.rs index f2dbe48da..bc292d7f9 100644 --- a/src/ipmode.rs +++ b/src/ipmode.rs @@ -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); } diff --git a/src/lib.rs b/src/lib.rs index e48990dcf..99b2eb256 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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() diff --git a/src/rpc.rs b/src/rpc.rs index 884b4566d..d59968abb 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -493,7 +493,6 @@ impl Message { #[cfg(test)] mod tests { use super::*; - use enr::EnrBuilder; use std::net::Ipv4Addr; #[test] @@ -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(); diff --git a/src/service/test.rs b/src/service/test.rs index 74dd832ad..bf1f10946 100644 --- a/src/service/test.rs +++ b/src/service/test.rs @@ -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}; @@ -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) @@ -174,7 +174,7 @@ 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) @@ -182,7 +182,7 @@ async fn test_connection_direction_on_inject_session_established() { 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)