コード例 #1
0
ファイル: Handshake.cs プロジェクト: XSWare/XSLibrary
        private bool ExecuteCryptoHandshake(IConnectionCrypto crypto, int timeout)
        {
            try
            {
                if (Receiving)
                {
                    Logger.Log(LogLevel.Error, "Crypto cannot be initiated after receive loop was started!");
                    return(false);
                }

                ExecutePreReceiveActions();

                if (!crypto.Handshake(
                        (data) => SafeSend(() => SendSpecialized(data), timeout),                              // send
                        (out byte[] data, out EndPoint source) => SafeReceive(out data, out source, timeout))) // receive
                {
                    return(false);
                }

                Crypto = crypto;
                Logger.Log(LogLevel.Information, "Crypto handshake successful.");
                return(true);
            }
            catch (Exception) { return(false); }
        }
コード例 #2
0
ファイル: IConnection.cs プロジェクト: XSWare/XSLibrary
        public IConnection(Socket connectionSocket)
        {
            Crypto = new NoCrypto();
            Logger = Logger.NoLog;

            m_preReceiveDone = false;

            InitializeSocket(connectionSocket);
        }
コード例 #3
0
ファイル: Handshake.cs プロジェクト: XSWare/XSLibrary
        public bool InitializeCrypto(IConnectionCrypto crypto, int timeout = 5000)
        {
            if (!m_handshakeLock.Execute(() => ExecuteCryptoHandshake(crypto, timeout)))
            {
                HandleHandshakeFailure();
                return(false);
            }

            return(true);
        }