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