mirror of
https://github.com/mimblewimble/grin.git
synced 2025-01-20 19:11:08 +03:00
add peer capabilities to tui peers screen (#3490)
This commit is contained in:
parent
97425af637
commit
3efe382e9c
3 changed files with 15 additions and 1 deletions
|
@ -26,6 +26,7 @@ use chrono::prelude::*;
|
||||||
|
|
||||||
use crate::chain::SyncStatus;
|
use crate::chain::SyncStatus;
|
||||||
use crate::p2p;
|
use crate::p2p;
|
||||||
|
use crate::p2p::Capabilities;
|
||||||
use grin_core::pow::Difficulty;
|
use grin_core::pow::Difficulty;
|
||||||
|
|
||||||
/// Server state info collection struct, to be passed around into internals
|
/// Server state info collection struct, to be passed around into internals
|
||||||
|
@ -192,6 +193,8 @@ pub struct PeerStats {
|
||||||
pub sent_bytes_per_sec: u64,
|
pub sent_bytes_per_sec: u64,
|
||||||
/// Number of bytes we've received from the peer.
|
/// Number of bytes we've received from the peer.
|
||||||
pub received_bytes_per_sec: u64,
|
pub received_bytes_per_sec: u64,
|
||||||
|
/// Peer advertised capability flags.
|
||||||
|
pub capabilities: Capabilities,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialEq for PeerStats {
|
impl PartialEq for PeerStats {
|
||||||
|
@ -239,6 +242,7 @@ impl PeerStats {
|
||||||
last_seen: peer.info.last_seen(),
|
last_seen: peer.info.last_seen(),
|
||||||
sent_bytes_per_sec: peer.last_min_sent_bytes().unwrap_or(0) / 60,
|
sent_bytes_per_sec: peer.last_min_sent_bytes().unwrap_or(0) / 60,
|
||||||
received_bytes_per_sec: peer.last_min_received_bytes().unwrap_or(0) / 60,
|
received_bytes_per_sec: peer.last_min_received_bytes().unwrap_or(0) / 60,
|
||||||
|
capabilities: peer.info.capabilities,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ pub enum PeerColumn {
|
||||||
Direction,
|
Direction,
|
||||||
Version,
|
Version,
|
||||||
UserAgent,
|
UserAgent,
|
||||||
|
Capabilities,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PeerColumn {
|
impl PeerColumn {
|
||||||
|
@ -53,6 +54,7 @@ impl PeerColumn {
|
||||||
PeerColumn::TotalDifficulty => "Total Difficulty",
|
PeerColumn::TotalDifficulty => "Total Difficulty",
|
||||||
PeerColumn::Direction => "Direction",
|
PeerColumn::Direction => "Direction",
|
||||||
PeerColumn::UserAgent => "User Agent",
|
PeerColumn::UserAgent => "User Agent",
|
||||||
|
PeerColumn::Capabilities => "Capabilities",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,6 +84,7 @@ impl TableViewItem<PeerColumn> for PeerStats {
|
||||||
PeerColumn::Direction => self.direction.clone(),
|
PeerColumn::Direction => self.direction.clone(),
|
||||||
PeerColumn::Version => format!("{}", self.version),
|
PeerColumn::Version => format!("{}", self.version),
|
||||||
PeerColumn::UserAgent => self.user_agent.clone(),
|
PeerColumn::UserAgent => self.user_agent.clone(),
|
||||||
|
PeerColumn::Capabilities => format!("{}", self.capabilities.bits()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,6 +118,10 @@ impl TableViewItem<PeerColumn> for PeerStats {
|
||||||
PeerColumn::Direction => self.direction.cmp(&other.direction).then(sort_by_addr()),
|
PeerColumn::Direction => self.direction.cmp(&other.direction).then(sort_by_addr()),
|
||||||
PeerColumn::Version => self.version.cmp(&other.version).then(sort_by_addr()),
|
PeerColumn::Version => self.version.cmp(&other.version).then(sort_by_addr()),
|
||||||
PeerColumn::UserAgent => self.user_agent.cmp(&other.user_agent).then(sort_by_addr()),
|
PeerColumn::UserAgent => self.user_agent.cmp(&other.user_agent).then(sort_by_addr()),
|
||||||
|
PeerColumn::Capabilities => self
|
||||||
|
.capabilities
|
||||||
|
.cmp(&other.capabilities)
|
||||||
|
.then(sort_by_addr()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +140,8 @@ impl TUIPeerView {
|
||||||
.column(PeerColumn::TotalDifficulty, "Total Difficulty", |c| {
|
.column(PeerColumn::TotalDifficulty, "Total Difficulty", |c| {
|
||||||
c.width_percent(24)
|
c.width_percent(24)
|
||||||
})
|
})
|
||||||
.column(PeerColumn::Version, "Proto", |c| c.width_percent(6))
|
.column(PeerColumn::Version, "Proto", |c| c.width_percent(4))
|
||||||
|
.column(PeerColumn::Capabilities, "Capab", |c| c.width_percent(4))
|
||||||
.column(PeerColumn::UserAgent, "User Agent", |c| c.width_percent(18));
|
.column(PeerColumn::UserAgent, "User Agent", |c| c.width_percent(18));
|
||||||
let peer_status_view = ResizedView::with_full_screen(
|
let peer_status_view = ResizedView::with_full_screen(
|
||||||
LinearLayout::new(Orientation::Vertical)
|
LinearLayout::new(Orientation::Vertical)
|
||||||
|
|
|
@ -995,6 +995,7 @@ impl<H: Copy + Clone + 'static> TableColumn<H> {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
use crate::p2p::Capabilities;
|
||||||
use crate::tui::peers::PeerColumn;
|
use crate::tui::peers::PeerColumn;
|
||||||
use crate::tui::table::TableView;
|
use crate::tui::table::TableView;
|
||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
|
@ -1060,6 +1061,7 @@ mod test {
|
||||||
last_seen: Utc::now(),
|
last_seen: Utc::now(),
|
||||||
sent_bytes_per_sec: 0,
|
sent_bytes_per_sec: 0,
|
||||||
received_bytes_per_sec: 0,
|
received_bytes_per_sec: 0,
|
||||||
|
capabilities: Capabilities::FULL_NODE,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue