requestStrategy

package
v0.0.0-...-6e19431 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 10, 2024 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRequestablePieces

func GetRequestablePieces(
	input Input, pro *PieceRequestOrder,

	requestPiece func(ih metainfo.Hash, pieceIndex int, orderState PieceRequestOrderState) bool,
)

Calls f with requestable pieces in order.

func NewAjwernerBtree

func NewAjwernerBtree() *ajwernerBtree

func NewTidwallBtree

func NewTidwallBtree() *tidwallBtree

Types

type Btree

type Btree interface {
	Delete(pieceRequestOrderItem)
	Add(pieceRequestOrderItem)
	Scan(func(pieceRequestOrderItem) bool)
}

type ChunkIndex

type ChunkIndex = RequestIndex

type ChunkSpec

type ChunkSpec = types.ChunkSpec

This can be made into a type-param later, will be great for testing.

type Input

type Input interface {
	Torrent(metainfo.Hash) Torrent
	// Storage capacity, shared among all Torrents with the same storage.TorrentCapacity pointer in
	// their storage.Torrent references.
	Capacity() (cap int64, capped bool)
	// Across all the Torrents. This might be partitioned by storage capacity key now.
	MaxUnverifiedBytes() int64
}

type PeerRequestState

type PeerRequestState struct {
	Interested bool
	Requests   PeerRequests
	// Cancelled and waiting response
	Cancelled typedRoaring.Bitmap[RequestIndex]
}

type PeerRequests

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) (all bool)
	// Must yield in order items were added.
	Iterator() iter.Seq[RequestIndex]
	// 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)
}

A set of request indices iterable by order added.

type Piece

type Piece interface {
	// Whether requests should be made for this piece. This would be false for cases like the piece
	// is currently being hashed, or already complete.
	Request() bool
	// Whether the piece should be counted towards the unverified bytes limit. The intention is to
	// prevent pieces being starved from the opportunity to move to the completed state.
	CountUnverified() bool
}

type PieceRequestOrder

type PieceRequestOrder struct {
	// contains filtered or unexported fields
}

func NewPieceOrder

func NewPieceOrder(btree Btree, cap int) *PieceRequestOrder

func (*PieceRequestOrder) Add

Returns the old state if the key was already present.

func (*PieceRequestOrder) Delete

func (*PieceRequestOrder) Len

func (me *PieceRequestOrder) Len() int

func (*PieceRequestOrder) Update

type PieceRequestOrderKey

type PieceRequestOrderKey struct {
	Index    int
	InfoHash metainfo.Hash
}

type PieceRequestOrderPathHint

type PieceRequestOrderPathHint = btree.PathHint

type PieceRequestOrderState

type PieceRequestOrderState struct {
	Availability int
	Priority     piecePriority
	Partial      bool
}

type Request

type Request = types.Request

type RequestIndex

type RequestIndex uint32

type Torrent

type Torrent interface {
	Piece(int) Piece
	PieceLength() int64
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL