Commit 110eef1d authored by Jeromy's avatar Jeromy

remove logging of dup blocks, move to counters for bitswap stat

parent d76b5e4a
......@@ -127,6 +127,9 @@ type Bitswap struct {
newBlocks chan *blocks.Block
provideKeys chan u.Key
blocksRecvd int
dupBlocksRecvd int
}
type blockRequest struct {
......@@ -219,14 +222,6 @@ func (bs *Bitswap) HasBlock(ctx context.Context, blk *blocks.Block) error {
return errors.New("bitswap is closed")
default:
}
has, err := bs.blockstore.Has(blk.Key())
if err != nil {
return err
}
if has {
log.Error(bs.self, "Dup Block! ", blk.Key())
}
if err := bs.blockstore.Put(blk); err != nil {
return err
......@@ -351,6 +346,10 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg
// Should only track *useful* messages in ledger
for _, block := range incoming.Blocks() {
bs.blocksRecvd++
if has, err := bs.blockstore.Has(block.Key()); err == nil && has {
bs.dupBlocksRecvd++
}
hasBlockCtx, cancel := context.WithTimeout(ctx, hasBlockTimeout)
if err := bs.HasBlock(hasBlockCtx, block); err != nil {
log.Debug(err)
......
......@@ -6,15 +6,19 @@ import (
)
type Stat struct {
ProvideBufLen int
Wantlist []u.Key
Peers []string
ProvideBufLen int
Wantlist []u.Key
Peers []string
BlocksReceived int
DupBlksReceived int
}
func (bs *Bitswap) Stat() (*Stat, error) {
st := new(Stat)
st.ProvideBufLen = len(bs.newBlocks)
st.Wantlist = bs.GetWantlist()
st.BlocksReceived = bs.blocksRecvd
st.DupBlksReceived = bs.dupBlocksRecvd
for _, p := range bs.engine.Peers() {
st.Peers = append(st.Peers, p.Pretty())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment