private bool PeerServer_Received(ServersManager<PeerConnection> s, BaseConnection с, ref ServerAsyncEventArgs e)
{
//lock (syncRoot)
{
try
{
Allocation allocation = allocations.Get(e.LocalEndPoint);
if (allocation != null)
{
if (allocation.Permissions.IsPermited(e.RemoteEndPoint))
{
allocation.TouchLifetime();
if (allocation.ActiveDestination.IsEqual(e.RemoteEndPoint))
{
if (e.LocalEndPoint.Protocol == ServerProtocol.Tcp)
{
TcpFramingHeader.GetBytes(e.Buffer, e.Offset, TcpFrameType.EndToEndData, e.BytesTransferred);
e.Count = e.OffsetOffset + e.BytesTransferred;
e.OffsetOffset = 0;
}
else
{
e.Count = e.BytesTransferred;
}
e.LocalEndPoint = allocation.Local;
e.RemoteEndPoint = allocation.Reflexive;
e.ConnectionId = ServerAsyncEventArgs.AnyConnectionId;
turnServer.SendAsync(e);
e = null;
}
else
{
TurnMessage message = new TurnMessage()
{
IsAttributePaddingDisabled = true,
MessageType = MessageType.DataIndication,
TransactionId = TransactionServer.GenerateTransactionId(),
MagicCookie = new MagicCookie(),
RemoteAddress = new RemoteAddress()
{
IpAddress = e.RemoteEndPoint.Address,
Port = (UInt16)e.RemoteEndPoint.Port,
},
Data = new Data()
{
ValueRef = e.Buffer,
ValueRefOffset = e.Offset,
ValueRefLength = e.BytesTransferred,
},
};
SendTurn(message, allocation.Local, allocation.Reflexive);
}
}
}
}
catch (Exception ex)
{
logger.WriteWarning(ex.ToString());
}
}
return true;
}