All TURN operations revolve around allocations and all TURN messages are associated with an Allocation. An allocation consists of:
When a TURN client sends an Allocate request, this TURN message is processed by server and tries to create a new Relayed Transport Address. By default, if there is any available UDP port, it will create a new Relayed Address, but you can use OnTURNBeforeAllocate event to reject a new Allocation request.
void OnTURNBeforeAllocate(TObject Sender, const TsgcSocketConnection aSocket,
const string aIP, Word aPort, ref bool Reject)
{
if (your own rules) == false
{
Reject = false;
}
}
If the process continues, the server creates a new allocation and the event OnTURNCreateAllocation is called. This event provides information about the Allocation through the class TsgcTURNAllocationItem.
void OnTURNCreateAllocation(TObject Sender, const TsgcSocketConnection aSocket,
const TsgcTURNAllocationItem Allocation)
{
DoLog("New Allocation: " + Allocation.RelayIP + ":" + IntToStr(Allocation.RelayPort));
}
When the Allocation expires or is deleted receiving a Refresh Request from client with a lifetime of zero, the event OnTURNDeleteAllocation event is fired.
void OnTURNDeleteAllocation(TObject Sender, const TsgcSocketConnection aSocket,
const TsgcTURNAllocationItem Allocation)
{
DoLog("Allocation Deleted: " + Allocation.RelayIP + ":" + IntToStr(Allocation.RelayPort));
}