Commit 2482dc8f authored by Jeromy Johnson's avatar Jeromy Johnson

Merge pull request #2713 from csasarak/swarm_verbose

Added a verbose option for swarm peers.
parents 1e9e94f8 584d4969
...@@ -50,6 +50,11 @@ var swarmPeersCmd = &cmds.Command{ ...@@ -50,6 +50,11 @@ var swarmPeersCmd = &cmds.Command{
'ipfs swarm peers' lists the set of peers this node is connected to. 'ipfs swarm peers' lists the set of peers this node is connected to.
`, `,
}, },
Options: []cmds.Option{
cmds.BoolOption("verbose", "v",
"Also display latency along with peer information in the following form: "+
"<peer address> <latency>"),
},
Run: func(req cmds.Request, res cmds.Response) { Run: func(req cmds.Request, res cmds.Response) {
log.Debug("ipfs swarm peers") log.Debug("ipfs swarm peers")
...@@ -64,12 +69,19 @@ var swarmPeersCmd = &cmds.Command{ ...@@ -64,12 +69,19 @@ var swarmPeersCmd = &cmds.Command{
return return
} }
verbose, _, _ := req.Option("verbose").Bool()
conns := n.PeerHost.Network().Conns() conns := n.PeerHost.Network().Conns()
addrs := make([]string, len(conns)) addrs := make([]string, len(conns))
for i, c := range conns { for i, c := range conns {
pid := c.RemotePeer() pid := c.RemotePeer()
addr := c.RemoteMultiaddr() addr := c.RemoteMultiaddr()
addrs[i] = fmt.Sprintf("%s/ipfs/%s", addr, pid.Pretty())
if verbose {
addrs[i] = fmt.Sprintf("%s/ipfs/%s %s", addr, pid.Pretty(), n.Peerstore.LatencyEWMA(pid))
} else {
addrs[i] = fmt.Sprintf("%s/ipfs/%s", addr, pid.Pretty())
}
} }
sort.Sort(sort.StringSlice(addrs)) sort.Sort(sort.StringSlice(addrs))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment