fix output formatting on stat
Jeromy committed
Feb 20, 2015 at 03:15 UTC
98a183d53ebd553ed76c1ffcccabe8bbd5cb80c3
4 files changed
+20
-12
core/commands/bitswap.go
+10
-5
@@ -2,7 +2,7 @@ package commands
2
3
import (
4
"bytes"
5
- "encoding/json"
5
+ "fmt"
6
cmds "github.com/jbenet/go-ipfs/commands"
7
bitswap "github.com/jbenet/go-ipfs/exchange/bitswap"
8
u "github.com/jbenet/go-ipfs/util"
@@ -75,10 +75,15 @@ var bitswapStatCmd = &cmds.Command{
75
return nil, u.ErrCast()
76
}
77
buf := new(bytes.Buffer)
78
- enc := json.NewEncoder(buf)
79
- err := enc.Encode(out)
80
- if err != nil {
81
- return nil, err
78
+ fmt.Fprintln(buf, "bitswap status")
79
+ fmt.Fprintf(buf, "\tprovides buffer: %d / %d\n", out.ProvideBufLen, bitswap.HasBlockBufferSize)
80
+ fmt.Fprintf(buf, "\twantlist [%d keys]\n", len(out.Wantlist))
81
+ for _, k := range out.Wantlist {
82
+ fmt.Fprintf(buf, "\t\t%s\n", k.B58String())
83
+ }
84
+ fmt.Fprintf(buf, "\tpartners [%d]\n", len(out.Peers))
85
+ for _, p := range out.Peers {
86
+ fmt.Fprintf(buf, "\t\t%s\n", p)
87
}
88
return buf, nil
89
},
core/commands/root.go
+2
-2
@@ -5,10 +5,10 @@ import (
5
"strings"
6
7
cmds "github.com/jbenet/go-ipfs/commands"
8
- u "github.com/jbenet/go-ipfs/util"
8
+ evlog "github.com/jbenet/go-ipfs/thirdparty/eventlog"
9
)
10
11
-var log = u.Logger("core/commands")
11
+var log = evlog.Logger("core/commands")
12
13
type TestOutput struct {
14
Foo string
exchange/bitswap/bitswap.go
+2
-2
@@ -40,7 +40,7 @@ const (
40
// kMaxPriority is the max priority as defined by the bitswap protocol
41
kMaxPriority = math.MaxInt32
42
43
- hasBlockBufferSize = 256
43
+ HasBlockBufferSize = 256
44
provideWorkers = 4
45
)
46
@@ -88,7 +88,7 @@ func New(parent context.Context, p peer.ID, network bsnet.BitSwapNetwork,
88
wantlist: wantlist.NewThreadSafe(),
89
batchRequests: make(chan *blockRequest, sizeBatchRequestChan),
90
process: px,
91
- newBlocks: make(chan *blocks.Block, hasBlockBufferSize),
91
+ newBlocks: make(chan *blocks.Block, HasBlockBufferSize),
92
}
93
network.SetDelegate(bs)
94
exchange/bitswap/stat.go
+6
-3
@@ -1,14 +1,14 @@
1
package bitswap
2
3
import (
4
- peer "github.com/jbenet/go-ipfs/p2p/peer"
4
u "github.com/jbenet/go-ipfs/util"
5
+ "sort"
6
)
7
8
type Stat struct {
9
ProvideBufLen int
10
Wantlist []u.Key
11
- Peers []peer.ID
11
+ Peers []string
12
}
13
14
func (bs *Bitswap) Stat() (*Stat, error) {
@@ -16,7 +16,10 @@ func (bs *Bitswap) Stat() (*Stat, error) {
16
st.ProvideBufLen = len(bs.newBlocks)
17
st.Wantlist = bs.GetWantlist()
18
19
- st.Peers = bs.engine.Peers()
19
+ for _, p := range bs.engine.Peers() {
20
+ st.Peers = append(st.Peers, p.Pretty())
21
+ }
22
+ sort.Strings(st.Peers)
23
24
return st, nil
25
}