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{
'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) {
log.Debug("ipfs swarm peers")
......@@ -64,13 +69,20 @@ var swarmPeersCmd = &cmds.Command{
return
}
verbose, _, _ := req.Option("verbose").Bool()
conns := n.PeerHost.Network().Conns()
addrs := make([]string, len(conns))
for i, c := range conns {
pid := c.RemotePeer()
addr := c.RemoteMultiaddr()
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))
res.SetOutput(&stringList{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