优化compare逻辑, 如果不为fuzzy statuscode, 则使用base

优化offset与limit的逻辑与显示
This commit is contained in:
M09Ic 2022-11-11 11:40:53 +08:00
parent 9f6199c243
commit f8f2fe839c
3 changed files with 14 additions and 11 deletions

View File

@ -55,7 +55,7 @@ type RequestOptions struct {
}
type MiscOptions struct {
Deadline int `long:"deadline" default:"600" description:"Int, deadline (seconds)"` // todo 总的超时时间,适配云函数的deadline
Deadline int `long:"deadline" default:"99999" description:"Int, deadline (seconds)"` // todo 总的超时时间,适配云函数的deadline
Timeout int `long:"timeout" default:"2" description:"Int, timeout with request (seconds)"`
PoolSize int `short:"p" long:"pool" default:"5" description:"Int, Pool size"`
Threads int `short:"t" long:"thread" default:"20" description:"Int, number of threads per pool (seconds)"`
@ -183,6 +183,8 @@ func (opt *Option) PrepareRunner() (*Runner, error) {
}
if r.Limit == 0 {
r.Limit = len(r.Wordlist)
} else {
r.Limit = r.Offset + opt.Limit
}
if opt.Uppercase {

View File

@ -212,7 +212,6 @@ func (p *Pool) Init() error {
}
func (p *Pool) Run(ctx context.Context, offset, limit int) {
maxreq := offset + limit
Loop:
for {
select {
@ -226,7 +225,7 @@ Loop:
continue
}
if p.reqCount > maxreq {
if p.reqCount > limit {
break Loop
}
@ -277,12 +276,14 @@ func (p *Pool) BaseCompare(bl *pkg.Baseline) {
}
var status int
base, ok := p.baselines[bl.Status]
if ok {
// 挑选对应状态码的baseline进行compare
if status = base.Compare(bl); status == 1 {
p.PutToInvalid(bl, "compare failed")
return
}
if !ok {
base = p.base
}
// 挑选对应状态码的baseline进行compare
if status = base.Compare(bl); status == 1 {
p.PutToInvalid(bl, "compare failed")
return
}
bl.Collect()
@ -293,7 +294,7 @@ func (p *Pool) BaseCompare(bl *pkg.Baseline) {
}
}
if status == 0 && ok && base.FuzzyCompare(bl) {
if status == 0 && base.FuzzyCompare(bl) {
p.PutToInvalid(bl, "fuzzy compare failed")
p.PutToFuzzy(bl)
return

View File

@ -74,7 +74,7 @@ func (r *Runner) Prepare(ctx context.Context) error {
logs.Log.Error(err.Error())
return
}
pool.bar = pkg.NewBar(u, len(r.Wordlist), r.Progress)
pool.bar = pkg.NewBar(u, r.Limit-r.Offset, r.Progress)
err = pool.Init()
if err != nil {
logs.Log.Error(err.Error())