@@ -5,20 +5,23 @@ use std::pin::Pin;
5
5
use std:: task:: { Context , Poll } ;
6
6
use std:: time:: Instant ;
7
7
8
- use discv5:: { Discv5 , Enr } ;
9
8
use discv5:: enr:: { CombinedKey , NodeId } ;
10
9
use discv5:: libp2p_identity:: { Keypair , PeerId } ;
11
10
use discv5:: multiaddr:: Multiaddr ;
12
- use futures:: { StreamExt , TryFutureExt } ;
13
- use futures:: FutureExt ;
11
+ use discv5:: { Discv5 , Enr } ;
14
12
use futures:: stream:: FuturesUnordered ;
15
- use libp2p:: core:: Endpoint ;
13
+ use futures:: FutureExt ;
14
+ use futures:: { StreamExt , TryFutureExt } ;
16
15
use libp2p:: core:: transport:: PortUse ;
17
- use libp2p:: swarm :: { ConnectionDenied , ConnectionId , FromSwarm , NetworkBehaviour , THandler , THandlerInEvent , THandlerOutEvent , ToSwarm } ;
16
+ use libp2p:: core :: Endpoint ;
18
17
use libp2p:: swarm:: dummy:: ConnectionHandler ;
19
- use lighthouse_network:: { CombinedKeyExt , Subnet } ;
20
- use lighthouse_network:: discovery:: DiscoveredPeers ;
18
+ use libp2p:: swarm:: {
19
+ ConnectionDenied , ConnectionId , FromSwarm , NetworkBehaviour , THandler , THandlerInEvent ,
20
+ THandlerOutEvent , ToSwarm ,
21
+ } ;
21
22
use lighthouse_network:: discovery:: enr_ext:: { QUIC6_ENR_KEY , QUIC_ENR_KEY } ;
23
+ use lighthouse_network:: discovery:: DiscoveredPeers ;
24
+ use lighthouse_network:: { CombinedKeyExt , Subnet } ;
22
25
use tokio:: sync:: mpsc;
23
26
24
27
use crate :: Config ;
@@ -86,11 +89,7 @@ pub struct Discovery {
86
89
}
87
90
88
91
impl Discovery {
89
- pub async fn new (
90
- local_keypair : Keypair ,
91
- network_config : & Config ,
92
- ) -> Result < Self , String > {
93
-
92
+ pub async fn new ( local_keypair : Keypair , network_config : & Config ) -> Result < Self , String > {
94
93
let _enr_dir = match network_config. network_dir . to_str ( ) {
95
94
Some ( path) => String :: from ( path) ,
96
95
None => String :: from ( "" ) ,
@@ -101,7 +100,8 @@ impl Discovery {
101
100
// "quic4" => ?local_enr.quic4(), "quic6" => ?local_enr.quic6()
102
101
// );
103
102
104
- let discv5_listen_config = discv5:: ListenConfig :: from_ip ( Ipv4Addr :: UNSPECIFIED . into ( ) , 9000 ) ;
103
+ let discv5_listen_config =
104
+ discv5:: ListenConfig :: from_ip ( Ipv4Addr :: UNSPECIFIED . into ( ) , 9000 ) ;
105
105
106
106
// discv5 configuration
107
107
let discv5_config = discv5:: ConfigBuilder :: new ( discv5_listen_config) . build ( ) ;
@@ -296,7 +296,7 @@ impl Discovery {
296
296
//debug!(self.log, "Discovery query yielded no results.");
297
297
}
298
298
Ok ( r) => {
299
- // debug!(self.log, "Discovery query completed"; "peers_found" => r.len());
299
+ // debug!(self.log, "Discovery query completed"; "peers_found" => r.len());
300
300
let results = r
301
301
. into_iter ( )
302
302
. map ( |enr| {
@@ -327,30 +327,48 @@ impl Discovery {
327
327
}
328
328
None
329
329
}
330
-
331
330
}
332
331
333
332
impl NetworkBehaviour for Discovery {
334
333
// Discovery is not a real NetworkBehaviour...
335
334
type ConnectionHandler = ConnectionHandler ;
336
335
type ToSwarm = DiscoveredPeers ;
337
336
338
- fn handle_established_inbound_connection ( & mut self , _connection_id : ConnectionId , _peer : PeerId , _local_addr : & Multiaddr , _remote_addr : & Multiaddr ) -> Result < THandler < Self > , ConnectionDenied > {
337
+ fn handle_established_inbound_connection (
338
+ & mut self ,
339
+ _connection_id : ConnectionId ,
340
+ _peer : PeerId ,
341
+ _local_addr : & Multiaddr ,
342
+ _remote_addr : & Multiaddr ,
343
+ ) -> Result < THandler < Self > , ConnectionDenied > {
339
344
Ok ( ConnectionHandler )
340
345
}
341
346
342
- fn handle_established_outbound_connection ( & mut self , _connection_id : ConnectionId , _peer : PeerId , _addr : & Multiaddr , _role_override : Endpoint , _port_use : PortUse ) -> Result < THandler < Self > , ConnectionDenied > {
347
+ fn handle_established_outbound_connection (
348
+ & mut self ,
349
+ _connection_id : ConnectionId ,
350
+ _peer : PeerId ,
351
+ _addr : & Multiaddr ,
352
+ _role_override : Endpoint ,
353
+ _port_use : PortUse ,
354
+ ) -> Result < THandler < Self > , ConnectionDenied > {
343
355
Ok ( ConnectionHandler )
344
356
}
345
357
346
- fn on_swarm_event ( & mut self , _event : FromSwarm ) {
358
+ fn on_swarm_event ( & mut self , _event : FromSwarm ) { }
347
359
360
+ fn on_connection_handler_event (
361
+ & mut self ,
362
+ _peer_id : PeerId ,
363
+ _connection_id : ConnectionId ,
364
+ _event : THandlerOutEvent < Self > ,
365
+ ) {
348
366
}
349
367
350
- fn on_connection_handler_event ( & mut self , _peer_id : PeerId , _connection_id : ConnectionId , _event : THandlerOutEvent < Self > ) {
351
- }
352
-
353
- fn poll ( & mut self , cx : & mut Context < ' _ > ) -> Poll < ToSwarm < Self :: ToSwarm , THandlerInEvent < Self > > > {
368
+ fn poll (
369
+ & mut self ,
370
+ cx : & mut Context < ' _ > ,
371
+ ) -> Poll < ToSwarm < Self :: ToSwarm , THandlerInEvent < Self > > > {
354
372
if !self . started {
355
373
return Poll :: Pending ;
356
374
}
@@ -368,10 +386,7 @@ impl NetworkBehaviour for Discovery {
368
386
}
369
387
370
388
/// Builds a anchor ENR given a `network::Config`.
371
- pub fn build_enr (
372
- enr_key : & CombinedKey ,
373
- config : & Config ,
374
- ) -> Result < Enr , String > {
389
+ pub fn build_enr ( enr_key : & CombinedKey , config : & Config ) -> Result < Enr , String > {
375
390
let mut builder = discv5:: enr:: Enr :: builder ( ) ;
376
391
let ( maybe_ipv4_address, maybe_ipv6_address) = & config. enr_address ;
377
392
0 commit comments