void SendToEncrypted(Span <byte> payload, uint userId, IPEndPoint endPoint, CachedEncryptionKey keyInfo) { var packet = _sendBufferPool.Get(); int packetLength = _packetEncryption.CreateEncryptedPacket(payload, packet, false, userId, keyInfo); _socket.SendTo(packet, 0, packetLength, SocketFlags.None, endPoint); _sendBufferPool.Add(packet); }
public void SendFloorIdle(ushort groupId, Span <IPEndPoint> endPoints, CachedEncryptionKey keyInfo) { var buffer = _sendBufferPool.Get(); // Packet Type buffer[0] = (byte)RopuPacketType.FloorIdle; // Group ID (ushort) buffer.WriteUshort(groupId, 1); BulkSendEncrypted(buffer.AsSpan(0, 3), groupId, endPoints, keyInfo); _sendBufferPool.Add(buffer); }
void BulkSendEncrypted(Span <byte> payload, ushort groupId, Span <IPEndPoint> endPoints, CachedEncryptionKey keyInfo) { var packet = _sendBufferPool.Get(); int packetLength = _packetEncryption.CreateEncryptedPacket(payload, packet, true, groupId, keyInfo); BulkSendAsync(packet, packetLength, endPoints, () => _sendBufferPool.Add(packet)); }
public void SendCallStartFailed(CallFailedReason reason, uint userId, IPEndPoint endPoint, CachedEncryptionKey keyInfo) { var buffer = _sendBufferPool.Get(); // Packet Type buffer[0] = (byte)RopuPacketType.CallStartFailed; // User ID (uint32) buffer.WriteUint(userId, 1); //* Reason (byte) 0 = insufficient resources, 255 = other reason buffer[5] = (byte)CallFailedReason.InsufficientResources; SendToEncrypted(buffer.AsSpan(0, 6), userId, endPoint, keyInfo); _sendBufferPool.Add(buffer); }
public void BulkSendAsync(byte[] buffer, int length, Span <IPEndPoint> endPoints, Action <object?> onComplete, object state, uint groupId, CachedEncryptionKey keyInfo) { var token = _bulkRequestTokenPool.Get(); token.Reset(); token.Finished = onComplete; token.State = state; for (int endpointIndex = 0; endpointIndex < endPoints.Length; endpointIndex++) { var args = _socketEventArgsPool.Get(); args.RemoteEndPoint = endPoints[endpointIndex]; SetBufferEncrypted(args, buffer, length, groupId, keyInfo); args.UserToken = token; if (!_socket.SendToAsync(args)) { //completed syncronously _socketEventArgsPool.Add(args); //release the memory back to the pool } else { token.IncrementWaitingCount(); } } lock (_asyncCompleteLock) { if (token.WaitingCount == 0) { token.Finish(); return; } } }
void SetBufferEncrypted(SocketAsyncEventArgs args, byte[] buffer, int length, uint groupId, CachedEncryptionKey keyInfo) { int packetLength = _packetEncryption.CreateEncryptedPacket(buffer.AsSpan(0, length), _encryptedBuffer, true, groupId, keyInfo); args.SetBuffer(_encryptedBuffer, 0, packetLength); }
public void SendGroupPacket(byte[] packet, int length, IPEndPoint target, uint groupId, CachedEncryptionKey keyInfo) { int packetLength = _packetEncryption.CreateEncryptedPacket(packet.AsSpan(0, length), _encryptedBuffer, true, groupId, keyInfo); _socket.SendTo(_encryptedBuffer, 0, packetLength, SocketFlags.None, target); }