fix: handle manually select in url-test
This commit is contained in:
parent
9b6e56a65e
commit
26acaee424
1 changed files with 16 additions and 15 deletions
|
@ -96,25 +96,30 @@ func (u *URLTest) Unwrap(metadata *C.Metadata, touch bool) C.Proxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *URLTest) fast(touch bool) C.Proxy {
|
func (u *URLTest) fast(touch bool) C.Proxy {
|
||||||
elm, _, shared := u.fastSingle.Do(func() (C.Proxy, error) {
|
|
||||||
var s C.Proxy
|
proxies := u.GetProxies(touch)
|
||||||
proxies := u.GetProxies(touch)
|
if u.selected != "" {
|
||||||
fast := proxies[0]
|
for _, proxy := range proxies {
|
||||||
if fast.Name() == u.selected {
|
if !proxy.Alive() {
|
||||||
s = fast
|
continue
|
||||||
|
}
|
||||||
|
if proxy.Name() == u.selected {
|
||||||
|
u.fastNode = proxy
|
||||||
|
return proxy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
elm, _, shared := u.fastSingle.Do(func() (C.Proxy, error) {
|
||||||
|
fast := proxies[0]
|
||||||
min := fast.LastDelay()
|
min := fast.LastDelay()
|
||||||
fastNotExist := true
|
fastNotExist := true
|
||||||
|
|
||||||
for _, proxy := range proxies[1:] {
|
for _, proxy := range proxies[1:] {
|
||||||
|
|
||||||
if u.fastNode != nil && proxy.Name() == u.fastNode.Name() {
|
if u.fastNode != nil && proxy.Name() == u.fastNode.Name() {
|
||||||
fastNotExist = false
|
fastNotExist = false
|
||||||
}
|
}
|
||||||
|
|
||||||
if proxy.Name() == u.selected {
|
|
||||||
s = proxy
|
|
||||||
}
|
|
||||||
if !proxy.Alive() {
|
if !proxy.Alive() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -124,16 +129,12 @@ func (u *URLTest) fast(touch bool) C.Proxy {
|
||||||
fast = proxy
|
fast = proxy
|
||||||
min = delay
|
min = delay
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
// tolerance
|
// tolerance
|
||||||
if u.fastNode == nil || fastNotExist || !u.fastNode.Alive() || u.fastNode.LastDelay() > fast.LastDelay()+u.tolerance {
|
if u.fastNode == nil || fastNotExist || !u.fastNode.Alive() || u.fastNode.LastDelay() > fast.LastDelay()+u.tolerance {
|
||||||
u.fastNode = fast
|
u.fastNode = fast
|
||||||
}
|
}
|
||||||
if s != nil {
|
|
||||||
if s.Alive() && s.LastDelay() < fast.LastDelay()+u.tolerance {
|
|
||||||
u.fastNode = s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return u.fastNode, nil
|
return u.fastNode, nil
|
||||||
})
|
})
|
||||||
if shared && touch { // a shared fastSingle.Do() may cause providers untouched, so we touch them again
|
if shared && touch { // a shared fastSingle.Do() may cause providers untouched, so we touch them again
|
||||||
|
|
Loading…
Reference in a new issue