Todas as operações TURN giram em torno de alocações e todas as mensagens TURN estão associadas a uma Allocation. Uma alocação consiste em:
Quando um cliente TURN envia uma requisição Allocate, esta mensagem TURN é processada pelo servidor, que tenta criar um novo Relayed Transport Address. Por padrão, se houver alguma porta UDP disponível, ele criará um novo Relayed Address, mas você pode utilizar o evento OnTURNBeforeAllocate para rejeitar uma nova requisição de Allocation.
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 o processo continuar, o servidor cria uma nova allocation e o evento OnTURNCreateAllocation é chamado. Este evento fornece informações sobre a Allocation através da classe TsgcTURNAllocationItem.
procedure OnTURNCreateAllocation(Sender: TObject; const aSocket: TsgcSocketConnection;
const Allocation: TsgcTURNAllocationItem);
begin
DoLog('New Allocation: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;
Quando a Allocation expira ou é excluída ao receber uma Refresh Request do cliente com um lifetime de zero, o evento OnTURNDeleteAllocation é disparado.
procedure OnTURNDeleteAllocation(Sender: TObject; const aSocket: TsgcSocketConnection;
const Allocation: TsgcTURNAllocationItem);
begin
DoLog('Allocation Deleted: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;