TURN module (rfc5766)

turn

TURN allocation identity types and transport helpers.

turn

TURN allocation identity types and transport helpers.

Classes

NameDescription
ClientTURN client that manages relay allocations, permissions, and data relay via RFC 5766.
FiveTupleTURN allocation identity tuple: client remote address, server local address, and transport protocol.
IAllocationBase class for TURN relay allocations shared by client and server flows.
PermissionPolicyLightweight server-side TURN permission policy.
RequestA STUN message annotated with the transport type and source/destination addresses needed for server-side routing and response generation.
ServerTURN server RFC 5766 / RFC 6062 implementation. Listens on UDP and/or TCP, authenticates requests via ServerObserver, and manages ServerAllocation objects for each 5-tuple.
ServerAllocationServer-side TURN allocation that tracks permissions, lifetime, and relay state. Handles Refresh and CreatePermission requests common to both UDP and TCP allocations. Subclassed by UDPAllocation and TCPAllocation for transport-specific behaviour.
TCPAllocationServer-side TCP TURN allocation with connection pair management per RFC 6062. Maintains a control connection for STUN signalling and an acceptor socket for incoming peer TCP connections. Each peer connection is tracked as a TCPConnectionPair and bridged to the client after a successful ConnectionBind.
TCPClientTCP transport TURN client with relay connection management per RFC 6062. Uses a single TCP control connection for STUN signalling and opens additional TCP relay connections for each peer via the Connect / ConnectionBind flow.
TCPConnectionPairPaired TCP connections forming a single TURN relay pipe between a client and a peer. Lifetime managed by IntrusivePtr; the owning TCPAllocation holds the Ptr in its pair map.
UDPAllocationServer-side UDP TURN allocation that relays datagrams to permitted peers. Binds a dedicated UDP relay socket for peer communication and forwards incoming datagrams to the client as Data Indications.
UDPClientUDP transport TURN client for datagram-based relay allocations. Uses a single UDP socket for both STUN signalling and Send/Data Indications. All Client methods apply; data is relayed via sendData() using Send Indications.
ClientObserverAbstract observer interface for TURN client events. Callers subclass this to receive allocation lifecycle and data relay callbacks.
ClientStateState machine states for the TURN client.
PermissionA single TURN permission entry associating a peer IP with a 5-minute expiry timer. Per RFC 5766 section 8, permissions last exactly 300 seconds and must be refreshed via a new CreatePermission request before they expire.
RelayConnectionBindingBinding metadata stored as socket opaque data during a ConnectionBind handshake. Associates a relay socket with its TURN connection ID and peer address.
ServerObserverObserver interface that the application must implement to participate in server-side allocation management and authentication.
ServerOptionsConfiguration options for the TURN server.
TCPClientObserverObserver interface for TCP TURN client events (RFC 6062). Extends ClientObserver with callbacks specific to TCP relay connections.

Enumerations

NameDescription
AuthenticationStateResult returned by ServerObserver::authenticateRequest() to control how the server proceeds with an incoming STUN request.

AuthenticationState

enum AuthenticationState

Result returned by ServerObserver::authenticateRequest() to control how the server proceeds with an incoming STUN request.

ValueDescription
AuthenticatingAuthentication is in progress; server holds the request.
AuthorizedCredentials verified; request may proceed.
QuotaReachedUser quota exceeded; respond with 486.
NotAuthorizedCredentials rejected; respond with 401.

Typedefs

ReturnNameDescription
KVCollection< net::Address, net::SocketEmitter >ConnectionManagerRelay connection registry keyed by peer address for RFC 6062 TCP relays.
ConnectionManager::MapConnectionManagerMapUnderlying map type used by the TCP relay connection registry.
std::vector< Permission >PermissionListActive TURN permissions associated with one allocation.
std::map< FiveTuple, std::unique_ptr< ServerAllocation > >ServerAllocationMapActive server allocations keyed by the client/server 5-tuple.
std::map< uint32_t, TCPConnectionPair::Ptr >TCPConnectionPairMapAccepted peer TCP connections keyed by TURN CONNECTION-ID.
std::vector< std::string >IPListList of peer IP strings used when creating or refreshing permissions.

