TURN module (rfc5766)

ServerAllocation

Server-side TURN allocation that tracks permissions, lifetime, and relay state.

ServerAllocation

#include <icy/turn/server/serverallocation.h>

Inherits: IAllocation Subclassed by: TCPAllocation, UDPAllocation

Server-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.

Public Methods

ReturnNameDescription
ServerAllocation#### Parameters
boolhandleRequest virtualDispatches incoming STUN requests to handleCreatePermission() or handleRefreshRequest(). Subclasses override to add transport-specific methods.
voidhandleRefreshRequest virtualProcesses a Refresh request; updates the lifetime or sets the delete flag if the requested lifetime is 0, then sends a success response.
voidhandleCreatePermission virtualProcesses a CreatePermission request; installs or refreshes permissions for each XOR-PEER-ADDRESS attribute, then sends a success response.
boolonTimerPeriodic maintenance callback called by Server::onTimer(). Removes expired permissions. Returns false to signal that this allocation should be destroyed.
std::int64_ttimeRemaining virtual const#### Returns
std::int64_tmaxTimeRemaining const#### Returns
boolhasPermission virtualChecks permission, auto-granting local IPs if enabled in server options.
boolhasPermission virtualChecks whether a permission exists for peerAddress. The port is ignored; TURN permissions are IP-only.
Server &server virtual#### Returns
voidprint virtual constWrites a detailed diagnostic dump of this allocation to os.
boolrefreshDeleteRequested const inlineReturns true if the refresh request set lifetime to 0, signaling the parent Server to delete this allocation.

ServerAllocation

ServerAllocation(Server & server, const FiveTuple & tuple, const std::string & username, std::int64_t lifetime)

Parameters

  • server Owning TURN server.

  • tuple 5-tuple uniquely identifying this allocation.

  • username Authenticated username from the Allocate request.

  • lifetime Initial lifetime in seconds as negotiated with the client.


handleRequest

virtual

virtual bool handleRequest(Request & request)

Dispatches incoming STUN requests to handleCreatePermission() or handleRefreshRequest(). Subclasses override to add transport-specific methods.

Parameters

  • request Incoming STUN request.

Returns

true if the request was handled; false signals the server to respond with a 600 "Operation Not Supported" error.


handleRefreshRequest

virtual

virtual void handleRefreshRequest(Request & request)

Processes a Refresh request; updates the lifetime or sets the delete flag if the requested lifetime is 0, then sends a success response.

Parameters

  • request Incoming Refresh request.

handleCreatePermission

virtual

virtual void handleCreatePermission(Request & request)

Processes a CreatePermission request; installs or refreshes permissions for each XOR-PEER-ADDRESS attribute, then sends a success response.

Parameters

  • request Incoming CreatePermission request.

onTimer

bool onTimer()

Periodic maintenance callback called by Server::onTimer(). Removes expired permissions. Returns false to signal that this allocation should be destroyed.

Returns

true to keep the allocation alive; false to destroy it.


timeRemaining

virtual const

virtual std::int64_t timeRemaining() const

Returns

The lesser of IAllocation::timeRemaining() and maxTimeRemaining().


maxTimeRemaining

const

std::int64_t maxTimeRemaining() const

Returns

Seconds remaining before the server-enforced maximum lifetime expires.


hasPermission

virtual

virtual bool hasPermission(const std::string & peerIP)

Checks permission, auto-granting local IPs if enabled in server options.


hasPermission

virtual

virtual bool hasPermission(const net::Address & peerAddress)

Checks whether a permission exists for peerAddress. The port is ignored; TURN permissions are IP-only.


server

virtual

virtual Server & server()

Returns

Reference to the owning TURN server.


print

virtual const

virtual void print(std::ostream & os) const

Writes a detailed diagnostic dump of this allocation to os.


refreshDeleteRequested

const inline

inline bool refreshDeleteRequested() const

Returns true if the refresh request set lifetime to 0, signaling the parent Server to delete this allocation.

Protected Attributes

ReturnNameDescription
uint32_t_maxLifetime
Server &_server
PermissionPolicy_permissionPolicy
bool_refreshDeleteRequested

_maxLifetime

uint32_t _maxLifetime

_server

Server & _server

_permissionPolicy

PermissionPolicy _permissionPolicy

_refreshDeleteRequested

bool _refreshDeleteRequested = false

Private Methods

ReturnNameDescription
ServerAllocationNonCopyable and NonMovable.
ServerAllocationDeleted constructor.

ServerAllocation

ServerAllocation(const ServerAllocation &) = delete

NonCopyable and NonMovable.


ServerAllocation

ServerAllocation(ServerAllocation &&) = delete

Deleted constructor.