request-strategy/order.go | 15 +++++++++------ diff --git a/request-strategy/order.go b/request-strategy/order.go index 477c44de51ebd1f391eeb8a11af0274cbaa07922..6b27261139cec8014c28af8e70fb018be0274953 100644 --- a/request-strategy/order.go +++ b/request-strategy/order.go @@ -50,11 +50,14 @@ var storageLeft *int64 if cap, ok := input.Capacity(); ok { storageLeft = &cap } - var allTorrentsUnverifiedBytes int64 - pro.tree.Scan(func(_i pieceRequestOrderItem) bool { - ih := _i.key.InfoHash + var ( + allTorrentsUnverifiedBytes int64 + maxUnverifiedBytes = input.MaxUnverifiedBytes() + ) + pro.tree.Scan(func(item pieceRequestOrderItem) bool { + ih := item.key.InfoHash var t = input.Torrent(ih) - var piece = t.Piece(_i.key.Index) + var piece = t.Piece(item.key.Index) pieceLength := t.PieceLength() if storageLeft != nil { if *storageLeft < pieceLength { @@ -67,11 +70,11 @@ // TODO: Clarify exactly what is verified. Stuff that's being hashed should be // considered unverified and hold up further requests. return true } - if input.MaxUnverifiedBytes() != 0 && allTorrentsUnverifiedBytes+pieceLength > input.MaxUnverifiedBytes() { + if maxUnverifiedBytes != 0 && allTorrentsUnverifiedBytes+pieceLength > maxUnverifiedBytes { return false } allTorrentsUnverifiedBytes += pieceLength - f(ih, _i.key.Index, _i.state) + f(ih, item.key.Index, item.state) return true }) return