[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1866: Try to be smarter about handling stopping or disconnecting f (in trunk: . src/gui)
Author: edmanm
Date: 2007-08-24 19:16:35 -0400 (Fri, 24 Aug 2007)
New Revision: 1866
Modified:
trunk/
trunk/src/gui/mainwindow.cpp
trunk/src/gui/mainwindow.h
Log:
r2053@adrastea: edmanm | 2007-08-24 19:15:54 -0400
Try to be smarter about handling stopping or disconnecting from Tor when
authentication fails (or the user cancels authentication when we can't find a
cookie) and either Tor disconnects us or not, both when Vidalia started Tor or
when Tor was already running.
Property changes on: trunk
___________________________________________________________________
svk:merge ticket from /vidalia/local/trunk [r2053] on 54b3572a-7227-0410-958f-53ecd705b71a
Modified: trunk/src/gui/mainwindow.cpp
===================================================================
--- trunk/src/gui/mainwindow.cpp 2007-08-24 23:16:16 UTC (rev 1865)
+++ trunk/src/gui/mainwindow.cpp 2007-08-24 23:16:35 UTC (rev 1866)
@@ -383,15 +383,17 @@
#endif
}
-/** Updates the UI to reflect Tor's current <b>status</b>. */
-void
+/** Updates the UI to reflect Tor's current <b>status</b>. Returns the
+ * previously set TorStatus value.*/
+MainWindow::TorStatus
MainWindow::updateTorStatus(TorStatus status)
{
QString statusText, actionText;
QString trayIconFile, statusIconFile;
-
+ TorStatus prevStatus = _status;
+
vNotice("Tor status changed from '%1' to '%2'.")
- .arg(toString(_status)).arg(toString(status));
+ .arg(toString(prevStatus)).arg(toString(status));
_status = status;
if (status == Stopped) {
@@ -451,11 +453,11 @@
ui.lblStartStopTor->setStatusTip(statusText);
ui.lblStartStopTor->setAnimation(QPixmap(ANIM_PROCESS_WORKING));
} else if (status == Connecting) {
- statusText = tr("Vidalia is connecting to Tor.");
+ statusText = tr("Vidalia is connecting to Tor");
} else if (status == Authenticating) {
- statusText = tr("Vidalia is authenticating to Tor.");
+ statusText = tr("Vidalia is authenticating to Tor");
} else if (status == Authenticated) {
- statusText = tr("Tor is running.");
+ statusText = tr("Tor is running");
trayIconFile = IMG_TOR_RUNNING;
statusIconFile = IMG_TOR_RUNNING_48;
}
@@ -475,6 +477,7 @@
_trayIcon.setToolTip(statusText);
ui.lblTorStatus->setText(statusText);
}
+ return prevStatus;
}
#if defined(USE_QSYSTEMTRAYICON)
@@ -500,6 +503,7 @@
void
MainWindow::start()
{
+ updateTorStatus(Starting);
/* This doesn't get set to false until Tor is actually up and running, so we
* don't yell at users twice if their Tor doesn't even start, due to the fact
* that QProcess::stopped() is emitted even if the process didn't even
@@ -507,7 +511,6 @@
_isIntentionalExit = true;
/* Kick off the Tor process */
_torControl->start();
- updateTorStatus(Starting);
}
/** Called when the Tor process fails to start, for example, because the path
@@ -551,6 +554,8 @@
_isIntentionalExit = false;
/* We haven't started a delayed shutdown yet. */
_delayedShutdownStarted = false;
+ /* Remember whether we started Tor or not */
+ _isVidaliaRunningTor = _torControl->isVidaliaRunningTor();
/* Try to connect to Tor's control port */
_torControl->connect();
}
@@ -560,6 +565,8 @@
void
MainWindow::connectFailed(QString errmsg)
{
+ updateTorStatus(Disconnected);
+
/* Ok, ok. It really isn't going to connect. I give up. */
int response = VMessageBox::warning(this,
tr("Error Connecting to Tor"), p(errmsg),
@@ -585,15 +592,9 @@
{
ServerSettings server(_torControl);
QString errmsg;
- bool rc, delayShutdown = false;
-
- /* If Vidalia is not running Tor and we were never authenticated, then
- * all we can do is simply disconnect the control socket. */
- if (!_torControl->isVidaliaRunningTor() && _status != Authenticated) {
- disconnect();
- return true;
- }
-
+ TorStatus prevStatus;
+ bool rc;
+
/* If we're running a server, give users the option of terminating
* gracefully so clients have time to find new servers. */
if (server.isServerEnabled() && !_delayedShutdownStarted) {
@@ -608,25 +609,22 @@
VMessageBox::No,
VMessageBox::Cancel|VMessageBox::Escape);
if (response == VMessageBox::Yes)
- delayShutdown = true;
+ _delayedShutdownStarted = true;
else if (response == VMessageBox::Cancel)
return false;
}
-
- if (delayShutdown) {
+
+ prevStatus = updateTorStatus(Stopping);
+ if (_delayedShutdownStarted) {
/* Start a delayed shutdown */
rc = _torControl->signal(TorSignal::Shutdown, &errmsg);
- _delayedShutdownStarted = rc;
} else {
/* We want Tor to stop now, regardless of whether we're a server. */
_isIntentionalExit = true;
rc = _torControl->stop(&errmsg);
}
- if (rc) {
- /* Indicate that Tor is about to shut down */
- updateTorStatus(Stopping);
- } else {
+ if (!rc) {
/* We couldn't tell Tor to stop, for some reason. */
int response = VMessageBox::warning(this, tr("Error Stopping Tor"),
p(tr("Vidalia was unable to stop Tor.")) + p(errmsg),
@@ -639,6 +637,8 @@
}
/* Tor is still running since stopping failed */
_isIntentionalExit = false;
+ _delayedShutdownStarted = false;
+ updateTorStatus(prevStatus);
}
return rc;
}
@@ -675,8 +675,7 @@
MainWindow::connected()
{
updateTorStatus(Connected);
- if (!authenticate())
- stop();
+ authenticate();
}
/** Called when Vidalia wants to disconnect from a Tor it did not start. */
@@ -691,13 +690,17 @@
void
MainWindow::disconnected()
{
+ updateTorStatus(Disconnected);
+ if (!_isVidaliaRunningTor) {
+ /* If we didn't start our own Tor process, interpret losing the control
+ * connection as "Tor is stopped". */
+ updateTorStatus(Stopped);
+ }
+
/*XXX We should warn here if we get disconnected when we didn't intend to */
- if (_torControl->isVidaliaRunningTor())
- updateTorStatus(Disconnected);
- else
- updateTorStatus(Stopped);
_newIdentityAct->setEnabled(false);
ui.lblNewIdentity->setEnabled(false);
+ _isVidaliaRunningTor = false;
}
/** Attempts to authenticate to Tor's control port, depending on the
@@ -739,13 +742,13 @@
VMessageBox::Browse, VMessageBox::Cancel);
if (ret == VMessageBox::Cancel)
- return false;
+ goto cancel;
QString cookieDir = QFileDialog::getOpenFileName(this,
tr("Tor Data Directory"),
settings.getDataDirectory(),
tr("Tor Control Cookie (control_auth_cookie)"));
if (cookieDir.isEmpty())
- return false;
+ goto cancel;
cookieDir = QFileInfo(cookieDir).absolutePath();
cookie = loadControlCookie(cookieDir);
}
@@ -757,6 +760,13 @@
}
/* No authentication. Send an empty password. */
return _torControl->authenticate(QString(""));
+
+cancel:
+ if (_isVidaliaRunningTor)
+ stop();
+ else
+ disconnect();
+ return false;
}
/** Called when Vidalia has successfully authenticated to Tor. */
@@ -812,7 +822,11 @@
tr("Error Authenticating to Tor"),
p(tr("Vidalia was unable to authenticate to Tor.")) + p(errmsg),
VMessageBox::Ok);
- stop();
+
+ if (_torControl->isRunning() && _isVidaliaRunningTor)
+ stop();
+ else if (_torControl->isConnected())
+ disconnect();
}
/** Searches for and attempts to load the control authentication cookie. This
Modified: trunk/src/gui/mainwindow.h
===================================================================
--- trunk/src/gui/mainwindow.h 2007-08-24 23:16:16 UTC (rev 1865)
+++ trunk/src/gui/mainwindow.h 2007-08-24 23:16:35 UTC (rev 1866)
@@ -136,8 +136,9 @@
void createMenuBar();
/** Returns true if we're running on a platform with tray icon support. */
bool isTrayIconSupported();
- /** Updates the UI to reflect Tor's current <b>status</b>. */
- void updateTorStatus(TorStatus status);
+ /** Updates the UI to reflect Tor's current <b>status</b>. Returns the
+ * previously set TorStatus value. */
+ TorStatus updateTorStatus(TorStatus status);
/** Converts a TorStatus enum value to a string for debug logging purposes. */
QString toString(TorStatus status);
/** Authenticates Vidalia to Tor's control port. */
@@ -155,6 +156,8 @@
bool _isIntentionalExit;
/** Tracks whether we started a delayed server shutdown. */
bool _delayedShutdownStarted;
+ /** Set to true if Vidalia started its own Tor process. */
+ bool _isVidaliaRunningTor;
/** A MessageLog object which handles logging Tor messages */
MessageLog* _messageLog;
/** A BandwidthGraph object which handles monitoring Tor bandwidth usage */