|
|
@ -37,16 +37,15 @@ Config Settings::getSettings() { |
|
|
|
if (server.trimmed().isEmpty()) { |
|
|
|
server = Settings::getRandomServer(); |
|
|
|
|
|
|
|
QString response = ""; |
|
|
|
bool isOnline = false; |
|
|
|
// make sure existing server in conf is alive, otherwise choose random one
|
|
|
|
try { |
|
|
|
char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); |
|
|
|
response = litelib_process_response(resp); |
|
|
|
bool isOnline = litelib_check_server_online(server.toStdString().c_str()); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); |
|
|
|
} |
|
|
|
|
|
|
|
if (response.toUpper().trimmed() != "OK") { |
|
|
|
if (!isOnline) { |
|
|
|
qDebug() << "Lite server in conf " << server << " is down, getting a random one"; |
|
|
|
server = Settings::getRandomServer(); |
|
|
|
s.setValue("connection/server", server); |
|
|
@ -333,11 +332,10 @@ QString Settings::getRandomServer() { |
|
|
|
while (tries < servers.size() ) { |
|
|
|
qDebug() << "Checking if lite server " << server << " is a alive, try=" << tries; |
|
|
|
|
|
|
|
QString response = ""; |
|
|
|
bool isOnline = ""; |
|
|
|
|
|
|
|
try { |
|
|
|
char* resp = litelib_initialize_existing(false, server.toStdString().c_str()); |
|
|
|
response = litelib_process_response(resp); |
|
|
|
isOnline = litelib_check_server_online(server.toStdString().c_str()); |
|
|
|
} catch (const std::exception& e) { |
|
|
|
qDebug() << __func__ << ": caught an exception, ignoring: " << e.what(); |
|
|
|
} |
|
|
@ -345,7 +343,7 @@ QString Settings::getRandomServer() { |
|
|
|
// if we see a valid connection, return this server. when the server is alive,
|
|
|
|
//it tries to read the wallet. This causes an error because it cannot find it (SDL only has a non-encrypted wallet.dat during storage processes)
|
|
|
|
// We can use that.
|
|
|
|
if (response.contains("Error: Cannot read wallet.")) { |
|
|
|
if (isOnline) { |
|
|
|
qDebug() << "Choosing lite server " << server; |
|
|
|
return server; |
|
|
|
} |
|
|
|