fixed a bug in ha mode

This commit is contained in:
nadoo 2017-07-15 10:41:52 +08:00
parent c79a9ee36d
commit 1f13a8d1e8
4 changed files with 7 additions and 5 deletions

View File

@ -10,7 +10,7 @@ import (
"syscall" "syscall"
) )
const version = "0.1" const version = "0.1.1"
var config struct { var config struct {
Verbose bool Verbose bool

View File

@ -25,7 +25,7 @@ type mixedproxy struct {
ss Proxy ss Proxy
} }
// MixedProxy returns a http mixed proxy. // MixedProxy returns a mixed proxy.
func MixedProxy(network, addr, user, pass string, upProxy Proxy) (Proxy, error) { func MixedProxy(network, addr, user, pass string, upProxy Proxy) (Proxy, error) {
p := &mixedproxy{ p := &mixedproxy{
Proxy: upProxy, Proxy: upProxy,

View File

@ -138,15 +138,17 @@ func check(p Proxy, target string, duration int) {
} }
firstTime = false firstTime = false
startTime := time.Now()
c, err := p.Dial("tcp", target) c, err := p.Dial("tcp", target)
if err != nil { if err != nil {
logf("proxy %s check error: %s, set to disabled.", p.Addr(), err) logf("proxy-check %s -> %s, error: %s, set to disabled.", p.Addr(), config.CheckSite, err)
p.SetEnable(false) p.SetEnable(false)
continue continue
} }
dialTime := time.Since(startTime)
c.Close() c.Close()
p.SetEnable(true) p.SetEnable(true)
logf("proxy %s check ok.", p.Addr()) logf("proxy-check: %s -> %s, connect time: %d", p.Addr(), config.CheckSite, dialTime)
} }
} }

View File

@ -74,7 +74,7 @@ type haproxy struct {
// newHAProxy . // newHAProxy .
func newHAProxy(addr string, forwarders []Proxy) Proxy { func newHAProxy(addr string, forwarders []Proxy) Proxy {
return newStrategyProxy(addr, forwarders) return &haproxy{Proxy: newStrategyProxy(addr, forwarders)}
} }
func (p *haproxy) GetProxy() Proxy { func (p *haproxy) GetProxy() Proxy {