]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Prevent webseed requests when torrent data download disallowed
authorMatt Joiner <anacrolix@gmail.com>
Thu, 31 Jul 2025 01:52:19 +0000 (11:52 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 31 Jul 2025 01:52:19 +0000 (11:52 +1000)
piece.go
webseed-peer.go
webseed-requesting.go

index 166da4d4cd2898f6ad1f101c378f370cfb2c6327..12d28be2d55043ae82eb9219ea8a75ab0ec0103b 100644 (file)
--- a/piece.go
+++ b/piece.go
@@ -292,7 +292,7 @@ func (p *Piece) purePriority() (ret PiecePriority) {
 }
 
 func (p *Piece) ignoreForRequests() bool {
-       return p.hashing || p.marking || !p.haveHash() || p.t.pieceComplete(p.index) || p.queuedForHash()
+       return p.hashing || p.marking || !p.haveHash() || p.t.pieceComplete(p.index) || p.queuedForHash() || p.t.dataDownloadDisallowed.IsSet()
 }
 
 // This is the priority adjusted for piece state like completion, hashing etc.
index 9b64680fe47bc73e760c429e1da54c6fecdb910a..d32aab93d40e0458956688265d830614247eba5f 100644 (file)
@@ -52,7 +52,9 @@ func (me *webseedPeer) isLowOnRequests() bool {
 }
 
 // Webseed requests are issued globally so per-connection reasons or handling make no sense.
-func (me *webseedPeer) onNeedUpdateRequests(updateRequestReason) {}
+func (me *webseedPeer) onNeedUpdateRequests(updateRequestReason) {
+       me.peer.cl.scheduleImmediateWebseedRequestUpdate()
+}
 
 func (me *webseedPeer) expectingChunks() bool {
        return len(me.activeRequests) > 0
index a386e09187b7a139e23af5de6c1e6882a87568a7..48d7eea4409d00f68e6ee3cf577b83aff1b3d2da 100644 (file)
@@ -102,6 +102,10 @@ func (cl *Client) updateWebseedRequests() {
        }
        // Add remaining existing requests.
        for key := range unusedExistingRequests {
+               // Don't reconsider existing requests that aren't wanted anymore.
+               if key.t.dataDownloadDisallowed.IsSet() {
+                       continue
+               }
                heapSlice = append(heapSlice, heapElem{key, existingRequests[key]})
        }
        aprioriHeap := heap.InterfaceForSlice(
@@ -136,6 +140,12 @@ func (cl *Client) updateWebseedRequests() {
                // handling overhead. Need the value to avoid looking this up again.
                costKey := elem.costKey
                panicif.Zero(costKey)
+               if elem.existingWebseedRequest == nil {
+                       // Existing requests might be within the allowed discard range.
+                       panicif.Eq(elem.priority, PiecePriorityNone)
+               }
+               panicif.True(elem.t.dataDownloadDisallowed.IsSet())
+               panicif.True(elem.t.closed.IsSet())
                if len(plan.byCost[costKey]) >= webseedHostRequestConcurrency {
                        continue
                }
@@ -363,7 +373,8 @@ func (cl *Client) scheduleImmediateWebseedRequestUpdate() {
        }
        // Set the timer to fire right away (this will coalesce consecutive updates without forcing an
        // update on every call to this method). Since we're holding the Client lock, and we cancelled
-       // the timer, and it wasn't active, nobody else should have reset it before us.
+       // the timer, and it wasn't active, nobody else should have reset it before us. Do we need to
+       // introduce a "reason" field here, (albeit Client-level?).
        panicif.True(cl.webseedRequestTimer.Reset(0))
 }