add max_fails & fail_timeout options support for load balancing
This commit is contained in:
parent
f89062a84b
commit
e8ad44cab3
@ -51,11 +51,20 @@ func (r *route) parseChain() (*gost.Chain, error) {
|
||||
}
|
||||
ngroup.AddNode(nodes...)
|
||||
|
||||
maxFails := nodes[0].GetInt("max_fails")
|
||||
if maxFails == 0 {
|
||||
maxFails = defaultMaxFails
|
||||
}
|
||||
failTimeout := nodes[0].GetDuration("fail_timeout")
|
||||
if failTimeout == 0 {
|
||||
failTimeout = defaultFailTimeout
|
||||
}
|
||||
|
||||
ngroup.SetSelector(nil,
|
||||
gost.WithFilter(
|
||||
&gost.FailFilter{
|
||||
MaxFails: defaultMaxFails,
|
||||
FailTimeout: defaultFailTimeout,
|
||||
MaxFails: maxFails,
|
||||
FailTimeout: failTimeout,
|
||||
},
|
||||
&gost.InvalidFilter{},
|
||||
),
|
||||
|
20
node.go
20
node.go
@ -7,6 +7,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -140,12 +141,21 @@ func (node *Node) GetInt(key string) int {
|
||||
return n
|
||||
}
|
||||
|
||||
func (node Node) String() string {
|
||||
if node.url == nil {
|
||||
return fmt.Sprintf("%s+%s://%s",
|
||||
node.Protocol, node.Transport, node.Addr)
|
||||
func (node *Node) GetDuration(key string) time.Duration {
|
||||
d, _ := time.ParseDuration(node.Values.Get(key))
|
||||
return d
|
||||
}
|
||||
return node.url.String()
|
||||
|
||||
func (node Node) String() string {
|
||||
var scheme string
|
||||
if node.url != nil {
|
||||
scheme = node.url.Scheme
|
||||
}
|
||||
if scheme == "" {
|
||||
scheme = fmt.Sprintf("%s+%s", node.Protocol, node.Transport)
|
||||
}
|
||||
return fmt.Sprintf("%s://%s",
|
||||
scheme, node.Addr)
|
||||
}
|
||||
|
||||
// NodeGroup is a group of nodes.
|
||||
|
4
socks.go
4
socks.go
@ -19,9 +19,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
// MethodTLS is an extended SOCKS5 method for TLS.
|
||||
// MethodTLS is an extended SOCKS5 method with tls encryption support.
|
||||
MethodTLS uint8 = 0x80
|
||||
// MethodTLSAuth is an extended SOCKS5 method for TLS+AUTH.
|
||||
// MethodTLSAuth is an extended SOCKS5 method with tls encryption and authentication support.
|
||||
MethodTLSAuth uint8 = 0x82
|
||||
// MethodMux is an extended SOCKS5 method for stream multiplexing.
|
||||
MethodMux = 0x88
|
||||
|
Loading…
Reference in New Issue
Block a user