]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
proxy: fix only allow onion services with feather managed daemon
authortobtoht <tob@featherwallet.org>
Mon, 13 Feb 2023 09:46:08 +0000 (10:46 +0100)
committertobtoht <tob@featherwallet.org>
Mon, 13 Feb 2023 10:50:06 +0000 (11:50 +0100)
src/utils/TorManager.cpp
src/utils/TorManager.h
src/utils/nodes.cpp

index 830dbd6beb37a186fd0de90bc2439f45ea2d9451..a4456543a709868f22498f14870777642db877cb 100644 (file)
@@ -41,6 +41,7 @@ void TorManager::init() {
     auto state = m_process.state();
     if (m_localTor && (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting)) {
         m_process.kill();
+        m_started = false;
     }
 
     featherTorPort = config()->get(Config::torManagedPort).toString().toUShort();
@@ -48,6 +49,7 @@ void TorManager::init() {
 
 void TorManager::stop() {
     m_process.kill();
+    m_started = false;
 }
 
 void TorManager::start() {
@@ -168,6 +170,10 @@ void TorManager::handleProcessError(QProcess::ProcessError error) {
 }
 
 bool TorManager::unpackBins() {
+    if (m_unpacked) {
+        return true;
+    }
+
     QString torBin = "tor";
 #if defined(Q_OS_WIN)
    torBin += ".exe";
@@ -211,6 +217,7 @@ bool TorManager::unpackBins() {
     | QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther);
 #endif
 
+    m_unpacked = true;
     return true;
 }
 
@@ -253,6 +260,10 @@ bool TorManager::shouldStartTorDaemon() {
         return false;
     }
 
+    if (m_started) {
+        return true;
+    }
+
     // Don't start a Tor daemon if one is already running
     if (Utils::portOpen(torHost, torPort)) {
         return false;
@@ -267,10 +278,8 @@ bool TorManager::shouldStartTorDaemon() {
     }
 
     // Tor daemon (or other service) is already running on our port (19450)
+
     if (Utils::portOpen(featherTorHost, featherTorPort)) {
-        // TODO: this is a hack, fix it later
-        config()->set(Config::socks5Host, featherTorHost);
-        config()->set(Config::socks5Port, featherTorPort);
         return false;
     }
 
index 16bf76c0f305674c0d844405039dd36482e7bfb2..a09b7107f561681466186ad80717289fc14a3a2b 100644 (file)
@@ -64,6 +64,7 @@ private:
     bool m_stopRetries = false;
     bool m_localTor;
     bool m_started = false;
+    bool m_unpacked = false;
     QTimer *m_checkConnectionTimer;
 };
 
index bcbd26e626ccaa1832147fc4a8f528f4fb80096b..6ff97cd474bdd62fd8c2428ffb60046e57d99940 100644 (file)
@@ -208,7 +208,8 @@ void Nodes::connectToNode(const FeatherNode &node) {
     }
 
     if (config()->get(Config::proxy).toInt() == Config::Proxy::Tor && config()->get(Config::torOnlyAllowOnion).toBool()) {
-        if (!node.isOnion()) {
+        if (!node.isOnion() && !node.isLocal()) {
+            // We only want to connect to .onion nodes, but local nodes get an exception.
             return;
         }
     }