From a67cfa5af69161a2270e7f5e553cea48e8afbe0e Mon Sep 17 00:00:00 2001 From: = <=> Date: Sun, 27 Oct 2024 12:12:08 +0100 Subject: [PATCH 1/2] [feat] Made Enr generic with Enr as default --- src/discv5.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/discv5.rs b/src/discv5.rs index 626e9117..7e440fb5 100644 --- a/src/discv5.rs +++ b/src/discv5.rs @@ -82,7 +82,7 @@ pub enum Event { /// The main Discv5 Service struct. This provides the user-level API for performing queries and /// interacting with the underlying service. -pub struct Discv5

+pub struct Discv5

where P: ProtocolIdentity, { @@ -96,17 +96,17 @@ where /// The local ENR of the server. local_enr: Arc>, /// The key associated with the local ENR, required for updating the local ENR. - enr_key: Arc>, + enr_key: Arc>, // Type of socket we are using ip_mode: IpMode, /// Phantom for the protocol id. _phantom: PhantomData

, } -impl Discv5

{ +impl Discv5 { pub fn new( local_enr: Enr, - enr_key: CombinedKey, + enr_key: K, mut config: Config, ) -> Result { // ensure the keypair matches the one that signed the enr. From 9e9cb6655fc2113732eef0d486ec4dbe1dc1a011 Mon Sep 17 00:00:00 2001 From: = <=> Date: Mon, 28 Oct 2024 22:02:42 +0100 Subject: [PATCH 2/2] fix : Lint errors --- src/discv5.rs | 14 +++++++++----- src/service.rs | 5 +++-- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/discv5.rs b/src/discv5.rs index 7e440fb5..5120fdb5 100644 --- a/src/discv5.rs +++ b/src/discv5.rs @@ -23,7 +23,7 @@ use crate::{ service::{QueryKind, Service, ServiceRequest, TalkRequest}, Config, DefaultProtocolId, Enr, IpMode, }; -use enr::{CombinedKey, EnrKey, Error as EnrError, NodeId}; +use enr::{CombinedKey, CombinedPublicKey ,EnrKey, Error as EnrError, NodeId}; use parking_lot::RwLock; use std::{ future::Future, @@ -82,9 +82,10 @@ pub enum Event { /// The main Discv5 Service struct. This provides the user-level API for performing queries and /// interacting with the underlying service. -pub struct Discv5

+pub struct Discv5

where P: ProtocolIdentity, + K: EnrKey, { config: Config, /// The channel to make requests from the main service. @@ -102,8 +103,11 @@ where /// Phantom for the protocol id. _phantom: PhantomData

, } - -impl Discv5 { +impl Discv5 +where + P: ProtocolIdentity, + K: EnrKey, + { pub fn new( local_enr: Enr, enr_key: K, @@ -737,7 +741,7 @@ impl Discv5 { } } -impl Drop for Discv5

{ +impl> Drop for Discv5 { fn drop(&mut self) { self.shutdown(); } diff --git a/src/service.rs b/src/service.rs index 8b409398..ecc680ef 100644 --- a/src/service.rs +++ b/src/service.rs @@ -17,6 +17,7 @@ use self::{ ip_vote::IpVote, query_info::{QueryInfo, QueryType}, }; +use enr::EnrKey; use crate::{ error::{RequestError, ResponseError}, handler::{Handler, HandlerIn, HandlerOut}, @@ -268,7 +269,7 @@ impl Default for NodesResponse { } } -impl Service { +impl Service { /// Builds the `Service` main struct. /// /// `local_enr` is the `ENR` representing the local node. This contains node identifying information, such @@ -276,7 +277,7 @@ impl Service { /// mechanism. pub async fn spawn( local_enr: Arc>, - enr_key: Arc>, + enr_key: Arc>, kbuckets: Arc>>, config: Config, ) -> Result<(oneshot::Sender<()>, mpsc::Sender), std::io::Error> {