From 28eb6e3fef2086c571a650cb9eb617c54034b39e Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 1 Aug 2025 13:38:51 +1000 Subject: [PATCH] Use unique.Handle for piece order infohashes --- internal/request-strategy/order.go | 9 ++++----- internal/request-strategy/piece-request-order.go | 3 ++- torrent.go | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/internal/request-strategy/order.go b/internal/request-strategy/order.go index 387b4db7..5aee49f4 100644 --- a/internal/request-strategy/order.go +++ b/internal/request-strategy/order.go @@ -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() diff --git a/internal/request-strategy/piece-request-order.go b/internal/request-strategy/piece-request-order.go index 3e572aed..a9cd07df 100644 --- a/internal/request-strategy/piece-request-order.go +++ b/internal/request-strategy/piece-request-order.go @@ -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 { diff --git a/torrent.go b/torrent.go index 014a443e..0af3a32f 100644 --- a/torrent.go +++ b/torrent.go @@ -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, } } -- 2.51.0