Skip to content

Commit

Permalink
feat(base-node): add client connection count to status line (#4774)
Browse files Browse the repository at this point in the history
Description
---
Adds client connection count to status line.

Motivation and Context
---
Knowing the number of client connections at a glance is potentially useful and avoids confusion over seeing zero connections when list-connections shows there are active connections.
```
State: Listening, Tip: 18579 (Wed, 05 Oct 2022 05:53:08 +0000), Mempool: 0tx (0g, +/- 0blks), Connections: 10|3, Banned: 10, Messages (last 60s): 22, Rpc: 8/100
```

How Has This Been Tested?
---
Manually
  • Loading branch information
sdbondi committed Oct 5, 2022
1 parent 953b0b7 commit 8339b1d
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions applications/tari_base_node/src/commands/command/status.rs
Expand Up @@ -27,7 +27,6 @@ use async_trait::async_trait;
use chrono::{DateTime, NaiveDateTime, Utc};
use clap::Parser;
use tari_app_utilities::consts;
use tari_comms::connectivity::ConnectivitySelection;
use tokio::time;

use super::{CommandContext, HandleCommand};
Expand Down Expand Up @@ -103,11 +102,15 @@ impl CommandContext {
status_line.add_field("Mempool", "query timed out");
};

let conns = self
.connectivity
.select_connections(ConnectivitySelection::all_nodes(vec![]))
.await?;
status_line.add_field("Connections", conns.len());
let conns = self.connectivity.get_active_connections().await?;
let (num_nodes, num_clients) = conns.iter().fold((0usize, 0usize), |(nodes, clients), conn| {
if conn.peer_features().is_node() {
(nodes + 1, clients)
} else {
(nodes, clients + 1)
}
});
status_line.add_field("Connections", format!("{}|{}", num_nodes, num_clients));
let banned_peers = self.fetch_banned_peers().await?;
status_line.add_field("Banned", banned_peers.len());

Expand Down

0 comments on commit 8339b1d

Please sign in to comment.