remove logging of dup blocks, move to counters for bitswap stat
Jeromy committed
May 4, 2015 at 03:12 UTC
6f04302a48fe642e96afe7734230743cc59f2fe4
3 files changed
+16
-11
core/commands/bitswap.go
+2
@@ -101,6 +101,8 @@ var bitswapStatCmd = &cmds.Command{
101
buf := new(bytes.Buffer)
102
fmt.Fprintln(buf, "bitswap status")
103
fmt.Fprintf(buf, "\tprovides buffer: %d / %d\n", out.ProvideBufLen, bitswap.HasBlockBufferSize)
104
+ fmt.Fprintf(buf, "\tblocks received: %d\n", out.BlocksReceived)
105
+ fmt.Fprintf(buf, "\tdup blocks received: %d\n", out.DupBlksReceived)
106
fmt.Fprintf(buf, "\twantlist [%d keys]\n", len(out.Wantlist))
107
for _, k := range out.Wantlist {
108
fmt.Fprintf(buf, "\t\t%s\n", k.B58String())
exchange/bitswap/bitswap.go
+7
-8
@@ -127,6 +127,9 @@ type Bitswap struct {
127
newBlocks chan *blocks.Block
128
129
provideKeys chan u.Key
130
+
131
+ blocksRecvd int
132
+ dupBlocksRecvd int
133
}
134
135
type blockRequest struct {
@@ -219,14 +222,6 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
222
return errors.New("bitswap is closed")
223
default:
224
}
222
- has, err := bs.blockstore.Has(blk.Key())
223
- if err != nil {
224
- return err
225
- }
226
-
227
- if has {
228
- log.Error(bs.self, "Dup Block! ", blk.Key())
229
- }
225
226
if err := bs.blockstore.Put(blk); err != nil {
227
return err
@@ -351,6 +346,10 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
346
// Should only track *useful* messages in ledger
347
348
for _, block := range incoming.Blocks() {
349
+ bs.blocksRecvd++
350
+ if has, err := bs.blockstore.Has(block.Key()); err == nil && has {
351
+ bs.dupBlocksRecvd++
352
+ }
353
hasBlockCtx, cancel := context.WithTimeout(ctx, hasBlockTimeout)
354
if err := bs.HasBlock(hasBlockCtx, block); err != nil {
355
log.Debug(err)
exchange/bitswap/stat.go
+7
-3
@@ -6,15 +6,19 @@ import (
6
)
7
8
type Stat struct {
9
- ProvideBufLen int
10
- Wantlist []u.Key
11
- Peers []string
9
+ ProvideBufLen int
10
+ Wantlist []u.Key
11
+ Peers []string
12
+ BlocksReceived int
13
+ DupBlksReceived int
14
}
15
16
func (bs *Bitswap) Stat() (*Stat, error) {
17
st := new(Stat)
18
st.ProvideBufLen = len(bs.newBlocks)
19
st.Wantlist = bs.GetWantlist()
20
+ st.BlocksReceived = bs.blocksRecvd
21
+ st.DupBlksReceived = bs.dupBlocksRecvd
22
23
for _, p := range bs.engine.Peers() {
24
st.Peers = append(st.Peers, p.Pretty())