TCPAllocation
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
| Return | Name | Description |
|---|---|---|
TCPAllocation | #### Parameters | |
bool | handleRequest virtual | Extends the base handler with Connect and ConnectionBind methods. |
void | handleConnectRequest | Handles a Connect request; creates a TCPConnectionPair and initiates a TCP connection to the peer address carried in XOR-PEER-ADDRESS. |
void | handleConnectionBindRequest | Handles a ConnectionBind request; associates the incoming TCP data socket with the pending TCPConnectionPair and activates the relay pipe. |
void | sendPeerConnectResponse | Sends a Connect success or failure response to the control connection. |
ssize_t | sendToControl | Sends a STUN message to the client over the control TCP connection. |
net::TCPSocket & | control | #### Returns |
net::Address | relayedAddress virtual const | #### Returns |
TCPConnectionPairMap & | pairs | #### Returns |
bool | onTimer | Periodic timer callback; removes expired or pending-delete connection pairs, then calls the base class timer. |
void | onPeerAccept | Accepts incoming peer sockets on the relay acceptor socket. Checks permissions and sends a ConnectionAttempt indication to the control. |
bool | onControlClosed | Called 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
serverOwning TURN server.controlThe accepted TCP socket used for STUN control messages.tuple5-tuple identifying this allocation.usernameAuthenticated username from the Allocate request.lifetimeInitial lifetime in seconds.
handleRequest
virtual
virtual bool handleRequest(Request & request)Extends the base handler with Connect and ConnectionBind methods.
Parameters
requestIncoming 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
requestIncoming 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
requestIncoming ConnectionBind request.
sendPeerConnectResponse
void sendPeerConnectResponse(TCPConnectionPair * pair, bool success)Sends a Connect success or failure response to the control connection.
Parameters
pairThe connection pair whose peer connection attempt completed.successtrue 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
messageMessage 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() constReturns
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
sockNewly accepted peer socket.
onControlClosed
bool onControlClosed(net::Socket & socket)Called when the control connection closes; marks the allocation for deletion.
Parameters
socketThe closed control socket.
Returns
false (event propagation convention).
Protected Attributes
| Return | Name | Description |
|---|---|---|
net::SocketEmitter | _control | |
net::SocketEmitter | _acceptor | |
TCPConnectionPairMap | _pairs |
_control
net::SocketEmitter _control_acceptor
net::SocketEmitter _acceptor_pairs
TCPConnectionPairMap _pairs