Nodes: initSyncThreshold

This commit is contained in:
tobtoht 2021-05-24 17:20:19 +02:00
parent 58b927f9a3
commit fba93e98fc
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
3 changed files with 27 additions and 2 deletions

View file

@ -74,7 +74,8 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::socks5Port, {QS("socks5Port"), "9050"}},
{Config::socks5User, {QS("socks5User"), ""}}, // Unused
{Config::socks5Pass, {QS("socks5Pass"), ""}}, // Unused
{Config::useLocalTor, {QS("useLocalTor"), false}}
{Config::useLocalTor, {QS("useLocalTor"), false}},
{Config::initSyncThreshold, {QS("initSyncThreshold"), 360}}
};

View file

@ -72,6 +72,7 @@ public:
socks5User,
socks5Pass,
useLocalTor, // Prevents Feather from starting bundled Tor daemon
initSyncThreshold
};
enum PrivacyLevel {

View file

@ -359,10 +359,18 @@ void Nodes::setCustomNodes(const QList<FeatherNode> &nodes) {
void Nodes::onWalletRefreshed() {
if (config()->get(Config::torPrivacyLevel).toInt() == Config::allTorExceptInitSync) {
// Don't reconnect if we're connected to a local node (traffic will not be routed through Tor)
if (m_connection.isLocal())
return;
// Don't reconnect if we're already connected to an .onion node
if (m_connection.isOnion())
return;
// Don't reconnect on Tails or Whonix (all traffic is already routed through Tor)
if (TailsOS::detect() || WhonixOS::detect())
return;
this->autoConnect(true);
}
}
@ -372,9 +380,24 @@ bool Nodes::useOnionNodes() {
return true;
}
auto privacyLevel = config()->get(Config::torPrivacyLevel).toInt();
if (privacyLevel == Config::allTor || (privacyLevel == Config::allTorExceptInitSync && m_ctx->refreshed)) {
if (privacyLevel == Config::allTor) {
return true;
}
if (privacyLevel == Config::allTorExceptInitSync) {
if (m_ctx->refreshed)
return true;
if (appData()->heights.contains(constants::networkType)) {
int initSyncThreshold = config()->get(Config::initSyncThreshold).toInt();
int networkHeight = appData()->heights[constants::networkType];
if (m_ctx->wallet->blockChainHeight() > (networkHeight - initSyncThreshold)) {
return true;
}
}
}
return false;
}