TsgcTURNServer › Eventi › OnTURNBeforeAllocate
Sollevato prima che venga creata una nuova Allocation; esamini l'IP/porta inoltrati e imposti Reject per rifiutare la richiesta ALLOCATE.
property OnTURNBeforeAllocate: TsgcTURNBeforeAllocateEvent;
// TsgcTURNBeforeAllocateEvent = procedure(Sender: TObject; const aSocket: TsgcSocketConnection; const aIP: String; aPort: Word; var Reject: Boolean) of object
—
Generato durante l'elaborazione di una richiesta ALLOCATE, dopo che il socket relay è stato riservato ma prima che l'oggetto Allocation venga aggiunto alla tabella interna. aIP/aPort portano l'indirizzo di trasporto relay che il server sta per pubblicizzare in XOR-RELAYED-ADDRESS — l'IP è preso da TURNOptions.Allocation.RelayIP (o Host se vuoto) e la porta dall'intervallo Allocation.MinPort–MaxPort. Utilizzare l'evento per applicare quote a livello applicativo, bloccare client o porte peer specifiche, o controllare le richieste di allocazione. Impostare Reject := True per rifiutare l'ALLOCATE; il server rilascia la porta relay e risponde con una risposta di errore (486 Allocation Quota Reached). Lasciare Reject come False per consentire la creazione dell'Allocation — il successivo evento OnTURNCreateAllocation conferma il successo. Viene eseguito sul thread del listener a meno che NotifyEvents non lo reindirizzi.
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;