mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-20 22:38:34 +00:00
Allow bootstrapper to scrape libp2p address
This commit is contained in:
@@ -5,7 +5,7 @@ use beacon_chain::{BeaconChain, BeaconChainTypes};
|
||||
use core::marker::PhantomData;
|
||||
use eth2_libp2p::Service as LibP2PService;
|
||||
use eth2_libp2p::Topic;
|
||||
use eth2_libp2p::{Enr, Libp2pEvent, PeerId};
|
||||
use eth2_libp2p::{Enr, Libp2pEvent, Multiaddr, PeerId, Swarm};
|
||||
use eth2_libp2p::{PubsubMessage, RPCEvent};
|
||||
use futures::prelude::*;
|
||||
use futures::Stream;
|
||||
@@ -64,6 +64,8 @@ impl<T: BeaconChainTypes + 'static> Service<T> {
|
||||
Ok((Arc::new(network_service), network_send))
|
||||
}
|
||||
|
||||
/// Returns the local ENR from the underlying Discv5 behaviour that external peers may connect
|
||||
/// to.
|
||||
pub fn local_enr(&self) -> Enr {
|
||||
self.libp2p_service
|
||||
.lock()
|
||||
@@ -73,10 +75,19 @@ impl<T: BeaconChainTypes + 'static> Service<T> {
|
||||
.clone()
|
||||
}
|
||||
|
||||
/// Returns the list of `Multiaddr` that the underlying libp2p instance is listening on.
|
||||
pub fn listen_multiaddrs(&self) -> Vec<Multiaddr> {
|
||||
Swarm::listeners(&self.libp2p_service.lock().swarm)
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the number of libp2p connected peers.
|
||||
pub fn connected_peers(&self) -> usize {
|
||||
self.libp2p_service.lock().swarm.connected_peers()
|
||||
}
|
||||
|
||||
/// Returns the set of `PeerId` that are connected via libp2p.
|
||||
pub fn connected_peer_set(&self) -> Vec<PeerId> {
|
||||
self.libp2p_service
|
||||
.lock()
|
||||
@@ -88,6 +99,7 @@ impl<T: BeaconChainTypes + 'static> Service<T> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Provides a reference to the underlying libp2p service.
|
||||
pub fn libp2p_service(&self) -> Arc<Mutex<LibP2PService>> {
|
||||
self.libp2p_service.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user