TCPClient
TCPClient
#include <icy/turn/client/tcpclient.h>Inherits:
Client
TCP 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.
Public Methods
| Return | Name | Description |
|---|---|---|
TCPClient | #### Parameters | |
void | start virtual | Connects the socket to the TURN server and starts the allocation sequence. Permissions must be added via addPermission() before calling this. |
void | stop virtual | Stops the control connection, cancels all relay connections, and calls the base class stop(). |
void | sendConnectRequest virtual | Sends a Connect request to the server asking it to open a TCP connection to peerAddress on the client's behalf (RFC 6062 section 4.3). |
void | sendData virtual | Sends raw data to peerAddress over the established relay connection. The peer must have an active permission and a bound relay connection. |
bool | handleResponse virtual | Extends the base handler with Connect, ConnectionBind, and ConnectionAttempt responses. |
void | handleConnectResponse virtual | Processes a successful Connect response; extracts the connection ID and calls createAndBindConnection(). |
void | handleConnectErrorResponse virtual | Processes a Connect error response; notifies the observer that binding failed. |
void | handleConnectionBindResponse virtual | Processes a successful ConnectionBind response; arms the relay socket for data transfer and notifies the observer. |
void | handleConnectionBindErrorResponse virtual | Processes a ConnectionBind error response; frees the failed connection. |
void | handleConnectionAttemptIndication virtual | Processes a ConnectionAttempt indication from the server; optionally accepts the incoming peer connection by calling createAndBindConnection(). |
bool | createAndBindConnection virtual | Opens a new TCP relay socket to the TURN server and sends a ConnectionBind request carrying connectionID. |
bool | onRelayConnectionConnect virtual | Relay socket connect callback; sends the ConnectionBind request. |
bool | onRelayDataReceived virtual | Relay socket receive callback; forwards data to the observer. |
bool | onRelayConnectionError virtual | Relay socket error callback; notifies the observer of the error. |
bool | onRelayConnectionClosed virtual | Relay socket close callback; notifies the observer and frees the connection. |
void | freeConnection | Removes the relay connection for peerAddress, unregisters its callbacks, and deletes the associated RelayConnectionBinding. |
int | transportProtocol virtual | #### Returns |
ConnectionManager & | connections | #### Returns |
const char * | className virtual const inline |
TCPClient
TCPClient(TCPClientObserver & observer, const Client::Options & options)Parameters
observerObserver for TCP-specific relay events.optionsClient configuration; defaults to loopback server, 5-min lifetime.
start
virtual
virtual void start()Connects the socket to the TURN server and starts the allocation sequence. Permissions must be added via addPermission() before calling this.
stop
virtual
virtual void stop()Stops the control connection, cancels all relay connections, and calls the base class stop().
sendConnectRequest
virtual
virtual void sendConnectRequest(const net::Address & peerAddress)Sends a Connect request to the server asking it to open a TCP connection to peerAddress on the client's behalf (RFC 6062 section 4.3).
Parameters
peerAddressTarget peer address.
sendData
virtual
virtual void sendData(const char * data, size_t size, const net::Address & peerAddress)Sends raw data to peerAddress over the established relay connection. The peer must have an active permission and a bound relay connection.
Parameters
dataPayload bytes.sizeNumber of bytes to send.peerAddressDestination peer (must have an entry in connections()).
handleResponse
virtual
virtual bool handleResponse(const stun::Message & response)Extends the base handler with Connect, ConnectionBind, and ConnectionAttempt responses.
Parameters
responseIncoming STUN response.
Returns
true if the message was handled.
handleConnectResponse
virtual
virtual void handleConnectResponse(const stun::Message & response)Processes a successful Connect response; extracts the connection ID and calls createAndBindConnection().
Parameters
responseConnect success response.
handleConnectErrorResponse
virtual
virtual void handleConnectErrorResponse(const stun::Message & response)Processes a Connect error response; notifies the observer that binding failed.
Parameters
responseConnect error response.
handleConnectionBindResponse
virtual
virtual void handleConnectionBindResponse(const stun::Message & response)Processes a successful ConnectionBind response; arms the relay socket for data transfer and notifies the observer.
Parameters
responseConnectionBind success response.
handleConnectionBindErrorResponse
virtual
virtual void handleConnectionBindErrorResponse(const stun::Message & response)Processes a ConnectionBind error response; frees the failed connection.
Parameters
responseConnectionBind error response.
handleConnectionAttemptIndication
virtual
virtual void handleConnectionAttemptIndication(const stun::Message & response)Processes a ConnectionAttempt indication from the server; optionally accepts the incoming peer connection by calling createAndBindConnection().
Parameters
responseConnectionAttempt indication message.
createAndBindConnection
virtual
virtual bool createAndBindConnection(uint32_t connectionID, const net::Address & peerAddress)Opens a new TCP relay socket to the TURN server and sends a ConnectionBind request carrying connectionID.
Parameters
connectionIDTURN CONNECTION-ID from the server.peerAddressPeer associated with this connection.
Returns
true on success.
onRelayConnectionConnect
virtual
virtual bool onRelayConnectionConnect(net::Socket & socket)Relay socket connect callback; sends the ConnectionBind request.
Parameters
socketThe relay socket that just connected.
onRelayDataReceived
virtual
virtual bool onRelayDataReceived(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)Relay socket receive callback; forwards data to the observer.
Parameters
socketThe receiving relay socket.bufferReceived data.peerAddressSource address (populated by the socket layer).
onRelayConnectionError
virtual
virtual bool onRelayConnectionError(net::Socket & socket, const Error & error)Relay socket error callback; notifies the observer of the error.
Parameters
socketThe affected relay socket.errorError descriptor.
onRelayConnectionClosed
virtual
virtual bool onRelayConnectionClosed(net::Socket & socket)Relay socket close callback; notifies the observer and frees the connection.
Parameters
socketThe closed relay socket.
freeConnection
void freeConnection(const net::Address & peerAddress)Removes the relay connection for peerAddress, unregisters its callbacks, and deletes the associated RelayConnectionBinding.
Parameters
peerAddressPeer whose connection to release.
transportProtocol
virtual
virtual int transportProtocol()Returns
kProtocolTCP (6).
connections
ConnectionManager & connections()Returns
Reference to the map of active relay connections keyed by peer address.
className
virtual const inline
virtual inline const char * className() constProtected Attributes
| Return | Name | Description |
|---|---|---|
TCPClientObserver & | _observer | |
ConnectionManager | _connections |
_observer
TCPClientObserver & _observer_connections
ConnectionManager _connections