Documentation
¶
Index ¶
- Variables
- type ConnectionState
- type Forward
- type TunnelManager
- func (tm *TunnelManager) AddForward(localPort, remotePort int) error
- func (tm *TunnelManager) Close() error
- func (tm *TunnelManager) Connect(ctx context.Context, host string, port int) error
- func (tm *TunnelManager) Exec(cmd string) ([]byte, error)
- func (tm *TunnelManager) ExecContext(ctx context.Context, cmd string) ([]byte, error)
- func (tm *TunnelManager) ForceReconnect()
- func (tm *TunnelManager) IsConnected() bool
- func (tm *TunnelManager) ListListeningPorts() ([]int, error)
- func (tm *TunnelManager) OpenShell() error
- func (tm *TunnelManager) RemoveForward(localPort int)
- func (tm *TunnelManager) SetConnectionStateCallback(cb func(ConnectionState))
- func (tm *TunnelManager) SetKeepAliveRTTCallback(cb func(time.Duration))
- func (tm *TunnelManager) SetReconnectTargetProvider(fn func(context.Context) (string, int, error))
- func (tm *TunnelManager) StartAutoDetect(interval time.Duration, configured map[int]struct{}, exclude map[int]struct{}, ...)
- func (tm *TunnelManager) WaitConnected(ctx context.Context) bool
Constants ¶
This section is empty.
Variables ¶
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 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) Exec ¶
func (tm *TunnelManager) Exec(cmd string) ([]byte, error)
Exec runs a remote command on the connected SSH client.
func (*TunnelManager) ExecContext ¶
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 (*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.