From ac381736a5473c2afe46a49d42896e73d3297032 Mon Sep 17 00:00:00 2001 From: Larvan2 <78135608+Larvan2@users.noreply.github.com> Date: Fri, 22 Dec 2023 21:18:17 +0800 Subject: [PATCH] chore: restore function name to AliveForTestUrl --- adapter/adapter.go | 10 +++++----- adapter/outboundgroup/fallback.go | 6 +++--- adapter/outboundgroup/loadbalance.go | 8 ++++---- adapter/outboundgroup/urltest.go | 12 ++++++------ adapter/provider/healthcheck.go | 2 +- constant/adapters.go | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) diff --git a/adapter/adapter.go b/adapter/adapter.go index a3af6471b..695033b79 100644 --- a/adapter/adapter.go +++ b/adapter/adapter.go @@ -33,13 +33,13 @@ type internalProxyState struct { type Proxy struct { C.ProxyAdapter - history *queue.Queue[C.DelayHistory] alive atomic.Bool + history *queue.Queue[C.DelayHistory] extra *xsync.MapOf[string, *internalProxyState] } -// Alive implements C.Proxy -func (p *Proxy) Alive(url string) bool { +// AliveForTestUrl implements C.Proxy +func (p *Proxy) AliveForTestUrl(url string) bool { if state, ok := p.extra.Load(url); ok { return state.alive.Load() } @@ -127,7 +127,7 @@ func (p *Proxy) ExtraDelayHistories() map[string]C.ProxyState { // LastDelayForTestUrl return last history record of the specified URL. if proxy is not alive, return the max value of uint16. // implements C.Proxy func (p *Proxy) LastDelayForTestUrl(url string) (delay uint16) { - var max uint16 = 0xffff + var maxDelay uint16 = 0xffff alive := false var history C.DelayHistory @@ -138,7 +138,7 @@ func (p *Proxy) LastDelayForTestUrl(url string) (delay uint16) { } if !alive || history.Delay == 0 { - return max + return maxDelay } return history.Delay } diff --git a/adapter/outboundgroup/fallback.go b/adapter/outboundgroup/fallback.go index 72d7e62a4..50427e53a 100644 --- a/adapter/outboundgroup/fallback.go +++ b/adapter/outboundgroup/fallback.go @@ -102,12 +102,12 @@ func (f *Fallback) findAliveProxy(touch bool) C.Proxy { proxies := f.GetProxies(touch) for _, proxy := range proxies { if len(f.selected) == 0 { - if proxy.Alive(f.testUrl) { + if proxy.AliveForTestUrl(f.testUrl) { return proxy } } else { if proxy.Name() == f.selected { - if proxy.Alive(f.testUrl) { + if proxy.AliveForTestUrl(f.testUrl) { return proxy } else { f.selected = "" @@ -133,7 +133,7 @@ func (f *Fallback) Set(name string) error { } f.selected = name - if !p.Alive(f.testUrl) { + if !p.AliveForTestUrl(f.testUrl) { ctx, cancel := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(5000)) defer cancel() expectedStatus, _ := utils.NewIntRanges[uint16](f.expectedStatus) diff --git a/adapter/outboundgroup/loadbalance.go b/adapter/outboundgroup/loadbalance.go index 8bcd661f0..79b189486 100644 --- a/adapter/outboundgroup/loadbalance.go +++ b/adapter/outboundgroup/loadbalance.go @@ -150,7 +150,7 @@ func strategyRoundRobin(url string) strategyFn { for ; i < length; i++ { id := (idx + i) % length proxy := proxies[id] - if proxy.Alive(url) { + if proxy.AliveForTestUrl(url) { i++ return proxy } @@ -168,14 +168,14 @@ func strategyConsistentHashing(url string) strategyFn { for i := 0; i < maxRetry; i, key = i+1, key+1 { idx := jumpHash(key, buckets) proxy := proxies[idx] - if proxy.Alive(url) { + if proxy.AliveForTestUrl(url) { return proxy } } // when availability is poor, traverse the entire list to get the available nodes for _, proxy := range proxies { - if proxy.Alive(url) { + if proxy.AliveForTestUrl(url) { return proxy } } @@ -201,7 +201,7 @@ func strategyStickySessions(url string) strategyFn { nowIdx := idx for i := 1; i < maxRetry; i++ { proxy := proxies[nowIdx] - if proxy.Alive(url) { + if proxy.AliveForTestUrl(url) { if nowIdx != idx { lruCache.Delete(key) lruCache.Set(key, nowIdx) diff --git a/adapter/outboundgroup/urltest.go b/adapter/outboundgroup/urltest.go index 2e533415b..29d749f9b 100644 --- a/adapter/outboundgroup/urltest.go +++ b/adapter/outboundgroup/urltest.go @@ -101,7 +101,7 @@ func (u *URLTest) fast(touch bool) C.Proxy { proxies := u.GetProxies(touch) if u.selected != "" { for _, proxy := range proxies { - if !proxy.Alive(u.testUrl) { + if !proxy.AliveForTestUrl(u.testUrl) { continue } if proxy.Name() == u.selected { @@ -113,7 +113,7 @@ func (u *URLTest) fast(touch bool) C.Proxy { elm, _, shared := u.fastSingle.Do(func() (C.Proxy, error) { fast := proxies[0] - min := fast.LastDelayForTestUrl(u.testUrl) + minDelay := fast.LastDelayForTestUrl(u.testUrl) fastNotExist := true for _, proxy := range proxies[1:] { @@ -121,19 +121,19 @@ func (u *URLTest) fast(touch bool) C.Proxy { fastNotExist = false } - if !proxy.Alive(u.testUrl) { + if !proxy.AliveForTestUrl(u.testUrl) { continue } delay := proxy.LastDelayForTestUrl(u.testUrl) - if delay < min { + if delay < minDelay { fast = proxy - min = delay + minDelay = delay } } // tolerance - if u.fastNode == nil || fastNotExist || !u.fastNode.Alive(u.testUrl) || u.fastNode.LastDelayForTestUrl(u.testUrl) > fast.LastDelayForTestUrl(u.testUrl)+u.tolerance { + if u.fastNode == nil || fastNotExist || !u.fastNode.AliveForTestUrl(u.testUrl) || u.fastNode.LastDelayForTestUrl(u.testUrl) > fast.LastDelayForTestUrl(u.testUrl)+u.tolerance { u.fastNode = fast } return u.fastNode, nil diff --git a/adapter/provider/healthcheck.go b/adapter/provider/healthcheck.go index 111185016..d8e56192e 100644 --- a/adapter/provider/healthcheck.go +++ b/adapter/provider/healthcheck.go @@ -202,7 +202,7 @@ func (hc *HealthCheck) execute(b *batch.Batch[bool], url, uid string, option *ex defer cancel() log.Debugln("Health Checking, proxy: %s, url: %s, id: {%s}", p.Name(), url, uid) _, _ = p.URLTest(ctx, url, expectedStatus) - log.Debugln("Health Checked, proxy: %s, url: %s, alive: %t, delay: %d ms uid: {%s}", p.Name(), url, p.Alive(url), p.LastDelayForTestUrl(url), uid) + log.Debugln("Health Checked, proxy: %s, url: %s, alive: %t, delay: %d ms uid: {%s}", p.Name(), url, p.AliveForTestUrl(url), p.LastDelayForTestUrl(url), uid) return false, nil }) } diff --git a/constant/adapters.go b/constant/adapters.go index 58b2a92b0..6d7acd638 100644 --- a/constant/adapters.go +++ b/constant/adapters.go @@ -156,7 +156,7 @@ type DelayHistoryStoreType int type Proxy interface { ProxyAdapter - Alive(url string) bool + AliveForTestUrl(url string) bool DelayHistory() []DelayHistory ExtraDelayHistories() map[string]ProxyState LastDelayForTestUrl(url string) uint16