Skip to content

Commit

Permalink
New settings SameDownloadInterval.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
Jehan committed Apr 4, 2024
1 parent 7c0cba3 commit e8775c4
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func defaultConfig() Configuration {
OutputMode: "auto",
ListenAddress: ":8080",
Gzip: false,
SameDownloadInterval: 600,
RedisAddress: "127.0.0.1:6379",
RedisPassword: "",
RedisDB: 0,
Expand Down Expand Up @@ -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"`
Expand Down
4 changes: 2 additions & 2 deletions http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions mirrorbits.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e8775c4

Please sign in to comment.