优化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 { 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)"` Timeout int `long:"timeout" default:"2" description:"Int, timeout with request (seconds)"`
PoolSize int `short:"p" long:"pool" default:"5" description:"Int, Pool size"` 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)"` 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 { if r.Limit == 0 {
r.Limit = len(r.Wordlist) r.Limit = len(r.Wordlist)
} else {
r.Limit = r.Offset + opt.Limit
} }
if opt.Uppercase { if opt.Uppercase {

View File

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

View File

@ -74,7 +74,7 @@ func (r *Runner) Prepare(ctx context.Context) error {
logs.Log.Error(err.Error()) logs.Log.Error(err.Error())
return 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() err = pool.Init()
if err != nil { if err != nil {
logs.Log.Error(err.Error()) logs.Log.Error(err.Error())