request-strategy/order.go | 10 ++++++++++ diff --git a/request-strategy/order.go b/request-strategy/order.go index 3b7284b2f44c2bd8e5670c3431d707a7f80d5b76..b009a10882e84eb9a235345b64f70cd2f2631f15 100644 --- a/request-strategy/order.go +++ b/request-strategy/order.go @@ -4,6 +4,7 @@ import ( "bytes" "expvar" + "github.com/anacrolix/generics" "github.com/anacrolix/multiless" "github.com/anacrolix/torrent/metainfo" @@ -54,7 +55,16 @@ if cap, ok := input.Capacity(); ok { storageLeft = &cap } var allTorrentsUnverifiedBytes int64 + var lastItem generics.Option[pieceRequestOrderItem] pro.tree.Scan(func(_i pieceRequestOrderItem) bool { + // Check that scan emits pieces in priority order. + if lastItem.Ok { + if _i.Less(&lastItem.Value) { + panic("scan not in order") + } + } + lastItem.Set(_i) + ih := _i.key.InfoHash var t = input.Torrent(ih) pieceLength := t.PieceLength()