コード例 #1
0
        /// <summary>
        /// Creates a new crypto decorator for the <see cref="NetworkClientBase"/>.
        /// Extends the <see cref="ReadAsync"/> and <see cref="WriteAsync"/> implementations to pass
        /// all bytes through the corresponding incoming and outgoing ciphers.
        /// </summary>
        /// <param name="decoratedClient">The client to decorate.</param>
        /// <param name="encryptionServiceProvider">The encryption service.</param>
        /// <param name="decryptionServiceProvider">The decryption service.</param>
        public NetworkClientFixedBlockSizeCryptoDecorator(NetworkClientBase decoratedClient, ICryptoServiceProvider encryptionServiceProvider, ICryptoServiceProvider decryptionServiceProvider, int blockSize, int cryptoBufferSize = 30000)
        {
            if (decoratedClient == null)
            {
                throw new ArgumentNullException(nameof(decoratedClient));
            }
            if (encryptionServiceProvider == null)
            {
                throw new ArgumentNullException(nameof(encryptionServiceProvider));
            }
            if (decryptionServiceProvider == null)
            {
                throw new ArgumentNullException(nameof(decryptionServiceProvider));
            }
            if (blockSize <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(blockSize));
            }

            DecoratedClient           = decoratedClient;
            EncryptionServiceProvider = encryptionServiceProvider;
            DecryptionServiceProvider = decryptionServiceProvider;
            BlockSize = blockSize;

            //One of the lobby packets is 14,000 bytes. We may even need bigger.
            ReadBuffer  = new AsyncLockableBuffer(cryptoBufferSize);
            WriteBuffer = new AsyncLockableBuffer(cryptoBufferSize);

            CryptoBlockOverflow          = new byte[Math.Max(blockSize - 1, 0)];   //we only need
            CryptoBlockOverflowReadIndex = CryptoBlockOverflow.Length;             //set this to last index to indicate empty initially
        }
コード例 #2
0
        public NetworkClientBufferWriteUntilSizeReachedDecorator(NetworkClientBase decoratedClient, int bufferedWaitSize, int bufferedCombinedSize = 30000)
        {
            if (decoratedClient == null)
            {
                throw new ArgumentNullException(nameof(decoratedClient));
            }
            if (bufferedWaitSize <= 1)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferedWaitSize), "Do not use this decorator if you don't need buffered data.");
            }

            DecoratedClient = decoratedClient;
            BufferedData    = new AsyncLockableBuffer(bufferedWaitSize);
            CombinedBuffer  = new AsyncLockableBuffer(bufferedCombinedSize);
        }
コード例 #3
0
        /// <summary>
        /// Creates a new crypto decorator for the <see cref="NetworkClientBase"/>.
        /// Extends the <see cref="ReadAsync"/> and <see cref="WriteAsync"/> implementations to pass
        /// all bytes through the corresponding incoming and outgoing ciphers.
        /// </summary>
        /// <param name="decoratedClient">The client to decorate.</param>
        /// <param name="encryptionServiceProvider">The encryption service.</param>
        /// <param name="decryptionServiceProvider">The decryption service.</param>
        public NetworkClientBlocklessCryptoDecorator(NetworkClientBase decoratedClient, ICryptoServiceProvider encryptionServiceProvider, ICryptoServiceProvider decryptionServiceProvider)
        {
            if (decoratedClient == null)
            {
                throw new ArgumentNullException(nameof(decoratedClient));
            }
            if (encryptionServiceProvider == null)
            {
                throw new ArgumentNullException(nameof(encryptionServiceProvider));
            }
            if (decryptionServiceProvider == null)
            {
                throw new ArgumentNullException(nameof(decryptionServiceProvider));
            }

            DecoratedClient           = decoratedClient;
            EncryptionServiceProvider = encryptionServiceProvider;
            DecryptionServiceProvider = decryptionServiceProvider;
        }
コード例 #4
0
        /// <summary>
        /// </summary>
        /// <param name="decoratedClient">The client to decorate.</param>
        /// <param name="serializer"></param>
        /// <param name="headerSize"></param>
        public NetworkClientPacketHeaderReaderWriterDecorator(NetworkClientBase decoratedClient, INetworkSerializationService serializer, int headerSize)
        {
            if (decoratedClient == null)
            {
                throw new ArgumentNullException(nameof(decoratedClient));
            }
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }
            if (headerSize < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(headerSize));
            }

            //We need to support up to the maximum block
            PacketHeaderBuffer = new byte[headerSize];
            DecoratedClient    = decoratedClient;
            Serializer         = serializer;
        }
コード例 #5
0
 /// <summary>
 /// Implementer should build the <see cref="IManagedNetworkClient{TPayloadWriteType,TPayloadReadType}"/>
 /// for the outgoing client.
 /// </summary>
 /// <param name="clientBase">The client base to use.</param>
 /// <param name="serializeService">The serializer to use.</param>
 /// <returns>The built managed client.</returns>
 protected abstract IManagedNetworkClient <TPayloadReadType, TPayloadWriteType> BuildOutgoingSessionManagedClient(NetworkClientBase clientBase, INetworkSerializationService serializeService);
コード例 #6
0
        /// <summary>
        /// Enables header reading functionality to a client.
        /// </summary>
        /// <param name="client">The client to add header reading to.</param>
        /// <returns>A client that can read headers from the network.</returns>
        public static NetworkClientPacketHeaderReaderWriterDecorator <TPacketHeaderType> AddHeaderReading <TPacketHeaderType>(this NetworkClientBase client, INetworkSerializationService serializer, int headerSize)
            where TPacketHeaderType : IPacketHeader
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (serializer == null)
            {
                throw new ArgumentNullException(nameof(serializer));
            }

            return(new NetworkClientPacketHeaderReaderWriterDecorator <TPacketHeaderType>(client, serializer, headerSize));
        }
コード例 #7
0
        /// <summary>
        /// Enables bufferred writing functionality. This means that the actual writing won't begin until the
        /// provided buffer threshold <see cref="bufferedCount"/> is reached.
        /// </summary>
        /// <param name="client">The client to decorate.</param>
        /// <param name="bufferedCount">The amount to wait for before writing.</param>
        /// <returns>The client decorated with buffered write functionality</returns>
        public static NetworkClientBufferWriteUntilSizeReachedDecorator AddBufferredWrite(this NetworkClientBase client, int bufferedCount)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }
            if (bufferedCount <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(bufferedCount));
            }

            return(new NetworkClientBufferWriteUntilSizeReachedDecorator(client, bufferedCount));
        }