diff --git a/core/commands/bitswap.go b/core/commands/bitswap.go index 75bfc7877a1..19e897d7bae 100644 --- a/core/commands/bitswap.go +++ b/core/commands/bitswap.go @@ -156,6 +156,7 @@ var bitswapStatCmd = &cmds.Command{ fmt.Fprintf(buf, "\tprovides buffer: %d / %d\n", out.ProvideBufLen, bitswap.HasBlockBufferSize) fmt.Fprintf(buf, "\tblocks received: %d\n", out.BlocksReceived) fmt.Fprintf(buf, "\tdup blocks received: %d\n", out.DupBlksReceived) + fmt.Fprintf(buf, "\tdup data received: %d\n", out.DupDataReceived) fmt.Fprintf(buf, "\twantlist [%d keys]\n", len(out.Wantlist)) for _, k := range out.Wantlist { fmt.Fprintf(buf, "\t\t%s\n", k.B58String()) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index 2f2e88ea404..32d74817708 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -131,6 +131,7 @@ type Bitswap struct { counterLk sync.Mutex blocksRecvd int dupBlocksRecvd int + dupDataRecvd uint64 } type blockRequest struct { @@ -320,7 +321,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg go func(b *blocks.Block) { defer wg.Done() - if err := bs.updateReceiveCounters(b.Key()); err != nil { + if err := bs.updateReceiveCounters(b); err != nil { return // ignore error, is either logged previously, or ErrAlreadyHaveBlock } @@ -338,17 +339,18 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg var ErrAlreadyHaveBlock = errors.New("already have block") -func (bs *Bitswap) updateReceiveCounters(k key.Key) error { +func (bs *Bitswap) updateReceiveCounters(b *blocks.Block) error { bs.counterLk.Lock() defer bs.counterLk.Unlock() bs.blocksRecvd++ - has, err := bs.blockstore.Has(k) + has, err := bs.blockstore.Has(b.Key()) if err != nil { log.Infof("blockstore.Has error: %s", err) return err } if err == nil && has { bs.dupBlocksRecvd++ + bs.dupDataRecvd += uint64(len(b.Data)) } if has { diff --git a/exchange/bitswap/stat.go b/exchange/bitswap/stat.go index 5fa0e285ee9..956a4c5b71e 100644 --- a/exchange/bitswap/stat.go +++ b/exchange/bitswap/stat.go @@ -11,6 +11,7 @@ type Stat struct { Peers []string BlocksReceived int DupBlksReceived int + DupDataReceived uint64 } func (bs *Bitswap) Stat() (*Stat, error) { @@ -20,6 +21,7 @@ func (bs *Bitswap) Stat() (*Stat, error) { bs.counterLk.Lock() st.BlocksReceived = bs.blocksRecvd st.DupBlksReceived = bs.dupBlocksRecvd + st.DupDataReceived = bs.dupDataRecvd bs.counterLk.Unlock() for _, p := range bs.engine.Peers() {