mirror of
https://github.com/ipfs/kubo.git
synced 2025-08-06 03:19:47 +08:00
Updated verbose swarm to not ping peers.
License: MIT Signed-off-by: Chris Sasarak <chris.sasarak@gmail.com>
This commit is contained in:
@ -7,7 +7,6 @@ import (
|
||||
"io"
|
||||
"path"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
iaddr "github.com/ipfs/go-ipfs/thirdparty/ipfsaddr"
|
||||
@ -16,7 +15,6 @@ import (
|
||||
|
||||
mafilter "gx/ipfs/QmUaRHbB7pUwj5mS9BS4CMvBiW48MpaH2wbGxeWfFhhHxK/multiaddr-filter"
|
||||
ma "gx/ipfs/QmYzDkkgAEmrcNzFCiYo6L1dTX4EAG1gZkbtdbd9trL4vd/go-multiaddr"
|
||||
context "gx/ipfs/QmZy2y8t9zQH2a1b8q2ZSLKp17ATuJoCNxxyMFG5qFExpt/go-net/context"
|
||||
)
|
||||
|
||||
type stringList struct {
|
||||
@ -54,12 +52,10 @@ var swarmPeersCmd = &cmds.Command{
|
||||
},
|
||||
Options: []cmds.Option{
|
||||
cmds.BoolOption("verbose", "v",
|
||||
`Also display latency along with peer information in the following form:
|
||||
<peer address> <latency>
|
||||
`),
|
||||
"Also display latency along with peer information in the following form: "+
|
||||
"<peer address> <latency>"),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
timeout := time.Duration(5) * time.Second
|
||||
|
||||
log.Debug("ipfs swarm peers")
|
||||
n, err := req.InvocContext().GetNode()
|
||||
@ -76,26 +72,13 @@ var swarmPeersCmd = &cmds.Command{
|
||||
verbose, _, _ := req.Option("verbose").Bool()
|
||||
conns := n.PeerHost.Network().Conns()
|
||||
addrs := make([]string, len(conns))
|
||||
pingService := n.Ping
|
||||
|
||||
for i, c := range conns {
|
||||
pid := c.RemotePeer()
|
||||
addr := c.RemoteMultiaddr()
|
||||
|
||||
if verbose {
|
||||
pContext, cancelFn := context.WithTimeout(req.Context(), timeout)
|
||||
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)
|
||||
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())
|
||||
}
|
||||
|
Reference in New Issue
Block a user