mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
## Issue Addressed NA ## Proposed Changes Shift practically all HTTP endpoint handlers to the blocking executor (some very light tasks are left on the core executor). ## Additional Info This PR covers the `rest_api` which will soon be refactored to suit the standard API. As such, I've cut a few corners and left some existing issues open in this patch. What I have done here should leave the API in state that is not necessary *exactly* the same, but good enough for us to run validators with. Specifically, the number of blocking workers that can be spawned is unbounded and I have not implemented a queue; this will need to be fixed when we implement the standard API.
49 lines
1.3 KiB
Rust
49 lines
1.3 KiB
Rust
//! This contains a collection of lighthouse specific HTTP endpoints.
|
|
|
|
use crate::{ApiError, Context};
|
|
use beacon_chain::BeaconChainTypes;
|
|
use eth2_libp2p::PeerInfo;
|
|
use serde::Serialize;
|
|
use std::sync::Arc;
|
|
use types::EthSpec;
|
|
|
|
/// Returns all known peers and corresponding information
|
|
pub fn peers<T: BeaconChainTypes>(ctx: Arc<Context<T>>) -> Result<Vec<Peer<T::EthSpec>>, ApiError> {
|
|
Ok(ctx
|
|
.network_globals
|
|
.peers
|
|
.read()
|
|
.peers()
|
|
.map(|(peer_id, peer_info)| Peer {
|
|
peer_id: peer_id.to_string(),
|
|
peer_info: peer_info.clone(),
|
|
})
|
|
.collect())
|
|
}
|
|
|
|
/// Returns all known connected peers and their corresponding information
|
|
pub fn connected_peers<T: BeaconChainTypes>(
|
|
ctx: Arc<Context<T>>,
|
|
) -> Result<Vec<Peer<T::EthSpec>>, ApiError> {
|
|
Ok(ctx
|
|
.network_globals
|
|
.peers
|
|
.read()
|
|
.connected_peers()
|
|
.map(|(peer_id, peer_info)| Peer {
|
|
peer_id: peer_id.to_string(),
|
|
peer_info: peer_info.clone(),
|
|
})
|
|
.collect())
|
|
}
|
|
|
|
/// Information returned by `peers` and `connected_peers`.
|
|
#[derive(Clone, Debug, Serialize)]
|
|
#[serde(bound = "T: EthSpec")]
|
|
pub struct Peer<T: EthSpec> {
|
|
/// The Peer's ID
|
|
peer_id: String,
|
|
/// The PeerInfo associated with the peer.
|
|
peer_info: PeerInfo<T>,
|
|
}
|