Commit 584d4969 authored by Chris Sasarak's avatar Chris Sasarak

Updated verbose swarm to not ping peers.

License: MIT
Signed-off-by: default avatarChris Sasarak <chris.sasarak@gmail.com>
parent 762aded6
...@@ -7,7 +7,6 @@ import ( ...@@ -7,7 +7,6 @@ import (
"io" "io"
"path" "path"
"sort" "sort"
"time"
cmds "github.com/ipfs/go-ipfs/commands" cmds "github.com/ipfs/go-ipfs/commands"
iaddr "github.com/ipfs/go-ipfs/thirdparty/ipfsaddr" iaddr "github.com/ipfs/go-ipfs/thirdparty/ipfsaddr"
...@@ -16,7 +15,6 @@ import ( ...@@ -16,7 +15,6 @@ import (
mafilter "gx/ipfs/QmUaRHbB7pUwj5mS9BS4CMvBiW48MpaH2wbGxeWfFhhHxK/multiaddr-filter" mafilter "gx/ipfs/QmUaRHbB7pUwj5mS9BS4CMvBiW48MpaH2wbGxeWfFhhHxK/multiaddr-filter"
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr" ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
) )
type stringList struct { type stringList struct {
...@@ -54,12 +52,10 @@ var swarmPeersCmd = &cmds.Command{ ...@@ -54,12 +52,10 @@ var swarmPeersCmd = &cmds.Command{
}, },
Options: []cmds.Option{ Options: []cmds.Option{
cmds.BoolOption("verbose", "v", cmds.BoolOption("verbose", "v",
`Also display latency along with peer information in the following form: "Also display latency along with peer information in the following form: "+
<peer address> <latency> "<peer address> <latency>"),
`),
}, },
Run: func(req cmds.Request, res cmds.Response) { Run: func(req cmds.Request, res cmds.Response) {
timeout := time.Duration(5) * time.Second
log.Debug("ipfs swarm peers") log.Debug("ipfs swarm peers")
n, err := req.InvocContext().GetNode() n, err := req.InvocContext().GetNode()
...@@ -76,26 +72,13 @@ var swarmPeersCmd = &cmds.Command{ ...@@ -76,26 +72,13 @@ var swarmPeersCmd = &cmds.Command{
verbose, _, _ := req.Option("verbose").Bool() 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))
pingService := n.Ping
for i, c := range conns { for i, c := range conns {
pid := c.RemotePeer() pid := c.RemotePeer()
addr := c.RemoteMultiaddr() addr := c.RemoteMultiaddr()
if verbose { if verbose {
pContext, cancelFn := context.WithTimeout(req.Context(), timeout) addrs[i] = fmt.Sprintf("%s/ipfs/%s %s", addr, pid.Pretty(), n.Peerstore.LatencyEWMA(pid))
defer cancelFn()
ch, _ := pingService.Ping(pContext, pid)
duration := <-ch
var durStr string
if pContext.Err() != nil {
durStr = pContext.Err().Error()
} else {
durStr = duration.String()
}
addrs[i] = fmt.Sprintf("%s/ipfs/%s %s", addr, pid.Pretty(), durStr)
} else { } else {
addrs[i] = fmt.Sprintf("%s/ipfs/%s", addr, pid.Pretty()) addrs[i] = fmt.Sprintf("%s/ipfs/%s", addr, pid.Pretty())
} }
......
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