]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Use unique.Handle for piece order infohashes
authorMatt Joiner <anacrolix@gmail.com>
Fri, 1 Aug 2025 03:38:51 +0000 (13:38 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Fri, 1 Aug 2025 03:38:51 +0000 (13:38 +1000)
internal/request-strategy/order.go
internal/request-strategy/piece-request-order.go
torrent.go

index 387b4db7cfb1bccce0f86fe629c6db956d682c18..5aee49f46df811e05030b7182371011fd085f0af 100644 (file)
@@ -36,10 +36,9 @@ func pieceOrderLess(i, j *PieceRequestOrderItem) multiless.Computation {
        ).Int(
                i.Key.Index, j.Key.Index,
        ).Lazy(func() multiless.Computation {
-               return multiless.New().Cmp(bytes.Compare(
-                       i.Key.InfoHash[:],
-                       j.Key.InfoHash[:],
-               ))
+               a := i.Key.InfoHash.Value()
+               b := j.Key.InfoHash.Value()
+               return multiless.New().Cmp(bytes.Compare(a[:], b[:]))
        })
 }
 
@@ -67,7 +66,7 @@ func GetRequestablePieces(
                maxUnverifiedBytes         = input.MaxUnverifiedBytes()
        )
        pro.tree.Scan(func(item PieceRequestOrderItem) bool {
-               ih := item.Key.InfoHash
+               ih := item.Key.InfoHash.Value()
                t := input.Torrent(ih)
                piece := t.Piece(item.Key.Index)
                pieceLength := t.PieceLength()
index 3e572aedd25ac6fe961b1f3c7bb2819d6ab8e29b..a9cd07df204d071763c633c4b088350d20cf4104 100644 (file)
@@ -2,6 +2,7 @@ package requestStrategy
 
 import (
        "iter"
+       "unique"
 
        g "github.com/anacrolix/generics"
 
@@ -27,8 +28,8 @@ type PieceRequestOrder struct {
 }
 
 type PieceRequestOrderKey struct {
+       InfoHash unique.Handle[metainfo.Hash]
        Index    int
-       InfoHash metainfo.Hash
 }
 
 type PieceRequestOrderState struct {
index 014a443e2f16333f8682319a33446022e3dc9ab0..0af3a32f50561a90c3de2b5c9531a193afdd4e17 100644 (file)
@@ -558,7 +558,7 @@ func (t *Torrent) setInfo(info *metainfo.Info) error {
 
 func (t *Torrent) pieceRequestOrderKey(i int) request_strategy.PieceRequestOrderKey {
        return request_strategy.PieceRequestOrderKey{
-               InfoHash: *t.canonicalShortInfohash(),
+               InfoHash: unique.Make(*t.canonicalShortInfohash()),
                Index:    i,
        }
 }