Skip to content

Commit

Permalink
fix output formatting on stat
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Feb 20, 2015
1 parent ad72382 commit 154a17a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
15 changes: 10 additions & 5 deletions core/commands/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
},
Expand Down
4 changes: 2 additions & 2 deletions core/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions exchange/bitswap/bitswap.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const (
// kMaxPriority is the max priority as defined by the bitswap protocol
kMaxPriority = math.MaxInt32

hasBlockBufferSize = 256
HasBlockBufferSize = 256
provideWorkers = 4
)

Expand Down Expand Up @@ -89,7 +89,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)

Expand Down
9 changes: 6 additions & 3 deletions exchange/bitswap/stat.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
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) {
st := new(Stat)
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
}

0 comments on commit 154a17a

Please sign in to comment.