mirror of
https://github.com/mimblewimble/grin.git
synced 2025-05-08 10:11:14 +03:00
List connected peers (#680)
* Removed unused crates * Add listconnectedpeers in grin client
This commit is contained in:
parent
62e44fa936
commit
53c85de43a
3 changed files with 42 additions and 8 deletions
|
@ -13,18 +13,17 @@ path = "src/bin/grin.rs"
|
|||
|
||||
[dependencies]
|
||||
grin_api = { path = "./api" }
|
||||
grin_wallet = { path = "./wallet" }
|
||||
grin_keychain = { path = "./keychain" }
|
||||
grin_grin = { path = "./grin" }
|
||||
grin_config = { path = "./config" }
|
||||
grin_core = { path = "./core" }
|
||||
grin_pow = { path = "./pow"}
|
||||
grin_grin = { path = "./grin" }
|
||||
grin_keychain = { path = "./keychain" }
|
||||
grin_p2p = { path = "./p2p"}
|
||||
grin_util = { path = "./util"}
|
||||
grin_wallet = { path = "./wallet" }
|
||||
blake2-rfc = "~0.2.17"
|
||||
clap = "^2.23.3"
|
||||
daemonize = "^0.2.3"
|
||||
serde = "~1.0.8"
|
||||
serde_derive = "~1.0.8"
|
||||
serde_json = "~1.0.7"
|
||||
slog = { version = "^2.0.12", features = ["max_level_trace", "release_max_level_trace"] }
|
||||
term = "~0.4.6"
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
extern crate term;
|
||||
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use api;
|
||||
use p2p;
|
||||
use grin::ServerConfig;
|
||||
|
||||
pub fn show_status(config: &ServerConfig) {
|
||||
|
@ -35,7 +37,8 @@ pub fn show_status(config: &ServerConfig) {
|
|||
writeln!(e, "Chain height: {}", status.tip.height).unwrap();
|
||||
writeln!(e, "Last block hash: {}", status.tip.last_block_pushed).unwrap();
|
||||
writeln!(e, "Previous block hash: {}", status.tip.prev_block_to_last).unwrap();
|
||||
writeln!(e, "Total difficulty: {}", status.tip.total_difficulty).unwrap()
|
||||
writeln!(e, "Total difficulty: {}", status.tip.total_difficulty).unwrap();
|
||||
|
||||
}
|
||||
Err(_) => writeln!(
|
||||
e,
|
||||
|
@ -43,7 +46,7 @@ pub fn show_status(config: &ServerConfig) {
|
|||
).unwrap(),
|
||||
};
|
||||
e.reset().unwrap();
|
||||
println!();
|
||||
println!()
|
||||
}
|
||||
|
||||
pub fn ban_peer(config: &ServerConfig, peer_addr: &SocketAddr) {
|
||||
|
@ -73,6 +76,32 @@ pub fn unban_peer(config: &ServerConfig, peer_addr: &SocketAddr) {
|
|||
Ok(_) => writeln!(e, "Successfully unbanned peer {}", peer_addr).unwrap(),
|
||||
Err(_) => writeln!(e, "Failed to unban peer {}", peer_addr).unwrap(),
|
||||
};
|
||||
e.reset().unwrap();
|
||||
}
|
||||
|
||||
pub fn list_connected_peers(config: &ServerConfig) {
|
||||
let mut e = term::stdout().unwrap();
|
||||
let url = format!(
|
||||
"http://{}/v1/peers/connected",
|
||||
config.api_http_addr
|
||||
);
|
||||
match api::client::get::<Vec<p2p::PeerInfo>>(url.as_str()).map_err(|e| Error::API(e)) {
|
||||
Ok(connected_peers) => {
|
||||
let mut index = 0;
|
||||
for connected_peer in connected_peers {
|
||||
writeln!(e, "Peer {}:", index).unwrap();
|
||||
writeln!(e, "Capabilities: {:?}", connected_peer.capabilities).unwrap();
|
||||
writeln!(e, "User agent: {}", connected_peer.user_agent).unwrap();
|
||||
writeln!(e, "Version: {}", connected_peer.version).unwrap();
|
||||
writeln!(e, "Peer address: {}", connected_peer.addr).unwrap();
|
||||
writeln!(e, "Total difficulty: {}", connected_peer.total_difficulty).unwrap();
|
||||
println!();
|
||||
index = index + 1;
|
||||
}
|
||||
},
|
||||
Err(_) => writeln!(e, "Failed to get connected peers").unwrap(),
|
||||
};
|
||||
e.reset().unwrap();
|
||||
}
|
||||
|
||||
fn get_status_from_node(config: &ServerConfig) -> Result<api::Status, Error> {
|
||||
|
|
|
@ -27,6 +27,7 @@ extern crate grin_config as config;
|
|||
extern crate grin_core as core;
|
||||
extern crate grin_grin as grin;
|
||||
extern crate grin_keychain as keychain;
|
||||
extern crate grin_p2p as p2p;
|
||||
extern crate grin_util as util;
|
||||
extern crate grin_wallet as wallet;
|
||||
|
||||
|
@ -151,7 +152,9 @@ fn main() {
|
|||
.subcommand(SubCommand::with_name("client")
|
||||
.about("Communicates with the Grin server")
|
||||
.subcommand(SubCommand::with_name("status")
|
||||
.about("current status of the Grin chain"))
|
||||
.about("Current status of the Grin chain"))
|
||||
.subcommand(SubCommand::with_name("listconnectedpeers")
|
||||
.about("Print a list of currently connected peers"))
|
||||
.subcommand(SubCommand::with_name("ban")
|
||||
.about("Ban peer")
|
||||
.arg(Arg::with_name("peer")
|
||||
|
@ -385,6 +388,9 @@ fn client_command(client_args: &ArgMatches, global_config: GlobalConfig) {
|
|||
("status", Some(_)) => {
|
||||
client::show_status(&server_config);
|
||||
}
|
||||
("listconnectedpeers", Some(_)) => {
|
||||
client::list_connected_peers(&server_config);
|
||||
}
|
||||
("ban", Some(peer_args)) => {
|
||||
if let Some(peer) = peer_args.value_of("peer") {
|
||||
if let Ok(addr) = peer.parse() {
|
||||
|
|
Loading…
Add table
Reference in a new issue