Documentation
¶
Overview ¶
Package relay forwards already-encrypted packets between nodes that cannot reach each other directly. Nodes hold a WebSocket to the coordinator and address each other by WireGuard public key; the relay never sees plaintext.
Frames are binary WebSocket messages:
client -> server: 0x01 | destination key (32) | payload server -> client: 0x02 | source key (32) | payload
Index ¶
Constants ¶
const (
// MaxPayload bounds a single packet; WireGuard packets are far smaller.
MaxPayload = 64 << 10
)
const Path = "/relay/v1"
Path is where the relay is mounted on the coordinator.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authenticator ¶
Authenticator maps a bearer token to the WireGuard key of the node it belongs to.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client keeps a connection to the relay open, reconnecting as needed.
func NewClient ¶
NewClient returns a client for the relay on the coordinator at baseURL. Received packets are delivered on Recv().
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the relay endpoint.
func NewServer ¶
func NewServer(auth Authenticator, bytesPerSec, burst int, log *slog.Logger) *Server
NewServer returns a relay that lets each node send bytesPerSec on average (with bursts up to burst bytes). Zero bytesPerSec means unlimited.
func (*Server) Connections ¶
Connections returns the number of connected nodes.
func (*Server) Prune ¶
Prune disconnects every node for which keep returns false, e.g. nodes that were deleted: their token no longer works, but an open connection would otherwise last until it next reconnects.