mirror of
https://github.com/tailscale/tailscale.git
synced 2025-08-11 05:07:33 +00:00
cmd/tsconnect: add progress and connection callbacks
Allows UI to display slightly more fine-grained progress when the SSH connection is being established. Updates tailscale/corp#7186 Signed-off-by: Mihai Parparita <mihai@tailscale.com>
This commit is contained in:

committed by
Mihai Parparita

parent
246274b8e9
commit
7741e9feb0
@@ -364,15 +364,21 @@ func (s *jsSSHSession) Run() {
|
||||
if jsTimeoutSeconds := s.termConfig.Get("timeoutSeconds"); jsTimeoutSeconds.Type() == js.TypeNumber {
|
||||
timeoutSeconds = jsTimeoutSeconds.Float()
|
||||
}
|
||||
onConnectionProgress := s.termConfig.Get("onConnectionProgress")
|
||||
onConnected := s.termConfig.Get("onConnected")
|
||||
onDone := s.termConfig.Get("onDone")
|
||||
defer onDone.Invoke()
|
||||
|
||||
writeError := func(label string, err error) {
|
||||
writeErrorFn.Invoke(fmt.Sprintf("%s Error: %v\r\n", label, err))
|
||||
}
|
||||
reportProgress := func(message string) {
|
||||
onConnectionProgress.Invoke(message)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(timeoutSeconds*float64(time.Second)))
|
||||
defer cancel()
|
||||
reportProgress(fmt.Sprintf("Connecting to %s…", strings.Split(s.host, ".")[0]))
|
||||
c, err := s.jsIPN.dialer.UserDial(ctx, "tcp", net.JoinHostPort(s.host, "22"))
|
||||
if err != nil {
|
||||
writeError("Dial", err)
|
||||
@@ -381,10 +387,16 @@ func (s *jsSSHSession) Run() {
|
||||
defer c.Close()
|
||||
|
||||
config := &ssh.ClientConfig{
|
||||
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
|
||||
User: s.username,
|
||||
HostKeyCallback: func(hostname string, remote net.Addr, key ssh.PublicKey) error {
|
||||
// Host keys are not used with Tailscale SSH, but we can use this
|
||||
// callback to know that the connection has been established.
|
||||
reportProgress("SSH connection established…")
|
||||
return nil
|
||||
},
|
||||
User: s.username,
|
||||
}
|
||||
|
||||
reportProgress("Starting SSH client…")
|
||||
sshConn, _, _, err := ssh.NewClientConn(c, s.host, config)
|
||||
if err != nil {
|
||||
writeError("SSH Connection", err)
|
||||
@@ -442,6 +454,7 @@ func (s *jsSSHSession) Run() {
|
||||
return
|
||||
}
|
||||
|
||||
onConnected.Invoke()
|
||||
err = session.Wait()
|
||||
if err != nil {
|
||||
writeError("Wait", err)
|
||||
|
Reference in New Issue
Block a user