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); } }
public IConnection(Socket connectionSocket) { Crypto = new NoCrypto(); Logger = Logger.NoLog; m_preReceiveDone = false; InitializeSocket(connectionSocket); }
public bool InitializeCrypto(IConnectionCrypto crypto, int timeout = 5000) { if (!m_handshakeLock.Execute(() => ExecuteCryptoHandshake(crypto, timeout))) { HandleHandshakeFailure(); return(false); } return(true); }