优化ssh资产一直卡在连接中的问题

This commit is contained in:
dushixiang
2021-11-15 16:23:26 +08:00
parent 1306c9dcd7
commit 569a1ad763
2 changed files with 32 additions and 42 deletions

View File

@ -21,14 +21,14 @@ import (
)
const (
TunnelClosed int = -1
Normal int = 0
NotFoundSession int = 800
NewTunnelError int = 801
ForcedDisconnect int = 802
AccessGatewayUnAvailable int = 803
AccessGatewayCreateError int = 804
AccessGatewayConnectError int = 804
TunnelClosed int = -1
Normal int = 0
NotFoundSession int = 800
NewTunnelError int = 801
ForcedDisconnect int = 802
AccessGatewayUnAvailable int = 803
AccessGatewayCreateError int = 804
AssetNotActive int = 805
)
func TunEndpoint(c echo.Context) error {
@ -99,6 +99,12 @@ func TunEndpoint(c echo.Context) error {
ip = exposedIP
port = exposedPort
}
active, err := utils.Tcping(ip, port)
if !active {
disconnect(ws, AssetNotActive, "目标资产不在线: "+err.Error())
return nil
}
configuration.SetParameter("hostname", ip)
configuration.SetParameter("port", strconv.Itoa(port))
@ -141,10 +147,9 @@ func TunEndpoint(c echo.Context) error {
if len(s.ConnectionId) == 0 {
if configuration.Protocol == constant.SSH {
nextTerminal, err := CreateNextTerminalBySession(s)
if err != nil {
return err
if err == nil {
nextSession.NextTerminal = nextTerminal
}
nextSession.NextTerminal = nextTerminal
}
nextSession.Observer = session.NewObserver(sessionId)