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 } }