TorManager: fix tor connection issue after crash

This commit is contained in:
tobtoht 2023-11-25 18:10:55 +01:00
parent a09b15f79e
commit b75ec4381a
No known key found for this signature in database
GPG key ID: E45B10DD027D2472
4 changed files with 12 additions and 6 deletions

View file

@ -638,7 +638,7 @@ void WindowManager::onProxySettingsChanged() {
QString host = conf()->get(Config::socks5Host).toString();
quint16 port = conf()->get(Config::socks5Port).toString().toUShort();
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && !torManager()->isLocalTor()) {
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && (!torManager()->isLocalTor() || torManager()->isAlreadyRunning())) {
host = torManager()->featherTorHost;
port = torManager()->featherTorPort;
}

View file

@ -3,9 +3,7 @@
#include "utils/TorManager.h"
#include <QScreen>
#include <QDesktopServices>
#include <QRegularExpression>
#include "utils/config.h"
#include "utils/Utils.h"
@ -122,7 +120,7 @@ void TorManager::checkConnection() {
this->setConnectionState(false);
}
else if (m_localTor) {
else if (m_localTor && !m_alreadyRunning) {
QString host = conf()->get(Config::socks5Host).toString();
quint16 port = conf()->get(Config::socks5Port).toString().toUShort();
this->setConnectionState(Utils::portOpen(host, port));
@ -236,10 +234,15 @@ bool TorManager::isStarted() {
return m_started;
}
bool TorManager::isAlreadyRunning() {
return m_alreadyRunning;
}
bool TorManager::shouldStartTorDaemon() {
QString torHost = conf()->get(Config::socks5Host).toString();
quint16 torPort = conf()->get(Config::socks5Port).toString().toUShort();
QString torHostPort = QString("%1:%2").arg(torHost, QString::number(torPort));
m_alreadyRunning = false;
// Don't start a Tor daemon if Feather is run with Torsocks
if (Utils::isTorsocks()) {
@ -287,6 +290,7 @@ bool TorManager::shouldStartTorDaemon() {
// Tor daemon (or other service) is already running on our port (19450)
if (Utils::portOpen(featherTorHost, featherTorPort)) {
m_alreadyRunning = true;
return false;
}

View file

@ -25,6 +25,7 @@ public:
bool unpackBins();
bool isLocalTor();
bool isStarted();
bool isAlreadyRunning();
SemanticVersion getVersion(const QString &fileName);
static TorManager* instance();
@ -62,9 +63,10 @@ private:
QProcess *m_process;
int m_restarts = 0;
bool m_stopRetries = false;
bool m_localTor;
bool m_localTor = false;
bool m_started = false;
bool m_unpacked = false;
bool m_alreadyRunning = false;
QTimer *m_checkConnectionTimer;
};

View file

@ -230,7 +230,7 @@ void Nodes::connectToNode(const FeatherNode &node) {
QString proxyAddress;
if (useSocks5Proxy(node)) {
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && !torManager()->isLocalTor()) {
if (conf()->get(Config::proxy).toInt() == Config::Proxy::Tor && (!torManager()->isLocalTor() || torManager()->isAlreadyRunning())) {
proxyAddress = QString("%1:%2").arg(torManager()->featherTorHost, QString::number(torManager()->featherTorPort));
} else {
proxyAddress = QString("%1:%2").arg(conf()->get(Config::socks5Host).toString(),