2
2
//!
3
3
//! This provides the main struct for running and interfacing with a discovery v5 server.
4
4
//!
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.
8
8
//!
9
9
//! Once a [`Discv5`] struct has been created the service is started by running the [`Discv5::start`]
10
10
//! functions with a UDP socket. This will start a discv5 server in the background listening on the
13
13
//! The server can be shutdown using the [`Discv5::shutdown`] function.
14
14
15
15
use crate :: {
16
- error:: { Discv5Error , QueryError , RequestError } ,
16
+ error:: { Error , QueryError , RequestError } ,
17
17
kbucket:: {
18
18
self , ConnectionDirection , ConnectionState , FailureReason , InsertResult , KBucketsTable ,
19
19
NodeStatus , UpdateResult ,
20
20
} ,
21
21
node_info:: NodeContact ,
22
22
packet:: ProtocolIdentity ,
23
23
service:: { QueryKind , Service , ServiceRequest , TalkRequest } ,
24
- DefaultProtocolId , Discv5Config , Enr , IpMode ,
24
+ Config , DefaultProtocolId , Enr , IpMode ,
25
25
} ;
26
26
use enr:: { CombinedKey , EnrError , EnrKey , NodeId } ;
27
27
use parking_lot:: RwLock ;
@@ -53,7 +53,7 @@ mod test;
53
53
54
54
/// Events that can be produced by the `Discv5` event stream.
55
55
#[ derive( Debug ) ]
56
- pub enum Discv5Event {
56
+ pub enum Event {
57
57
/// A node has been discovered from a FINDNODES request.
58
58
///
59
59
/// The ENR of the node is returned. Various properties can be derived from the ENR.
@@ -81,7 +81,7 @@ pub struct Discv5<P = DefaultProtocolId>
81
81
where
82
82
P : ProtocolIdentity ,
83
83
{
84
- config : Discv5Config ,
84
+ config : Config ,
85
85
/// The channel to make requests from the main service.
86
86
service_channel : Option < mpsc:: Sender < ServiceRequest > > ,
87
87
/// The exit channel to shutdown the underlying service.
@@ -102,7 +102,7 @@ impl<P: ProtocolIdentity> Discv5<P> {
102
102
pub fn new (
103
103
local_enr : Enr ,
104
104
enr_key : CombinedKey ,
105
- mut config : Discv5Config ,
105
+ mut config : Config ,
106
106
) -> Result < Self , & ' static str > {
107
107
// ensure the keypair matches the one that signed the enr.
108
108
if local_enr. public_key ( ) != enr_key. public ( ) {
@@ -154,10 +154,10 @@ impl<P: ProtocolIdentity> Discv5<P> {
154
154
}
155
155
156
156
/// 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 > {
158
158
if self . service_channel . is_some ( ) {
159
159
warn ! ( "Service is already started" ) ;
160
- return Err ( Discv5Error :: ServiceAlreadyStarted ) ;
160
+ return Err ( Error :: ServiceAlreadyStarted ) ;
161
161
}
162
162
163
163
// create the main service
@@ -670,7 +670,7 @@ impl<P: ProtocolIdentity> Discv5<P> {
670
670
/// Creates an event stream channel which can be polled to receive Discv5 events.
671
671
pub fn event_stream (
672
672
& self ,
673
- ) -> impl Future < Output = Result < mpsc:: Receiver < Discv5Event > , Discv5Error > > + ' static {
673
+ ) -> impl Future < Output = Result < mpsc:: Receiver < Event > , Error > > + ' static {
674
674
let channel = self . clone_channel ( ) ;
675
675
676
676
async move {
@@ -682,20 +682,18 @@ impl<P: ProtocolIdentity> Discv5<P> {
682
682
channel
683
683
. send ( event)
684
684
. await
685
- . map_err ( |_| Discv5Error :: ServiceChannelClosed ) ?;
685
+ . map_err ( |_| Error :: ServiceChannelClosed ) ?;
686
686
687
- callback_recv
688
- . await
689
- . map_err ( |_| Discv5Error :: ServiceChannelClosed )
687
+ callback_recv. await . map_err ( |_| Error :: ServiceChannelClosed )
690
688
}
691
689
}
692
690
693
691
/// 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 > {
695
693
if let Some ( channel) = self . service_channel . as_ref ( ) {
696
694
Ok ( channel. clone ( ) )
697
695
} else {
698
- Err ( Discv5Error :: ServiceNotStarted )
696
+ Err ( Error :: ServiceNotStarted )
699
697
}
700
698
}
701
699
}
0 commit comments