这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions pkg/ffuf/rate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down