MCPcopy
hub / github.com/wavetermdev/waveterm / StartConnServer

Method StartConnServer

pkg/remote/conncontroller/conncontroller.go:432–588  ·  view source on GitHub ↗

returns (needsInstall, clientVersion, osArchStr, error) if wsh is not installed, the clientVersion will be "not-installed", and it will also return an osArchStr if clientVersion is set, then no osArchStr will be returned if useRouterMode is true, will start connserver with --router-domainsocket flag

(ctx context.Context, afterUpdate bool, useRouterMode bool)

Source from the content-addressed store, hash-verified

430// if clientVersion is set, then no osArchStr will be returned
431// if useRouterMode is true, will start connserver with --router-domainsocket flag
432func (conn *SSHConn) StartConnServer(ctx context.Context, afterUpdate bool, useRouterMode bool) (bool, string, string, error) {
433 conn.Infof(ctx, "running StartConnServer (routerMode=%v)...\n", useRouterMode)
434 allowed := WithLockRtn(conn, func() bool {
435 return conn.Status == Status_Connecting
436 })
437 if !allowed {
438 return false, "", "", fmt.Errorf("cannot start conn server for %q when status is %q", conn.GetName(), conn.GetStatus())
439 }
440 client := conn.GetClient()
441 wshPath := conn.getWshPath()
442 sockName := conn.GetDomainSocketName()
443 var rpcCtx wshrpc.RpcContext
444 if useRouterMode {
445 rpcCtx = wshrpc.RpcContext{
446 IsRouter: true,
447 SockName: sockName,
448 Conn: conn.GetName(),
449 }
450 } else {
451 rpcCtx = wshrpc.RpcContext{
452 RouteId: wshutil.MakeConnectionRouteId(conn.GetName()),
453 SockName: sockName,
454 Conn: conn.GetName(),
455 }
456 }
457 jwtToken, err := wshutil.MakeClientJWTToken(rpcCtx)
458 if err != nil {
459 return false, "", "", fmt.Errorf("unable to create jwt token for conn controller: %w", err)
460 }
461 conn.Infof(ctx, "SSH-NEWSESSION (StartConnServer)\n")
462 sshSession, err := client.NewSession()
463 if err != nil {
464 return false, "", "", fmt.Errorf("unable to create ssh session for conn controller: %w", err)
465 }
466 pipeRead, pipeWrite := io.Pipe()
467 sshSession.Stdout = pipeWrite
468 sshSession.Stderr = pipeWrite
469 stdinPipe, err := sshSession.StdinPipe()
470 if err != nil {
471 return false, "", "", fmt.Errorf("unable to get stdin pipe: %w", err)
472 }
473 devFlag := ""
474 if wavebase.IsDevMode() {
475 devFlag = "--dev"
476 }
477 routerFlag := ""
478 if useRouterMode {
479 routerFlag = "--router-domainsocket"
480 }
481 cmdStr := fmt.Sprintf(ConnServerCmdTemplate, wshPath, wshPath, shellutil.HardQuote(conn.GetName()), devFlag, routerFlag)
482 log.Printf("starting conn controller: %q\n", cmdStr)
483 shWrappedCmdStr := fmt.Sprintf("sh -c %s", shellutil.HardQuote(cmdStr))
484 blocklogger.Debugf(ctx, "[conndebug] wrapped command:\n%s\n", shWrappedCmdStr)
485 err = sshSession.Start(shWrappedCmdStr)
486 if err != nil {
487 return false, "", "", fmt.Errorf("unable to start conn controller command: %w", err)
488 }
489 linesChan := utilfn.StreamToLinesChan(pipeRead)

Callers 1

tryEnableWshMethod · 0.95

Calls 15

InfofMethod · 0.95
GetNameMethod · 0.95
GetStatusMethod · 0.95
GetClientMethod · 0.95
getWshPathMethod · 0.95
GetDomainSocketNameMethod · 0.95
WithLockMethod · 0.95
GetMonitorMethod · 0.95
MakeConnectionRouteIdFunction · 0.92
MakeClientJWTTokenFunction · 0.92
IsDevModeFunction · 0.92
HardQuoteFunction · 0.92

Tested by

no test coverage detected