Documentation
¶
Overview ¶
Package relay carries HTTP exchanges over one WebSocket between the platform and a runner behind NAT (platform SP-BUILDER-13, sprout SP-159).
The runner dials the platform; the platform then opens one stream per HTTP request and the runner serves it. Streams are correlated by id, so many run concurrently without head-of-line blocking, and each direction of each stream has a credit window so a large transfer cannot starve an interactive call or grow memory without bound.
Frames are JSON text messages:
{"t":"open","id":"1","ws":"<workspace>","method":"POST","path":"/api/txn/run","hdr":{…}}
{"t":"head","id":"1","status":200,"hdr":{…}}
{"t":"data","id":"1","b64":"<chunk>"} (≤ ChunkSize bytes, either direction)
{"t":"ack","id":"1","n":65536} (credit returned for consumed bytes)
{"t":"end","id":"1","err":""} (direction finished; err non-empty resets)
This file is kept identical in the sprout and platform repositories; the wire format is pinned in the platform's docs/runners/PROTOCOL.md.
Index ¶
Constants ¶
const ( // ChunkSize bounds one data frame's payload. ChunkSize = 64 << 10 // Window is the unacknowledged bytes a sender may have in flight per // stream direction. Window = 4 << 20 )
Variables ¶
var ErrClosed = errors.New("relay: connection closed")
ErrClosed is returned for streams on a mux whose connection has ended.
Functions ¶
This section is empty.
Types ¶
type Handler ¶
type Handler func(ws string, w http.ResponseWriter, r *http.Request)
Handler serves one relayed request for workspace ws.
type Mux ¶
type Mux struct {
// contains filtered or unexported fields
}
Mux multiplexes streams over one WebSocket. Either side may open streams; in practice the platform opens and the runner serves.
func (*Mux) RoundTripper ¶
func (m *Mux) RoundTripper(ws string) http.RoundTripper
RoundTripper returns a transport that sends requests to workspace ws through the peer. The request URL's path and query are forwarded; scheme and host are ignored.