mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2024-11-15 13:41:23 +08:00
Change: adjust tolerance logic (#864)
This commit is contained in:
parent
92a23f1eab
commit
83a684c551
@ -22,7 +22,6 @@ func urlTestWithTolerance(tolerance uint16) urlTestOption {
|
|||||||
type URLTest struct {
|
type URLTest struct {
|
||||||
*outbound.Base
|
*outbound.Base
|
||||||
tolerance uint16
|
tolerance uint16
|
||||||
lastDelay uint16
|
|
||||||
fastNode C.Proxy
|
fastNode C.Proxy
|
||||||
single *singledo.Single
|
single *singledo.Single
|
||||||
fastSingle *singledo.Single
|
fastSingle *singledo.Single
|
||||||
@ -63,13 +62,6 @@ func (u *URLTest) proxies() []C.Proxy {
|
|||||||
|
|
||||||
func (u *URLTest) fast() C.Proxy {
|
func (u *URLTest) fast() C.Proxy {
|
||||||
elm, _, _ := u.fastSingle.Do(func() (interface{}, error) {
|
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()
|
proxies := u.proxies()
|
||||||
fast := proxies[0]
|
fast := proxies[0]
|
||||||
min := fast.LastDelay()
|
min := fast.LastDelay()
|
||||||
@ -85,9 +77,12 @@ func (u *URLTest) fast() C.Proxy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
u.fastNode = fast
|
// tolerance
|
||||||
u.lastDelay = fast.LastDelay()
|
if u.fastNode == nil || u.fastNode.LastDelay() > fast.LastDelay() + u.tolerance {
|
||||||
return fast, nil
|
u.fastNode = fast
|
||||||
|
}
|
||||||
|
|
||||||
|
return u.fastNode, nil
|
||||||
})
|
})
|
||||||
|
|
||||||
return elm.(C.Proxy)
|
return elm.(C.Proxy)
|
||||||
|
Loading…
Reference in New Issue
Block a user