]> Sergey Matveev's repositories - btrtrc.git/blobdiff - request-strategy/peer.go
Drop support for go 1.20
[btrtrc.git] / request-strategy / peer.go
index d5366d7603fb65baab9629f37ef180132b596ae0..4176188cebb8a766f6e46e4ee62dbcb5b5dab5bb 100644 (file)
@@ -1,14 +1,32 @@
-package request_strategy
+package requestStrategy
 
 import (
-       "github.com/RoaringBitmap/roaring"
+       typedRoaring "github.com/anacrolix/torrent/typed-roaring"
 )
 
 type PeerRequestState struct {
        Interested bool
-       // Expecting. TODO: This should be ordered so webseed requesters initiate in the same order they
-       // were assigned.
-       Requests roaring.Bitmap
+       Requests   PeerRequests
        // Cancelled and waiting response
-       Cancelled roaring.Bitmap
+       Cancelled typedRoaring.Bitmap[RequestIndex]
+}
+
+// A set of request indices iterable by order added.
+type PeerRequests interface {
+       // Can be more efficient than GetCardinality.
+       IsEmpty() bool
+       // See roaring.Bitmap.GetCardinality.
+       GetCardinality() uint64
+       Contains(RequestIndex) bool
+       // Should not adjust iteration order if item already exists, although I don't think that usage
+       // exists.
+       Add(RequestIndex)
+       // See roaring.Bitmap.Rank.
+       Rank(RequestIndex) uint64
+       // Must yield in order items were added.
+       Iterate(func(RequestIndex) bool)
+       // See roaring.Bitmap.CheckedRemove.
+       CheckedRemove(RequestIndex) bool
+       // Iterate a snapshot of the values. It is safe to mutate the underlying data structure.
+       IterateSnapshot(func(RequestIndex) bool)
 }