2
0
mirror of synced 2025-02-23 22:28:11 +00:00

Add a check that piece request order items are scanned in order

It's not clear from btree documentation that scan should be ordered.
This commit is contained in:
Matt Joiner 2023-01-04 01:25:57 +11:00
parent 8e0e36887f
commit a512c0df61
No known key found for this signature in database
GPG Key ID: 6B990B8185E7F782

View File

@ -4,6 +4,7 @@ import (
"bytes"
"expvar"
"github.com/anacrolix/generics"
"github.com/anacrolix/multiless"
"github.com/anacrolix/torrent/metainfo"
@ -54,7 +55,16 @@ func GetRequestablePieces(
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()