TURN module (rfc5766)

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

Defined in src/turn/include/icy/turn/types.h:50

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

using ConnectionManager = KVCollection< net::Address, net::SocketEmitter >

Type: KVCollection< net::Address, net::SocketEmitter >

Defined in src/turn/include/icy/turn/client/tcpclient.h:78

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


ConnectionManagerMap

using ConnectionManagerMap = ConnectionManager::Map

Type: ConnectionManager::Map

Defined in src/turn/include/icy/turn/client/tcpclient.h:81

Underlying map type used by the TCP relay connection registry.


PermissionList

using PermissionList = std::vector< Permission >

Type: std::vector< Permission >

Defined in src/turn/include/icy/turn/permission.h:140

Active TURN permissions associated with one allocation.


ServerAllocationMap

using ServerAllocationMap = std::map< FiveTuple, std::unique_ptr< ServerAllocation > >

Type: std::map< FiveTuple, std::unique_ptr< ServerAllocation > >

Defined in src/turn/include/icy/turn/server/server.h:120

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


TCPConnectionPairMap

using TCPConnectionPairMap = std::map< uint32_t, TCPConnectionPair::Ptr >

Type: std::map< uint32_t, TCPConnectionPair::Ptr >

Defined in src/turn/include/icy/turn/server/tcpallocation.h:29

Accepted peer TCP connections keyed by TURN CONNECTION-ID.


IPList

using IPList = std::vector< std::string >

Defined in src/turn/include/icy/turn/types.h:104

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

Variables

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

kClientTimerInterval

static constexpr

constexpr std::int64_t kClientTimerInterval = 30 * 1000

Defined in src/turn/include/icy/turn/client/client.h:114

Timer interval for client maintenance (30 seconds)


kClientDefaultLifetime

static constexpr

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

Defined in src/turn/include/icy/turn/client/client.h:117

Default client allocation lifetime (5 minutes, in milliseconds)


kClientDefaultTimeout

static constexpr

constexpr long kClientDefaultTimeout = 10 * 1000

Defined in src/turn/include/icy/turn/client/client.h:120

Default client transaction timeout (10 seconds)


kDefaultAllocationLifetime

static constexpr

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

Defined in src/turn/include/icy/turn/iallocation.h:28

Default allocation lifetime: 10 minutes (in milliseconds)


PERMISSION_LIFETIME

static constexpr

constexpr int PERMISSION_LIFETIME = 5 * 60 * 1000

Defined in src/turn/include/icy/turn/permission.h:31

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


kServerDefaultLifetime

static constexpr

constexpr uint32_t kServerDefaultLifetime = 2 * 60 * 1000

Defined in src/turn/include/icy/turn/server/server.h:37

Default server allocation lifetime (2 minutes, in milliseconds)


kServerMaxLifetime

static constexpr

constexpr uint32_t kServerMaxLifetime = 15 * 60 * 1000

Defined in src/turn/include/icy/turn/server/server.h:40

Maximum server allocation lifetime (15 minutes, in milliseconds)


kServerMaxPermissions

static constexpr

constexpr int kServerMaxPermissions = 10

Defined in src/turn/include/icy/turn/server/server.h:43

Maximum number of permissions per allocation.


kServerTimerInterval

static constexpr

constexpr int kServerTimerInterval = 10 * 1000

Defined in src/turn/include/icy/turn/server/server.h:46

Server timer interval (10 seconds)


kServerEarlyMediaBufferSize

static constexpr

constexpr int kServerEarlyMediaBufferSize = 8192

Defined in src/turn/include/icy/turn/server/server.h:49

Early media buffer size.


kConnectionBindTimeout

static constexpr

constexpr int kConnectionBindTimeout = 30 * 1000

Defined in src/turn/include/icy/turn/server/tcpconnectionpair.h:29

ConnectionBind request timeout (30 seconds, in milliseconds)


CLIENT_SOCK_BUF_SIZE

static constexpr

constexpr int CLIENT_SOCK_BUF_SIZE = 65536

Defined in src/turn/include/icy/turn/types.h:24

Default socket buffer size for TURN client sockets.


SERVER_SOCK_BUF_SIZE

static constexpr

constexpr int SERVER_SOCK_BUF_SIZE = CLIENT_SOCK_BUF_SIZE * 32

Defined in src/turn/include/icy/turn/types.h:25

Default socket buffer size for TURN server sockets.


kProtocolUDP

static constexpr

constexpr uint8_t kProtocolUDP = 17

Defined in src/turn/include/icy/turn/types.h:28

TURN protocol numbers.

IP protocol number for UDP.


kProtocolTCP

static constexpr

constexpr uint8_t kProtocolTCP = 6

Defined in src/turn/include/icy/turn/types.h:29

IP protocol number for TCP.


kErrorTryAlternate

static constexpr

constexpr int kErrorTryAlternate = 300

Defined in src/turn/include/icy/turn/types.h:32

TURN/STUN error codes used in this module.

Client should retry against an alternate TURN server.


kErrorBadRequest

static constexpr

constexpr int kErrorBadRequest = 400

Defined in src/turn/include/icy/turn/types.h:33

Request was malformed or missing required attributes.


kErrorNotAuthorized

static constexpr

constexpr int kErrorNotAuthorized = 401

Defined in src/turn/include/icy/turn/types.h:34

Authentication failed or credentials were not accepted.


kErrorForbidden

static constexpr

constexpr int kErrorForbidden = 403

Defined in src/turn/include/icy/turn/types.h:35

Request was understood but is not permitted for this client.


kErrorUnknownAttribute

static constexpr

constexpr int kErrorUnknownAttribute = 420

Defined in src/turn/include/icy/turn/types.h:36

Request included an unsupported comprehension-required attribute.


kErrorUnsupportedTransport

static constexpr

constexpr int kErrorUnsupportedTransport = 442

Defined in src/turn/include/icy/turn/types.h:37

Requested transport protocol is not supported by the server.


kErrorAllocationMismatch

static constexpr

constexpr int kErrorAllocationMismatch = 437

Defined in src/turn/include/icy/turn/types.h:38

Client attempted an allocation operation that conflicts with existing state.


kErrorStaleNonce

static constexpr

constexpr int kErrorStaleNonce = 438

Defined in src/turn/include/icy/turn/types.h:39

Authentication nonce expired and must be refreshed.


kErrorWrongCredentials

static constexpr

constexpr int kErrorWrongCredentials = 441

Defined in src/turn/include/icy/turn/types.h:40

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


kErrorConnectionAlreadyExists

static constexpr

constexpr int kErrorConnectionAlreadyExists = 446

Defined in src/turn/include/icy/turn/types.h:41

TURN TCP connection binding already exists.


kErrorConnectionTimeoutOrFailure

static constexpr

constexpr int kErrorConnectionTimeoutOrFailure = 447

Defined in src/turn/include/icy/turn/types.h:42

TURN TCP peer connection attempt timed out or failed.


kErrorAllocationQuotaReached

static constexpr

constexpr int kErrorAllocationQuotaReached = 486

Defined in src/turn/include/icy/turn/types.h:43

User or server allocation quota was exceeded.


kErrorInsufficientCapacity

static constexpr

constexpr int kErrorInsufficientCapacity = 508

Defined in src/turn/include/icy/turn/types.h:44

Server lacks capacity to satisfy the request.


kErrorOperationNotSupported

static constexpr

constexpr int kErrorOperationNotSupported = 600

Defined in src/turn/include/icy/turn/types.h:45

Request is recognized but not implemented by this server.