From e8775c4ad5776e46826743d5383c81adf5fc722a Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 5 Apr 2024 01:28:49 +0200 Subject: [PATCH] New settings SameDownloadInterval. This lets admins customize the time interval (in seconds) between which they want to consider 2 range downloads to be the same download. Setting SameDownloadInterval to 0 disables the same download detection logic (i.e. that every range download counts as a full download, just as it used to happen until now). --- config/config.go | 2 ++ http/http.go | 4 ++-- mirrorbits.conf | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index aa877893..4650575f 100644 --- a/config/config.go +++ b/config/config.go @@ -37,6 +37,7 @@ func defaultConfig() Configuration { OutputMode: "auto", ListenAddress: ":8080", Gzip: false, + SameDownloadInterval: 600, RedisAddress: "127.0.0.1:6379", RedisPassword: "", RedisDB: 0, @@ -70,6 +71,7 @@ type Configuration struct { OutputMode string `yaml:"OutputMode"` ListenAddress string `yaml:"ListenAddress"` Gzip bool `yaml:"Gzip"` + SameDownloadInterval int `yaml:"SameDownloadInterval"` RedisAddress string `yaml:"RedisAddress"` RedisPassword string `yaml:"RedisPassword"` RedisDB int `yaml:"RedisDB"` diff --git a/http/http.go b/http/http.go index cd1f979f..e0e027db 100644 --- a/http/http.go +++ b/http/http.go @@ -321,7 +321,8 @@ func (h *HTTP) mirrorHandler(w http.ResponseWriter, r *http.Request, ctx *Contex if !ctx.IsMirrorlist() { logs.LogDownload(resultRenderer.Type(), status, results, err) if len(mlist) > 0 { - if r.Header.Get("Range") == "" { + timeout := GetConfig().SameDownloadInterval + if r.Header.Get("Range") == "" || timeout == 0 { h.stats.CountDownload(mlist[0], fileInfo) } else { downloaderID := remoteIP+"/"+r.Header.Get("User-Agent") @@ -335,7 +336,6 @@ func (h *HTTP) mirrorHandler(w http.ResponseWriter, r *http.Request, ctx *Contex tempKey := "DOWNLOADED_"+chk+"_"+urlPath prev := "" - timeout := 600 if h.redis.IsAtLeastVersion("6.2.0") { // Get and set the key in one command. prev, _ = redis.String(rconn.Do("SET", tempKey, 1, "GET", "EX", timeout)) diff --git a/mirrorbits.conf b/mirrorbits.conf index e373ebd1..eccd358c 100644 --- a/mirrorbits.conf +++ b/mirrorbits.conf @@ -30,6 +30,12 @@ ## Enable Gzip compression # Gzip: false +## Interval in seconds between which 2 range downloads of a given file +## from a same origin (hashed (IP, user-agent) couple) are considered +## to be the same download. In particular, download statistics are not +## incremented for this file. +# SameDownloadInterval: 600 + ## Host and port to listen on # ListenAddress: :8080