-func iterUnbiasedPieceRequestOrder(cn requestStrategyConnection, f func(piece pieceIndex) bool) bool {
- now, readahead := cn.torrent().readerPiecePriorities()
- skip := bitmap.Flip(cn.peerPieces(), 0, cn.torrent().numPieces())
- skip.Union(cn.torrent().ignorePieces())
- // Return an iterator over the different priority classes, minus the skip pieces.
- return iter.All(
- func(_piece interface{}) bool {
- return f(pieceIndex(_piece.(bitmap.BitIndex)))
- },
- iterBitmapsDistinct(&skip, now, readahead),
- // We have to iterate _pendingPieces separately because it isn't a Bitmap.
- func(cb iter.Callback) {
- cn.torrent().pendingPieces().IterTyped(func(piece int) bool {
- if skip.Contains(piece) {
- return true
- }
- more := cb(piece)
- skip.Add(piece)
- return more
- })
- },
- )
-}
-
-// The connection should download highest priority pieces first, without any inclination toward
-// avoiding wastage. Generally we might do this if there's a single connection, or this is the
-// fastest connection, and we have active readers that signal an ordering preference. It's
-// conceivable that the best connection should do this, since it's least likely to waste our time if
-// assigned to the highest priority pieces, and assigning more than one this role would cause
-// significant wasted bandwidth.
-func (cn *Peer) shouldRequestWithoutBias() bool {
- return cn.t.requestStrategy.shouldRequestWithoutBias(cn.requestStrategyConnection())
-}
-
-func (cn *Peer) iterPendingPieces(f func(pieceIndex) bool) {
- if !cn.t.haveInfo() {
- return
- }
- if cn.closed.IsSet() {
- return
- }
- cn.t.requestStrategy.iterPendingPieces(cn, f)
-}
-func (cn *Peer) iterPendingPiecesUntyped(f iter.Callback) {
- cn.iterPendingPieces(func(i pieceIndex) bool { return f(i) })
-}
-
-func (cn *Peer) iterPendingRequests(piece pieceIndex, f func(Request) bool) bool {
- return cn.t.requestStrategy.iterUndirtiedChunks(
- cn.t.piece(piece).requestStrategyPiece(),
- func(cs ChunkSpec) bool {
- return f(Request{pp.Integer(piece), cs})
- },
- )
-}
-