ConnectionManager

KVCollection< net::Address, net::SocketEmitter > ConnectionManager()

Relay connection registry keyed by peer address for RFC 6062 TCP relays.


ConnectionManagerMap

ConnectionManager::Map ConnectionManagerMap()

Underlying map type used by the TCP relay connection registry.


PermissionList

std::vector< Permission > PermissionList()

Active TURN permissions associated with one allocation.


ServerAllocationMap

std::map< FiveTuple, std::unique_ptr< ServerAllocation > > ServerAllocationMap()

Active server allocations keyed by the client/server 5-tuple.


TCPConnectionPairMap

std::map< uint32_t, TCPConnectionPair::Ptr > TCPConnectionPairMap()

Accepted peer TCP connections keyed by TURN CONNECTION-ID.


IPList

std::vector< std::string > IPList()

List of peer IP strings used when creating or refreshing permissions.

Variables

ReturnNameDescription
constexpr std::int64_tkClientTimerInterval staticTimer interval for client maintenance (30 seconds)
constexpr std::int64_tkClientDefaultLifetime staticDefault client allocation lifetime (5 minutes, in milliseconds)
constexpr longkClientDefaultTimeout staticDefault client transaction timeout (10 seconds)
constexpr std::int64_tkDefaultAllocationLifetime staticDefault allocation lifetime: 10 minutes (in milliseconds)
constexpr intPERMISSION_LIFETIME staticPermission Lifetime MUST be 300 seconds (= 5 minutes).
constexpr uint32_tkServerDefaultLifetime staticDefault server allocation lifetime (2 minutes, in milliseconds)
constexpr uint32_tkServerMaxLifetime staticMaximum server allocation lifetime (15 minutes, in milliseconds)
constexpr intkServerMaxPermissions staticMaximum number of permissions per allocation.
constexpr intkServerTimerInterval staticServer timer interval (10 seconds)
constexpr intkServerEarlyMediaBufferSize staticEarly media buffer size.
constexpr intkConnectionBindTimeout staticConnectionBind request timeout (30 seconds, in milliseconds)
constexpr intCLIENT_SOCK_BUF_SIZE staticDefault socket buffer size for TURN client sockets.
constexpr intSERVER_SOCK_BUF_SIZE staticDefault socket buffer size for TURN server sockets.
constexpr uint8_tkProtocolUDP staticTURN protocol numbers.
constexpr uint8_tkProtocolTCP staticIP protocol number for TCP.
constexpr intkErrorTryAlternate staticTURN/STUN error codes used in this module.
constexpr intkErrorBadRequest staticRequest was malformed or missing required attributes.
constexpr intkErrorNotAuthorized staticAuthentication failed or credentials were not accepted.
constexpr intkErrorForbidden staticRequest was understood but is not permitted for this client.
constexpr intkErrorUnknownAttribute staticRequest included an unsupported comprehension-required attribute.
constexpr intkErrorUnsupportedTransport staticRequested transport protocol is not supported by the server.
constexpr intkErrorAllocationMismatch staticClient attempted an allocation operation that conflicts with existing state.
constexpr intkErrorStaleNonce staticAuthentication nonce expired and must be refreshed.
constexpr intkErrorWrongCredentials staticSupplied credentials were well formed but did not match the allocation.
constexpr intkErrorConnectionAlreadyExists staticTURN TCP connection binding already exists.
constexpr intkErrorConnectionTimeoutOrFailure staticTURN TCP peer connection attempt timed out or failed.
constexpr intkErrorAllocationQuotaReached staticUser or server allocation quota was exceeded.
constexpr intkErrorInsufficientCapacity staticServer lacks capacity to satisfy the request.
constexpr intkErrorOperationNotSupported staticRequest is recognized but not implemented by this server.

kClientTimerInterval

static

constexpr std::int64_t kClientTimerInterval = 30 * 1000

Timer interval for client maintenance (30 seconds)


kClientDefaultLifetime

static

constexpr std::int64_t kClientDefaultLifetime = 5 * 60 * 1000

