diff --git a/db.go b/db.go index 28eba24..595ae39 100644 --- a/db.go +++ b/db.go @@ -79,20 +79,26 @@ func (model *Model) AutoSave() bool { return false } +type dldEntry struct { + ip string + path string +} + // DldCounter is used to validate duplicated download requests type DldCounter struct { - IPHistory map[string]time.Time + IPHistory map[dldEntry]time.Time } var DCounter DldCounter = DldCounter{} var DldInterval float64 = 60.0 // seconds -func (counter *DldCounter) Validate(ip string) bool { +func (counter *DldCounter) Validate(ip string, path string) bool { if counter.IPHistory == nil { - counter.IPHistory = make(map[string]time.Time) + counter.IPHistory = make(map[dldEntry]time.Time) } - if time.Since(counter.IPHistory[ip]).Seconds() > DldInterval { - counter.IPHistory[ip] = time.Now() + entry := dldEntry{ip, path} + if time.Since(counter.IPHistory[entry]).Seconds() > DldInterval { + counter.IPHistory[entry] = time.Now() // fmt.Println("valid", ip) return true } diff --git a/httpstaticserver.go b/httpstaticserver.go index db9663a..672263a 100644 --- a/httpstaticserver.go +++ b/httpstaticserver.go @@ -770,7 +770,7 @@ func checkFilename(name string) error { func DldIncre(model Model, rAddress string, path string) { ip, _, _ := net.SplitHostPort(rAddress) - if DCounter.Validate(ip) { + if DCounter.Validate(ip, path) { model.Incre(path) } }