Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add peer capabilities to tui peers screen #3490

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions servers/src/common/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use chrono::prelude::*;

use crate::chain::SyncStatus;
use crate::p2p;
use crate::p2p::Capabilities;
use grin_core::pow::Difficulty;

/// Server state info collection struct, to be passed around into internals
Expand Down Expand Up @@ -192,6 +193,8 @@ pub struct PeerStats {
pub sent_bytes_per_sec: u64,
/// Number of bytes we've received from the peer.
pub received_bytes_per_sec: u64,
/// Peer advertised capability flags.
pub capabilities: Capabilities,
}

impl PartialEq for PeerStats {
Expand Down Expand Up @@ -239,6 +242,7 @@ impl PeerStats {
last_seen: peer.info.last_seen(),
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,
capabilities: peer.info.capabilities,
}
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/bin/tui/peers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ pub enum PeerColumn {
Direction,
Version,
UserAgent,
Capabilities,
}

impl PeerColumn {
Expand All @@ -53,6 +54,7 @@ impl PeerColumn {
PeerColumn::TotalDifficulty => "Total Difficulty",
PeerColumn::Direction => "Direction",
PeerColumn::UserAgent => "User Agent",
PeerColumn::Capabilities => "Capabilities",
}
}
}
Expand Down Expand Up @@ -82,6 +84,7 @@ impl TableViewItem<PeerColumn> for PeerStats {
PeerColumn::Direction => self.direction.clone(),
PeerColumn::Version => format!("{}", self.version),
PeerColumn::UserAgent => self.user_agent.clone(),
PeerColumn::Capabilities => format!("{}", self.capabilities.bits()),
}
}

Expand Down Expand Up @@ -115,6 +118,10 @@ impl TableViewItem<PeerColumn> for PeerStats {
PeerColumn::Direction => self.direction.cmp(&other.direction).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::Capabilities => self
.capabilities
.cmp(&other.capabilities)
.then(sort_by_addr()),
}
}
}
Expand All @@ -133,7 +140,8 @@ impl TUIPeerView {
.column(PeerColumn::TotalDifficulty, "Total Difficulty", |c| {
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));
let peer_status_view = ResizedView::with_full_screen(
LinearLayout::new(Orientation::Vertical)
Expand Down
2 changes: 2 additions & 0 deletions src/bin/tui/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,6 +995,7 @@ impl<H: Copy + Clone + 'static> TableColumn<H> {

#[cfg(test)]
mod test {
use crate::p2p::Capabilities;
use crate::tui::peers::PeerColumn;
use crate::tui::table::TableView;
use chrono::Utc;
Expand Down Expand Up @@ -1060,6 +1061,7 @@ mod test {
last_seen: Utc::now(),
sent_bytes_per_sec: 0,
received_bytes_per_sec: 0,
capabilities: Capabilities::FULL_NODE,
}
}
}
Expand Down