Merge pull request 'Windows: kill tor on exit' (#1) from tobtoht/feather:windows_tor_fix into master

Reviewed-on: https://git.wownero.com/feather/feather/pulls/1
This commit is contained in:
dsc 2020-10-09 13:52:58 +00:00
commit 144ad14d84
3 changed files with 14 additions and 8 deletions

View file

@ -169,7 +169,7 @@ AppContext::AppContext(QCommandLineParser *cmdargs) {
} }
void AppContext::initTor() { void AppContext::initTor() {
this->tor = new Tor(this); this->tor = new Tor(this, this);
this->tor->start(); this->tor->start();
if (!(isTails || isWhonix)) { if (!(isTails || isWhonix)) {

View file

@ -932,6 +932,8 @@ void MainWindow::homeWidgetChanged(const QString &widgetName) {
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
m_ctx->tor->stop();
this->saveGeo(); this->saveGeo();
if(m_wizard != nullptr) if(m_wizard != nullptr)
m_wizard->close(); m_wizard->close();

View file

@ -50,6 +50,13 @@ Tor::Tor(AppContext *ctx, QObject *parent)
return; return;
} }
// Don't spawn Tor on default port to avoid conflicts
Tor::torPort = 19450;
if (Utils::portOpen(Tor::torHost, Tor::torPort)) {
this->localTor = true;
return;
}
qDebug() << "Using embedded tor instance"; qDebug() << "Using embedded tor instance";
m_process.setProcessChannelMode(QProcess::MergedChannels); m_process.setProcessChannelMode(QProcess::MergedChannels);
@ -58,6 +65,10 @@ Tor::Tor(AppContext *ctx, QObject *parent)
connect(&m_process, &QProcess::stateChanged, this, &Tor::stateChanged); connect(&m_process, &QProcess::stateChanged, this, &Tor::stateChanged);
} }
void Tor::stop() {
m_process.kill();
}
void Tor::start() { void Tor::start() {
if (this->localTor) { if (this->localTor) {
this->checkConnection(); this->checkConnection();
@ -65,9 +76,6 @@ void Tor::start() {
return; return;
} }
// Don't spawn Tor on default port to avoid conflicts
Tor::torPort = 19450;
auto state = m_process.state(); auto state = m_process.state();
if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) { if (state == QProcess::ProcessState::Running || state == QProcess::ProcessState::Starting) {
this->errorMsg = "Can't start Tor, already running or starting"; this->errorMsg = "Can't start Tor, already running or starting";
@ -101,10 +109,6 @@ void Tor::start() {
m_process.start(this->torPath, arguments); m_process.start(this->torPath, arguments);
} }
void Tor::stop() {
m_process.terminate();
}
void Tor::checkConnection() { void Tor::checkConnection() {
// We might not be able to connect to localhost if torsocks is used to start feather // We might not be able to connect to localhost if torsocks is used to start feather
if (m_ctx->isTorSocks) if (m_ctx->isTorSocks)