ssh

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLocalPortInUse = errors.New("local port already in use")

Functions

This section is empty.

Types

type ConnectionState

type ConnectionState string
const (
	StateDisconnected ConnectionState = "disconnected"
	StateReconnecting ConnectionState = "reconnecting"
	StateConnected    ConnectionState = "connected"
)

type Forward

type Forward struct {
	LocalPort  int
	RemotePort int
	Auto       bool
}

Forward describes one local->remote tunnel mapping over SSH.

type TunnelManager

type TunnelManager struct {
	SSHUser           string
	SSHKeyPath        string
	ForwardAgentSock  string
	RemotePort        int
	Env               map[string]string
	KeepAliveInterval time.Duration
	KeepAliveTimeout  time.Duration
	KeepAliveCountMax int
	// contains filtered or unexported fields
}

TunnelManager manages one SSH client connection and a set of local forwards.

func (*TunnelManager) AddForward

func (tm *TunnelManager) AddForward(localPort, remotePort int) error

AddForward starts a local listener and forwards accepted connections to remotePort.

func (*TunnelManager) Close

func (tm *TunnelManager) Close() error

Close tears down all listeners and the SSH connection.

func (*TunnelManager) Connect

func (tm *TunnelManager) Connect(ctx context.Context, host string, port int) error

Connect establishes an SSH connection to host:port.

func (*TunnelManager) Exec

func (tm *TunnelManager) Exec(cmd string) ([]byte, error)

Exec runs a remote command on the connected SSH client.

func (*TunnelManager) ExecContext

func (tm *TunnelManager) ExecContext(ctx context.Context, cmd string) ([]byte, error)

func (*TunnelManager) ForceReconnect added in v0.2.1

func (tm *TunnelManager) ForceReconnect()

ForceReconnect tears down the current SSH client and triggers a background reconnect. Use this when the transport looks alive but sessions are dead (e.g. NewSession returns EOF). Callers should follow up with WaitConnected.

func (*TunnelManager) IsConnected

func (tm *TunnelManager) IsConnected() bool

IsConnected reports if an SSH client is present.

func (*TunnelManager) ListListeningPorts

func (tm *TunnelManager) ListListeningPorts() ([]int, error)

ListListeningPorts queries remote TCP listeners.

func (*TunnelManager) OpenShell

func (tm *TunnelManager) OpenShell() error

OpenShell opens an interactive shell over the current SSH client.

func (*TunnelManager) RemoveForward

func (tm *TunnelManager) RemoveForward(localPort int)

RemoveForward stops a local listener for localPort.

func (*TunnelManager) SetConnectionStateCallback

func (tm *TunnelManager) SetConnectionStateCallback(cb func(ConnectionState))

func (*TunnelManager) SetKeepAliveRTTCallback

func (tm *TunnelManager) SetKeepAliveRTTCallback(cb func(time.Duration))

func (*TunnelManager) SetReconnectTargetProvider

func (tm *TunnelManager) SetReconnectTargetProvider(fn func(context.Context) (string, int, error))

func (*TunnelManager) StartAutoDetect

func (tm *TunnelManager) StartAutoDetect(interval time.Duration, configured map[int]struct{}, exclude map[int]struct{}, onAdd func(port int), onRemove func(port int))

StartAutoDetect polls listening ports and calls onAdd/onRemove for diffs.

func (*TunnelManager) WaitConnected added in v0.2.1

func (tm *TunnelManager) WaitConnected(ctx context.Context) bool

WaitConnected blocks until the tunnel is connected or the context is cancelled. Returns false if the tunnel is closed or the context expires.

Jump to

Keyboard shortcuts

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