panicif.LessThan(last, begin)
// Hello C++ my old friend.
end := last + 1
+ truncateEndToCacheBoundary(begin, &end, t.chunkSize)
if webseed.PrintDebug && end != fileEnd {
debugLogger.Debug(
"shortened webseed request",
}
}
+// Limit a webseed request end request index so that the required response body size fits within
+// cache limits for a WebSeed provider.
+func truncateEndToCacheBoundary(start RequestIndex, end *RequestIndex, chunkSize pp.Integer) {
+ // Cloudflare caches up to 512 MB responses by default.
+ const cacheResponseBodyLimit = 256 << 20
+ chunksPerAlignedResponse := RequestIndex(cacheResponseBodyLimit / chunkSize)
+ startIndex := start / chunksPerAlignedResponse
+ *end = min(*end, (startIndex+1)*chunksPerAlignedResponse)
+}
+
func (cl *Client) dumpCurrentWebseedRequests() {
if webseed.PrintDebug {
fmt.Println("current webseed requests:")
return nil, err
}
// We avoid Range requests if we can. We check the Content-Length elsewhere so that early
- // detection is not lost.
+ // detection is not lost. TODO: Try disabling this for CloudFlare?
if offset != 0 || length != fileInfo.Length {
req.Header.Set("Range", fmt.Sprintf("bytes=%d-%d", offset, offset+length-1))
}