Documentation
¶
Index ¶
- Constants
- func ClientMux(conn net.Conn) (*yamux.Session, error)
- func MarshalStreamMeta(v interface{}) ([]byte, error)
- func MuxConfig() *yamux.Config
- func ReadStreamHeader(r io.Reader) (streamType byte, metadata []byte, err error)
- func ServerMux(conn net.Conn) (*yamux.Session, error)
- func UnmarshalStreamMeta(data []byte, v interface{}) error
- func WriteStreamHeader(w io.Writer, streamType byte, metadata []byte) error
- type HTTPResponseMeta
- type HTTPStreamMeta
- type Registry
- type Tunnel
- type WSConn
- func (c *WSConn) Close() error
- func (c *WSConn) LocalAddr() net.Addr
- func (c *WSConn) Read(b []byte) (int, error)
- func (c *WSConn) RemoteAddr() net.Addr
- func (c *WSConn) SetDeadline(t time.Time) error
- func (c *WSConn) SetReadDeadline(t time.Time) error
- func (c *WSConn) SetWriteDeadline(t time.Time) error
- func (c *WSConn) Write(b []byte) (int, error)
Constants ¶
const ( StreamTypeHTTP byte = 0x01 // HTTP proxy request (server → agent) StreamTypeTerminal byte = 0x02 // Terminal bidirectional stream (server → agent) StreamTypeControl byte = 0x03 // Control message: agent info, etc. (agent → server) )
Stream types identify the purpose of each yamux stream.
Variables ¶
This section is empty.
Functions ¶
func ClientMux ¶ added in v0.27.0
ClientMux creates a yamux client session over conn. The local agent acts as the yamux client: it opens streams towards the server (control messages) and accepts streams from the server (HTTP proxy, terminal).
func MarshalStreamMeta ¶ added in v0.27.0
MarshalStreamMeta marshals metadata to JSON for WriteStreamHeader.
func ReadStreamHeader ¶ added in v0.27.0
ReadStreamHeader reads the stream header and returns the type and metadata.
func ServerMux ¶ added in v0.27.0
ServerMux creates a yamux server session over conn. The agentserver side acts as the yamux server: it accepts streams opened by the agent (control messages) and opens streams towards the agent (HTTP proxy, terminal).
func UnmarshalStreamMeta ¶ added in v0.27.0
UnmarshalStreamMeta unmarshals metadata JSON from ReadStreamHeader.
Types ¶
type HTTPResponseMeta ¶ added in v0.27.0
type HTTPResponseMeta struct {
Status int `json:"status"`
Headers map[string]string `json:"headers"`
}
HTTPResponseMeta is the response header written by the agent on an HTTP stream.
type HTTPStreamMeta ¶ added in v0.27.0
type HTTPStreamMeta struct {
Method string `json:"method"`
Path string `json:"path"`
Headers map[string]string `json:"headers"`
BodyLen int `json:"body_len"`
}
HTTPStreamMeta is the metadata for an HTTP proxy stream (server → agent). BodyLen indicates the number of request body bytes that follow the stream header.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry tracks active WebSocket tunnels keyed by sandbox ID.
type Tunnel ¶
type Tunnel struct {
SandboxID string
// OnAgentInfo is called when the agent sends a control message with agent info.
OnAgentInfo func(data json.RawMessage)
// contains filtered or unexported fields
}
Tunnel represents an active multiplexed tunnel to a local agent. It wraps a WebSocket connection with yamux for stream multiplexing.
func (*Tunnel) Close ¶
func (t *Tunnel) Close()
Close shuts down the tunnel and underlying connections.
func (*Tunnel) Done ¶
func (t *Tunnel) Done() <-chan struct{}
Done returns a channel that is closed when the tunnel shuts down.
func (*Tunnel) OpenHTTPStream ¶ added in v0.27.0
func (t *Tunnel) OpenHTTPStream(ctx context.Context, meta HTTPStreamMeta, reqBody []byte) (HTTPResponseMeta, io.ReadCloser, error)
OpenHTTPStream opens a new yamux stream for proxying an HTTP request. The caller must close the returned body reader when done.
Protocol:
- Server writes: stream header (StreamTypeHTTP + HTTPStreamMeta with BodyLen)
- Server writes: request body bytes (exactly BodyLen bytes)
- Agent reads BodyLen bytes, processes request, then writes response.
- Agent writes: stream header (StreamTypeHTTP + HTTPResponseMeta)
- Agent writes: response body until stream close.
type WSConn ¶ added in v0.27.0
type WSConn struct {
// contains filtered or unexported fields
}
WSConn wraps a WebSocket connection as a net.Conn interface. Inspired by xray-core transport/internet/websocket/connection.go.
Write sends each call as a single BinaryMessage. Read transparently iterates over WebSocket messages, caching the current message reader between calls (xray-core reader-caching pattern).
func (*WSConn) Read ¶ added in v0.27.0
Read reads from the WebSocket message stream. Messages are transparently concatenated: when one message ends (EOF), the next message is fetched automatically.