Skip to content

Commit

Permalink
Merge pull request #2713 from csasarak/swarm_verbose
Browse files Browse the repository at this point in the history
Added a verbose option for swarm peers.
  • Loading branch information
whyrusleeping committed May 18, 2016
2 parents 1e9e94f + 584d496 commit 2482dc8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -64,12 +69,19 @@ 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()
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))
Expand Down

0 comments on commit 2482dc8

Please sign in to comment.