proxy

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentConn

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

AgentConn manages a binary-framed connection to a guest agent.

func Dial

func Dial(addr string, timeout time.Duration) (*AgentConn, error)

Dial connects to the agent using the DefaultDialer.

func DialWith

func DialWith(d Dialer, addr string, timeout time.Duration) (*AgentConn, error)

DialWith connects to the agent using the provided Dialer.

func Wrap

func Wrap(conn net.Conn) *AgentConn

Wrap creates an AgentConn from an existing net.Conn.

func (*AgentConn) Authenticate

func (a *AgentConn) Authenticate(token string, timeout time.Duration) error

Authenticate sends an auth.token RPC to the agent and verifies the response. Must be called before any other RPC when the agent requires a token.

func (*AgentConn) Close

func (a *AgentConn) Close() error

Close closes the underlying connection.

func (*AgentConn) Ping

func (a *AgentConn) Ping(timeout time.Duration) error

Ping sends a ping frame and waits for a pong response within the timeout.

func (*AgentConn) ReadFrame

func (a *AgentConn) ReadFrame() (byte, []byte, error)

ReadFrame reads a binary-framed message. Returns (type, payload, error).

func (*AgentConn) SetDeadline

func (a *AgentConn) SetDeadline(t time.Time) error

SetDeadline sets the read and write deadline on the connection.

func (*AgentConn) SetReadDeadline

func (a *AgentConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline.

func (*AgentConn) SetWriteDeadline

func (a *AgentConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline.

func (*AgentConn) WriteFrame

func (a *AgentConn) WriteFrame(frameType byte, payload []byte) error

WriteFrame writes a binary-framed message: [1-byte type][4-byte length][payload].

type Dialer

type Dialer interface {
	Dial(addr string, timeout time.Duration) (net.Conn, error)
}

Dialer abstracts how connections are established to guest agents. The default implementation dials TCP, but alternatives (e.g., vsock for Firecracker microVMs) can be provided by implementing this interface.

var DefaultDialer Dialer = TCPDialer{}

DefaultDialer is the package-level default dialer used by Dial().

type Session

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

Session bridges a client WebSocket connection to a guest agent TCP connection. It translates JSON-RPC messages from the client into binary frames for the agent and relays responses and notifications back.

func NewSession

func NewSession(ws *websocket.Conn, agent *AgentConn, log *slog.Logger) *Session

NewSession creates a new proxy session.

func (*Session) Close

func (s *Session) Close()

Close terminates the session.

func (*Session) Done

func (s *Session) Done() <-chan struct{}

Done returns a channel that is closed when the session ends.

func (*Session) Run

func (s *Session) Run(ctx context.Context) error

Run starts bidirectional proxying. It blocks until the session ends.

func (*Session) SendNotification

func (s *Session) SendNotification(method string, params interface{}) error

SendNotification sends a JSON-RPC notification to the client over WebSocket.

func (*Session) SendRawJSON

func (s *Session) SendRawJSON(data []byte) error

SendRawJSON sends pre-marshaled JSON data as a text WebSocket message.

type TCPDialer

type TCPDialer struct{}

TCPDialer is the default Dialer that connects over TCP.

func (TCPDialer) Dial

func (TCPDialer) Dial(addr string, timeout time.Duration) (net.Conn, error)

Dial connects to the agent at the given TCP address (host:port).

Jump to

Keyboard shortcuts

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