mirror of
https://github.com/nadoo/glider.git
synced 2026-11-23 23:49:41 +08:00
direct: support dial timeout and relay timeout (#97)
This commit is contained in:
1 parent
3392db41de
commit
665d722d2c
7 files changed
+65
-32
No files matched your search
+5
-4
@@ -6,6 +6,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/nadoo/glider/common/log"
|
||||
"github.com/nadoo/glider/proxy"
|
||||
@@ -28,7 +29,7 @@ type Forwarder struct {
|
||||
}
|
||||
|
||||
// ForwarderFromURL parses `forward=` command value and returns a new forwarder.
|
||||
func ForwarderFromURL(s, intface string) (f *Forwarder, err error) {
|
||||
func ForwarderFromURL(s, intface string, dialTimeout, relayTimeout time.Duration) (f *Forwarder, err error) {
|
||||
f = &Forwarder{}
|
||||
|
||||
ss := strings.Split(s, "#")
|
||||
@@ -42,7 +43,7 @@ func ForwarderFromURL(s, intface string) (f *Forwarder, err error) {
|
||||
}
|
||||
|
||||
var d proxy.Dialer
|
||||
d, err = proxy.NewDirect(iface)
|
||||
d, err = proxy.NewDirect(iface, dialTimeout, relayTimeout)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -64,8 +65,8 @@ func ForwarderFromURL(s, intface string) (f *Forwarder, err error) {
|
||||
}
|
||||
|
||||
// DirectForwarder returns a direct forwarder.
|
||||
func DirectForwarder(intface string) *Forwarder {
|
||||
d, err := proxy.NewDirect(intface)
|
||||
func DirectForwarder(intface string, dialTimeout, relayTimeout time.Duration) *Forwarder {
|
||||
d, err := proxy.NewDirect(intface, dialTimeout, relayTimeout)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ type Config struct {
|
||||
CheckTimeout int
|
||||
CheckDisabledOnly bool
|
||||
MaxFailures int
|
||||
DialTimeout int
|
||||
RelayTimeout int
|
||||
IntFace string
|
||||
}
|
||||
|
||||
@@ -48,7 +50,8 @@ type Proxy struct {
|
||||
func NewProxy(s []string, c *Config) *Proxy {
|
||||
var fwdrs []*Forwarder
|
||||
for _, chain := range s {
|
||||
fwdr, err := ForwarderFromURL(chain, c.IntFace)
|
||||
fwdr, err := ForwarderFromURL(chain, c.IntFace,
|
||||
time.Duration(c.DialTimeout)*time.Second, time.Duration(c.RelayTimeout)*time.Second)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
@@ -58,7 +61,8 @@ func NewProxy(s []string, c *Config) *Proxy {
|
||||
|
||||
if len(fwdrs) == 0 {
|
||||
// direct forwarder
|
||||
fwdrs = append(fwdrs, DirectForwarder(c.IntFace))
|
||||
fwdrs = append(fwdrs, DirectForwarder(c.IntFace,
|
||||
time.Duration(c.DialTimeout)*time.Second, time.Duration(c.RelayTimeout)*time.Second))
|
||||
c.Strategy = "rr"
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user