mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-09 23:42:20 +08:00
fix output formatting on stat
This commit is contained in:
@ -2,7 +2,7 @@ package commands
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
cmds "github.com/jbenet/go-ipfs/commands"
|
||||
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
@ -75,10 +75,15 @@ var bitswapStatCmd = &cmds.Command{
|
||||
return nil, u.ErrCast()
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
enc := json.NewEncoder(buf)
|
||||
err := enc.Encode(out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
fmt.Fprintln(buf, "bitswap status")
|
||||
fmt.Fprintf(buf, "\tprovides buffer: %d / %d\n", out.ProvideBufLen, bitswap.HasBlockBufferSize)
|
||||
fmt.Fprintf(buf, "\twantlist [%d keys]\n", len(out.Wantlist))
|
||||
for _, k := range out.Wantlist {
|
||||
fmt.Fprintf(buf, "\t\t%s\n", k.B58String())
|
||||
}
|
||||
fmt.Fprintf(buf, "\tpartners [%d]\n", len(out.Peers))
|
||||
for _, p := range out.Peers {
|
||||
fmt.Fprintf(buf, "\t\t%s\n", p)
|
||||
}
|
||||
return buf, nil
|
||||
},
|
||||
|
@ -5,10 +5,10 @@ import (
|
||||
"strings"
|
||||
|
||||
cmds "github.com/jbenet/go-ipfs/commands"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
evlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
|
||||
)
|
||||
|
||||
var log = u.Logger("core/commands")
|
||||
var log = evlog.Logger("core/commands")
|
||||
|
||||
type TestOutput struct {
|
||||
Foo string
|
||||
|
@ -40,7 +40,7 @@ const (
|
||||
// kMaxPriority is the max priority as defined by the bitswap protocol
|
||||
kMaxPriority = math.MaxInt32
|
||||
|
||||
hasBlockBufferSize = 256
|
||||
HasBlockBufferSize = 256
|
||||
provideWorkers = 4
|
||||
)
|
||||
|
||||
@ -88,7 +88,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
|
||||
wantlist: wantlist.NewThreadSafe(),
|
||||
batchRequests: make(chan *blockRequest, sizeBatchRequestChan),
|
||||
process: px,
|
||||
newBlocks: make(chan *blocks.Block, hasBlockBufferSize),
|
||||
newBlocks: make(chan *blocks.Block, HasBlockBufferSize),
|
||||
}
|
||||
network.SetDelegate(bs)
|
||||
|
||||
|
@ -1,14 +1,14 @@
|
||||
package bitswap
|
||||
|
||||
import (
|
||||
peer "github.com/jbenet/go-ipfs/p2p/peer"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
"sort"
|
||||
)
|
||||
|
||||
type Stat struct {
|
||||
ProvideBufLen int
|
||||
Wantlist []u.Key
|
||||
Peers []peer.ID
|
||||
Peers []string
|
||||
}
|
||||
|
||||
func (bs *Bitswap) Stat() (*Stat, error) {
|
||||
@ -16,7 +16,10 @@ func (bs *Bitswap) Stat() (*Stat, error) {
|
||||
st.ProvideBufLen = len(bs.newBlocks)
|
||||
st.Wantlist = bs.GetWantlist()
|
||||
|
||||
st.Peers = bs.engine.Peers()
|
||||
for _, p := range bs.engine.Peers() {
|
||||
st.Peers = append(st.Peers, p.Pretty())
|
||||
}
|
||||
sort.Strings(st.Peers)
|
||||
|
||||
return st, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user