TsgcTURNServer › Events › OnSTUNRequestError
在服务器发送 STUN/TURN 错误响应之前触发;允许处理程序检查或抑制回复。
property OnSTUNRequestError: TsgcSTUNRequestErrorEvent;
// TsgcSTUNRequestErrorEvent = procedure(Sender: TObject; const aSocket: TsgcSocketConnection; const aRequest: TsgcSTUN_Message; const aResponse: TsgcSTUN_Message; var Accept: Boolean) of object
—
当服务器构建了错误响应(例如 400 Bad Request、401 Unauthorized、403 Forbidden、437 Allocation Mismatch、438 Stale Nonce、441 Wrong Credentials、442 Unsupported Transport Protocol、486 Allocation Quota Reached、508 Insufficient Capacity)并即将发回给客户端时触发。检查 aRequest / aResponse(尤其是 aResponse 的 ERROR-CODE 属性)可记录失败原因。将 Accept := False 设置为丢弃数据报且不向客户端回复,这在来自同一来源的重复无效请求需要避免放大攻击时很有用。处理程序在监听线程上运行,除非 NotifyEvents 选择了其他模式。
procedure TForm1.OnSTUNRequestError(Sender: TObject;
const aSocket: TsgcSocketConnection; const aRequest: TsgcSTUN_Message;
const aResponse: TsgcSTUN_Message; var Accept: Boolean);
begin
Memo1.Lines.Add('TURN error for ' + aSocket.PeerIP);
Accept := True;
end;