"github.com/anacrolix/multiless"
"github.com/lispad/go-generics-tools/binheap"
- request_strategy "github.com/anacrolix/torrent/request-strategy"
+ requestStrategy "github.com/anacrolix/torrent/request-strategy"
+ typedRoaring "github.com/anacrolix/torrent/typed-roaring"
)
-func (t *Torrent) requestStrategyPieceOrderState(i int) request_strategy.PieceRequestOrderState {
- return request_strategy.PieceRequestOrderState{
+type (
+ // Since we have to store all the requests in memory, we can't reasonably exceed what could be
+ // indexed with the memory space available.
+ maxRequests = int
+)
+
+func (t *Torrent) requestStrategyPieceOrderState(i int) requestStrategy.PieceRequestOrderState {
+ return requestStrategy.PieceRequestOrderState{
Priority: t.piece(i).purePriority(),
Partial: t.piecePartiallyDownloaded(i),
Availability: t.piece(i).availability(),
}
type (
- RequestIndex = request_strategy.RequestIndex
- chunkIndexType = request_strategy.ChunkIndex
+ RequestIndex = requestStrategy.RequestIndex
+ chunkIndexType = requestStrategy.ChunkIndex
)
type desiredPeerRequests struct {
requestIndexes []RequestIndex
peer *Peer
- pieceStates []request_strategy.PieceRequestOrderState
+ pieceStates []requestStrategy.PieceRequestOrderState
}
func (p *desiredPeerRequests) Len() int {
// torrent. This would probably require reconsideration of how readahead priority works.
ml = ml.Int(leftPieceIndex, rightPieceIndex)
} else {
- // TODO: To prevent unnecessarily requesting from disparate pieces, and to ensure pieces are
- // selected randomly when availability is even, there should be some fixed ordering of
- // pieces.
+ ml = ml.Int(t.pieceRequestOrder[leftPieceIndex], t.pieceRequestOrder[rightPieceIndex])
}
return ml.Less()
}
pieceStates: t.requestPieceStates,
requestIndexes: t.requestIndexes,
}
- request_strategy.GetRequestablePieces(
+ // Caller-provided allocation for roaring bitmap iteration.
+ var it typedRoaring.Iterator[RequestIndex]
+ requestStrategy.GetRequestablePieces(
input,
t.getPieceRequestOrder(),
- func(ih InfoHash, pieceIndex int, pieceExtra request_strategy.PieceRequestOrderState) {
+ func(ih InfoHash, pieceIndex int, pieceExtra requestStrategy.PieceRequestOrderState) {
if ih != t.infoHash {
return
}
}
requestHeap.pieceStates[pieceIndex] = pieceExtra
allowedFast := p.peerAllowedFast.Contains(pieceIndex)
- p.t.piece(pieceIndex).undirtiedChunksIter.Iter(func(ci request_strategy.ChunkIndex) {
- r := p.t.pieceRequestIndexOffset(pieceIndex) + ci
+ t.iterUndirtiedRequestIndexesInPiece(&it, pieceIndex, func(r requestStrategy.RequestIndex) {
if !allowedFast {
// We must signal interest to request this. TODO: We could set interested if the
// peers pieces (minus the allowed fast set) overlap with our missing pieces if