From 6c2f5919d296b0333c0cd4427c1d87e42fe9f39d Mon Sep 17 00:00:00 2001 From: M09Ic Date: Fri, 6 Jan 2023 11:30:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96pool=E7=9A=84init,=20?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BA=92=E6=96=A5=E9=94=81=E6=8F=90=E9=AB=98?= =?UTF-8?q?=E5=B9=B6=E5=8F=91=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/pool.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/internal/pool.go b/internal/pool.go index 796b98a..92b255f 100644 --- a/internal/pool.go +++ b/internal/pool.go @@ -146,20 +146,14 @@ type Pool struct { func (pool *Pool) Init() error { // 分成两步是为了避免闭包的线程安全问题 - pool.initwg.Add(1) + pool.initwg.Add(2) pool.reqPool.Invoke(newUnit("/", InitIndexSource)) + pool.reqPool.Invoke(newUnit(pkg.RandPath(), InitRandomSource)) pool.initwg.Wait() if pool.index.ErrString != "" { return fmt.Errorf(pool.index.String()) } logs.Log.Info("[baseline.index] " + pool.index.Format([]string{"status", "length", "spend", "title", "frame", "redirect"})) - if pool.index.Status == 200 || (pool.index.Status/100) == 3 { - pool.OutputCh <- pool.index - } - - pool.initwg.Add(1) - pool.reqPool.Invoke(newUnit(pkg.RandPath(), InitRandomSource)) - pool.initwg.Wait() // 检测基本访问能力 if pool.random.ErrString != "" { return fmt.Errorf(pool.random.String()) @@ -323,13 +317,20 @@ func (pool *Pool) Invoke(v interface{}) { switch unit.source { case InitRandomSource: bl.Collect() + pool.locker.Lock() pool.random = bl + pool.locker.Unlock() pool.addFuzzyBaseline(bl) pool.initwg.Done() case InitIndexSource: bl.Collect() + pool.locker.Lock() pool.index = bl + pool.locker.Unlock() pool.wg.Add(1) + if bl.Status == 200 || (bl.Status/100) == 3 { + pool.OutputCh <- bl + } pool.doCrawl(bl) pool.initwg.Done() case CheckSource: