Home
TURN module (rfc5766)

TCPAllocation

Server-side TCP TURN allocation with connection pair management per RFC 6062.

TCPAllocation

#include <icy/turn/server/tcpallocation.h>
class TCPAllocation

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

Inherits: ServerAllocation

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

List of all members

NameKindOwner
TCPAllocationfunctionDeclared here
~TCPAllocationfunctionDeclared here
handleRequestfunctionDeclared here
handleConnectRequestfunctionDeclared here
handleConnectionBindRequestfunctionDeclared here
sendPeerConnectResponsefunctionDeclared here
sendToControlfunctionDeclared here
controlfunctionDeclared here
relayedAddressfunctionDeclared here
pairsfunctionDeclared here
onTimerfunctionDeclared here
onPeerAcceptfunctionDeclared here
onControlClosedfunctionDeclared here
_controlvariableDeclared here
_acceptorvariableDeclared here
_pairsvariableDeclared here
ServerfriendInherited from ServerAllocation
ServerAllocationfunctionInherited from ServerAllocation
~ServerAllocationfunctionInherited from ServerAllocation
handleRequestfunctionInherited from ServerAllocation
handleRefreshRequestfunctionInherited from ServerAllocation
handleCreatePermissionfunctionInherited from ServerAllocation
onTimerfunctionInherited from ServerAllocation
timeRemainingfunctionInherited from ServerAllocation
maxTimeRemainingfunctionInherited from ServerAllocation
hasPermissionfunctionInherited from ServerAllocation
hasPermissionfunctionInherited from ServerAllocation
serverfunctionInherited from ServerAllocation
printfunctionInherited from ServerAllocation
refreshDeleteRequestedfunctionInherited from ServerAllocation
_maxLifetimevariableInherited from ServerAllocation
_servervariableInherited from ServerAllocation
_permissionPolicyvariableInherited from ServerAllocation
_refreshDeleteRequestedvariableInherited from ServerAllocation
ServerAllocationfunctionInherited from ServerAllocation
operator=functionInherited from ServerAllocation
ServerAllocationfunctionInherited from ServerAllocation
operator=functionInherited from ServerAllocation
operator<<friendInherited from IAllocation
IAllocationfunctionInherited from IAllocation
~IAllocationfunctionInherited from IAllocation
IAllocationfunctionInherited from IAllocation
operator=functionInherited from IAllocation
IAllocationfunctionInherited from IAllocation
operator=functionInherited from IAllocation
updateUsagefunctionInherited from IAllocation
setLifetimefunctionInherited from IAllocation
setBandwidthLimitfunctionInherited from IAllocation
expiredfunctionInherited from IAllocation
deletedfunctionInherited from IAllocation
bandwidthLimitfunctionInherited from IAllocation
bandwidthUsedfunctionInherited from IAllocation
bandwidthRemainingfunctionInherited from IAllocation
timeRemainingfunctionInherited from IAllocation
tuplefunctionInherited from IAllocation
usernamefunctionInherited from IAllocation
lifetimefunctionInherited from IAllocation
permissionsfunctionInherited from IAllocation
relayedAddressfunctionInherited from IAllocation
addPermissionfunctionInherited from IAllocation
addPermissionfunctionInherited from IAllocation
addPermissionsfunctionInherited from IAllocation
removePermissionfunctionInherited from IAllocation
removePermissionfunctionInherited from IAllocation
removeAllPermissionsfunctionInherited from IAllocation
removeExpiredPermissionsfunctionInherited from IAllocation
hasPermissionfunctionInherited from IAllocation
hasPermissionfunctionInherited from IAllocation
printfunctionInherited from IAllocation
_tuplevariableInherited from IAllocation
_usernamevariableInherited from IAllocation
_permissionsvariableInherited from IAllocation
_lifetimevariableInherited from IAllocation
_bandwidthLimitvariableInherited from IAllocation
_bandwidthUsedvariableInherited from IAllocation
_createdAtvariableInherited from IAllocation
_updatedAtvariableInherited from IAllocation
_deletedvariableInherited from IAllocation

Inherited from ServerAllocation

KindNameDescription
friendServer
functionServerAllocation
function~ServerAllocation virtual
functionhandleRequest virtualDispatches incoming STUN requests to handleCreatePermission() or handleRefreshRequest(). Subclasses override to add transport-specific methods.
functionhandleRefreshRequest virtualProcesses a Refresh request; updates the lifetime or sets the delete flag if the requested lifetime is 0, then sends a success response.
functionhandleCreatePermission virtualProcesses a CreatePermission request; installs or refreshes permissions for each XOR-PEER-ADDRESS attribute, then sends a success response.
functiononTimerPeriodic maintenance callback called by Server::onTimer(). Removes expired permissions. Returns false to signal that this allocation should be destroyed.
functiontimeRemaining virtual const override
functionmaxTimeRemaining const
functionhasPermission virtual overrideChecks permission, auto-granting local IPs if enabled in server options.
functionhasPermission virtual overrideChecks whether a permission exists for peerAddress. The port is ignored; TURN permissions are IP-only.
functionserver virtual
functionprint virtual const overrideWrites a detailed diagnostic dump of this allocation to os.
functionrefreshDeleteRequested const inlineReturns true if the refresh request set lifetime to 0, signaling the parent Server to delete this allocation.
variable_maxLifetime
variable_server
variable_permissionPolicy
variable_refreshDeleteRequested
functionServerAllocationNonCopyable and NonMovable.
functionoperator=Deleted assignment operator.
functionServerAllocationDeleted constructor.
functionoperator=Deleted assignment operator.

Inherited from IAllocation

KindNameDescription
friendoperator<< inline
functionIAllocation
function~IAllocation virtual
functionIAllocationDeleted constructor.
functionoperator=Deleted assignment operator.
functionIAllocationDeleted constructor.
functionoperator=Deleted assignment operator.
functionupdateUsage virtualUpdates the last-activity timestamp and accumulates bandwidth usage. Call this whenever data is relayed through the allocation.
functionsetLifetime virtualSets the allocation lifetime in seconds and resets the activity timestamp, effectively extending the expiry from the current moment.
functionsetBandwidthLimit virtualSets the maximum number of bytes this allocation may relay in its lifetime. Pass 0 to disable bandwidth limiting.
functionexpired virtual const
functiondeleted virtual constReturns true if the allocation's deleted flag is set and or if the allocation has expired.
functionbandwidthLimit virtual const
functionbandwidthUsed virtual const
functionbandwidthRemaining virtual const
functiontimeRemaining virtual const
functiontuple virtual
functionusername virtual const
functionlifetime virtual const
functionpermissions virtual const
functionrelayedAddress virtual const
functionaddPermission virtualAdds a permission for ip, or refreshes the existing one.
functionaddPermission virtualAdds a permission for address, or refreshes the existing one. The port is ignored; TURN permissions are IP-only.
functionaddPermissions virtualAdds (or refreshes) permissions for multiple IPs.
functionremovePermission virtualRemoves the permission for ip if present.
functionremovePermission virtualRemoves the permission for address if present. The port is ignored; TURN permissions are IP-only.
functionremoveAllPermissions virtualRemoves all permissions from the list.
functionremoveExpiredPermissions virtualRemoves any permissions whose 5-minute lifetime has elapsed.
functionhasPermission virtualChecks whether a permission exists for peerIP. Local addresses (192.168.x.x and 127.x.x.x) are always permitted.
functionhasPermission virtualChecks whether a permission exists for peerAddress. The port is ignored; TURN permissions are IP-only.
functionprint virtual const inline
variable_tuple
variable_username
variable_permissions
variable_lifetime
variable_bandwidthLimit
variable_bandwidthUsed
variable_createdAt
variable_updatedAt
variable_deleted

Public Methods

