mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 17:35:40 +08:00
strategy: avoid returning nil dialer in lha.nextDialer
This commit is contained in:
parent
39ccbc5adf
commit
88ff8997b5
@ -215,9 +215,9 @@ Available forward strategies:
|
||||
ha: High Availability mode
|
||||
lha: Latency based High Availability mode
|
||||
|
||||
Forwarder option scheme: FORWARD_URL[#OPTIONS]
|
||||
Available options for forwarders:
|
||||
Forwarder option scheme: FORWARD_URL#OPTIONS
|
||||
priority: set the priority of that forwarder, default:0
|
||||
-
|
||||
Examples:
|
||||
socks5://1.1.1.1:1080#priority=100
|
||||
vmess://[security:]uuid@host:port?alterID=num#priority=200
|
||||
|
3
conf.go
3
conf.go
@ -193,7 +193,8 @@ func usage() {
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Forwarder option scheme: FORWARD_URL#OPTIONS\n")
|
||||
fmt.Fprintf(os.Stderr, " priority: set the priority of that forwarder, default:0\n")
|
||||
fmt.Fprintf(os.Stderr, " e.g.:\n")
|
||||
fmt.Fprintf(os.Stderr, " -\n")
|
||||
fmt.Fprintf(os.Stderr, " Examples:\n")
|
||||
fmt.Fprintf(os.Stderr, " socks5://1.1.1.1:1080#priority=100\n")
|
||||
fmt.Fprintf(os.Stderr, " vmess://[security:]uuid@host:port?alterID=num#priority=200\n")
|
||||
fmt.Fprintf(os.Stderr, "\n")
|
||||
|
@ -248,24 +248,23 @@ func newLHADialer(dialers []*proxy.Forwarder, webhost string, duration int) prox
|
||||
|
||||
func (lha *lhaDialer) nextDialer(dstAddr string) *proxy.Forwarder {
|
||||
var latency int64
|
||||
var d *proxy.Forwarder
|
||||
for _, fwder := range lha.fwdrs {
|
||||
for i, fwder := range lha.fwdrs {
|
||||
if fwder.Enabled() {
|
||||
lha.priority = fwder.Priority
|
||||
latency = fwder.Latency()
|
||||
d = fwder
|
||||
lha.idx = i
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
for _, fwder := range lha.fwdrs {
|
||||
for i, fwder := range lha.fwdrs {
|
||||
if fwder.Enabled() && fwder.Priority >= lha.priority && fwder.Latency() < latency {
|
||||
latency = fwder.Latency()
|
||||
d = fwder
|
||||
lha.idx = i
|
||||
}
|
||||
}
|
||||
|
||||
return d
|
||||
return lha.fwdrs[lha.idx]
|
||||
}
|
||||
|
||||
func (lha *lhaDialer) Dial(network, addr string) (net.Conn, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user