public void Run(TcpClient client) { try { logger.Log(this, String.Format("Godot has been activated. Client IP address is {0}", LUtils.GetIpAddress(client))); godotCounter.IncreaseRunning(); stream = new SslStream(client.GetStream(), false, CertificateValidation); stream.AuthenticateAsServer(serverCert, true, SslProtocols.Tls12, false); logger.Log(this, "SSL authentication completed. Starting Handshake."); this.connectionInfo = Handshake.Run(stream, Log, config); bool running = true; while (running) { ConnectionCommand command = BinaryEncoder.ReadCommand(stream); switch (command) { case ConnectionCommand.TRUST_CONTACT: Log("TRUST_CONTACT command received."); TrustContact(); break; case ConnectionCommand.UNTRUST_CONTACT: Log("UNTRUST_CONTACT command received."); UntrustContact(); break; case ConnectionCommand.PULL: #if (DEBUG) Log("PULL command received."); #endif Push(); break; case ConnectionCommand.PUSH: #if (DEBUG) Log("PUSH command received."); #endif Pull(); break; case ConnectionCommand.SEARCH_CONTACT: Log("SEARCH_CONTACT command received."); SearchContact(); break; case ConnectionCommand.END_CONNECTION: Log("END_CONNECTION command received."); running = false; break; default: throw new Exception("Received unknown command."); } } } catch (Exception ex) { logger.Log(this, "Godot has crashed."); logger.LogException(this, ex); } finally { stream.Close(); client.Close(); godotCounter.IncreaseDestroyed(); logger.Log(this, "Godot has died."); } }