tunnel

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrameTypeRequest = "request"
	FrameTypeStream  = "stream"
)

FrameType indicates the kind of tunnel message.

Variables

This section is empty.

Functions

func DecodeFrameHeader

func DecodeFrameHeader(msg []byte) (headerJSON []byte, payload []byte, err error)

DecodeFrameHeader decodes only the JSON header and returns the payload offset.

func EncodeFrame

func EncodeFrame(header interface{}, payload []byte) ([]byte, error)

EncodeFrame encodes a JSON header and binary payload into a single binary message.

Types

type IncomingHeader

type IncomingHeader struct {
	Type string `json:"type"`
	ID   string `json:"id"`
}

IncomingHeader is used for initial JSON unmarshaling to determine frame type.

type Registry

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

Registry tracks active WebSocket tunnels keyed by sandbox ID.

func NewRegistry

func NewRegistry() *Registry

NewRegistry creates a new tunnel registry.

func (*Registry) Get

func (r *Registry) Get(sandboxID string) (*Tunnel, bool)

Get returns the active tunnel for a sandbox, if any.

func (*Registry) Register

func (r *Registry) Register(sandboxID string, conn *websocket.Conn) *Tunnel

Register adds a tunnel for the given sandbox.

func (*Registry) Unregister

func (r *Registry) Unregister(sandboxID string, t *Tunnel)

Unregister removes the tunnel for the given sandbox (only if it matches the provided tunnel).

type RequestHeader

type RequestHeader struct {
	Type    string            `json:"type"`
	ID      string            `json:"id"`
	Method  string            `json:"method"`
	Path    string            `json:"path"`
	Headers map[string]string `json:"headers"`
}

RequestHeader is the JSON metadata for a request frame (server → agent).

type StreamHeader

type StreamHeader struct {
	Type    string            `json:"type"`
	ID      string            `json:"id"`
	Status  int               `json:"status,omitempty"`
	Headers map[string]string `json:"headers,omitempty"`
	Done    bool              `json:"done"`
}

StreamHeader is the JSON metadata for a stream frame (agent → server).

type StreamMessage

type StreamMessage struct {
	Header  StreamHeader
	Payload []byte
}

StreamMessage holds a decoded stream frame header and its binary payload.

type Tunnel

type Tunnel struct {
	SandboxID string
	Conn      *websocket.Conn
	// contains filtered or unexported fields
}

Tunnel represents an active WebSocket tunnel to a local agent.

func (*Tunnel) CleanupRequest

func (t *Tunnel) CleanupRequest(requestID string)

CleanupRequest removes a pending waiter after the request is done.

func (*Tunnel) Close

func (t *Tunnel) Close()

Close shuts down the tunnel.

func (*Tunnel) Done

func (t *Tunnel) Done() <-chan struct{}

Done returns a channel that is closed when the tunnel shuts down.

func (*Tunnel) SendRequest

func (t *Tunnel) SendRequest(ctx context.Context, header *RequestHeader, body []byte) (<-chan *StreamMessage, error)

SendRequest sends a request frame through the tunnel and returns a channel for receiving streamed response messages.

Jump to

Keyboard shortcuts

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