rendezvous

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: BSD-3-Clause Imports: 18 Imported by: ? 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 rendezvous is a signalling relay for WebRTC peers, as a gRPC service (turn.v1.Turnd, proto/turn/v1/turnd.proto). A logged-in host opens a room (CreateRoom) and shares its 128-bit random ID; a guest knocks with it (JoinRoom) and is PENDING until the host admits it. The room is ONE bidirectional stream (Room): events down, messages up, routed host to guest and guest to host. An admitted peer can get TURN credentials that expire with the room, charged to the host's subject.

A leaked room link therefore lets a stranger knock, not enter: a pending guest can receive and nothing else, it cannot send and it cannot spend the host's TURN quota.

Every resource is bounded (see Limits) and every refusal is tested as a gRPC status code. A message that breaks the protocol (too large, a spoofed "from", a bad kind, a pending sender, guest to guest) ends the sender's stream with that status, which for a guest is leaving and for the host closes the room. A message that fails for what the OTHER peer is (gone, queue full) leaves the stream open and comes back as a sys.error event, "<Code>: <reason>".

Index

Constants

View Source
const HostID = "host"

HostID is the peer ID of a room's host.

View Source
const MaxNameLen = 64

MaxNameLen bounds a guest's display name, in characters.

View Source
const RoomMetadata = "x-turn-room"

RoomMetadata is the metadata key naming the room on the Room stream.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Auth returns the subject of a session or access token (host operations).
	Auth func(ctx context.Context, token string) (subject string, err error)
	// Keyring signs the TURN credentials.
	Keyring *creds.Keyring
	// STUN and TURN are the URLs advertised in credential responses.
	STUN, TURN []string
	Limits     Limits
	// CredTTL is the lifetime of host credentials (default 1 hour); a guest's
	// never outlive the room.
	CredTTL time.Duration
	Now     func() time.Time
}

Config configures New.

type Limits

type Limits struct {
	// MaxMessageBytes bounds a message body (default 16 KiB). The handshake blob
	// of the playground is an SDP description with its ICE candidates, a few KiB.
	MaxMessageBytes int
	// MaxQueue bounds the events waiting for one peer (default 64).
	MaxQueue int
	// MaxGuests bounds the guests ever ADMITTED to one room (default 8).
	MaxGuests int
	// MaxPending bounds the guests waiting for the host's decision in one room
	// (default 8); PendingTTL is how long one may wait (default 2 minutes).
	MaxPending int
	PendingTTL time.Duration
	// MaxRoomsPerSubject bounds the live rooms of one subject (default 4).
	MaxRoomsPerSubject int
	// MaxRooms bounds the live rooms of the server (default 1024).
	MaxRooms int
	// RoomTTL is a room's whole life (default 1 hour).
	RoomTTL time.Duration
	// MaxCredsPerRoom bounds the credential requests of one room (default 64).
	MaxCredsPerRoom int
}

Limits bounds what a client can make the server hold. Zero fields take the default shown.

type Server

type Server struct {
	turnv1.UnimplementedTurndServer
	// contains filtered or unexported fields
}

Server is the rendezvous. Build it with New and Server.Register it.

func New

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

New validates cfg.

func (*Server) Admit

func (s *Server) Admit(ctx context.Context, req *turnv1.DecideRequest) (*turnv1.Ack, error)

Admit implements turn.v1.Turnd.

func (*Server) CloseRoom

func (s *Server) CloseRoom(ctx context.Context, req *turnv1.RoomRef) (*turnv1.Ack, error)

CloseRoom implements turn.v1.Turnd.

func (*Server) CreateRoom

CreateRoom implements turn.v1.Turnd.

func (*Server) Credentials

func (s *Server) Credentials(ctx context.Context, _ *turnv1.CredentialsRequest) (*turnv1.IceServers, error)

Credentials implements turn.v1.Turnd.

func (*Server) Deny

func (s *Server) Deny(ctx context.Context, req *turnv1.DecideRequest) (*turnv1.Ack, error)

Deny implements turn.v1.Turnd: it refuses a waiting guest, or removes an admitted one. Its token is dead.

func (*Server) JoinRoom

JoinRoom implements turn.v1.Turnd.

func (*Server) MaxRecvMsgSize

func (s *Server) MaxRecvMsgSize() int

MaxRecvMsgSize is the gRPC receive bound that fits a message at its limit.

func (*Server) Register

func (s *Server) Register(gs grpc.ServiceRegistrar)

Register adds the service to a gRPC server. Give that server grpc.MaxRecvMsgSize of at least Server.MaxRecvMsgSize.

func (*Server) Room

Room implements turn.v1.Turnd.

func (*Server) RoomCredentials

func (s *Server) RoomCredentials(ctx context.Context, req *turnv1.RoomRef) (*turnv1.IceServers, error)

RoomCredentials implements turn.v1.Turnd.

func (*Server) Rooms

func (s *Server) Rooms() int

Rooms is the number of live rooms.

func (*Server) Run

func (s *Server) Run(ctx context.Context, every time.Duration)

Run sweeps expired rooms every interval until ctx ends.

func (*Server) Sweep

func (s *Server) Sweep()

Sweep closes the rooms whose time is over and drops the guests whose wait is.

Directories

Path Synopsis
Package client is the rendezvous client: a real grpc-go client of turn.v1.Turnd, dialed over a WebSocket (github.com/grpc-transports/websocket), which in a browser (GOOS=js) is the browser's WebSocket through syscall/js.
Package client is the rendezvous client: a real grpc-go client of turn.v1.Turnd, dialed over a WebSocket (github.com/grpc-transports/websocket), which in a browser (GOOS=js) is the browser's WebSocket through syscall/js.

Jump to

Keyboard shortcuts

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