private void TurnServer_TurnDataReceived(ref ServerAsyncEventArgs e)
{
//lock (syncRoot)
{
TurnMessage response = null;
try
{
if (true)//(TransactionServer.GetCachedResponse(e, out response) == false)
{
TurnMessage request = TurnMessage.Parse(e.Buffer, e.Offset, e.BytesTransferred, TurnMessageRfc.MsTurn);
if (Authentificater.Process(request, out response))
{
Allocation allocation = null;
if (request.MsSequenceNumber != null)
allocation = allocations.Get(request.MsSequenceNumber.ConnectionId);
if (allocation != null)
{
if (request.MsSequenceNumber != null)
response = allocation.GetResponse(request.MsSequenceNumber.SequenceNumber);
}
if (response == null)
{
if (allocation != null)
allocation.TouchLifetime();
switch (request.MessageType)
{
case MessageType.AllocateRequest:
response = ProcessAllocateRequest(ref allocation, request, e.LocalEndPoint, e.RemoteEndPoint);
break;
case MessageType.SendRequest:
response = ProcessSendRequest(allocation, request, ref e);
break;
case MessageType.SetActiveDestinationRequest:
response = ProcessSetActiveDestinationRequest(allocation, request, e.RemoteEndPoint);
break;
}
if (allocation != null && response != null)
allocation.SetResponse(response);
}
}
//TransactionServer.CacheResponse(e, response);
}
}
catch (TurnMessageException ex)
{
response = GetErrorResponse(ex.ErrorCode, e);
}
catch (TurnServerException ex)
{
response = GetErrorResponse(ex.ErrorCode, e);
}
catch (Exception ex)
{
response = GetErrorResponse(ErrorCode.ServerError, e);
logger.WriteError(ex.ToString());
}
if (response != null)
SendTurn(response, e.LocalEndPoint, e.RemoteEndPoint);
}
}