peer.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. package requestStrategy
  2. import (
  3. typedRoaring "github.com/anacrolix/torrent/typed-roaring"
  4. "iter"
  5. )
  6. type PeerRequestState struct {
  7. Interested bool
  8. Requests PeerRequests
  9. // Cancelled and waiting response
  10. Cancelled typedRoaring.Bitmap[RequestIndex]
  11. }
  12. // A set of request indices iterable by order added.
  13. type PeerRequests interface {
  14. // Can be more efficient than GetCardinality.
  15. IsEmpty() bool
  16. // See roaring.Bitmap.GetCardinality.
  17. GetCardinality() uint64
  18. Contains(RequestIndex) bool
  19. // Should not adjust iteration order if item already exists, although I don't think that usage
  20. // exists.
  21. Add(RequestIndex)
  22. // See roaring.Bitmap.Rank.
  23. Rank(RequestIndex) uint64
  24. // Must yield in order items were added.
  25. Iterate(func(RequestIndex) bool) (all bool)
  26. // Must yield in order items were added.
  27. Iterator() iter.Seq[RequestIndex]
  28. // See roaring.Bitmap.CheckedRemove.
  29. CheckedRemove(RequestIndex) bool
  30. // Iterate a snapshot of the values. It is safe to mutate the underlying data structure.
  31. IterateSnapshot(func(RequestIndex) bool)
  32. }