2024-02-10 18:23:50 +08:00
|
|
|
package pool
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"github.com/chainreactors/parsers"
|
|
|
|
"github.com/chainreactors/spray/internal/ihttp"
|
|
|
|
"github.com/chainreactors/spray/pkg"
|
|
|
|
"github.com/chainreactors/words"
|
|
|
|
"sync"
|
|
|
|
)
|
|
|
|
|
2024-05-17 17:47:11 +08:00
|
|
|
type BasePool struct {
|
2024-02-10 18:23:50 +08:00
|
|
|
*Config
|
|
|
|
Statistor *pkg.Statistor
|
|
|
|
Bar *pkg.Bar
|
|
|
|
Worder *words.Worder
|
2024-05-30 23:33:57 +08:00
|
|
|
Cancel context.CancelFunc
|
2024-02-10 18:23:50 +08:00
|
|
|
client *ihttp.Client
|
|
|
|
ctx context.Context
|
2024-05-30 23:33:57 +08:00
|
|
|
processCh chan *pkg.Baseline // 待处理的baseline
|
2024-02-10 18:23:50 +08:00
|
|
|
dir string
|
|
|
|
reqCount int
|
|
|
|
failedCount int
|
|
|
|
additionCh chan *Unit
|
|
|
|
closeCh chan struct{}
|
2024-08-12 15:12:43 +08:00
|
|
|
wg *sync.WaitGroup
|
2024-02-10 18:23:50 +08:00
|
|
|
}
|
|
|
|
|
2024-05-17 17:47:11 +08:00
|
|
|
func (pool *BasePool) doRedirect(bl *pkg.Baseline, depth int) {
|
2024-02-10 18:23:50 +08:00
|
|
|
if depth >= MaxRedirect {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
reURL := pkg.FormatURL(bl.Url.Path, bl.RedirectURL)
|
|
|
|
pool.wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer pool.wg.Done()
|
|
|
|
pool.addAddition(&Unit{
|
|
|
|
path: reURL,
|
2024-08-29 01:41:00 +08:00
|
|
|
host: bl.Host,
|
2024-02-10 18:23:50 +08:00
|
|
|
source: parsers.RedirectSource,
|
|
|
|
frontUrl: bl.UrlString,
|
|
|
|
depth: depth + 1,
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2024-05-17 17:47:11 +08:00
|
|
|
func (pool *BasePool) doRetry(bl *pkg.Baseline) {
|
2024-08-25 23:06:10 +08:00
|
|
|
if bl.Retry >= pool.RetryLimit {
|
2024-02-10 18:23:50 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
pool.wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer pool.wg.Done()
|
|
|
|
pool.addAddition(&Unit{
|
|
|
|
path: bl.Path,
|
2024-08-29 01:41:00 +08:00
|
|
|
host: bl.Host,
|
2024-02-10 18:23:50 +08:00
|
|
|
source: parsers.RetrySource,
|
|
|
|
retry: bl.Retry + 1,
|
|
|
|
})
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
2024-05-17 17:47:11 +08:00
|
|
|
func (pool *BasePool) addAddition(u *Unit) {
|
2024-02-10 18:23:50 +08:00
|
|
|
// 强行屏蔽报错, 防止goroutine泄露
|
|
|
|
pool.wg.Add(1)
|
|
|
|
defer func() {
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
pool.additionCh <- u
|
|
|
|
}
|
|
|
|
|
2024-05-17 17:47:11 +08:00
|
|
|
func (pool *BasePool) putToOutput(bl *pkg.Baseline) {
|
2024-07-01 19:51:16 +08:00
|
|
|
if bl.IsValid || bl.IsFuzzy {
|
|
|
|
bl.Collect()
|
|
|
|
}
|
2024-07-14 04:08:50 +08:00
|
|
|
pool.Outwg.Add(1)
|
2024-02-10 18:23:50 +08:00
|
|
|
pool.OutputCh <- bl
|
|
|
|
}
|
|
|
|
|
2024-05-17 17:47:11 +08:00
|
|
|
func (pool *BasePool) putToFuzzy(bl *pkg.Baseline) {
|
2024-07-14 04:08:50 +08:00
|
|
|
pool.Outwg.Add(1)
|
2024-02-10 18:23:50 +08:00
|
|
|
bl.IsFuzzy = true
|
|
|
|
pool.FuzzyCh <- bl
|
|
|
|
}
|