TURN サーバー | アロケーション

すべてのTURN操作はアロケーションを中心に展開され、すべてのTURNメッセージはアロケーションに関連付けられています。アロケーションは以下で構成されます。

 

 

TURN クライアントが Allocate リクエストを送信すると、この TURN メッセージはサーバーで処理され、新しいリレードトランスポートアドレスの作成が試みられます。デフォルトでは、利用可能な UDP ポートがあれば新しいリレードアドレスが作成されますが、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;

 

アロケーションの有効期限が切れるか、またはクライアントから lifetime に 0 を指定したリフレッシュリクエストを受信して削除された場合、OnTURNDeleteAllocation イベントが発火します。

 


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