turn

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// UDP listener (TURN over UDP)
	ListenAddr string

	// TCP/TLS listeners (optional)
	TCPListenAddr string
	TLSListenAddr string

	// TLS configuration (either provide Cert/Key files or TLSConfig)
	TLSCertFile string
	TLSKeyFile  string
	TLSConfig   *tls.Config

	// Public relay settings
	PublicIP     string
	RelayMinPort uint16 // optional; if zero, default system range is used
	RelayMaxPort uint16 // optional; if zero, default system range is used
	Realm        string
	Users        []User // static users

	// Dynamic (REST) credentials
	Dynamic *DynamicAuth
}

Config controls the TURN server.

ListenAddr is the local UDP address to bind, e.g. ":3478". PublicIP is the external/public IP address that peers will use to reach relays. RelayMinPort/RelayMaxPort control the relay port range. Realm is the authentication realm. Users is a static list of username/password pairs (long-term credential).

type DynamicAuth

type DynamicAuth struct {
	Secret string
	MaxTTL time.Duration
}

DynamicAuth enables time-limited credentials. Username is an expiry epoch (seconds), credential is base64(HMAC-SHA1(secret, username)). Requests are accepted if not expired and within MaxTTL.

type Server

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

Server is a TURN server using pion/turn. It also handles STUN Binding requests on the same port.

func (*Server) Close

func (s *Server) Close() error

Close stops the TURN server.

func (*Server) GenerateRESTCredentials

func (s *Server) GenerateRESTCredentials(ttl time.Duration) (string, string)

GenerateRESTCredentials returns (username, credential) for time-limited TURN auth.

func (*Server) ICEServerFor

func (s *Server) ICEServerFor(username string) webrtc.ICEServer

ICEServer returns a webrtc.ICEServer for a given static user. The PublicAddr should be the externally reachable host:port, i.e., PublicIP:port.

func (*Server) Start

func (s *Server) Start(cfg Config) error

Start launches the TURN server.

type User

type User struct {
	Username string
	Password string
}

User represents static auth credentials.

Jump to

Keyboard shortcuts

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