-
Notifications
You must be signed in to change notification settings - Fork 161
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
feat: forest-cli net info #3292
Changes from 6 commits
3073513
316af82
2c7ff33
421339b
c5ce5f0
5f37e0b
6515999
4301e90
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ use crate::rpc_client::net_ops::*; | |
use ahash::HashSet; | ||
use cid::multibase; | ||
use clap::Subcommand; | ||
use itertools::Itertools; | ||
|
||
use super::{handle_rpc_err, print_stdout, Config}; | ||
use crate::cli::subcommands::cli_error_and_die; | ||
|
@@ -15,6 +16,8 @@ use crate::cli::subcommands::cli_error_and_die; | |
pub enum NetCommands { | ||
/// Lists `libp2p` swarm listener addresses | ||
Listen, | ||
/// Lists `libp2p` swarm network info | ||
Info, | ||
/// Lists `libp2p` swarm peers | ||
Peers, | ||
/// Connects to a peer by its peer ID and multi-addresses | ||
|
@@ -44,6 +47,19 @@ impl NetCommands { | |
print_stdout(addresses.join("\n")); | ||
Ok(()) | ||
} | ||
Self::Info => { | ||
let info = net_info((), &config.client.rpc_token) | ||
.await | ||
.map_err(handle_rpc_err)?; | ||
println!("forest libp2p swarm info:"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps we could implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought about it but not sure if it's good practice to implement a multi-line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm good with either approach. |
||
println!("num peers: {}", info.num_peers); | ||
println!("num connections: {}", info.num_connections); | ||
println!("num pending: {}", info.num_pending); | ||
println!("num pending incoming: {}", info.num_pending_incoming); | ||
println!("num pending outgoing: {}", info.num_pending_outgoing); | ||
println!("num established: {}", info.num_established); | ||
Ok(()) | ||
} | ||
Self::Peers => { | ||
let addrs = net_peers((), &config.client.rpc_token) | ||
.await | ||
|
@@ -60,8 +76,7 @@ impl NetCommands { | |
_ => true, | ||
}) | ||
.map(|addr| addr.to_string()) | ||
.collect::<HashSet<_>>() | ||
.into_iter() | ||
.unique() | ||
.collect(); | ||
if addresses.is_empty() { | ||
return None; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? what does it have to do with this subcommand?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was using this to cross-check the correctness of the metrics, it's part of #3218 and I can convert it into a separate PR if you like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do it in a separate PR and comment on it some more, then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed