mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
chore: remove legacy remote launcher
The Legacy Launch function was kept as a way to maintain the old ssh system while adding the new one. Now that the new system has been released with minimal issues, it is safe to fully remove the legacy launcher.
This commit is contained in:
parent
c3917444a2
commit
bb8f5dc660
@ -43,8 +43,6 @@ import (
|
||||
"golang.org/x/mod/semver"
|
||||
)
|
||||
|
||||
const UseSshLibrary = true
|
||||
|
||||
const RemoteTypeMShell = "mshell"
|
||||
const DefaultTerm = "xterm-256color"
|
||||
const DefaultMaxPtySize = 1024 * 1024
|
||||
@ -128,12 +126,6 @@ type pendingStateKey struct {
|
||||
RemotePtr sstore.RemotePtrType
|
||||
}
|
||||
|
||||
// for conditional launch method based on ssh library in use
|
||||
// remove once ssh library is stabilized
|
||||
type Launcher interface {
|
||||
Launch(*MShellProc, bool)
|
||||
}
|
||||
|
||||
type MShellProc struct {
|
||||
Lock *sync.Mutex
|
||||
Remote *sstore.RemoteType
|
||||
@ -162,7 +154,6 @@ type MShellProc struct {
|
||||
|
||||
RunningCmds map[base.CommandKey]RunCmdType
|
||||
PendingStateCmds map[pendingStateKey]base.CommandKey // key=[remoteinstance name]
|
||||
launcher Launcher // for conditional launch method based on ssh library in use. remove once ssh library is stabilized
|
||||
Client *ssh.Client
|
||||
}
|
||||
|
||||
@ -184,12 +175,6 @@ func CanComplete(remoteType string) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// for conditional launch method based on ssh library in use
|
||||
// remove once ssh library is stabilized
|
||||
func (msh *MShellProc) Launch(interactive bool) {
|
||||
msh.launcher.Launch(msh, interactive)
|
||||
}
|
||||
|
||||
func (msh *MShellProc) GetStatus() string {
|
||||
msh.Lock.Lock()
|
||||
defer msh.Lock.Unlock()
|
||||
@ -707,14 +692,8 @@ func MakeMShell(r *sstore.RemoteType) *MShellProc {
|
||||
RunningCmds: make(map[base.CommandKey]RunCmdType),
|
||||
PendingStateCmds: make(map[pendingStateKey]base.CommandKey),
|
||||
StateMap: server.MakeShellStateMap(),
|
||||
launcher: LegacyLauncher{}, // for conditional launch method based on ssh library in use. remove once ssh library is stabilized
|
||||
DataPosMap: utilfn.MakeSyncMap[base.CommandKey, int64](),
|
||||
}
|
||||
// for conditional launch method based on ssh library in use
|
||||
// remove once ssh library is stabilized
|
||||
if UseSshLibrary {
|
||||
rtn.launcher = NewLauncher{}
|
||||
}
|
||||
|
||||
rtn.WriteToPtyBuffer("console for connection [%s]\n", r.GetName())
|
||||
return rtn
|
||||
@ -1570,12 +1549,7 @@ func (msh *MShellProc) createWaveshellSession(clientCtx context.Context, remoteC
|
||||
return wsSession, nil
|
||||
}
|
||||
|
||||
// for conditional launch method based on ssh library in use
|
||||
// remove once ssh library is stabilized
|
||||
type NewLauncher struct{}
|
||||
|
||||
// func (msh *MShellProc) LaunchNew(interactive bool) {
|
||||
func (NewLauncher) Launch(msh *MShellProc, interactive bool) {
|
||||
func (msh *MShellProc) Launch(interactive bool) {
|
||||
remoteCopy := msh.GetRemoteCopy()
|
||||
if remoteCopy.Archived {
|
||||
msh.WriteToPtyBuffer("cannot launch archived remote\n")
|
||||
@ -1683,146 +1657,6 @@ func (NewLauncher) Launch(msh *MShellProc, interactive bool) {
|
||||
go msh.NotifyRemoteUpdate()
|
||||
}
|
||||
|
||||
// for conditional launch method based on ssh library in use
|
||||
// remove once ssh library is stabilized
|
||||
type LegacyLauncher struct{}
|
||||
|
||||
// func (msh *MShellProc) LaunchLegacy(interactive bool) {
|
||||
func (LegacyLauncher) Launch(msh *MShellProc, interactive bool) {
|
||||
remoteCopy := msh.GetRemoteCopy()
|
||||
if remoteCopy.Archived {
|
||||
msh.WriteToPtyBuffer("cannot launch archived remote\n")
|
||||
return
|
||||
}
|
||||
curStatus := msh.GetStatus()
|
||||
if curStatus == StatusConnected {
|
||||
msh.WriteToPtyBuffer("remote is already connected (no action taken)\n")
|
||||
return
|
||||
}
|
||||
if curStatus == StatusConnecting {
|
||||
msh.WriteToPtyBuffer("remote is already connecting, disconnect before trying to connect again\n")
|
||||
return
|
||||
}
|
||||
sapi, err := shellapi.MakeShellApi(msh.GetShellType())
|
||||
if err != nil {
|
||||
msh.WriteToPtyBuffer("*error, %v\n", err)
|
||||
return
|
||||
}
|
||||
istatus := msh.GetInstallStatus()
|
||||
if istatus == StatusConnecting {
|
||||
msh.WriteToPtyBuffer("remote is trying to install, cancel install before trying to connect again\n")
|
||||
return
|
||||
}
|
||||
if remoteCopy.SSHOpts.SSHPort != 0 && remoteCopy.SSHOpts.SSHPort != 22 {
|
||||
msh.WriteToPtyBuffer("connecting to %s (port %d)...\n", remoteCopy.RemoteCanonicalName, remoteCopy.SSHOpts.SSHPort)
|
||||
} else {
|
||||
msh.WriteToPtyBuffer("connecting to %s...\n", remoteCopy.RemoteCanonicalName)
|
||||
}
|
||||
sshOpts := convertSSHOpts(remoteCopy.SSHOpts)
|
||||
sshOpts.SSHErrorsToTty = true
|
||||
if remoteCopy.ConnectMode != sstore.ConnectModeManual && remoteCopy.SSHOpts.SSHPassword == "" && !interactive {
|
||||
sshOpts.BatchMode = true
|
||||
}
|
||||
var cmdStr string
|
||||
if sshOpts.SSHHost == "" && remoteCopy.Local {
|
||||
var err error
|
||||
cmdStr, err = MakeLocalMShellCommandStr(remoteCopy.IsSudo())
|
||||
if err != nil {
|
||||
msh.WriteToPtyBuffer("*error, cannot find local mshell binary: %v\n", err)
|
||||
return
|
||||
}
|
||||
} else {
|
||||
cmdStr = MakeServerCommandStr()
|
||||
}
|
||||
ecmd := sshOpts.MakeSSHExecCmd(cmdStr, sapi)
|
||||
cmdPty, err := msh.addControllingTty(ecmd)
|
||||
if err != nil {
|
||||
statusErr := fmt.Errorf("cannot attach controlling tty to mshell command: %w", err)
|
||||
msh.WriteToPtyBuffer("*error, %s\n", statusErr.Error())
|
||||
msh.setErrorStatus(statusErr)
|
||||
return
|
||||
}
|
||||
defer func() {
|
||||
if len(ecmd.ExtraFiles) > 0 {
|
||||
ecmd.ExtraFiles[len(ecmd.ExtraFiles)-1].Close()
|
||||
}
|
||||
}()
|
||||
go msh.RunPtyReadLoop(cmdPty)
|
||||
if remoteCopy.SSHOpts.SSHPassword != "" {
|
||||
go msh.WaitAndSendPassword(remoteCopy.SSHOpts.SSHPassword)
|
||||
}
|
||||
var makeClientCtx context.Context
|
||||
var makeClientCancelFn context.CancelFunc
|
||||
msh.WithLock(func() {
|
||||
deadlineTime := time.Now().Add(RemoteConnectTimeout)
|
||||
makeClientCtx, makeClientCancelFn = context.WithDeadline(context.Background(), deadlineTime)
|
||||
defer makeClientCancelFn()
|
||||
msh.Err = nil
|
||||
msh.ErrNoInitPk = false
|
||||
msh.Status = StatusConnecting
|
||||
msh.MakeClientCancelFn = makeClientCancelFn
|
||||
msh.MakeClientDeadline = &deadlineTime
|
||||
go msh.NotifyRemoteUpdate()
|
||||
})
|
||||
go msh.watchClientDeadlineTime()
|
||||
cproc, err := shexec.MakeClientProc(makeClientCtx, shexec.CmdWrap{Cmd: ecmd})
|
||||
msh.WithLock(func() {
|
||||
msh.MakeClientCancelFn = nil
|
||||
msh.MakeClientDeadline = nil
|
||||
msh.StateMap.Clear()
|
||||
// no notify here, because we'll call notify in either case below
|
||||
})
|
||||
if err == context.DeadlineExceeded {
|
||||
msh.WriteToPtyBuffer("*connect timeout\n")
|
||||
msh.setErrorStatus(errors.New("connect timeout"))
|
||||
return
|
||||
} else if err == context.Canceled {
|
||||
msh.WriteToPtyBuffer("*forced disconnection\n")
|
||||
msh.WithLock(func() {
|
||||
msh.Status = StatusDisconnected
|
||||
go msh.NotifyRemoteUpdate()
|
||||
})
|
||||
return
|
||||
} else if serr, ok := err.(shexec.WaveshellLaunchError); ok {
|
||||
msh.WithLock(func() {
|
||||
msh.UName = serr.InitPk.UName
|
||||
if semver.Compare(serr.InitPk.Version, scbase.MShellVersion) < 0 {
|
||||
// only set NeedsMShellUpgrade if we got an InitPk
|
||||
msh.NeedsMShellUpgrade = true
|
||||
}
|
||||
msh.InitPkShellType = serr.InitPk.Shell
|
||||
})
|
||||
msh.WriteToPtyBuffer("*error, %s\n", serr.Error())
|
||||
msh.setErrorStatus(serr)
|
||||
go msh.tryAutoInstall()
|
||||
return
|
||||
} else if err != nil {
|
||||
msh.WriteToPtyBuffer("*error, %s\n", serr.Error())
|
||||
msh.setErrorStatus(err)
|
||||
return
|
||||
}
|
||||
|
||||
msh.updateRemoteStateVars(context.Background(), msh.RemoteId, cproc.InitPk)
|
||||
msh.WithLock(func() {
|
||||
msh.ServerProc = cproc
|
||||
msh.Status = StatusConnected
|
||||
})
|
||||
go func() {
|
||||
exitErr := cproc.Cmd.Wait()
|
||||
exitCode := shexec.GetExitCode(exitErr)
|
||||
msh.WithLock(func() {
|
||||
if msh.Status == StatusConnected || msh.Status == StatusConnecting {
|
||||
msh.Status = StatusDisconnected
|
||||
go msh.NotifyRemoteUpdate()
|
||||
}
|
||||
})
|
||||
msh.WriteToPtyBuffer("*disconnected exitcode=%d\n", exitCode)
|
||||
}()
|
||||
go msh.ProcessPackets()
|
||||
msh.initActiveShells()
|
||||
go msh.NotifyRemoteUpdate()
|
||||
}
|
||||
|
||||
func (msh *MShellProc) initActiveShells() {
|
||||
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancelFn()
|
||||
|
Loading…
Reference in New Issue
Block a user