Commit e8ad44ca authored by ginuerzh's avatar ginuerzh

add max_fails & fail_timeout options support for load balancing

parent f89062a8
...@@ -51,11 +51,20 @@ func (r *route) parseChain() (*gost.Chain, error) { ...@@ -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{},
), ),
......
...@@ -7,6 +7,7 @@ import ( ...@@ -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 { ...@@ -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
}
if scheme == "" {
scheme = fmt.Sprintf("%s+%s", node.Protocol, node.Transport)
} }
return node.url.String() return fmt.Sprintf("%s://%s",
scheme, node.Addr)
} }
// NodeGroup is a group of nodes. // NodeGroup is a group of nodes.
......
...@@ -19,9 +19,9 @@ import ( ...@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment