From fba93e98fc2f11389d5b0ba704ad7c1e97577367 Mon Sep 17 00:00:00 2001 From: tobtoht Date: Mon, 24 May 2021 17:20:19 +0200 Subject: [PATCH] Nodes: initSyncThreshold --- src/utils/config.cpp | 3 ++- src/utils/config.h | 1 + src/utils/nodes.cpp | 25 ++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/utils/config.cpp b/src/utils/config.cpp index c8d2208f..fd393647 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -74,7 +74,8 @@ static const QHash 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}} }; diff --git a/src/utils/config.h b/src/utils/config.h index 062b531b..5a0fb4b0 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -72,6 +72,7 @@ public: socks5User, socks5Pass, useLocalTor, // Prevents Feather from starting bundled Tor daemon + initSyncThreshold }; enum PrivacyLevel { diff --git a/src/utils/nodes.cpp b/src/utils/nodes.cpp index e477fd20..ef292ff9 100644 --- a/src/utils/nodes.cpp +++ b/src/utils/nodes.cpp @@ -359,10 +359,18 @@ void Nodes::setCustomNodes(const QList &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; }