TURN module (rfc5766)

TCPAllocation

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

TCPAllocation

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

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.

Public Methods

ReturnNameDescription
TCPAllocation#### Parameters
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#### Returns
net::AddressrelayedAddress virtual const#### Returns
TCPConnectionPairMap &pairs#### Returns
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)

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)

Extends the base handler with Connect and ConnectionBind methods.

Parameters

  • request Incoming STUN request.

Returns

true if handled.


handleConnectRequest

void handleConnectRequest(Request & request)

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)

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)

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)

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()

Returns

Reference to the TCP control socket.


relayedAddress

virtual const

virtual net::Address relayedAddress() const

Returns

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


pairs

TCPConnectionPairMap & pairs()

Returns

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


onTimer

bool onTimer()

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)

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)

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

_acceptor

net::SocketEmitter _acceptor

_pairs

TCPConnectionPairMap _pairs