|
|
@@ -669,7 +669,7 @@ func (h *Hub) BindForServer(host *conn.HostInfo) (err error) {
|
|
|
// 代理连接,在已经连接的基础上进行代理连接
|
|
|
func (h *Hub) ClientProxyConnect(line *Line, remoteChannel string) (err error) {
|
|
|
// 获取主机地址
|
|
|
- host, err := h.connectHostFunc(remoteChannel, HostTypeDirect)
|
|
|
+ host, err := h.connectHostFunc(remoteChannel, HostTypeDirect, true)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -726,7 +726,7 @@ func (h *Hub) ConnectToServer(remoteChannel string, force bool, host *conn.HostI
|
|
|
return errors.New("not connect host func found")
|
|
|
}
|
|
|
// 获取服务地址等信息
|
|
|
- host, err = h.connectHostFunc(remoteChannel, HostTypeBoth)
|
|
|
+ host, err = h.connectHostFunc(remoteChannel, HostTypeBoth, true)
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
@@ -767,6 +767,7 @@ func (h *Hub) ConnectToServer(remoteChannel string, force bool, host *conn.HostI
|
|
|
}
|
|
|
}
|
|
|
line = ln
|
|
|
+ line.started = time.Now()
|
|
|
line.proxyChannel = proxyChannel
|
|
|
line.Start(remoteChannel, connect, host)
|
|
|
return false
|
|
|
@@ -803,15 +804,16 @@ func (h *Hub) ConnectToServerX(channel string, force bool, host *conn.HostInfo)
|
|
|
} else {
|
|
|
hostType = HostTypeProxy
|
|
|
}
|
|
|
- // 循环不同类型,避免一直使用代理
|
|
|
- count = (count + 1) % 8
|
|
|
- hx, err := h.connectHostFunc(channel, hostType)
|
|
|
+
|
|
|
+ hx, err := h.connectHostFunc(channel, hostType, count != 0)
|
|
|
if err == nil {
|
|
|
err := h.ConnectToServer(channel, force, hx, true)
|
|
|
if err == nil {
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
+ // 循环不同类型,避免一直使用代理
|
|
|
+ count = (count + 1) % 8
|
|
|
log.Println("[ConnectToServerX] connectHostFunc error with channel:", channel, err)
|
|
|
} else {
|
|
|
err := h.ConnectToServer(channel, force, host, true)
|
|
|
@@ -844,7 +846,7 @@ func (h *Hub) checkConnect() {
|
|
|
now := time.Now().UnixMilli()
|
|
|
h.lines.Range(func(id int, line *Line) bool {
|
|
|
if line.host != nil && line.state == StateProxied && now-line.started.UnixMilli() > int64(h.cf.ProxyTimeout) {
|
|
|
- host, err := h.connectHostFunc(line.channel, HostTypeDirect)
|
|
|
+ host, err := h.connectHostFunc(line.channel, HostTypeDirect, true)
|
|
|
if err != nil {
|
|
|
log.Println("[proxyTicker connectHostFunc]", err)
|
|
|
return false
|