From de9ac86677818de0743d8db24147c81c96b73a74 Mon Sep 17 00:00:00 2001 From: Joona Hoikkala <5235109+joohoi@users.noreply.github.com> Date: Sun, 22 Oct 2023 17:34:24 +0300 Subject: [PATCH] Fixed setting unlimited rate in interactive console (#748) * Fixed setting unlimited rate in interactive console * Add changelog entry --- CHANGELOG.md | 1 + pkg/ffuf/rate.go | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6af810..bfbc7f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ - New - Changed - Fix a bug in autocalibration strategy merging, when two files have the same strategy key + - Fix panic when setting rate to 0 in the interactive console - v2.1.0 - New diff --git a/pkg/ffuf/rate.go b/pkg/ffuf/rate.go index e8a0f50..4e6eec5 100644 --- a/pkg/ffuf/rate.go +++ b/pkg/ffuf/rate.go @@ -19,15 +19,13 @@ func NewRateThrottle(conf *Config) *RateThrottle { Config: conf, lastAdjustment: time.Now(), } + if conf.Rate > 0 { r.rateCounter = ring.New(int(conf.Rate * 5)) - } else { - r.rateCounter = ring.New(conf.Threads * 5) - } - if conf.Rate > 0 { ratemicros := 1000000 / conf.Rate r.RateLimiter = time.NewTicker(time.Microsecond * time.Duration(ratemicros)) } else { + r.rateCounter = ring.New(conf.Threads * 5) //Million rps is probably a decent hardcoded upper speedlimit r.RateLimiter = time.NewTicker(time.Microsecond * 1) } @@ -72,10 +70,17 @@ func (r *RateThrottle) ChangeRate(rate int) { } r.RateLimiter.Stop() - r.RateLimiter = time.NewTicker(time.Microsecond * time.Duration(ratemicros)) + if rate > 0 { + r.RateLimiter = time.NewTicker(time.Microsecond * time.Duration(ratemicros)) + // reset the rate counter + r.rateCounter = ring.New(rate * 5) + } else { + r.RateLimiter = time.NewTicker(time.Microsecond * 1) + // reset the rate counter + r.rateCounter = ring.New(r.Config.Threads * 5) + } + r.Config.Rate = int64(rate) - // reset the rate counter - r.rateCounter = ring.New(rate * 5) } // rateTick adds a new duration measurement tick to rate counter