mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 23:04:53 +00:00
Allow bootstrapper to scrape libp2p address
This commit is contained in:
@@ -1,9 +1,28 @@
|
||||
use crate::{success_response, ApiError, ApiResult, NetworkService};
|
||||
use beacon_chain::BeaconChainTypes;
|
||||
use eth2_libp2p::{Enr, PeerId};
|
||||
use eth2_libp2p::{Enr, Multiaddr, PeerId};
|
||||
use hyper::{Body, Request};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// HTTP handle to return the list of libp2p multiaddr the client is listening on.
|
||||
///
|
||||
/// Returns a list of `Multiaddr`, serialized according to their `serde` impl.
|
||||
pub fn get_listen_addresses<T: BeaconChainTypes + Send + Sync + 'static>(
|
||||
req: Request<Body>,
|
||||
) -> ApiResult {
|
||||
let network = req
|
||||
.extensions()
|
||||
.get::<Arc<NetworkService<T>>>()
|
||||
.ok_or_else(|| ApiError::ServerError("NetworkService extension missing".to_string()))?;
|
||||
|
||||
let multiaddresses: Vec<Multiaddr> = network.listen_multiaddrs();
|
||||
|
||||
Ok(success_response(Body::from(
|
||||
serde_json::to_string(&multiaddresses)
|
||||
.map_err(|e| ApiError::ServerError(format!("Unable to serialize Enr: {:?}", e)))?,
|
||||
)))
|
||||
}
|
||||
|
||||
/// HTTP handle to return the Discv5 ENR from the client's libp2p service.
|
||||
///
|
||||
/// ENR is encoded as base64 string.
|
||||
|
||||
Reference in New Issue
Block a user