From 44277e5dd2a095c68b5e18cfced67a195fdb79f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 10 May 2024 17:40:54 +0800 Subject: [PATCH] Fix urltest logic --- outbound/urltest.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/outbound/urltest.go b/outbound/urltest.go index f6366c05..aa7cff6c 100644 --- a/outbound/urltest.go +++ b/outbound/urltest.go @@ -287,8 +287,23 @@ func (g *URLTestGroup) Close() error { func (g *URLTestGroup) Select(network string) (adapter.Outbound, bool) { var minDelay uint16 - var minTime time.Time var minOutbound adapter.Outbound + switch network { + case N.NetworkTCP: + if g.selectedOutboundTCP != nil { + if history := g.history.LoadURLTestHistory(RealTag(g.selectedOutboundTCP)); history != nil { + minOutbound = g.selectedOutboundTCP + minDelay = history.Delay + } + } + case N.NetworkUDP: + if g.selectedOutboundUDP != nil { + if history := g.history.LoadURLTestHistory(RealTag(g.selectedOutboundUDP)); history != nil { + minOutbound = g.selectedOutboundUDP + minDelay = history.Delay + } + } + } for _, detour := range g.outbounds { if !common.Contains(detour.Network(), network) { continue @@ -297,9 +312,8 @@ func (g *URLTestGroup) Select(network string) (adapter.Outbound, bool) { if history == nil { continue } - if minDelay == 0 || minDelay > history.Delay+g.tolerance || minDelay > history.Delay-g.tolerance && minTime.Before(history.Time) { + if minDelay == 0 || minDelay > history.Delay+g.tolerance { minDelay = history.Delay - minTime = history.Time minOutbound = detour } }