From: Matt Joiner Date: Tue, 5 Aug 2025 12:40:18 +0000 (+1000) Subject: Expose TORRENT_WEBSEED_REQUEST_CHUNK_SIZE X-Git-Tag: v1.59.0~2^2~56 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=64a11e2464d300efa5eebed9e4f9ee407a49d016;p=btrtrc.git Expose TORRENT_WEBSEED_REQUEST_CHUNK_SIZE --- diff --git a/env.go b/env.go index c8759d6e..996e1a8f 100644 --- a/env.go +++ b/env.go @@ -8,12 +8,20 @@ import ( "golang.org/x/exp/constraints" ) -func initIntFromEnv[T constraints.Integer](key string, defaultValue T, bitSize int) T { +func initIntFromEnv[T constraints.Signed](key string, defaultValue T, bitSize int) T { + return strconvFromEnv(key, defaultValue, bitSize, strconv.ParseInt) +} + +func initUIntFromEnv[T constraints.Unsigned](key string, defaultValue T, bitSize int) T { + return strconvFromEnv(key, defaultValue, bitSize, strconv.ParseUint) +} + +func strconvFromEnv[T, U constraints.Integer](key string, defaultValue T, bitSize int, conv func(s string, base, bitSize int) (U, error)) T { s := os.Getenv(key) if s == "" { return defaultValue } - i64, err := strconv.ParseInt(s, 10, bitSize) + i64, err := conv(s, 10, bitSize) panicif.Err(err) return T(i64) } diff --git a/webseed-requesting.go b/webseed-requesting.go index d41d909c..d290d525 100644 --- a/webseed-requesting.go +++ b/webseed-requesting.go @@ -233,8 +233,9 @@ func (t *Torrent) getWebseedRequestEnd(begin RequestIndex, debugLogger *slog.Log return end } -// Cloudflare caches up to 512 MB responses by default. This is also an alignment. -var webseedRequestChunkSize uint64 = 256 << 20 +// Cloudflare caches up to 512 MB responses by default. This is also an alignment. Making this +// smaller will allow requests to complete a smaller set of files faster. +var webseedRequestChunkSize = initUIntFromEnv[uint64]("TORRENT_WEBSEED_REQUEST_CHUNK_SIZE", 64<<20, 64) func (t *Torrent) endRequestForAlignedWebseedResponse(start RequestIndex) RequestIndex { end := min(t.maxEndRequest(), nextMultiple(start, t.chunksPerAlignedWebseedResponse()))