From: Matt Joiner Date: Wed, 30 Jul 2025 07:47:31 +0000 (+1000) Subject: Expose TORRENT_WEBSEED_HOST_REQUEST_CONCURRENCY X-Git-Tag: v1.59.0~2^2~85 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=0026e7aaee042e4bc318491e66f90297ecc5d8b6;p=btrtrc.git Expose TORRENT_WEBSEED_HOST_REQUEST_CONCURRENCY --- diff --git a/client.go b/client.go index 9a62e40d..999282cf 100644 --- a/client.go +++ b/client.go @@ -1931,7 +1931,7 @@ func (cl *Client) Stats() ClientStats { func (cl *Client) underWebSeedHttpRequestLimit(key webseedHostKeyHandle) bool { panicif.Zero(key) - return cl.numWebSeedRequests[key] < defaultRequestsPerWebseedHost + return cl.numWebSeedRequests[key] < webseedHostRequestConcurrency } // Check for bad arrangements. This is a candidate for an error state check method. diff --git a/webseed-requesting.go b/webseed-requesting.go index 6cd88655..a386e091 100644 --- a/webseed-requesting.go +++ b/webseed-requesting.go @@ -5,6 +5,8 @@ import ( "fmt" "iter" "maps" + "os" + "strconv" "strings" "sync" "unique" @@ -18,7 +20,13 @@ import ( "github.com/anacrolix/torrent/webseed" ) -const defaultRequestsPerWebseedHost = 10 +var webseedHostRequestConcurrency int + +func init() { + i64, err := strconv.ParseInt(cmp.Or(os.Getenv("TORRENT_WEBSEED_HOST_REQUEST_CONCURRENCY"), "10"), 10, 0) + panicif.Err(err) + webseedHostRequestConcurrency = int(i64) +} type ( webseedHostKey string @@ -128,7 +136,7 @@ func (cl *Client) updateWebseedRequests() { // handling overhead. Need the value to avoid looking this up again. costKey := elem.costKey panicif.Zero(costKey) - if len(plan.byCost[costKey]) >= defaultRequestsPerWebseedHost { + if len(plan.byCost[costKey]) >= webseedHostRequestConcurrency { continue } g.MakeMapIfNil(&plan.byCost)