diff --git a/forest/src/cli/net_cmd.rs b/forest/src/cli/net_cmd.rs index dce26122a522..4dcd410fd68c 100644 --- a/forest/src/cli/net_cmd.rs +++ b/forest/src/cli/net_cmd.rs @@ -3,6 +3,7 @@ use forest_libp2p::{Multiaddr, Protocol}; use rpc_api::data_types::AddrInfo; +use std::collections::HashSet; use structopt::StructOpt; use crate::cli::cli_error_and_die; @@ -50,12 +51,26 @@ impl NetCommands { Self::Peers => match net_peers(()).await { Ok(addrs) => { let output: Vec = addrs - .iter() - .map(|info| { - let addresses: Vec = - info.addrs.iter().map(|addr| addr.to_string()).collect(); + .into_iter() + .filter_map(|info| { + let addresses: Vec = info + .addrs + .into_iter() + .filter(|addr| match addr.iter().next().unwrap() { + Protocol::Ip4(ip_addr) => !ip_addr.is_loopback(), + Protocol::Ip6(ip_addr) => !ip_addr.is_loopback(), + _ => true, + }) + .map(|addr| addr.to_string()) + .collect::>() + .into_iter() + .collect(); + + if addresses.is_empty() { + return None; + } - format!("{}, [{}]", info.id, addresses.join(", ")) + Some(format!("{}, [{}]", info.id, addresses.join(", "))) }) .collect();