コード例 #1
0
 public int Receive(byte[] recv_buffer, int size, SocketFlags flags, out int bytesRead, out int protocolSize, out bool sendback)
 {
     bytesRead    = _socket.Receive(recv_buffer, size, flags);
     protocolSize = 0;
     if (bytesRead > 0)
     {
         lock (_decryptionLock)
         {
             int    bytesToSend = 0;
             int    obfsRecvSize;
             byte[] remoteRecvObfsBuffer = _obfs.ClientDecode(recv_buffer, bytesRead, out obfsRecvSize, out sendback);
             if (obfsRecvSize > 0)
             {
                 Util.Utils.SetArrayMinSize(ref ReceiveDecryptBuffer, obfsRecvSize);
                 _encryptor.Decrypt(remoteRecvObfsBuffer, obfsRecvSize, ReceiveDecryptBuffer, out bytesToSend);
                 int outlength;
                 protocolSize = bytesToSend;
                 byte[] buffer = _protocol.ClientPostDecrypt(ReceiveDecryptBuffer, bytesToSend, out outlength);
                 TcpMSS = _protocol.GetTcpMSS();
                 //if (recv_buffer.Length < outlength) //ASSERT
                 Array.Copy(buffer, 0, recv_buffer, 0, outlength);
                 return(outlength);
             }
         }
         return(0);
     }
     else
     {
         sendback = false;
         _close   = true;
     }
     return(bytesRead);
 }
コード例 #2
0
        public int EndReceive(IAsyncResult ar, out bool sendback)
        {
            int bytesRead = _socket.EndReceive(ar);

            sendback = false;
            if (bytesRead > 0)
            {
                CallbackState st = (CallbackState)ar.AsyncState;
                st.size = bytesRead;

                lock (_decryptionLock)
                {
                    int    bytesToSend = 0;
                    int    obfsRecvSize;
                    byte[] remoteRecvObfsBuffer = _obfs.ClientDecode(st.buffer, bytesRead, out obfsRecvSize, out sendback);
                    if (obfsRecvSize > 0)
                    {
                        _encryptor.Decrypt(remoteRecvObfsBuffer, obfsRecvSize, ReceiveDecryptBuffer, out bytesToSend);
                        int    outlength;
                        byte[] buffer = _protocol.ClientPostDecrypt(ReceiveDecryptBuffer, bytesToSend, out outlength);
                        Array.Copy(buffer, 0, st.buffer, 0, outlength);
                        return(outlength);
                    }
                }
                return(0);
            }
            else
            {
                _close = true;
            }
            return(bytesRead);
        }
コード例 #3
0
 public override byte[] ClientDecode(byte[] encryptdata, int datalength, out int outlength, out bool needsendback)
 {
     if (subObfs != null)
     {
         return(subObfs.ClientDecode(encryptdata, datalength, out outlength, out needsendback));
     }
     outlength    = datalength;
     needsendback = false;
     return(encryptdata);
 }