Skip to content
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

Added a verbose option for swarm peers. #2713

Merged
merged 2 commits into from
May 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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