Default client allocation lifetime (5 minutes, in milliseconds)


kClientDefaultTimeout

static

constexpr long kClientDefaultTimeout = 10 * 1000

Default client transaction timeout (10 seconds)


kDefaultAllocationLifetime

static

constexpr std::int64_t kDefaultAllocationLifetime = 10 * 60 * 1000

Default allocation lifetime: 10 minutes (in milliseconds)


PERMISSION_LIFETIME

static

constexpr int PERMISSION_LIFETIME = 5 * 60 * 1000

Permission Lifetime MUST be 300 seconds (= 5 minutes).


kServerDefaultLifetime

static

constexpr uint32_t kServerDefaultLifetime = 2 * 60 * 1000

Default server allocation lifetime (2 minutes, in milliseconds)


kServerMaxLifetime

static

constexpr uint32_t kServerMaxLifetime = 15 * 60 * 1000

Maximum server allocation lifetime (15 minutes, in milliseconds)


kServerMaxPermissions

static

constexpr int kServerMaxPermissions = 10

Maximum number of permissions per allocation.


kServerTimerInterval

static

constexpr int kServerTimerInterval = 10 * 1000

Server timer interval (10 seconds)


kServerEarlyMediaBufferSize

static

constexpr int kServerEarlyMediaBufferSize = 8192

Early media buffer size.


kConnectionBindTimeout

static

constexpr int kConnectionBindTimeout = 30 * 1000

ConnectionBind request timeout (30 seconds, in milliseconds)


CLIENT_SOCK_BUF_SIZE

static

constexpr int CLIENT_SOCK_BUF_SIZE = 65536

Default socket buffer size for TURN client sockets.


SERVER_SOCK_BUF_SIZE

static

constexpr int SERVER_SOCK_BUF_SIZE = CLIENT_SOCK_BUF_SIZE * 32

Default socket buffer size for TURN server sockets.


kProtocolUDP

static

constexpr uint8_t kProtocolUDP = 17

TURN protocol numbers.

IP protocol number for UDP.


kProtocolTCP

static

constexpr uint8_t kProtocolTCP = 6

IP protocol number for TCP.


kErrorTryAlternate

static

constexpr int kErrorTryAlternate = 300

TURN/STUN error codes used in this module.

Client should retry against an alternate TURN server.


kErrorBadRequest

static

constexpr int kErrorBadRequest = 400

Request was malformed or missing required attributes.


kErrorNotAuthorized

static

constexpr int kErrorNotAuthorized = 401

Authentication failed or credentials were not accepted.


kErrorForbidden

static

constexpr int kErrorForbidden = 403

Request was understood but is not permitted for this client.


kErrorUnknownAttribute

static

constexpr int kErrorUnknownAttribute = 420

Request included an unsupported comprehension-required attribute.


kErrorUnsupportedTransport

static

constexpr int kErrorUnsupportedTransport = 442

Requested transport protocol is not supported by the server.


kErrorAllocationMismatch

static

constexpr int kErrorAllocationMismatch = 437

Client attempted an allocation operation that conflicts with existing state.


kErrorStaleNonce

static

constexpr int kErrorStaleNonce = 438

Authentication nonce expired and must be refreshed.


kErrorWrongCredentials

static

constexpr int kErrorWrongCredentials = 441

Supplied credentials were well formed but did not match the allocation.


kErrorConnectionAlreadyExists

static

constexpr int kErrorConnectionAlreadyExists = 446

TURN TCP connection binding already exists.


kErrorConnectionTimeoutOrFailure

static

constexpr int kErrorConnectionTimeoutOrFailure = 447

TURN TCP peer connection attempt timed out or failed.


kErrorAllocationQuotaReached

static

constexpr int kErrorAllocationQuotaReached = 486

User or server allocation quota was exceeded.


kErrorInsufficientCapacity

static

constexpr int kErrorInsufficientCapacity = 508

Server lacks capacity to satisfy the request.


kErrorOperationNotSupported

static

constexpr int kErrorOperationNotSupported = 600

Request is recognized but not implemented by this server.