TURN module (rfc5766)

UDPAllocation

Server-side UDP TURN allocation that relays datagrams to permitted peers.

UDPAllocation

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

Inherits: ServerAllocation

Server-side UDP TURN allocation that relays datagrams to permitted peers. Binds a dedicated UDP relay socket for peer communication and forwards incoming datagrams to the client as Data Indications.

Public Methods

ReturnNameDescription
UDPAllocationBinds the relay UDP socket and registers the peer receive callback.
boolonPeerDataReceivedReceive callback for the relay UDP socket; validates permissions, updates bandwidth usage, and forwards data to the client as a Data Indication.
boolhandleRequest virtualExtends the base handler with Send Indication support.
voidhandleSendIndicationHandles a Send Indication from the client; validates permissions and relays the DATA attribute payload to the peer via the relay socket. Silently discards on permission or attribute errors.
ssize_tsendSends raw data to peerAddress via the relay UDP socket. Updates bandwidth usage and returns -1 if the allocation is expired.
net::AddressrelayedAddress virtual const#### Returns

UDPAllocation

UDPAllocation(Server & server, const FiveTuple & tuple, const std::string & username, const uint32_t & lifetime)

Binds the relay UDP socket and registers the peer receive callback.

Parameters

  • server Owning TURN server.

  • tuple 5-tuple identifying this allocation.

  • username Authenticated username from the Allocate request.

  • lifetime Initial lifetime in seconds.


onPeerDataReceived

bool onPeerDataReceived(net::Socket & socket, const MutableBuffer & buffer, const net::Address & peerAddress)

Receive callback for the relay UDP socket; validates permissions, updates bandwidth usage, and forwards data to the client as a Data Indication.

Parameters

  • socket The relay socket.

  • buffer Received datagram.

  • peerAddress Source address of the peer datagram.


handleRequest

virtual

virtual bool handleRequest(Request & request)

Extends the base handler with Send Indication support.

Parameters

  • request Incoming STUN request or indication.

Returns

true if handled.


handleSendIndication

void handleSendIndication(Request & request)

Handles a Send Indication from the client; validates permissions and relays the DATA attribute payload to the peer via the relay socket. Silently discards on permission or attribute errors.

Parameters

  • request Incoming Send Indication.

send

ssize_t send(const char * data, size_t size, const net::Address & peerAddress)

Sends raw data to peerAddress via the relay UDP socket. Updates bandwidth usage and returns -1 if the allocation is expired.

Parameters

  • data Payload bytes to relay.

  • size Number of bytes.

  • peerAddress Destination peer address.

Returns

Number of bytes sent, or -1 if the quota is exhausted.


relayedAddress

virtual const

virtual net::Address relayedAddress() const

Returns

The bound address of the relay UDP socket.

Private Attributes

ReturnNameDescription
net::SocketEmitter_relaySocket

_relaySocket

net::SocketEmitter _relaySocket