From 47239ec7a7a0282047bf8a0cf2fb41bf2c590fe4 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 2 May 2017 10:55:43 -0700 Subject: [PATCH] clean up wantlists on non-session success case License: MIT Signed-off-by: Jeromy --- exchange/bitswap/bitswap.go | 2 ++ exchange/bitswap/bitswap_test.go | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/exchange/bitswap/bitswap.go b/exchange/bitswap/bitswap.go index c5645dfebbb2..34d0d62a1513 100644 --- a/exchange/bitswap/bitswap.go +++ b/exchange/bitswap/bitswap.go @@ -255,6 +255,7 @@ func (bs *Bitswap) GetBlocks(ctx context.Context, keys []*cid.Cid) (<-chan block return } + bs.CancelWants([]*cid.Cid{blk.Cid()}, mses) remaining.Remove(blk.Cid()) select { case out <- blk: @@ -371,6 +372,7 @@ func (bs *Bitswap) ReceiveMessage(ctx context.Context, p peer.ID, incoming bsmsg for _, ses := range bs.SessionsForBlock(k) { ses.ReceiveBlock(p, b) + bs.CancelWants([]*cid.Cid{k}, ses.id) } log.Debugf("got block %s from %s", b, p) if err := bs.HasBlock(b); err != nil { diff --git a/exchange/bitswap/bitswap_test.go b/exchange/bitswap/bitswap_test.go index 22e7cb9b70d1..9a7908c8124f 100644 --- a/exchange/bitswap/bitswap_test.go +++ b/exchange/bitswap/bitswap_test.go @@ -341,6 +341,11 @@ func TestBasicBitswap(t *testing.T) { t.Fatal(err) } + time.Sleep(time.Millisecond * 20) + if len(instances[1].Exchange.GetWantlist()) != 0 { + t.Fatal("shouldnt have anything in wantlist") + } + st0, err := instances[0].Exchange.Stat() if err != nil { t.Fatal(err)