Documentation
¶
Index ¶
- Constants
- func DisconnectClient(opts *remote.SSHOpts) error
- func EnsureConnection(ctx context.Context, connName string) error
- func GetAllConnStatus() []wshrpc.ConnStatus
- func GetConnectionsFromConfig() ([]string, error)
- func GetConnectionsFromInternalConfig() []string
- func GetConnectionsList() ([]string, error)
- func IsConnected(connName string) (bool, error)
- func IsLocalConnName(connName string) bool
- func IsWshVersionUpToDate(logCtx context.Context, wshVersionLine string) (bool, string, string, error)
- func IsWslConnName(connName string) bool
- func MakeConnServerCommand(primaryPath string, fallbackPath string, connName string, flags ...string) string
- func NotifySystemResume() int
- func SetAutoReconnectPolicy(policyFn func(connName string) bool)
- func WithLockRtn[T any](conn *SSHConn, fn func() T) T
- type ConnMonitor
- type SSHConn
- func (conn *SSHConn) ClearWshError()
- func (conn *SSHConn) Close() error
- func (conn *SSHConn) Connect(ctx context.Context, connFlags *wconfig.ConnKeywords) error
- func (conn *SSHConn) Debugf(ctx context.Context, format string, args ...any)
- func (conn *SSHConn) DeriveConnStatus() wshrpc.ConnStatus
- func (conn *SSHConn) FireConnChangeEvent()
- func (conn *SSHConn) GetClient() *ssh.Client
- func (conn *SSHConn) GetConfigShellPath() string
- func (conn *SSHConn) GetConnHealthStatus() string
- func (conn *SSHConn) GetDomainSocketName() string
- func (conn *SSHConn) GetEnvironmentMaps(ctx context.Context) (map[string]string, map[string]string, error)
- func (conn *SSHConn) GetMonitor() *ConnMonitor
- func (conn *SSHConn) GetName() string
- func (conn *SSHConn) GetStatus() string
- func (conn *SSHConn) Infof(ctx context.Context, format string, args ...any)
- func (conn *SSHConn) InstallWsh(ctx context.Context, osArchStr string) error
- func (conn *SSHConn) OpenDomainSocketListener(ctx context.Context) error
- func (conn *SSHConn) SetConnHealthStatus(client *ssh.Client, status string)
- func (conn *SSHConn) SetWshError(err error)
- func (conn *SSHConn) StartConnServer(ctx context.Context, afterUpdate bool, useRouterMode bool) (bool, string, string, error)
- func (conn *SSHConn) UpdateWsh(ctx context.Context, clientDisplayName string, remoteInfo *wshrpc.RemoteInfo) error
- func (conn *SSHConn) WaitForConnect(ctx context.Context) error
- func (conn *SSHConn) WithLock(fn func())
- type WshCheckResult
- type WshInstallOpts
Constants ¶
const ( Status_Init = "init" Status_Connecting = "connecting" Status_Connected = "connected" Status_Disconnected = "disconnected" Status_Error = "error" )
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" NoWshCode_InstallingBackground = "installing-background" )
const ( ConnHealthStatus_Good = "good" ConnHealthStatus_Degraded = "degraded" ConnHealthStatus_Stalled = "stalled" )
const DefaultConnectionTimeout = 60 * time.Second
const ReconnectAttemptTimeout = 45 * time.Second
const ReconnectInitialDelay = 1 * time.Second
const ReconnectJitterFraction = 0.2
const ReconnectMaxDelay = 60 * time.Second
Variables ¶
This section is empty.
Functions ¶
func DisconnectClient ¶
func EnsureConnection ¶
Convenience function for ensuring a connection is established
func GetAllConnStatus ¶
func GetAllConnStatus() []wshrpc.ConnStatus
func GetConnectionsFromInternalConfig ¶
func GetConnectionsFromInternalConfig() []string
func GetConnectionsList ¶
func IsConnected ¶
func IsLocalConnName ¶
func IsWshVersionUpToDate ¶
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 ¶
func MakeConnServerCommand ¶
func NotifySystemResume ¶ added in v0.4.79
func NotifySystemResume() int
NotifySystemResume probes every live connection right away (a connection that slept through a network change is usually dead but looks fine until TCP times out) and skips the backoff wait of any pending automatic reconnect.
func SetAutoReconnectPolicy ¶ added in v0.5.0
SetAutoReconnectPolicy registers the predicate deciding whether a dropped connection is worth reconnecting automatically (e.g. it has durable jobs or open terminal blocks). It lives outside this package to avoid an import cycle with the block/job controllers.
func WithLockRtn ¶
Types ¶
type ConnMonitor ¶
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
KeepAlive remote.KeepAliveSettings
// 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 ¶
func MakeConnMonitor(conn *SSHConn, client *ssh.Client) *ConnMonitor
func (*ConnMonitor) Close ¶
func (cm *ConnMonitor) Close()
func (*ConnMonitor) NotifyCheck ¶ added in v0.4.79
func (cm *ConnMonitor) NotifyCheck()
func (*ConnMonitor) NotifyInput ¶
func (cm *ConnMonitor) NotifyInput()
func (*ConnMonitor) ProbeAfterResume ¶ added in v0.5.0
func (cm *ConnMonitor) ProbeAfterResume()
ProbeAfterResume sends an immediate keepalive with a short timeout. After sleep the TCP connection is often silently dead; waiting for the regular stall detection would leave durable sessions detached for much longer than necessary.
func (*ConnMonitor) SendKeepAlive ¶
func (cm *ConnMonitor) SendKeepAlive() error
SendKeepAlive sends an SSH-level keepalive@openssh.com global request. It works with or without the remote helper, since any SSH server answers (or rejects) global requests.
func (*ConnMonitor) UpdateLastActivityTime ¶
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
Reconnecting bool
ReconnectAttempt int
NextReconnectTs int64
// contains filtered or unexported fields
}
func MaybeGetConn ¶
does NOT connect, can return nil
func (*SSHConn) ClearWshError ¶
func (conn *SSHConn) ClearWshError()
func (*SSHConn) Close ¶
Close is the user-facing disconnect: it stops any automatic reconnect loop and aborts an in-flight connect attempt (so a hung handshake can't block the disconnect behind lifecycleLock) before tearing the connection down.
func (*SSHConn) DeriveConnStatus ¶
func (conn *SSHConn) DeriveConnStatus() wshrpc.ConnStatus
func (*SSHConn) FireConnChangeEvent ¶
func (conn *SSHConn) FireConnChangeEvent()
func (*SSHConn) GetConfigShellPath ¶
func (*SSHConn) GetConnHealthStatus ¶
func (*SSHConn) GetDomainSocketName ¶
func (*SSHConn) GetEnvironmentMaps ¶
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 ¶
func (conn *SSHConn) GetMonitor() *ConnMonitor
func (*SSHConn) InstallWsh ¶
func (*SSHConn) OpenDomainSocketListener ¶
func (*SSHConn) SetConnHealthStatus ¶
func (*SSHConn) SetWshError ¶
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