mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-10 04:01:51 +00:00
Add /network/listen_port API endpoint
This commit is contained in:
@@ -18,6 +18,7 @@ use tokio::sync::{mpsc, oneshot};
|
||||
/// Service that handles communication between internal services and the eth2_libp2p network service.
|
||||
pub struct Service<T: BeaconChainTypes> {
|
||||
libp2p_service: Arc<Mutex<LibP2PService>>,
|
||||
libp2p_port: u16,
|
||||
_libp2p_exit: oneshot::Sender<()>,
|
||||
_network_send: mpsc::UnboundedSender<NetworkMessage>,
|
||||
_phantom: PhantomData<T>, //message_handler: MessageHandler,
|
||||
@@ -56,6 +57,7 @@ impl<T: BeaconChainTypes + 'static> Service<T> {
|
||||
)?;
|
||||
let network_service = Service {
|
||||
libp2p_service,
|
||||
libp2p_port: config.libp2p_port,
|
||||
_libp2p_exit: libp2p_exit,
|
||||
_network_send: network_send.clone(),
|
||||
_phantom: PhantomData,
|
||||
@@ -87,6 +89,11 @@ impl<T: BeaconChainTypes + 'static> Service<T> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the libp2p port that this node has been configured to listen using.
|
||||
pub fn listen_port(&self) -> u16 {
|
||||
self.libp2p_port
|
||||
}
|
||||
|
||||
/// Returns the number of libp2p connected peers.
|
||||
pub fn connected_peers(&self) -> usize {
|
||||
self.libp2p_service.lock().swarm.connected_peers()
|
||||
|
||||
Reference in New Issue
Block a user