Help us shape the future of Go! Take the 2026 Go Developer Survey

relay

package
v0.32.7 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

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

View Source
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

View Source
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 NewMux

func NewMux(conn *websocket.Conn, handler Handler) *Mux

NewMux wraps conn. handler serves streams the peer opens; nil refuses them.

func (*Mux) Close

func (m *Mux) Close()

Close ends the connection and every stream on it.

func (*Mux) Done

func (m *Mux) Done() <-chan struct{}

Done is closed when the connection ends.

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.

func (*Mux) Serve

func (m *Mux) Serve(ctx context.Context) error

Serve runs the mux until the connection ends or ctx is cancelled.

Jump to

Keyboard shortcuts

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