mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Fix URLTest recheck
This commit is contained in:
parent
ce04488b67
commit
ecb3bae1bf
@ -72,7 +72,7 @@ func (s *URLTest) Start() error {
|
|||||||
outbounds = append(outbounds, detour)
|
outbounds = append(outbounds, detour)
|
||||||
}
|
}
|
||||||
s.group = NewURLTestGroup(s.ctx, s.router, s.logger, outbounds, s.link, s.interval, s.tolerance)
|
s.group = NewURLTestGroup(s.ctx, s.router, s.logger, outbounds, s.link, s.interval, s.tolerance)
|
||||||
go s.group.CheckOutbounds()
|
go s.group.CheckOutbounds(false)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ func (s *URLTest) NewPacketConnection(ctx context.Context, conn N.PacketConn, me
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *URLTest) InterfaceUpdated() error {
|
func (s *URLTest) InterfaceUpdated() error {
|
||||||
go s.group.CheckOutbounds()
|
go s.group.CheckOutbounds(true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,22 +248,26 @@ func (g *URLTestGroup) Fallback(used adapter.Outbound) []adapter.Outbound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (g *URLTestGroup) loopCheck() {
|
func (g *URLTestGroup) loopCheck() {
|
||||||
go g.CheckOutbounds()
|
go g.CheckOutbounds(true)
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-g.close:
|
case <-g.close:
|
||||||
return
|
return
|
||||||
case <-g.ticker.C:
|
case <-g.ticker.C:
|
||||||
g.CheckOutbounds()
|
g.CheckOutbounds(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *URLTestGroup) CheckOutbounds() {
|
func (g *URLTestGroup) CheckOutbounds(force bool) {
|
||||||
_, _ = g.URLTest(g.ctx, g.link)
|
_, _ = g.urlTest(g.ctx, g.link, force)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *URLTestGroup) URLTest(ctx context.Context, link string) (map[string]uint16, error) {
|
func (g *URLTestGroup) URLTest(ctx context.Context, link string) (map[string]uint16, error) {
|
||||||
|
return g.urlTest(ctx, link, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *URLTestGroup) urlTest(ctx context.Context, link string, force bool) (map[string]uint16, error) {
|
||||||
b, _ := batch.New(ctx, batch.WithConcurrencyNum[any](10))
|
b, _ := batch.New(ctx, batch.WithConcurrencyNum[any](10))
|
||||||
checked := make(map[string]bool)
|
checked := make(map[string]bool)
|
||||||
result := make(map[string]uint16)
|
result := make(map[string]uint16)
|
||||||
@ -275,7 +279,7 @@ func (g *URLTestGroup) URLTest(ctx context.Context, link string) (map[string]uin
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
history := g.history.LoadURLTestHistory(realTag)
|
history := g.history.LoadURLTestHistory(realTag)
|
||||||
if history != nil && time.Now().Sub(history.Time) < g.interval {
|
if !force && history != nil && time.Now().Sub(history.Time) < g.interval {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
checked[realTag] = true
|
checked[realTag] = true
|
||||||
|
Loading…
x
Reference in New Issue
Block a user