Documentation
¶
Overview ¶
Package server is `lectern relay`: a single-process, stateless router of opaque frames between a Lectern host and that host's paired devices. It holds no keys and never sees plaintext (docs/relay.md). What it does check:
- a host proves it owns its channel (Ed25519 over a fresh challenge) and knows this relay's host secret (HMAC), so strangers cannot use the relay as a free message bus;
- a device presents a route token whose hash that host registered, before anything it sends is forwarded;
- sizes, rates and connection counts stay inside fixed limits.
It never dials out and serves no HTML or JavaScript: only two WebSocket endpoints and a plain-text health check.
Index ¶
Constants ¶
const ( CodeBadRequest websocket.StatusCode = 4400 CodeHostOffline websocket.StatusCode = 4404 CodeAuthTimeout websocket.StatusCode = 4408 CodeTooBig websocket.StatusCode = 4413 CodeTooMany websocket.StatusCode = 4429 CodeReplaced websocket.StatusCode = 4409 CodeSlow websocket.StatusCode = 4503 )
Close codes the relay sends. 4xxx is the application range; phones show a message per code.
const MinHostSecret = 32
MinHostSecret is the shortest host secret New accepts.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// HostSecret must be known (as an HMAC key) by every host allowed to
// register a channel. Required.
HostSecret string
// TrustForwarded takes the client IP from X-Forwarded-For's first hop.
// Only for a relay reachable solely through a proxy you run; otherwise a
// client could pick its own address and dodge the per-IP limits.
TrustForwarded bool
MaxConns int // total open connections (1024)
MaxConnsPerIP int // open connections per client IP (32)
ConnectsPerMinute int // new connections per client IP per minute (120)
MaxChannels int // connected hosts (64)
MaxDevicesPerChannel int // open device connections per host (32)
MaxRoutesPerChannel int // registered route tokens per host (512)
DeviceRate int // device → host bytes per second (256 KiB)
DeviceBurst int // device → host burst bytes (2 MiB)
DeviceQueue int // bytes queued toward one slow device before dropping it (4 MiB)
AuthTimeout time.Duration // time a new connection has to authenticate (10s)
PingInterval time.Duration // keepalive ping (30s)
// OnFrame, when set, sees every payload the relay forwards — the
// ciphertext exactly as it crossed the relay. Tests use it to prove the
// relay never holds plaintext.
OnFrame func(direction, channel string, conn uint32, payload []byte)
Log *slog.Logger
}
Config sets the relay's secret and limits. Zero values take the defaults documented on each field.