Documentation
¶
Overview ¶
Package poplink is the R74 home↔PoP link protocol (docs/76): length-prefixed JSON records exchanged between a PoP relay and its home fleet over the link session. Go to Go only; it is not a wire type.
Index ¶
- Constants
- Variables
- func BearerToken(h string) string
- func CheckProto(q url.Values) (minor int, err error)
- func CloseCode(err error) (code uint32, ok bool)
- func ProtoQuery() string
- func Read(r io.Reader) (any, error)
- func RefusalReason(err error) string
- func SessionEndErr(s Session) error
- func TypeOf(rec any) string
- func Write(w io.Writer, rec any) error
- type Ban
- type Bye
- type CSR
- type Certificate
- type Config
- type Credential
- type Health
- type Hello
- type Refuse
- type Release
- type Reserve
- type Reserved
- type RoomOpen
- type Session
- type State
- type Stats
- type TelemetryConfig
- type TelemetryMint
- type TelemetryObs
- type TelemetryRefused
- type TelemetryTokens
- type Wall
- type Want
Constants ¶
const ( LinkIdleTimeout = 15 * time.Second LinkKeepAlive = 5 * time.Second // LeaseRenew is how often the link-home pod renews status.lease. LeaseRenew = 5 * time.Second )
Link timers (docs/76 item 10). The PoP's dialer sets them: one listener serves every route, so home cannot set per-route timers, and the effective idle timeout is the lower of the two ends.
const ( ReasonUnknown = "unknown" ReasonUsed = "used" ReasonPairingExpired = "pairing-expired" ReasonLimited = "limited" ReasonProto = "proto" )
Refusal reasons a home sends in ReasonHeader (besides ByeRepair, ByeRevoked and ByeExpired for a link credential).
const ( // PoP → home. THello = "hello" TReserve = "reserve" TRelease = "release" TState = "state" TWall = "wall" TRefuse = "refuse" TCSR = "csr" TStats = "stats" THealth = "health" // R77 (docs/78 D2, D7): token requests and the PoP's relay-side view. TTelemetryMint = "telemetryMint" TTelemetryObs = "telemetryObs" // Home → PoP. TCredential = "credential" TConfig = "config" TReserved = "reserved" TWant = "want" TBan = "ban" TCertificate = "certificate" TBye = "bye" // R77 (docs/78 D2): minted tokens, or why not. TTelemetryTokens = "telemetryTokens" TTelemetryRefused = "telemetryRefused" // The first record on a room-proxy bidi stream (W3-wall). TRoomOpen = "roomOpen" )
Record type names: the "t" of every frame. A name is the protocol; never rename one, add a new type instead.
const ( WallAttach = "attach" WallDetach = "detach" RefuseBudget = "budget" RefuseNotLive = "not-live" RefuseUnknown = "unknown" RefuseBanned = "banned" ReservedOK = "ok" ReservedConflict = "conflict" ReservedLimit = "limit" // Bye reasons (docs/76 item 11): the console tells them apart, which // close code 4006 alone cannot. ByeRepair = "repair" ByeRevoked = "revoked" ByeExpired = "expired" // TelemetryRefused reasons (docs/78 D4). TelemetryRefusedScope = "scope" TelemetryRefusedRate = "rate" TelemetryRefusedOff = "off" // TelemetryRefusedError: home failed to mint; ask again later. TelemetryRefusedError = "error" )
Enumerated string values.
const CloseCodeLinkEnd = 4006
CloseCodeLinkEnd closes a link home ends for good (repair, revoked, expired): wire.CloseCodeTerminatedByOperator, always after a Bye.
const DefaultRelayPort = 4433
DefaultRelayPort is the port a PoP relay serves WebTransport on unless gawk-relay -addr says otherwise.
const MaxRecordBytes = 64 << 10
MaxRecordBytes caps one record's JSON body.
const MaxTelemetryMint = 8
MaxTelemetryMint is the most tokens one TelemetryMint may ask for.
const Origin = "gawk-relay://pop"
Origin is the Origin header every PoP dial carries; home honours it only on /pop/* (transport's popOrigin, pinned equal by a test there).
const ProtoMajor = 1
ProtoMajor is the link protocol's major version, sent as ?proto= on every /pop/* dial. A home that does not speak it answers 426 (docs/22 D16); minor additions are additive (unknown records and fields are ignored).
const ReasonHeader = "Gawk-Pop-Reason"
ReasonHeader names a /pop/* refusal in the HTTP response, beside its status, so the console can tell refusals that share one apart (a used and an expired pairing string are both 410). Values: the Reason* constants and the Bye reasons.
Variables ¶
var ( // ErrProtoMajor: a /pop/* dial without ?proto= or with another major. ErrProtoMajor = errors.New("poplink: unsupported protocol major") // ErrRecordTooLarge: a record over MaxRecordBytes. ErrRecordTooLarge = errors.New("poplink: record too large") )
var BanLifted = time.Unix(1, 0).UTC()
BanLifted is the Until of a lift record: any time in the past would do.
Functions ¶
func BearerToken ¶
BearerToken extracts the credential from an Authorization header value ("" when it is not a bearer token).
func CheckProto ¶
CheckProto reads ?proto=<major>[.<minor>] off a /pop/* dial. A missing value or another major is ErrProtoMajor (the handler answers 426).
func CloseCode ¶
CloseCode reports the application close code a session ended with, as seen from the reading side (ok false for anything but a peer's or our own CloseWithError).
func Read ¶
Read reads one record and returns it as a pointer to its type (*Hello, *Config, ...). An unknown type returns (nil, nil): minor additions are ignored, and the stream stays in sync. A clean end of stream before a record is io.EOF.
func RefusalReason ¶
RefusalReason names a pops refusal for ReasonHeader, so the console can tell refusals that share a status apart ("" for anything else).
func SessionEndErr ¶
SessionEndErr is the error a pipe end reports once its session closed, for tests asserting the close code.
Types ¶
type Ban ¶
Ban forwards an ID ban for a broadcast the PoP owns. Until nil is permanent. An Until already past lifts a ban forwarded earlier on the link (an operator removed it, or ended a cooldown early): home sends BanLifted, which a PoP that predates lifting ignores as an expired ban.
type Bye ¶
type Bye struct {
Reason string `json:"reason,omitempty"`
}
Bye is the last record before home closes the link with 4006.
type CSR ¶
type CSR struct {
PEM string `json:"pem,omitempty"`
}
CSR carries the named tier's certificate request.
type Certificate ¶
type Certificate struct {
ChainPEM string `json:"chainPEM,omitempty"`
ForCSRSHA256 string `json:"forCSRSHA256,omitempty"`
}
Certificate delivers the named tier's chain for one CSR.
type Config ¶
type Config struct {
PopName string `json:"popName,omitempty"`
UID string `json:"uid,omitempty"`
DisplayName string `json:"displayName,omitempty"`
HomeOrigin string `json:"homeOrigin,omitempty"`
WallCode string `json:"wallCode,omitempty"`
NamedHost string `json:"namedHost,omitempty"`
Uplink pops.Budget `json:"uplink,omitempty"`
Downlink pops.Budget `json:"downlink,omitempty"`
MaxBroadcasts int `json:"maxBroadcasts,omitempty"`
AutoSwitch bool `json:"autoSwitch,omitempty"`
ScreeningNotice bool `json:"screeningNotice,omitempty"`
HomeRooms bool `json:"homeRooms,omitempty"`
NotAfter *time.Time `json:"notAfter,omitempty"`
// Telemetry is set while home collects telemetry (docs/78 D2): the PoP
// then asks home for tokens and sends its sessions hellos. Absent, the
// PoP sends none, as before R77.
Telemetry *TelemetryConfig `json:"telemetry,omitempty"`
}
Config is what home tells a linked PoP, sent after its Hello and again whenever the Pop changes.
type Credential ¶
type Credential struct {
Credential string `json:"credential,omitempty"`
}
Credential is the first record home sends after a pairing redeem, once.
type Health ¶
type Health struct {
Lines []adminapi.HealthLine `json:"lines,omitempty"`
}
Health is the PoP's self-check, sent when it changes.
type Hello ¶
type Hello struct {
Version string `json:"version,omitempty"`
Proto int `json:"proto,omitempty"`
LanAddr string `json:"lanAddr,omitempty"`
LanCandidates []string `json:"lanCandidates,omitempty"`
PinnedHashes []string `json:"pinnedHashes,omitempty"`
NamedHost string `json:"namedHost,omitempty"`
Health []adminapi.HealthLine `json:"health,omitempty"`
}
Hello is the PoP's first record on a link, and is sent again whenever what it carries changes (a certificate rotation, a new LAN address). NamedHost is the name the PoP already holds a certificate for, so home can tell a fresh install from a restart. LanAddr is an IP literal, with ":port" when the relay listens elsewhere than DefaultRelayPort.
type Release ¶
type Release struct {
IDs []string `json:"ids,omitempty"`
}
Release gives reserved IDs back.
type Reserve ¶
type Reserve struct {
IDs []string `json:"ids,omitempty"`
}
Reserve asks home to reserve broadcast IDs minted at the PoP; home answers one Reserved per ID.
type RoomOpen ¶
type RoomOpen struct {
Path string `json:"path,omitempty"`
RawQuery string `json:"rawQuery,omitempty"`
}
RoomOpen is the first record on a room-proxy stream; raw room-control bytes follow it.
type Session ¶
type Session interface {
OpenStream(ctx context.Context) (io.ReadWriteCloser, error)
AcceptStream(ctx context.Context) (io.ReadWriteCloser, error)
CloseWithError(code uint32, msg string) error
Context() context.Context
RemoteAddr() net.Addr
LocalAddr() net.Addr
}
Session is a link (or leg) session as both ends see it: the slice of a webtransport.Session the link uses, so tests can fake it. The PoP opens the control stream; extra bidi streams carry proxied room control.
func Pipe ¶
Pipe returns two connected in-memory Sessions, a stand-in for one QUIC link in unit tests: a stream one end opens is the next the other end accepts, and CloseWithError ends both, the peer reading a remote *webtransport.SessionError with the code (CloseCode reads it).
func WrapSession ¶
func WrapSession(s *webtransport.Session) Session
WrapSession adapts a WebTransport session to Session: both ends of a link see the same narrow interface, so the home and PoP logic run against in-memory fakes in their unit tests.
type State ¶
type State struct {
ID string `json:"id,omitempty"`
Live bool `json:"live,omitempty"`
Label string `json:"label,omitempty"`
PublisherLanAddr string `json:"publisherLanAddr,omitempty"`
}
State is a broadcast's live/away state at the PoP.
type Stats ¶
type Stats struct {
UplinkMbps float64 `json:"uplinkMbps,omitempty"`
UplinkStreams int `json:"uplinkStreams,omitempty"`
Uplink pops.Budget `json:"uplink,omitempty"`
Downlink pops.Budget `json:"downlink,omitempty"`
DownlinkStreams int `json:"downlinkStreams,omitempty"`
GuestsConnected int `json:"guestsConnected,omitempty"`
Broadcasts []adminapi.PopBroadcast `json:"broadcasts,omitempty"`
}
Stats is the PoP's periodic use report. Uplink and Downlink are the host-lowered ceilings (zero fields: not lowered).
type TelemetryConfig ¶ added in v0.37.0
type TelemetryConfig struct {
ReportIntervalMs uint16 `json:"reportIntervalMs,omitempty"`
AdvertiseURL string `json:"advertiseURL,omitempty"`
}
TelemetryConfig is what a PoP's telemetry hellos and ingest-URL records carry, so they are byte-identical to a home pod's.
type TelemetryMint ¶ added in v0.37.0
type TelemetryMint struct {
ID string `json:"id,omitempty"`
Role string `json:"role,omitempty"`
N int `json:"n,omitempty"`
}
TelemetryMint asks home for up to N tokens (at most MaxTelemetryMint) for sessions of broadcast ID in Role ("viewer" or "broadcaster").
type TelemetryObs ¶ added in v0.37.0
type TelemetryObs struct {
ID string `json:"id,omitempty"`
Part int `json:"part,omitempty"`
Broadcast json.RawMessage `json:"broadcast,omitempty"`
Subscribers []json.RawMessage `json:"subscribers,omitempty"`
}
TelemetryObs is one broadcast's relay-side view at the PoP (docs/78 D7): its hub's /statusz entry by raw ID. Part 0 carries Broadcast (the entry without its subscriber details) and starts a new snapshot; Subscribers are the details, split over parts 0..n so a record stays under MaxRecordBytes.
type TelemetryRefused ¶ added in v0.37.0
type TelemetryRefused struct {
ID string `json:"id,omitempty"`
Role string `json:"role,omitempty"`
Reason string `json:"reason,omitempty"`
}
TelemetryRefused answers a TelemetryMint home will not mint for.
type TelemetryTokens ¶ added in v0.37.0
type TelemetryTokens struct {
ID string `json:"id,omitempty"`
Role string `json:"role,omitempty"`
BroadcastKey string `json:"broadcastKey,omitempty"`
Tokens []string `json:"tokens,omitempty"`
}
TelemetryTokens answers a TelemetryMint: hex tokens minted by home under the fleet key, over home's BroadcastKey (hex) for ID, each marked with this PoP's issuer key (docs/78 D3).