server

package
v4.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package server implements the private API to implement a TURN server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleRequest

func HandleRequest(r Request) error

HandleRequest processes the give Request.

Types

type NonceHash

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

NonceHash is used to create and verify nonces.

func (*NonceHash) Generate

func (n *NonceHash) Generate() (string, error)

Generate a nonce.

func (*NonceHash) Validate

func (n *NonceHash) Validate(nonce string) error

Validate checks that nonce is signed and is not expired.

type NonceManager added in v4.1.2

type NonceManager interface {
	Generate() (string, error)
	Validate(nonce string) error
}

NonceManager interface that both implementations satisfy.

func NewNonceHash

func NewNonceHash() (NonceManager, error)

NewNonceHash creates a NonceHash.

func NewShortNonceHash added in v4.1.2

func NewShortNonceHash(hmacLen int) (NonceManager, error)

NewShortNonceHash creates a ShortNonceHash. The hmacLen argument specifies the number of HMAC bytes to include (2-32 bytes). The total nonce size will be 4 + hmacLen bytes, default hmaclen is 12 bytes. The 4 bytes timestamp gives about ~8000 years before nonces would start to repeat (safe until year 10,135).

type Request

type Request struct {
	// Current Request State
	Conn    net.PacketConn
	SrcAddr net.Addr
	Buff    []byte

	// Server State
	AllocationManager *allocation.Manager
	NonceHash         NonceManager

	// User Configuration
	AuthHandler func(username string, realm string, srcAddr net.Addr) (key []byte, ok bool)

	// Quota Handler
	QuotaHandler func(username string, realm string, srcAddr net.Addr) (ok bool)

	Log                logging.LeveledLogger
	Realm              string
	ChannelBindTimeout time.Duration
}

Request contains all the state needed to process a single incoming datagram.

type ShortNonceHash added in v4.1.2

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

ShortNonceHash is used to create and verify short nonces.

func (*ShortNonceHash) Generate added in v4.1.2

func (s *ShortNonceHash) Generate() (string, error)

Generate a short nonce (4 + hmacLen bytes encoded as base36).

func (*ShortNonceHash) Validate added in v4.1.2

func (s *ShortNonceHash) Validate(nonce string) error

Validate checks that nonce is signed and is not expired.

Jump to

Keyboard shortcuts

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