TsgcTURNServerEvents › OnTURNBeforeAllocate

OnTURNBeforeAllocate Event

Raised before a new Allocation is created; inspect the relayed IP/port and set Reject to refuse the ALLOCATE request.

Syntax

property OnTURNBeforeAllocate: TsgcTURNBeforeAllocateEvent;
// TsgcTURNBeforeAllocateEvent = procedure(Sender: TObject; const aSocket: TsgcSocketConnection; const aIP: String; aPort: Word; var Reject: Boolean) of object

Default Value

Remarks

Fired while processing an ALLOCATE request, after the relay socket has been reserved but before the Allocation object is added to the internal table. aIP/aPort carry the relayed transport address that the server is about to advertise in XOR-RELAYED-ADDRESS — the IP is taken from TURNOptions.Allocation.RelayIP (or Host when empty) and the port from the Allocation.MinPort–MaxPort range. Use the event to enforce application-level quotas, block specific clients or peer ports, or audit allocation requests. Set Reject := True to refuse the ALLOCATE; the server releases the relay port and answers with an error response (486 Allocation Quota Reached). Leave Reject as False to let the Allocation be created — the subsequent OnTURNCreateAllocation event confirms the success. Runs on the listener thread unless NotifyEvents redirects it.

Example

procedure TForm1.OnTURNBeforeAllocate(Sender: TObject;
  const aSocket: TsgcSocketConnection; const aIP: String; aPort: Word;
  var Reject: Boolean);
begin
  Memo1.Lines.Add(Format('Allocate %s:%d for %s', [aIP, aPort, aSocket.PeerIP]));
  Reject := BlackList.Contains(aSocket.PeerIP);
end;

Back to Events