From a5d945a437cfd5c3c63227637599ae29f0dd7563 Mon Sep 17 00:00:00 2001 From: Age Manning Date: Tue, 17 Sep 2024 13:54:43 +1000 Subject: [PATCH] Update to latest version of discv5 and bump to 0.6.0 --- Cargo.toml | 18 +++++++++--------- src/lib.rs | 8 -------- src/main.rs | 4 ++-- src/request_enr/enr_ext.rs | 1 + src/request_enr/mod.rs | 4 ++-- src/server/enr_build.rs | 2 +- src/server/mod.rs | 4 ++-- src/server/services/events.rs | 14 +++++++------- 8 files changed, 24 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e03f8f1..47a1e47 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "discv5-cli" -version = "0.5.0" +version = "0.6.0" description = "Simple CLI utility for creating and debugging discovery v5 servers" authors = ["Age Manning "] edition = "2018" @@ -15,20 +15,20 @@ exclude = [ ] [dependencies] -discv5 = { version = "0.3.0", features = ["libp2p"] } +discv5 = { version = "0.7", features = ["libp2p"] } sha2 = "0.10" libsecp256k1 = "0.7" -libp2p-identity = { version = "0.1.2", features = ["secp256k1"] } -libp2p-core = "0.39" -clap = { version = "4.3", features = ["derive"] } +libp2p-identity = { version = "0.2.9", features = ["secp256k1"] } +libp2p-core = "0.42" +clap = { version = "4.5", features = ["derive"] } hex = "0.4" log = "0.4" -simple_logger = "4.1" +simple_logger = "5.0" futures = "0.3" tokio = { version = "1", features = ["full"] } -eyre = "0.6.8" -serde = "1.0.163" -serde_json = "1.0.96" +eyre = "0.6.12" +serde = "1.0.210" +serde_json = "1.0.128" [[bin]] name = "discv5-cli" diff --git a/src/lib.rs b/src/lib.rs index bd6f82c..fa16961 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,6 @@ #![warn(missing_docs)] #![warn(unused_extern_crates)] #![forbid(unsafe_code)] -#![forbid(where_clauses_object_safety)] //! Core library for the discv5 cli. @@ -19,10 +18,3 @@ pub mod server; /// Utility functions pub mod utils; - -/// A prelude for re-exporting commonly used items. -pub mod prelude { - pub use crate::packet::*; - pub use crate::request_enr::*; - pub use crate::server::*; -} diff --git a/src/main.rs b/src/main.rs index 136ace8..e96a5be 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ #![doc=include_str!("../README.md")] use clap::Parser; -use discv5_cli::{cli, packet, prelude::Packet}; +use discv5_cli::{cli, packet}; #[tokio::main] async fn main() { @@ -19,7 +19,7 @@ async fn main() { Some(cli::Subcommand::RequestEnr(ref request_enr)) => { discv5_cli::request_enr::run(request_enr).await; } - Some(cli::Subcommand::Packet(Packet { subcommand })) => match subcommand { + Some(cli::Subcommand::Packet(packet::Packet { subcommand })) => match subcommand { packet::PacketSubcommand::Decode(ref decode) => { packet::decode(decode); } diff --git a/src/request_enr/enr_ext.rs b/src/request_enr/enr_ext.rs index 4c11320..365d513 100644 --- a/src/request_enr/enr_ext.rs +++ b/src/request_enr/enr_ext.rs @@ -23,6 +23,7 @@ pub trait CombinedKeyPublicExt { } /// Extend ENR CombinedKey for conversion to libp2p keys. +#[allow(dead_code)] pub trait CombinedKeyExt { /// Converts a libp2p key into an ENR combined key. fn from_libp2p(key: &Keypair) -> Result; diff --git a/src/request_enr/mod.rs b/src/request_enr/mod.rs index f936410..816749b 100644 --- a/src/request_enr/mod.rs +++ b/src/request_enr/mod.rs @@ -28,14 +28,14 @@ pub async fn run(req: &RequestEnr) { let enr_key = enr::CombinedKey::generate_secp256k1(); // Build a local ENR - let enr = enr::EnrBuilder::new("v4") + let enr = enr::Builder::default() .ip4(listen_address) .udp4(listen_port) .build(&enr_key) .unwrap(); // Construct the discv5 service - let config = discv5::Discv5ConfigBuilder::new(listen_config).build(); + let config = discv5::ConfigBuilder::new(listen_config).build(); let mut discv5: discv5::Discv5 = discv5::Discv5::new(enr, enr_key, config).unwrap(); // Start the server diff --git a/src/server/enr_build.rs b/src/server/enr_build.rs index adf1406..b7c7094 100644 --- a/src/server/enr_build.rs +++ b/src/server/enr_build.rs @@ -7,7 +7,7 @@ pub fn build( server: &super::command::Server, enr_key: &enr::CombinedKey, ) -> eyre::Result> { - let mut builder = enr::EnrBuilder::new("v4"); + let mut builder = enr::Builder::default(); // Extract params from server config let mut ipv4_address = None; diff --git a/src/server/mod.rs b/src/server/mod.rs index 534b1a3..aa275dc 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -1,4 +1,4 @@ -use discv5::{enr, Discv5, Discv5ConfigBuilder, ListenConfig}; +use discv5::{enr, ConfigBuilder, Discv5, ListenConfig}; use std::{ convert::TryInto, net::{IpAddr, SocketAddrV4, SocketAddrV6}, @@ -59,7 +59,7 @@ pub async fn run(server: &Server) { log::info!("Server listening on {:?}", listen_config); // Build the discv5 server using a default config - let config = Discv5ConfigBuilder::new(listen_config) + let config = ConfigBuilder::new(listen_config) .enr_peer_update_min(peer_update_min.try_into().unwrap()) .build(); let mut discv5 = Discv5::new(enr, enr_key, config).unwrap(); diff --git a/src/server/services/events.rs b/src/server/services/events.rs index 4a26c89..2aebd9c 100644 --- a/src/server/services/events.rs +++ b/src/server/services/events.rs @@ -1,38 +1,38 @@ use std::sync::Arc; -use discv5::{Discv5, Discv5Event}; +use discv5::{Discv5, Event}; /// Streams the discv5 server event stream. pub async fn run(discv5: Arc) { let mut event_stream = discv5.event_stream().await.unwrap(); loop { match event_stream.recv().await { - Some(Discv5Event::SocketUpdated(addr)) => { + Some(Event::SocketUpdated(addr)) => { log::info!("Nodes ENR socket address has been updated to: {:?}", addr); } - Some(Discv5Event::Discovered(enr)) => { + Some(Event::Discovered(enr)) => { log::info!("A peer has been discovered: {}", enr.node_id()); } - Some(discv5::Discv5Event::EnrAdded { enr, .. }) => { + Some(Event::UnverifiableEnr { enr, .. }) => { log::info!( "A peer has been added to the routing table with enr: {}", enr ); } - Some(discv5::Discv5Event::NodeInserted { node_id, .. }) => { + Some(Event::NodeInserted { node_id, .. }) => { log::info!( "A peer has been added to the routing table with node_id: {}", node_id ); } - Some(discv5::Discv5Event::SessionEstablished(enr, addr)) => { + Some(Event::SessionEstablished(enr, addr)) => { log::info!( "A session has been established with peer: {} at address: {}", enr, addr ); } - Some(discv5::Discv5Event::TalkRequest(talk_request)) => { + Some(Event::TalkRequest(talk_request)) => { log::info!( "A talk request has been received from peer: {}", talk_request.node_id()