conncontroller

package
v0.14.0-beta.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Status_Init         = "init"
	Status_Connecting   = "connecting"
	Status_Connected    = "connected"
	Status_Disconnected = "disconnected"
	Status_Error        = "error"
)
View Source
const (
	NoWshCode_Disabled              = "disabled"
	NoWshCode_PermissionError       = "permission-error"
	NoWshCode_UserDeclined          = "user-declined"
	NoWshCode_DomainSocketError     = "domainsocket-error"
	NoWshCode_ConnServerStartError  = "connserver-start-error"
	NoWshCode_InstallError          = "install-error"
	NoWshCode_PostInstallStartError = "postinstall-start-error"
	NoWshCode_InstallVerifyError    = "install-verify-error"
)
View Source
const (
	ConnHealthStatus_Good     = "good"
	ConnHealthStatus_Degraded = "degraded"
	ConnHealthStatus_Stalled  = "stalled"
)
View Source
const DefaultConnectionTimeout = 60 * time.Second

Variables

View Source
var ConnServerCmdTemplate = strings.TrimSpace(
	strings.Join([]string{
		"%s version 2> /dev/null || (echo -n \"not-installed \"; uname -sm; exit 0);",
		"exec %s connserver --conn %s %s %s",
	}, "\n"))

Functions

func DisconnectClient

func DisconnectClient(opts *remote.SSHOpts) error

func EnsureConnection

func EnsureConnection(ctx context.Context, connName string) error

Convenience function for ensuring a connection is established

func GetAllConnStatus

func GetAllConnStatus() []wshrpc.ConnStatus

func GetConnectionsFromConfig

func GetConnectionsFromConfig() ([]string, error)

func GetConnectionsFromInternalConfig added in v0.10.0

func GetConnectionsFromInternalConfig() []string

func GetConnectionsList

func GetConnectionsList() ([]string, error)

func GetNumSSHHasConnected added in v0.9.3

func GetNumSSHHasConnected() int

func IsConnected added in v0.14.0

func IsConnected(connName string) (bool, error)

func IsLocalConnName added in v0.13.1

func IsLocalConnName(connName string) bool

func IsWshVersionUpToDate added in v0.11.0

func IsWshVersionUpToDate(logCtx context.Context, wshVersionLine string) (bool, string, string, error)

expects the output of `wsh version` which looks like `wsh v0.10.4` or "not-installed os [arch]" returns (up-to-date, semver, osArchStr, error) if not up to date, or error, version might be ""

func IsWslConnName added in v0.14.0

func IsWslConnName(connName string) bool

func WithLockRtn added in v0.11.0

func WithLockRtn[T any](conn *SSHConn, fn func() T) T

Types

type ConnMonitor added in v0.14.0

type ConnMonitor struct {
	Conn              *SSHConn    // always non-nil, set at creation
	Client            *ssh.Client // always non-nil, set at creation
	LastActivityTime  atomic.Int64
	LastInputTime     atomic.Int64
	KeepAliveSentTime atomic.Int64
	KeepAliveInFlight bool
	// contains filtered or unexported fields
}

Lock ordering: conn.lock > cm.lock (conn.lock is outer, cm.lock is inner) CRITICAL: Methods that hold cm.lock must NEVER call into SSHConn (deadlock - violates ordering). Methods called from SSHConn while conn.lock is held should avoid acquiring cm.lock (keep locking simple).

func MakeConnMonitor added in v0.14.0

func MakeConnMonitor(conn *SSHConn, client *ssh.Client) *ConnMonitor

func (*ConnMonitor) Close added in v0.14.0

func (cm *ConnMonitor) Close()

func (*ConnMonitor) NotifyInput added in v0.14.0

func (cm *ConnMonitor) NotifyInput()

func (*ConnMonitor) SendKeepAlive added in v0.14.0

func (cm *ConnMonitor) SendKeepAlive() error

func (*ConnMonitor) UpdateLastActivityTime added in v0.14.0

func (cm *ConnMonitor) UpdateLastActivityTime()

type SSHConn

