mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
Merge 256e9d8c3d
into 52c91e0862
This commit is contained in:
commit
1b010e3a9c
|
@ -5,8 +5,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/adapter/outbound"
|
"github.com/metacubex/mihomo/adapter/outbound"
|
||||||
|
@ -134,32 +134,32 @@ func (lb *LoadBalance) IsL3Protocol(metadata *C.Metadata) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func strategyRoundRobin(url string) strategyFn {
|
func strategyRoundRobin(url string) strategyFn {
|
||||||
|
var availableProxies []C.Proxy
|
||||||
idx := 0
|
idx := 0
|
||||||
idxMutex := sync.Mutex{}
|
idxMutex := sync.Mutex{}
|
||||||
|
|
||||||
return func(proxies []C.Proxy, metadata *C.Metadata, touch bool) C.Proxy {
|
return func(proxies []C.Proxy, metadata *C.Metadata, touch bool) C.Proxy {
|
||||||
idxMutex.Lock()
|
idxMutex.Lock()
|
||||||
defer idxMutex.Unlock()
|
defer idxMutex.Unlock()
|
||||||
|
|
||||||
i := 0
|
|
||||||
length := len(proxies)
|
|
||||||
|
|
||||||
if touch {
|
if touch {
|
||||||
defer func() {
|
// check list
|
||||||
idx = (idx + i) % length
|
availableProxies = []C.Proxy{}
|
||||||
}()
|
for _, proxy := range proxies {
|
||||||
}
|
|
||||||
|
|
||||||
for ; i < length; i++ {
|
|
||||||
id := (idx + i) % length
|
|
||||||
proxy := proxies[id]
|
|
||||||
if proxy.AliveForTestUrl(url) {
|
if proxy.AliveForTestUrl(url) {
|
||||||
i++
|
availableProxies = append(availableProxies, proxy)
|
||||||
return proxy
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// fallback
|
||||||
|
if len(availableProxies) == 0 {
|
||||||
return proxies[0]
|
return proxies[0]
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
proxy := availableProxies[idx]
|
||||||
|
// reset idx
|
||||||
|
idx = (idx + 1) % len(availableProxies)
|
||||||
|
return proxy
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func strategyConsistentHashing(url string) strategyFn {
|
func strategyConsistentHashing(url string) strategyFn {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user