diff --git a/core/commands/swarm.go b/core/commands/swarm.go index 565de73b0db..f5cde07773f 100644 --- a/core/commands/swarm.go +++ b/core/commands/swarm.go @@ -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: "+ + " "), + }, Run: func(req cmds.Request, res cmds.Response) { log.Debug("ipfs swarm peers") @@ -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))