]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Fix cancellation for global requesting
authorMatt Joiner <anacrolix@gmail.com>
Mon, 20 Sep 2021 05:24:24 +0000 (15:24 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 20 Sep 2021 05:24:24 +0000 (15:24 +1000)
requesting.go

index 2c7b4582452c8c3012a3bf36b0a8bcbc2fa74342..dbb51730b49511d90639cde7a316c83559c44529 100644 (file)
@@ -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(&current.Requests, &next.Requests)
+       cancel.Iterate(func(req uint32) bool {
+               more = p.cancel(req)
+               return more
        })
        if !more {
                return false