type SSHConn struct {
	Status             string
	ConnHealthStatus   string
	WshEnabled         *atomic.Bool
	Opts               *remote.SSHOpts
	Client             *ssh.Client
	DomainSockName     string // if "", then no domain socket
	DomainSockListener net.Listener
	ConnController     *ssh.Session
	Error              string
	WshError           string
	NoWshReason        string
	WshVersion         string
	LastConnectTime    int64
	ActiveConnNum      int
	Monitor            *ConnMonitor // will not be nil
	// contains filtered or unexported fields
}

func GetConn

func GetConn(opts *remote.SSHOpts) *SSHConn

does NOT connect, does not return nil

func MaybeGetConn added in v0.14.0

func MaybeGetConn(opts *remote.SSHOpts) *SSHConn

does NOT connect, can return nil

func (*SSHConn) ClearWshError added in v0.11.0

func (conn *SSHConn) ClearWshError()

func (*SSHConn) Close

func (conn *SSHConn) Close() error

func (*SSHConn) Connect

func (conn *SSHConn) Connect(ctx context.Context, connFlags *wconfig.ConnKeywords) error

does not return an error since that error is stored inside of SSHConn

func (*SSHConn) Debugf added in v0.11.0

func (conn *SSHConn) Debugf(ctx context.Context, format string, args ...any)

func (*SSHConn) DeriveConnStatus

func (conn *SSHConn) DeriveConnStatus() wshrpc.ConnStatus

func (*SSHConn) FireConnChangeEvent

func (conn *SSHConn) FireConnChangeEvent()

func (*SSHConn) GetClient

func (conn *SSHConn) GetClient() *ssh.Client

func (*SSHConn) GetConfigShellPath added in v0.11.0

func (conn *SSHConn) GetConfigShellPath() string

func (*SSHConn) GetConnHealthStatus added in v0.14.0

func (conn *SSHConn) GetConnHealthStatus() string

func (*SSHConn) GetDomainSocketName

func (conn *SSHConn) GetDomainSocketName() string

func (*SSHConn) GetEnvironmentMaps added in v0.14.0

func (conn *SSHConn) GetEnvironmentMaps(ctx context.Context) (map[string]string, map[string]string, error)

for testing only -- trying to determine the env difference when attaching or not attaching a pty to an ssh session

func (*SSHConn) GetMonitor added in v0.14.0

func (conn *SSHConn) GetMonitor() *ConnMonitor

func (*SSHConn) GetName

func (conn *SSHConn) GetName() string

func (*SSHConn) GetStatus

func (conn *SSHConn) GetStatus() string

func (*SSHConn) Infof added in v0.11.0

func (conn *SSHConn) Infof(ctx context.Context, format string, args ...any)

func (*SSHConn) InstallWsh added in v0.11.0

func (conn *SSHConn) InstallWsh(ctx context.Context, osArchStr string) error

func (*SSHConn) OpenDomainSocketListener

func (conn *SSHConn) OpenDomainSocketListener(ctx context.Context) error

func (*SSHConn) SetConnHealthStatus added in v0.14.0

func (conn *SSHConn) SetConnHealthStatus(client *ssh.Client, status string)

func (*SSHConn) SetWshError added in v0.11.0

func (conn *SSHConn) SetWshError(err error)

func (*SSHConn) StartConnServer

func (conn *SSHConn) StartConnServer(ctx context.Context, afterUpdate bool, useRouterMode bool) (bool, string, string, error)

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

func (*SSHConn) UpdateWsh added in v0.11.0

func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, remoteInfo *wshrpc.RemoteInfo) error

func (*SSHConn) WaitForConnect

func (conn *SSHConn) WaitForConnect(ctx context.Context) error

func (*SSHConn) WithLock

func (conn *SSHConn) WithLock(fn func())

type WshCheckResult added in v0.11.0

type WshCheckResult struct {
	WshEnabled    bool
	ClientVersion string
	NoWshReason   string
	NoWshCode     string
	WshError      error
}

type WshInstallOpts

type WshInstallOpts struct {
	Force        bool
	NoUserPrompt bool
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL