From 110b6f3fd36cbfdd85ac22965bac279a4cd96c65 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Mon, 20 Sep 2021 15:24:24 +1000 Subject: [PATCH] Fix cancellation for global requesting --- requesting.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/requesting.go b/requesting.go index 2c7b4582..dbb51730 100644 --- a/requesting.go +++ b/requesting.go @@ -4,6 +4,7 @@ import ( "time" "unsafe" + "github.com/RoaringBitmap/roaring" "github.com/anacrolix/missinggo/v2/bitmap" "github.com/anacrolix/chansync" @@ -208,12 +209,10 @@ func (p *Peer) applyNextRequestState() bool { return false } more := true - current.Requests.Iterate(func(req uint32) bool { - if !next.Requests.Contains(req) { - more = p.cancel(req) - return more - } - return true + cancel := roaring.AndNot(¤t.Requests, &next.Requests) + cancel.Iterate(func(req uint32) bool { + more = p.cancel(req) + return more }) if !more { return false -- 2.48.1