From 83a684c5516c09d13d4e8d3666c35181be383ab9 Mon Sep 17 00:00:00 2001 From: Fndroid Date: Thu, 6 Aug 2020 20:12:03 +0800 Subject: [PATCH] Change: adjust tolerance logic (#864) --- adapters/outboundgroup/urltest.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/adapters/outboundgroup/urltest.go b/adapters/outboundgroup/urltest.go index 750d809bf..7073b5ec8 100644 --- a/adapters/outboundgroup/urltest.go +++ b/adapters/outboundgroup/urltest.go @@ -22,7 +22,6 @@ func urlTestWithTolerance(tolerance uint16) urlTestOption { type URLTest struct { *outbound.Base tolerance uint16 - lastDelay uint16 fastNode C.Proxy single *singledo.Single fastSingle *singledo.Single @@ -63,13 +62,6 @@ func (u *URLTest) proxies() []C.Proxy { func (u *URLTest) fast() C.Proxy { elm, _, _ := u.fastSingle.Do(func() (interface{}, error) { - // tolerance - if u.tolerance != 0 && u.fastNode != nil { - if u.fastNode.LastDelay() < u.lastDelay+u.tolerance { - return u.fastNode, nil - } - } - proxies := u.proxies() fast := proxies[0] min := fast.LastDelay() @@ -85,9 +77,12 @@ func (u *URLTest) fast() C.Proxy { } } - u.fastNode = fast - u.lastDelay = fast.LastDelay() - return fast, nil + // tolerance + if u.fastNode == nil || u.fastNode.LastDelay() > fast.LastDelay() + u.tolerance { + u.fastNode = fast + } + + return u.fastNode, nil }) return elm.(C.Proxy)