Signed-off-by: arraykeys@gmail.com <arraykeys@gmail.com>

This commit is contained in:
arraykeys@gmail.com
2017-10-20 12:59:23 +08:00
parent 3cd0d91c22
commit a80e4df6f0
2 changed files with 23 additions and 11 deletions

View File

@ -190,17 +190,28 @@ func (s *HTTP) OutToTCP(useProxy bool, address string, inConn *net.Conn, req *ut
} }
var outConn net.Conn var outConn net.Conn
var _outConn interface{} var _outConn interface{}
if useProxy { tryCount := 0
if *s.cfg.ParentType == "ssh" { maxTryCount := 5
outConn, err = s.getSSHConn(address) for {
} else { if useProxy {
_outConn, err = s.outPool.Pool.Get() if *s.cfg.ParentType == "ssh" {
if err == nil { outConn, err = s.getSSHConn(address)
outConn = _outConn.(net.Conn) } else {
_outConn, err = s.outPool.Pool.Get()
if err == nil {
outConn = _outConn.(net.Conn)
}
} }
} else {
outConn, err = utils.ConnectHost(address, *s.cfg.Timeout)
}
tryCount++
if err == nil || tryCount > maxTryCount {
break
} else {
log.Printf("connect to %s , err:%s,retrying...", *s.cfg.Parent, err)
time.Sleep(time.Second * 2)
} }
} else {
outConn, err = utils.ConnectHost(address, *s.cfg.Timeout)
} }
if err != nil { if err != nil {
log.Printf("connect to %s , err:%s", *s.cfg.Parent, err) log.Printf("connect to %s , err:%s", *s.cfg.Parent, err)
@ -242,7 +253,7 @@ RETRY:
return return
} }
wait := make(chan bool, 1) wait := make(chan bool, 1)
func() { go func() {
defer func() { defer func() {
if err == nil { if err == nil {
err = recover() err = recover()

View File

@ -392,7 +392,7 @@ func (s *Socks) proxyTCP(inConn *net.Conn, methodReq socks.MethodsRequest, reque
var err interface{} var err interface{}
useProxy := true useProxy := true
tryCount := 0 tryCount := 0
maxTryCount := 3 maxTryCount := 5
for { for {
if *s.cfg.Always { if *s.cfg.Always {
outConn, err = s.getOutConn(methodReq.Bytes(), request.Bytes(), request.Addr()) outConn, err = s.getOutConn(methodReq.Bytes(), request.Bytes(), request.Addr())
@ -414,6 +414,7 @@ func (s *Socks) proxyTCP(inConn *net.Conn, methodReq socks.MethodsRequest, reque
break break
} else { } else {
log.Printf("get out conn fail,%s,retrying...", err) log.Printf("get out conn fail,%s,retrying...", err)
time.Sleep(time.Second * 2)
} }
} }
if err != nil { if err != nil {