This repository has been archived by the owner on Jun 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tendermint-rs: /net_info RPC endpoint
- Loading branch information
1 parent
2753d24
commit 55f1404
Showing
6 changed files
with
450 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
//! Tendermint JSONRPC endpoints | ||
|
||
mod net_info; | ||
mod status; | ||
|
||
pub use net_info::{NetInfoRequest, NetInfoResponse}; | ||
pub use status::{StatusRequest, StatusResponse}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
//! RPC wrapper for `/net_info` endpoint | ||
|
||
use crate::{channel::Channel, node, rpc, Timestamp}; | ||
use serde::{Deserialize, Serialize}; | ||
use std::{ | ||
fmt::{self, Display}, | ||
net::IpAddr, | ||
time::Duration, | ||
}; | ||
|
||
/// Request the status of the node | ||
#[derive(Debug, Default)] | ||
pub struct NetInfoRequest; | ||
|
||
impl rpc::Request for NetInfoRequest { | ||
type Response = NetInfoResponse; | ||
|
||
fn path(&self) -> rpc::request::Path { | ||
"/net_info".parse().unwrap() | ||
} | ||
} | ||
|
||
/// Status responses | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct NetInfoResponse { | ||
/// Are we presently listening? | ||
pub listening: bool, | ||
|
||
/// Active listeners | ||
pub listeners: Vec<Listener>, | ||
|
||
/// Number of connected peers | ||
#[serde( | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
pub n_peers: u64, | ||
|
||
/// Peer information | ||
pub peers: Vec<PeerInfo>, | ||
} | ||
|
||
impl rpc::Response for NetInfoResponse {} | ||
|
||
/// Listener information | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Listener(String); | ||
|
||
impl Display for Listener { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
/// Peer information | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct PeerInfo { | ||
/// Node information | ||
pub node_info: node::Info, | ||
|
||
/// Is this an outbound connection? | ||
pub is_outbound: bool, | ||
|
||
/// Connection status | ||
pub connection_status: ConnectionStatus, | ||
|
||
/// Remote IP address | ||
pub remote_ip: IpAddr, | ||
} | ||
|
||
/// Connection status information | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct ConnectionStatus { | ||
/// Duration of this connection | ||
#[serde( | ||
rename = "Duration", | ||
serialize_with = "rpc::response::serialize_duration", | ||
deserialize_with = "rpc::response::parse_duration" | ||
)] | ||
pub duration: Duration, | ||
|
||
/// Send monitor | ||
#[serde(rename = "SendMonitor")] | ||
pub send_monitor: Monitor, | ||
|
||
/// Receive monitor | ||
#[serde(rename = "RecvMonitor")] | ||
pub recv_monitor: Monitor, | ||
|
||
/// Channels | ||
#[serde(rename = "Channels")] | ||
pub channels: Vec<Channel>, | ||
} | ||
|
||
/// Monitor | ||
#[derive(Clone, Debug, Deserialize, Serialize)] | ||
pub struct Monitor { | ||
/// Is this monitor active? | ||
#[serde(rename = "Active")] | ||
pub active: bool, | ||
|
||
/// When the monitor started | ||
#[serde(rename = "Start")] | ||
pub start: Timestamp, | ||
|
||
/// Duration of this monitor | ||
#[serde( | ||
rename = "Duration", | ||
serialize_with = "rpc::response::serialize_duration", | ||
deserialize_with = "rpc::response::parse_duration" | ||
)] | ||
pub duration: Duration, | ||
|
||
/// Idle duration for this monitor | ||
#[serde( | ||
rename = "Idle", | ||
serialize_with = "rpc::response::serialize_duration", | ||
deserialize_with = "rpc::response::parse_duration" | ||
)] | ||
pub idle: Duration, | ||
|
||
/// Bytes | ||
#[serde( | ||
rename = "Bytes", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
bytes: u64, | ||
|
||
/// Samples | ||
#[serde( | ||
rename = "Samples", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
samples: u64, | ||
|
||
/// Instant rate | ||
#[serde( | ||
rename = "InstRate", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
inst_rate: u64, | ||
|
||
/// Current rate | ||
#[serde( | ||
rename = "CurRate", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
cur_rate: u64, | ||
|
||
/// Average rate | ||
#[serde( | ||
rename = "AvgRate", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
avg_rate: u64, | ||
|
||
/// Peak rate | ||
#[serde( | ||
rename = "PeakRate", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
peak_rate: u64, | ||
|
||
/// Bytes remaining | ||
#[serde( | ||
rename = "BytesRem", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
bytes_rem: u64, | ||
|
||
/// Time remaining | ||
#[serde( | ||
rename = "TimeRem", | ||
serialize_with = "rpc::response::serialize_u64", | ||
deserialize_with = "rpc::response::parse_u64" | ||
)] | ||
time_rem: u64, | ||
|
||
/// Progress | ||
#[serde(rename = "Progress")] | ||
progress: u64, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.