mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-15 08:28:20 +00:00
a3552a4b70
## Issue Addressed `node` endpoints in #1434 ## Proposed Changes Implement these: ``` /eth/v1/node/health /eth/v1/node/peers/{peer_id} /eth/v1/node/peers ``` - Add an `Option<Enr>` to `PeerInfo` - Finish implementation of `/eth/v1/node/identity` ## Additional Info - should update the `peers` endpoints when #1764 is resolved Co-authored-by: realbigsean <seananderson33@gmail.com>
76 lines
2.3 KiB
Rust
76 lines
2.3 KiB
Rust
/// This crate contains the main link for lighthouse to rust-libp2p. It therefore re-exports
|
|
/// all required libp2p functionality.
|
|
///
|
|
/// This crate builds and manages the libp2p services required by the beacon node.
|
|
#[macro_use]
|
|
extern crate lazy_static;
|
|
|
|
pub mod behaviour;
|
|
mod config;
|
|
pub mod discovery;
|
|
mod metrics;
|
|
mod peer_manager;
|
|
pub mod rpc;
|
|
mod service;
|
|
pub mod types;
|
|
|
|
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
|
|
use std::str::FromStr;
|
|
|
|
/// Wrapper over a libp2p `PeerId` which implements `Serialize` and `Deserialize`
|
|
#[derive(Clone, Debug)]
|
|
pub struct PeerIdSerialized(libp2p::PeerId);
|
|
|
|
impl From<PeerIdSerialized> for PeerId {
|
|
fn from(peer_id: PeerIdSerialized) -> Self {
|
|
peer_id.0
|
|
}
|
|
}
|
|
|
|
impl FromStr for PeerIdSerialized {
|
|
type Err = String;
|
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
Ok(Self(
|
|
PeerId::from_str(s).map_err(|e| format!("Invalid peer id: {}", e))?,
|
|
))
|
|
}
|
|
}
|
|
|
|
impl Serialize for PeerIdSerialized {
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
where
|
|
S: Serializer,
|
|
{
|
|
serializer.serialize_str(&self.0.to_string())
|
|
}
|
|
}
|
|
|
|
impl<'de> Deserialize<'de> for PeerIdSerialized {
|
|
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
|
where
|
|
D: Deserializer<'de>,
|
|
{
|
|
let s: String = Deserialize::deserialize(deserializer)?;
|
|
Ok(Self(PeerId::from_str(&s).map_err(|e| {
|
|
de::Error::custom(format!("Failed to deserialise peer id: {:?}", e))
|
|
})?))
|
|
}
|
|
}
|
|
|
|
pub use crate::types::{error, Enr, GossipTopic, NetworkGlobals, PubsubMessage, SubnetDiscovery};
|
|
pub use behaviour::{BehaviourEvent, Gossipsub, PeerRequestId, Request, Response};
|
|
pub use config::Config as NetworkConfig;
|
|
pub use config::{GossipsubConfig, GossipsubConfigBuilder, GossipsubMessage};
|
|
pub use discovery::{CombinedKeyExt, EnrExt, Eth2Enr};
|
|
pub use discv5;
|
|
pub use libp2p::gossipsub::{MessageAcceptance, MessageId, Topic, TopicHash};
|
|
pub use libp2p::{core::ConnectedPoint, PeerId, Swarm};
|
|
pub use libp2p::{multiaddr, Multiaddr};
|
|
pub use metrics::scrape_discovery_metrics;
|
|
pub use peer_manager::{
|
|
client::Client, score::PeerAction, ConnectionDirection, PeerConnectionStatus, PeerDB, PeerInfo,
|
|
PeerSyncStatus, SyncInfo,
|
|
};
|
|
pub use service::{load_private_key, Libp2pEvent, Service, NETWORK_KEY_FILENAME};
|