/
peer.go
32 lines (29 loc) · 956 Bytes
/
peer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package requestStrategy
import (
typedRoaring "github.com/anacrolix/torrent/typed-roaring"
)
type PeerRequestState struct {
Interested bool
Requests PeerRequests
// Cancelled and waiting response
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)
}