add max_fails & fail_timeout options support for load balancing

This commit is contained in:
ginuerzh 2019-06-19 13:21:10 +08:00
parent f89062a84b
commit e8ad44cab3
3 changed files with 27 additions and 8 deletions

View File

@ -51,11 +51,20 @@ func (r *route) parseChain() (*gost.Chain, error) {
} }
ngroup.AddNode(nodes...) 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, ngroup.SetSelector(nil,
gost.WithFilter( gost.WithFilter(
&gost.FailFilter{ &gost.FailFilter{
MaxFails: defaultMaxFails, MaxFails: maxFails,
FailTimeout: defaultFailTimeout, FailTimeout: failTimeout,
}, },
&gost.InvalidFilter{}, &gost.InvalidFilter{},
), ),

18
node.go
View File

@ -7,6 +7,7 @@ import (
"strconv" "strconv"
"strings" "strings"
"sync" "sync"
"time"
) )
var ( var (
@ -140,12 +141,21 @@ func (node *Node) GetInt(key string) int {
return n return n
} }
func (node *Node) GetDuration(key string) time.Duration {
d, _ := time.ParseDuration(node.Values.Get(key))
return d
}
func (node Node) String() string { func (node Node) String() string {
if node.url == nil { var scheme string
return fmt.Sprintf("%s+%s://%s", if node.url != nil {
node.Protocol, node.Transport, node.Addr) scheme = node.url.Scheme
} }
return node.url.String() 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. // NodeGroup is a group of nodes.

View File

@ -19,9 +19,9 @@ import (
) )
const ( const (
// MethodTLS is an extended SOCKS5 method for TLS. // MethodTLS is an extended SOCKS5 method with tls encryption support.
MethodTLS uint8 = 0x80 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 MethodTLSAuth uint8 = 0x82
// MethodMux is an extended SOCKS5 method for stream multiplexing. // MethodMux is an extended SOCKS5 method for stream multiplexing.
MethodMux = 0x88 MethodMux = 0x88