server

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	CodeBadRequest   websocket.StatusCode = 4400
	CodeUnauthorized websocket.StatusCode = 4401
	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.

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

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is one relay.

func New

func New(cfg Config) (*Server, error)

New validates cfg and builds a relay.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler serves the relay endpoints. Anything else is a bodyless 404: the relay must never be somewhere a browser loads a page or a script from.

Jump to

Keyboard shortcuts

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