]> Sergey Matveev's repositories - btrtrc.git/blobdiff - peerconn.go
Track dirty chunks in a single bitmap on Torrent
[btrtrc.git] / peerconn.go
index 8d3f6d819f84fdd72c37c6d7539e8755fe744218..03749e0ef21ccbb782ed55a6b72561774c84874b 100644 (file)
@@ -181,10 +181,12 @@ func (cn *Peer) expectingChunks() bool {
        if !cn.actualRequestState.Interested {
                return false
        }
-       if cn.peerAllowedFast.IterTyped(func(_i int) bool {
-               i := RequestIndex(_i)
-               return cn.actualRequestState.Requests.Rank((i+1)*cn.t.chunksPerRegularPiece())-
-                       cn.actualRequestState.Requests.Rank(i*cn.t.chunksPerRegularPiece()) == 0
+       if cn.peerAllowedFast.IterTyped(func(i int) bool {
+               return roaringBitmapRangeCardinality(
+                       &cn.actualRequestState.Requests,
+                       cn.t.pieceRequestIndexOffset(i),
+                       cn.t.pieceRequestIndexOffset(i+1),
+               ) == 0
        }) {
                return true
        }