]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Strongly type client piece request order keys
authorMatt Joiner <anacrolix@gmail.com>
Thu, 24 Apr 2025 13:08:38 +0000 (23:08 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 24 Apr 2025 13:08:38 +0000 (23:08 +1000)
client-piece-request-order.go [new file with mode: 0644]
client.go
torrent-piece-request-order.go

diff --git a/client-piece-request-order.go b/client-piece-request-order.go
new file mode 100644 (file)
index 0000000..787fc7e
--- /dev/null
@@ -0,0 +1,19 @@
+package torrent
+
+import (
+       "github.com/anacrolix/torrent/storage"
+)
+
+type clientPieceRequestOrderKeyTypes interface {
+       storage.TorrentCapacity | *Torrent
+}
+
+type clientPieceRequestOrderKey[T clientPieceRequestOrderKeyTypes] struct {
+       inner T
+}
+
+func (me clientPieceRequestOrderKey[T]) isAClientPieceRequestOrderKeyType() {}
+
+type clientPieceRequestOrderKeySumType interface {
+       isAClientPieceRequestOrderKeyType()
+}
index 0561b00764a76fb870c2acacd04fdf014df35060..1d618f9716da41c0a66952fa37bf54225f4d3196 100644 (file)
--- a/client.go
+++ b/client.go
@@ -84,7 +84,7 @@ type Client struct {
        // info has been obtained, there's no knowing if an infohash belongs to v1 or v2.
        torrentsByShortHash map[InfoHash]*Torrent
 
-       pieceRequestOrder map[interface{}]*request_strategy.PieceRequestOrder
+       pieceRequestOrder map[clientPieceRequestOrderKeySumType]*request_strategy.PieceRequestOrder
 
        acceptLimiter map[ipStr]int
        numHalfOpen   int
index b2bde8dc9e9cd4236462db3652bcc3ae3c247e52..02044f916fe2c53310c3b6279b4ffa726380b511 100644 (file)
@@ -2,6 +2,7 @@ package torrent
 
 import (
        g "github.com/anacrolix/generics"
+       "github.com/anacrolix/torrent/storage"
 
        request_strategy "github.com/anacrolix/torrent/request-strategy"
 )
@@ -27,11 +28,11 @@ func (t *Torrent) updatePieceRequestOrderPiece(pieceIndex int) {
        }
 }
 
-func (t *Torrent) clientPieceRequestOrderKey() interface{} {
+func (t *Torrent) clientPieceRequestOrderKey() clientPieceRequestOrderKeySumType {
        if t.storage.Capacity == nil {
-               return t
+               return clientPieceRequestOrderKey[*Torrent]{t}
        }
-       return t.storage.Capacity
+       return clientPieceRequestOrderKey[storage.TorrentCapacity]{t.storage.Capacity}
 }
 
 func (t *Torrent) deletePieceRequestOrder() {