From 68104f22476e0f3ce52ca282899d3bee2b619b6e Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Sun, 11 Apr 2021 00:42:19 -0400 Subject: [PATCH] Fix stuff and get sticky --- src/settings.cpp | 46 +++++++++++++++++++++++++++------------------- src/settings.h | 3 +++ 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/settings.cpp b/src/settings.cpp index a97f71e..0b4f22b 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -24,36 +24,44 @@ Config Settings::getSettings() { QSettings s; // this domain is stolen and malicious! + // More info: https://git.hush.is/hush/fraud/#gilardh auto malicious = "https://lite.myhush.org"; auto server = s.value("connection/server").toString(); - bool torOnly = s.value("connectoin/torOnly").toBool(); + bool sticky = s.value("connection/stickyServer").toBool(); + bool torOnly = s.value("connection/torOnly").toBool(); - // default behavior is no server listed in conf, and randomly choose from those listed in code + // Users that have old configs generated from old SDLs will have this hostname + if(server == malicious) { + qDebug() << "Replacing malicious SDL server with " << server; + server = "https://lite.hush.is"; + s.setValue("connection/server", server); + } + + // default behavior : no server listed in conf, randomly choose from server list, unless sticky if (server.trimmed().isEmpty()) { server = Settings::getRandomServer(); - } - // make sure existing server in conf is alive, otherwise choose random one - char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); - QString response = litelib_process_response(resp); + // make sure existing server in conf is alive, otherwise choose random one + char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); + QString response = litelib_process_response(resp); - // if we see a valid connection, return this server - if (response.toUpper().trimmed() != "OK") { - qDebug() << "Lite server in conf " << server << " is down, getting a random one"; - server = Settings::getRandomServer(); - s.setValue("connection/server", server); + if (response.toUpper().trimmed() != "OK") { + qDebug() << "Lite server in conf " << server << " is down, getting a random one"; + server = Settings::getRandomServer(); + s.setValue("connection/server", server); + } + } else { + if (sticky) { + qDebug() << server << " is sticky"; + } + // if it's down, oh well } - // Users that have old configs generated from old SDLs will have this hostname - if(server == malicious) { - qDebug() << "Replacing malicious SDL server with " << server; - s.setValue("connection/server", server); - } s.sync(); // re-init to load correct settings init(); - return Config{server, torOnly}; + return Config{server, torOnly, sticky}; } void Settings::saveSettings(const QString& server) { @@ -294,8 +302,8 @@ QString Settings::getRandomServer() { servers[0] = "https://lite.hush.is"; servers[1] = "https://devo.crabdance.com"; servers[2] = "https://bies.xyz"; - servers[3] = "https://hush.leto.net"; - servers[4] = "https://milktoast.attackingzcash.com"; + //servers[3] = "https://hush.leto.net"; + //servers[4] = "https://milktoast.attackingzcash.com"; // start at a random place in the list int x = rand() % servers.size(); diff --git a/src/settings.h b/src/settings.h index 2c536f4..d8b5d4b 100644 --- a/src/settings.h +++ b/src/settings.h @@ -11,7 +11,10 @@ using json = nlohmann::json; struct Config { // The randomly chosen server we are talking to OR user-specific server QString server; + // Shouuld we only speak Tor to this server? bool torOnly {false}; + // Should we randomly try other servers if specified server is down? + bool stickyServer {false}; }; struct ToFields;