]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Ignore webseed request start offset in prioritization
authorMatt Joiner <anacrolix@gmail.com>
Mon, 21 Jul 2025 12:04:34 +0000 (22:04 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Tue, 22 Jul 2025 13:17:42 +0000 (23:17 +1000)
torrent.go
webseed-requesting.go
webseed/client.go

index ff6a4c9315b12f0b32a50459d2055308f06da0f6..e854c38a91debb2f00ff9a9fbbf788f4014e2286 100644 (file)
@@ -179,7 +179,7 @@ type Torrent struct {
 
        connsWithAllPieces map[*Peer]struct{}
 
-       // Last active request for each chunks. TODO: Change to PeerConn specific?
+       // Last active PeerConn request for each chunk.
        requestState map[RequestIndex]requestState
        // Chunks we've written to since the corresponding piece was last checked.
        dirtyChunks typedRoaring.Bitmap[RequestIndex]
index 71a1ec7079de481c285eac68c65b9d63b4d3bed6..5d50f949c17ae1c6c3e61f6b27de8a5d91dc12dc 100644 (file)
@@ -99,15 +99,16 @@ func (cl *Client) updateWebseedRequests() {
        aprioriHeap := heap.InterfaceForSlice(
                &heapSlice,
                func(l heapElem, r heapElem) bool {
-                       // Prefer the highest priority, then existing requests, then longest remaining file extent.
+                       // Prefer the highest priority, then existing requests, then largest files.
                        return cmp.Or(
                                -cmp.Compare(l.priority, r.priority),
                                // Existing requests are assigned the priority of the piece they're reading next.
                                compareBool(l.existingWebseedRequest == nil, r.existingWebseedRequest == nil),
-                               // This won't thrash because we already preferred existing requests, so we'll finish out small extents.
+                               // Note this isn't correct if the starting piece is split across multiple files. But
+                               // I plan to refactor to key on starting piece to handle this case.
                                -cmp.Compare(
-                                       l.t.Files()[l.fileIndex].length-l.startOffset,
-                                       r.t.Files()[r.fileIndex].length-r.startOffset),
+                                       l.t.Files()[l.fileIndex].length,
+                                       r.t.Files()[r.fileIndex].length),
                        ) < 0
                },
        )
index a4d432747d38cb6e0a05e417b38d0f38b5018892..babbe0f507f4fb25b9cc6a78278f546fde7418e3 100644 (file)
@@ -64,7 +64,7 @@ type Client struct {
        Logger     *slog.Logger
        HttpClient *http.Client
        Url        string
-       // Max concurrent requests to a WebSeed for a given torrent.
+       // Max concurrent requests to a WebSeed for a given torrent. TODO: Unused.
        MaxRequests int
 
        fileIndex *segments.Index
@@ -73,7 +73,7 @@ type Client struct {
        // given that's how requests are mapped to webseeds, but the torrent.Client works at the piece
        // level. We can map our file-level adjustments to the pieces here. This probably need to be
        // private in the future, if Client ever starts removing pieces. TODO: This belongs in
-       // webseedPeer.
+       // webseedPeer. TODO: Unused.
        Pieces roaring.Bitmap
        // This wraps http.Response bodies, for example to limit the download rate.
        ResponseBodyWrapper     ResponseBodyWrapper