proxy: fix only allow onion services with feather managed daemon

This commit is contained in:
tobtoht 2023-02-13 10:46:08 +01:00
parent 199e085709
commit c11ca77599
3 changed files with 15 additions and 4 deletions

View file

@ -41,6 +41,7 @@ void TorManager::init() {
auto state = m_process.state(); auto state = m_process.state();
if (m_localTor && (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting)) { if (m_localTor && (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting)) {
m_process.kill(); m_process.kill();
m_started = false;
} }
featherTorPort = config()->get(Config::torManagedPort).toString().toUShort(); featherTorPort = config()->get(Config::torManagedPort).toString().toUShort();
@ -48,6 +49,7 @@ void TorManager::init() {
void TorManager::stop() { void TorManager::stop() {
m_process.kill(); m_process.kill();
m_started = false;
} }
void TorManager::start() { void TorManager::start() {
@ -168,6 +170,10 @@ void TorManager::handleProcessError(QProcess::ProcessError error) {
} }
bool TorManager::unpackBins() { bool TorManager::unpackBins() {
if (m_unpacked) {
return true;
}
QString torBin = "tor"; QString torBin = "tor";
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
torBin += ".exe"; torBin += ".exe";
@ -211,6 +217,7 @@ bool TorManager::unpackBins() {
| QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther); | QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther);
#endif #endif
m_unpacked = true;
return true; return true;
} }
@ -253,6 +260,10 @@ bool TorManager::shouldStartTorDaemon() {
return false; return false;
} }
if (m_started) {
return true;
}
// Don't start a Tor daemon if one is already running // Don't start a Tor daemon if one is already running
if (Utils::portOpen(torHost, torPort)) { if (Utils::portOpen(torHost, torPort)) {
return false; return false;
@ -267,10 +278,8 @@ bool TorManager::shouldStartTorDaemon() {
} }
// Tor daemon (or other service) is already running on our port (19450) // Tor daemon (or other service) is already running on our port (19450)
if (Utils::portOpen(featherTorHost, featherTorPort)) { 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; return false;
} }

View file

@ -64,6 +64,7 @@ private:
bool m_stopRetries = false; bool m_stopRetries = false;
bool m_localTor; bool m_localTor;
bool m_started = false; bool m_started = false;
bool m_unpacked = false;
QTimer *m_checkConnectionTimer; QTimer *m_checkConnectionTimer;
}; };

View 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 (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; return;
} }
} }