transport

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package transport provides a unified abstraction for hub-agent communication over different transports (WebSocket, SSH).

Index

Constants

This section is empty.

Variables

View Source
var ErrWebSocketNotConnected = errors.New("websocket not connected")

ErrWebSocketNotConnected indicates a WebSocket transport is not currently connected.

Functions

func UnmarshalResponse

func UnmarshalResponse(resp common.AgentResponse, action common.WebSocketAction, dest any) error

UnmarshalResponse unmarshals an AgentResponse into the destination type. It first checks the generic Data field (0.19+ agents), then falls back to legacy typed fields for backward compatibility with 0.18.0 agents.

Types

type SSHTransport

type SSHTransport struct {
	// contains filtered or unexported fields
}

SSHTransport implements Transport over SSH connections. It owns the single SSH connection to an agent, which is shared by all requests and sessions.

func NewSSHTransport

func NewSSHTransport(cfg SSHTransportConfig) *SSHTransport

NewSSHTransport creates a new SSH transport with the given configuration.

func (*SSHTransport) Close

func (t *SSHTransport) Close()

Close terminates the SSH connection.

func (*SSHTransport) CloseClient added in v0.21.0

func (t *SSHTransport) CloseClient(client *ssh.Client)

CloseClient closes client and clears it if it is still the current connection, so a late close never discards a replacement connection.

func (*SSHTransport) Connect added in v0.21.0

func (t *SSHTransport) Connect(ctx context.Context) (*ssh.Client, error)

Connect returns the current client or establishes a new cancellable SSH connection, calling OnConnect when a new connection is stored.

func (*SSHTransport) GetClient

func (t *SSHTransport) GetClient() *ssh.Client

GetClient returns the current SSH client, or nil if not connected.

func (*SSHTransport) IsConnected

func (t *SSHTransport) IsConnected() bool

IsConnected returns true if the SSH connection is active.

func (*SSHTransport) NewSession added in v0.21.0

func (t *SSHTransport) NewSession(ctx context.Context, client *ssh.Client) (*ssh.Session, error)

NewSession opens a session on client, bounded by the transport timeout independently of ctx. The connection is closed if session creation stalls.

func (*SSHTransport) Request

func (t *SSHTransport) Request(ctx context.Context, action common.WebSocketAction, req any, dest any) (err error)

Request sends a request to the agent via SSH and unmarshals the response.

func (*SSHTransport) RequestWithRetry

func (t *SSHTransport) RequestWithRetry(ctx context.Context, action common.WebSocketAction, req any, dest any, retries int) error

RequestWithRetry sends a request with automatic retry on connection failures.

type SSHTransportConfig

type SSHTransportConfig struct {
	Host    string
	Port    string
	Config  *ssh.ClientConfig
	Timeout time.Duration
	// OnConnect is called when a new connection is established, before it is
	// available to other callers, with the agent version from its SSH server
	// version string. It runs under the transport lock and must not call back
	// into the transport.
	OnConnect func(agentVersion semver.Version)
}

SSHTransportConfig holds configuration for creating an SSH transport.

type Transport

type Transport interface {
	// Request sends a request to the agent and unmarshals the response into dest.
	// The dest parameter should be a pointer to the expected response type.
	Request(ctx context.Context, action common.WebSocketAction, req any, dest any) error
	// IsConnected returns true if the transport connection is active.
	IsConnected() bool
	// Close terminates the transport connection.
	Close()
}

Transport defines the interface for hub-agent communication. Both WebSocket and SSH transports implement this interface.

type WebSocketTransport

type WebSocketTransport struct {
	// contains filtered or unexported fields
}

WebSocketTransport implements Transport over WebSocket connections.

func NewWebSocketTransport

func NewWebSocketTransport(wsConn *ws.WsConn) *WebSocketTransport

NewWebSocketTransport creates a new WebSocket transport wrapper.

func (*WebSocketTransport) Close

func (t *WebSocketTransport) Close()

Close terminates the WebSocket connection.

func (*WebSocketTransport) IsConnected

func (t *WebSocketTransport) IsConnected() bool

IsConnected returns true if the WebSocket connection is active.

func (*WebSocketTransport) Request

func (t *WebSocketTransport) Request(ctx context.Context, action common.WebSocketAction, req any, dest any) error

Request sends a request to the agent via WebSocket and unmarshals the response.

Jump to

Keyboard shortcuts

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