ReturnNameDescription
TCPAllocation
boolhandleRequest virtualExtends the base handler with Connect and ConnectionBind methods.
voidhandleConnectRequestHandles a Connect request; creates a TCPConnectionPair and initiates a TCP connection to the peer address carried in XOR-PEER-ADDRESS.
voidhandleConnectionBindRequestHandles a ConnectionBind request; associates the incoming TCP data socket with the pending TCPConnectionPair and activates the relay pipe.
voidsendPeerConnectResponseSends a Connect success or failure response to the control connection.
ssize_tsendToControlSends a STUN message to the client over the control TCP connection.
net::TCPSocket &control
net::AddressrelayedAddress virtual const
TCPConnectionPairMap &pairs
boolonTimerPeriodic timer callback; removes expired or pending-delete connection pairs, then calls the base class timer.
voidonPeerAcceptAccepts incoming peer sockets on the relay acceptor socket. Checks permissions and sends a ConnectionAttempt indication to the control.
boolonControlClosedCalled when the control connection closes; marks the allocation for deletion.

TCPAllocation

TCPAllocation(Server & server, const net::Socket::Ptr & control, const FiveTuple & tuple, const std::string & username, const uint32_t & lifetime)

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

Parameters

  • server Owning TURN server.

  • control The accepted TCP socket used for STUN control messages.

  • tuple 5-tuple identifying this allocation.

  • username Authenticated username from the Allocate request.

  • lifetime Initial lifetime in seconds.


handleRequest

virtual

virtual bool handleRequest(Request & request)

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

Extends the base handler with Connect and ConnectionBind methods.

Parameters

  • request Incoming STUN request.

Returns

true if handled.

Reimplements

handleConnectRequest

void handleConnectRequest(Request & request)

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

Handles a Connect request; creates a TCPConnectionPair and initiates a TCP connection to the peer address carried in XOR-PEER-ADDRESS.

Parameters

  • request Incoming Connect request.

handleConnectionBindRequest

void handleConnectionBindRequest(Request & request)

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

Handles a ConnectionBind request; associates the incoming TCP data socket with the pending TCPConnectionPair and activates the relay pipe.

Parameters

  • request Incoming ConnectionBind request.

sendPeerConnectResponse

void sendPeerConnectResponse(TCPConnectionPair * pair, bool success)

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

Sends a Connect success or failure response to the control connection.

Parameters

  • pair The connection pair whose peer connection attempt completed.

  • success true if the peer TCP connection succeeded.


sendToControl

ssize_t sendToControl(stun::Message & message)

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

Sends a STUN message to the client over the control TCP connection.

Parameters

  • message Message to send.

Returns

Number of bytes sent, or a negative value on error.


control

net::TCPSocket & control()

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

Returns

Reference to the TCP control socket.


relayedAddress

virtual const

virtual net::Address relayedAddress() const

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

Returns

The listen address of the peer acceptor socket (used as the relayed address).

Reimplements

pairs

TCPConnectionPairMap & pairs()

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

Returns

Reference to the map of active TCPConnectionPairs keyed by connection ID.


onTimer

bool onTimer()

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

Periodic timer callback; removes expired or pending-delete connection pairs, then calls the base class timer.

Returns

false if the allocation should be destroyed.


onPeerAccept

void onPeerAccept(const net::TCPSocket::Ptr & sock)

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

Accepts incoming peer sockets on the relay acceptor socket. Checks permissions and sends a ConnectionAttempt indication to the control.

Parameters

  • sock Newly accepted peer socket.

onControlClosed

bool onControlClosed(net::Socket & socket)

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

Called when the control connection closes; marks the allocation for deletion.

Parameters

  • socket The closed control socket.

Returns

false (event propagation convention).

Protected Attributes

ReturnNameDescription
net::SocketEmitter_control
net::SocketEmitter_acceptor
TCPConnectionPairMap_pairs

_control

net::SocketEmitter _control

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


_acceptor

net::SocketEmitter _acceptor

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


_pairs

TCPConnectionPairMap _pairs

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