コード例 #1
0
ファイル: Packets.cs プロジェクト: swax/CodePerspective
 public static CryptPadding Decode(G2ReceivedPacket packet)
 {
     CryptPadding padding = new CryptPadding();
     return padding;
 }
コード例 #2
0
ファイル: XConnection.cs プロジェクト: swax/CodePerspective
        public void TrySend()
        {
            // cant send if we're in the process of sending
            if (FinalSendBuffSize > 0 || State != TcpState.Connected || OnlyFillerInSendBuffer)
                return;

            if (Encryptor == null)
                CreateEncryptor();

            // try to move from send buff to final buff
            lock (FinalSendBuffer)
            {
                int remainder = SendBuffSize % Encryptor.InputBlockSize;
                if (remainder > 0)
                {
                    CryptPadding padding = new CryptPadding();

                    int fillerNeeded = Encryptor.InputBlockSize - remainder;

                    if (fillerNeeded > 2)
                        padding.Filler = new byte[fillerNeeded - 2];

                    var filler = padding.Encode(Protocol);
                    filler.CopyTo(SendBuffer, SendBuffSize);
                    SendBuffSize += filler.Length;
                    OnlyFillerInSendBuffer = true;
                }

                int tryTransform = SendBuffSize - (SendBuffSize % Encryptor.InputBlockSize);
                if (tryTransform > 0)
                {
                    int tranformed = Encryptor.TransformBlock(SendBuffer, 0, tryTransform, FinalSendBuffer, FinalSendBuffSize);
                    if (tranformed > 0)
                    {
                        FinalSendBuffSize += tranformed;
                        SendBuffSize -= tranformed;
                        Buffer.BlockCopy(SendBuffer, tranformed, SendBuffer, 0, SendBuffSize);
                    }
                }
            }

            if (FinalSendBuffSize == 0)
                return;

            try
            {
                lock (FinalSendBuffer)
                {
                    //Core.UpdateConsole("Begin Send " + SendBufferSize.ToString());

                    //TcpSocket.Blocking = false
                    //Log("x", "Sending " + FinalSendBuffSize.ToString() + " bytes");
                    TcpSocket.BeginSend(FinalSendBuffer, 0, FinalSendBuffSize, SocketFlags.None, new AsyncCallback(Socket_Send), TcpSocket);
                    //bytesSent = TcpSocket.Send(FinalSendBuffer, FinalSendBuffSize, SocketFlags.None);
                }
            }

            catch (Exception ex)
            {
                Log("TrySend", ex.Message);
                Disconnect();
            }
        }
コード例 #3
0
        public static CryptPadding Decode(G2ReceivedPacket packet)
        {
            CryptPadding padding = new CryptPadding();

            return(padding);
        }
コード例 #4
0
        public void TrySend()
        {
            // cant send if we're in the process of sending
            if (FinalSendBuffSize > 0 || State != TcpState.Connected || OnlyFillerInSendBuffer)
            {
                return;
            }

            if (Encryptor == null)
            {
                CreateEncryptor();
            }

            // try to move from send buff to final buff
            lock (FinalSendBuffer)
            {
                int remainder = SendBuffSize % Encryptor.InputBlockSize;
                if (remainder > 0)
                {
                    CryptPadding padding = new CryptPadding();

                    int fillerNeeded = Encryptor.InputBlockSize - remainder;

                    if (fillerNeeded > 2)
                    {
                        padding.Filler = new byte[fillerNeeded - 2];
                    }

                    var filler = padding.Encode(Protocol);
                    filler.CopyTo(SendBuffer, SendBuffSize);
                    SendBuffSize          += filler.Length;
                    OnlyFillerInSendBuffer = true;
                }

                int tryTransform = SendBuffSize - (SendBuffSize % Encryptor.InputBlockSize);
                if (tryTransform > 0)
                {
                    int tranformed = Encryptor.TransformBlock(SendBuffer, 0, tryTransform, FinalSendBuffer, FinalSendBuffSize);
                    if (tranformed > 0)
                    {
                        FinalSendBuffSize += tranformed;
                        SendBuffSize      -= tranformed;
                        Buffer.BlockCopy(SendBuffer, tranformed, SendBuffer, 0, SendBuffSize);
                    }
                }
            }

            if (FinalSendBuffSize == 0)
            {
                return;
            }

            try
            {
                lock (FinalSendBuffer)
                {
                    //Core.UpdateConsole("Begin Send " + SendBufferSize.ToString());

                    //TcpSocket.Blocking = false
                    //Log("x", "Sending " + FinalSendBuffSize.ToString() + " bytes");
                    TcpSocket.BeginSend(FinalSendBuffer, 0, FinalSendBuffSize, SocketFlags.None, new AsyncCallback(Socket_Send), TcpSocket);
                    //bytesSent = TcpSocket.Send(FinalSendBuffer, FinalSendBuffSize, SocketFlags.None);
                }
            }

            catch (Exception ex)
            {
                Log("TrySend", ex.Message);
                Disconnect();
            }
        }