Tutte le operazioni TURN ruotano attorno alle allocazioni e tutti i messaggi TURN sono associati a un'Allocazione. Un'allocazione è composta da:
Quando un client TURN invia una richiesta Allocate, questo messaggio TURN viene elaborato dal server che tenta di creare un nuovo Relayed Transport Address. Per impostazione predefinita, se è disponibile una porta UDP, verrà creato un nuovo Relayed Address, ma è possibile utilizzare l'evento OnTURNBeforeAllocate per rifiutare una nuova richiesta di allocazione.
procedure OnTURNBeforeAllocate(Sender: TObject; const aSocket: TsgcSocketConnection;
const aIP: string; aPort: Word; var Reject: Boolean);
begin
if not (your own rules) then
Reject := false;
end;
Se il processo prosegue, il server crea una nuova allocazione e viene chiamato l'evento OnTURNCreateAllocation. Questo evento fornisce informazioni sull'Allocation tramite la classe TsgcTURNAllocationItem.
procedure OnTURNCreateAllocation(Sender: TObject; const aSocket: TsgcSocketConnection;
const Allocation: TsgcTURNAllocationItem);
begin
DoLog('New Allocation: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;
Quando l'Allocation scade o viene eliminata ricevendo una Refresh Request dal client con lifetime pari a zero, viene attivato l'evento OnTURNDeleteAllocation.
procedure OnTURNDeleteAllocation(Sender: TObject; const aSocket: TsgcSocketConnection;
const Allocation: TsgcTURNAllocationItem);
begin
DoLog('Allocation Deleted: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;