TURN Server | Allocations

모든 TURN 작업은 할당을 중심으로 이루어지며 모든 TURN 메시지는 Allocation과 연결됩니다. 할당은 다음으로 구성됩니다:

 

 

TURN 클라이언트가 Allocate 요청을 보내면, 이 TURN 메시지는 서버에 의해 처리되어 새 Relayed Transport Address를 생성하려고 시도합니다. 기본적으로 사용 가능한 UDP 포트가 있으면 새 Relayed Address를 생성하지만, OnTURNBeforeAllocate 이벤트를 사용하여 새 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;

프로세스가 계속되면 서버는 새 allocation을 생성하고 OnTURNCreateAllocation 이벤트가 호출됩니다. 이 이벤트는 TsgcTURNAllocationItem 클래스를 통해 Allocation에 대한 정보를 제공합니다.

 


procedure OnTURNCreateAllocation(Sender: TObject; const aSocket: TsgcSocketConnection; 
  const Allocation: TsgcTURNAllocationItem);
begin
  DoLog('New Allocation: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;

 

Allocation이 만료되거나 lifetime이 0인 Refresh Request를 클라이언트로부터 수신하여 삭제될 때 OnTURNDeleteAllocation 이벤트가 발생합니다.

 


procedure OnTURNDeleteAllocation(Sender: TObject; const aSocket: TsgcSocketConnection; 
  const Allocation: TsgcTURNAllocationItem);
begin
  DoLog('Allocation Deleted: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;