[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r4054: Switch all Tor asynch event handling over to using proper si (in vidalia/trunk/src: torcontrol vidalia vidalia/bwgraph vidalia/log vidalia/network)
Author: edmanm
Date: 2009-08-16 22:25:08 -0400 (Sun, 16 Aug 2009)
New Revision: 4054
Removed:
vidalia/trunk/src/torcontrol/AddressMapEvent.h
vidalia/trunk/src/torcontrol/BandwidthEvent.h
vidalia/trunk/src/torcontrol/BootstrapStatusEvent.h
vidalia/trunk/src/torcontrol/CircuitEstablishedEvent.h
vidalia/trunk/src/torcontrol/CircuitEvent.h
vidalia/trunk/src/torcontrol/ClientStatusEvent.cpp
vidalia/trunk/src/torcontrol/ClientStatusEvent.h
vidalia/trunk/src/torcontrol/DangerousPortEvent.cpp
vidalia/trunk/src/torcontrol/DangerousPortEvent.h
vidalia/trunk/src/torcontrol/DangerousVersionEvent.cpp
vidalia/trunk/src/torcontrol/DangerousVersionEvent.h
vidalia/trunk/src/torcontrol/GeneralStatusEvent.cpp
vidalia/trunk/src/torcontrol/GeneralStatusEvent.h
vidalia/trunk/src/torcontrol/NewDescriptorEvent.h
vidalia/trunk/src/torcontrol/OrConnEvent.cpp
vidalia/trunk/src/torcontrol/OrConnEvent.h
vidalia/trunk/src/torcontrol/ServerStatusEvent.cpp
vidalia/trunk/src/torcontrol/ServerStatusEvent.h
vidalia/trunk/src/torcontrol/StatusEvent.h
vidalia/trunk/src/torcontrol/StreamEvent.h
vidalia/trunk/src/torcontrol/UnrecognizedClientStatusEvent.h
vidalia/trunk/src/torcontrol/UnrecognizedGeneralStatusEvent.h
vidalia/trunk/src/torcontrol/UnrecognizedServerStatusEvent.h
vidalia/trunk/src/torcontrol/eventtype.h
Modified:
vidalia/trunk/src/torcontrol/BootstrapStatus.h
vidalia/trunk/src/torcontrol/CMakeLists.txt
vidalia/trunk/src/torcontrol/Circuit.h
vidalia/trunk/src/torcontrol/ControlConnection.h
vidalia/trunk/src/torcontrol/ControlSocket.cpp
vidalia/trunk/src/torcontrol/SendCommandEvent.cpp
vidalia/trunk/src/torcontrol/SendCommandEvent.h
vidalia/trunk/src/torcontrol/Stream.h
vidalia/trunk/src/torcontrol/TorControl.cpp
vidalia/trunk/src/torcontrol/TorControl.h
vidalia/trunk/src/torcontrol/TorEvents.cpp
vidalia/trunk/src/torcontrol/TorEvents.h
vidalia/trunk/src/torcontrol/tcglobal.cpp
vidalia/trunk/src/torcontrol/tcglobal.h
vidalia/trunk/src/vidalia/MainWindow.cpp
vidalia/trunk/src/vidalia/MainWindow.h
vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.cpp
vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.h
vidalia/trunk/src/vidalia/log/LogTreeItem.cpp
vidalia/trunk/src/vidalia/log/LogTreeItem.h
vidalia/trunk/src/vidalia/log/LogTreeWidget.cpp
vidalia/trunk/src/vidalia/log/LogTreeWidget.h
vidalia/trunk/src/vidalia/log/MessageLog.cpp
vidalia/trunk/src/vidalia/log/MessageLog.h
vidalia/trunk/src/vidalia/network/NetViewer.cpp
vidalia/trunk/src/vidalia/network/NetViewer.h
Log:
Switch all Tor asynch event handling over to using proper signals and
slots rather than custom QEvent subclasses. This allows multiple objects
to listen for the same event and makes handling events easier since no
customEvent() override and event type casting is needed. It also seems to
make logging at debug level significantly more responsive and resulted in
removing more lines of code than I added (woo). This patch also has some
assorted cleanups in it from removing trailing whitespace.
Modified: vidalia/trunk/src/torcontrol/BootstrapStatus.h
===================================================================
--- vidalia/trunk/src/torcontrol/BootstrapStatus.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/BootstrapStatus.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -20,6 +20,7 @@
#include "tcglobal.h"
#include <QString>
+#include <QMetaType>
class BootstrapStatus
@@ -140,5 +141,7 @@
Recommendation _action;
};
+Q_DECLARE_METATYPE(BootstrapStatus);
+
#endif
Modified: vidalia/trunk/src/torcontrol/CMakeLists.txt
===================================================================
--- vidalia/trunk/src/torcontrol/CMakeLists.txt 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/CMakeLists.txt 2009-08-17 02:25:08 UTC (rev 4054)
@@ -15,22 +15,15 @@
AddressMap.cpp
BootstrapStatus.cpp
Circuit.cpp
- ClientStatusEvent.cpp
ControlCommand.cpp
ControlConnection.cpp
ControlReply.cpp
ControlSocket.cpp
- DangerousPortEvent.cpp
- DangerousVersionEvent.cpp
- GeneralStatusEvent.cpp
- LogEvent.cpp
- OrConnEvent.cpp
ProtocolInfo.cpp
ReplyLine.cpp
RouterDescriptor.cpp
RouterStatus.cpp
SendCommandEvent.cpp
- ServerStatusEvent.cpp
Stream.cpp
tcglobal.cpp
TorControl.cpp
Modified: vidalia/trunk/src/torcontrol/Circuit.h
===================================================================
--- vidalia/trunk/src/torcontrol/Circuit.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/Circuit.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -19,6 +19,7 @@
#include <QCoreApplication>
#include <QStringList>
+#include <QMetaType>
/** Circuit IDs contains 1-16 alphanumeric ASCII characters. */
typedef QString CircuitId;
@@ -75,6 +76,8 @@
bool _isValid;
};
+Q_DECLARE_METATYPE(Circuit);
+
/** A collection of circuits. */
typedef QList<Circuit> CircuitList;
Modified: vidalia/trunk/src/torcontrol/ControlConnection.h
===================================================================
--- vidalia/trunk/src/torcontrol/ControlConnection.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/ControlConnection.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -21,7 +21,6 @@
#include "ControlSocket.h"
#include "TorEvents.h"
#include "SendCommandEvent.h"
-#include "eventtype.h"
#include <QThread>
#include <QMutex>
Modified: vidalia/trunk/src/torcontrol/ControlSocket.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/ControlSocket.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/ControlSocket.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -43,7 +43,7 @@
void
ControlSocket::customEvent(QEvent *event)
{
- if (event->type() == CustomEventType::SendCommandEvent) {
+ if (event->type() == QEvent::User) {
SendCommandEvent *sce = dynamic_cast<SendCommandEvent *>(event);
if (! sce)
return;
Modified: vidalia/trunk/src/torcontrol/SendCommandEvent.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/SendCommandEvent.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/SendCommandEvent.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -21,7 +21,7 @@
SendCommandEvent::SendCommandEvent(const ControlCommand &cmd, SendWaiter *w)
- : QEvent((QEvent::Type)CustomEventType::SendCommandEvent)
+ : QEvent(QEvent::User)
{
_cmd = cmd;
_waiter = w;
Modified: vidalia/trunk/src/torcontrol/SendCommandEvent.h
===================================================================
--- vidalia/trunk/src/torcontrol/SendCommandEvent.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/SendCommandEvent.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -19,7 +19,6 @@
#define _SENDCOMMANDEVENT_H
#include "ControlCommand.h"
-#include "eventtype.h"
#include <QEvent>
#include <QMutex>
Modified: vidalia/trunk/src/torcontrol/Stream.h
===================================================================
--- vidalia/trunk/src/torcontrol/Stream.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/Stream.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -23,8 +23,8 @@
#include <QString>
#include <QObject>
#include <QList>
+#include <QMetaType>
-
/** Stream IDs contains 1-16 alphanumeric ASCII characters. */
typedef QString StreamId;
@@ -92,6 +92,8 @@
quint16 _port; /**< Stream target port. */
};
+Q_DECLARE_METATYPE(Stream);
+
/** A collection of Stream objects. */
typedef QList<Stream> StreamList;
Modified: vidalia/trunk/src/torcontrol/TorControl.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/TorControl.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/TorControl.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -1,6 +1,6 @@
/*
** This file is part of Vidalia, and is subject to the license terms in the
-** LICENSE file, found in the top level directory of this distribution. If
+** LICENSE file, found in the top level directory of this distribution. If
** you did not receive the LICENSE file with this file, you may obtain it
** from the Vidalia source package distributed by the Vidalia Project at
** http://www.vidalia-project.net/. No part of Vidalia, including this file,
@@ -8,52 +8,70 @@
** the terms described in the LICENSE file.
*/
-/*
+/*
** \file TorControl.cpp
** \version $Id$
** \brief Object for interacting with the Tor process and control interface
*/
#include "TorControl.h"
-
+#include "RouterDescriptor.h"
+#include "ProtocolInfo.h"
+#include "RouterStatus.h"
#include "file.h"
#include "stringutil.h"
#include <QHostAddress>
+#include <QVariantMap>
/** Default constructor */
TorControl::TorControl()
{
+#define RELAY_SIGNAL(src, sig) \
+ QObject::connect((src), (sig), this, (sig))
+
+ /* Create a TorEvents object to receive and parse asynchronous events
+ * from Tor's control port, and relay them as external signals from
+ * this TorControl object. */
+ _eventHandler = new TorEvents(this);
+ RELAY_SIGNAL(_eventHandler, SIGNAL(circuitEstablished()));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(dangerousTorVersion(tc::TorVersionStatus,
+ QString, QStringList)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(bandwidthUpdate(quint64, quint64)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(circuitStatusChanged(Circuit)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(streamStatusChanged(Stream)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(newDescriptors(QStringList)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(logMessage(tc::Severity, QString)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(dangerousPort(quint16, bool)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(socksError(tc::SocksError, QString)));
+ RELAY_SIGNAL(_eventHandler, SIGNAL(bootstrapStatusChanged(BootstrapStatus)));
+
/* Create an instance of a connection to Tor's control interface and give
* it an object to use to handle asynchronous events. */
- _controlConn = new ControlConnection(&_torEvents);
- QObject::connect(_controlConn, SIGNAL(connected()),
- this, SIGNAL(connected()));
- QObject::connect(_controlConn, SIGNAL(connectFailed(QString)),
- this, SIGNAL(connectFailed(QString)));
+ _controlConn = new ControlConnection(_eventHandler);
+ RELAY_SIGNAL(_controlConn, SIGNAL(connected()));
+ RELAY_SIGNAL(_controlConn, SIGNAL(connectFailed(QString)));
QObject::connect(_controlConn, SIGNAL(disconnected()),
this, SLOT(onDisconnected()));
/* Create an object used to start and stop a Tor process. */
_torProcess = new TorProcess(this);
- QObject::connect(_torProcess, SIGNAL(started()),
- this, SIGNAL(started()));
+ RELAY_SIGNAL(_torProcess, SIGNAL(started()));
+ RELAY_SIGNAL(_torProcess, SIGNAL(startFailed(QString)));
QObject::connect(_torProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(onStopped(int, QProcess::ExitStatus)));
- QObject::connect(_torProcess, SIGNAL(startFailed(QString)),
- this, SIGNAL(startFailed(QString)));
QObject::connect(_torProcess, SIGNAL(log(QString, QString)),
this, SLOT(onLogStdout(QString, QString)));
#if defined(Q_OS_WIN32)
_torService = new TorService(this);
- QObject::connect(_torService, SIGNAL(started()), this, SIGNAL(started()));
+ RELAY_SIGNAL(_torService, SIGNAL(started()));
+ RELAY_SIGNAL(_torService, SIGNAL(startFailed(QString)));
QObject::connect(_torService, SIGNAL(finished(int, QProcess::ExitStatus)),
this, SLOT(onStopped(int, QProcess::ExitStatus)));
- QObject::connect(_torService, SIGNAL(startFailed(QString)),
- this, SIGNAL(startFailed(QString)));
#endif
+#undef RELAY_SIGNAL
}
/** Default destructor */
@@ -110,7 +128,7 @@
{
if (_controlConn->status() == ControlConnection::Connecting)
_controlConn->cancelConnect();
-
+
emit stopped();
emit stopped(exitCode, exitStatus);
}
@@ -142,10 +160,9 @@
/** Called when Tor has printed a log message to stdout. */
void
-TorControl::onLogStdout(QString severity, QString message)
+TorControl::onLogStdout(const QString &severity, const QString &message)
{
- LogEvent::Severity s = LogEvent::toSeverity(severity);
- _torEvents.dispatch(TorEvents::toTorEvent(s), new LogEvent(s, message));
+ emit logMessage(tc::severityFromString(severity), message.trimmed());
}
/** Connect to Tor's control port. The control port to use is determined by
@@ -171,7 +188,7 @@
if (_torProcess) {
/* If we're running a Tor process, then start reading logs from stdout
* again, in case our control connection just died but Tor is still
- * running. In this case, there may be relevant information in the logs. */
+ * running. In this case, there may be relevant information in the logs. */
_torProcess->openStdout();
}
/* Tor isn't running, so it has no version */
@@ -215,7 +232,7 @@
}
/** Sends an authentication cookie to Tor. The syntax is:
- *
+ *
* "AUTHENTICATE" SP 1*HEXDIG CRLF
*/
bool
@@ -224,32 +241,31 @@
ControlCommand cmd("AUTHENTICATE", base16_encode(cookie));
ControlReply reply;
QString str;
-
+
if (!send(cmd, reply, &str)) {
emit authenticationFailed(str);
return err(errmsg, str);
}
- onAuthenticated();
+ onAuthenticated();
return true;
}
/** Sends an authentication password to Tor. The syntax is:
- *
+ *
* "AUTHENTICATE" SP QuotedString CRLF
*/
bool
-TorControl::authenticate(const QString password, QString *errmsg)
+TorControl::authenticate(const QString &password, QString *errmsg)
{
- ControlCommand cmd("AUTHENTICATE", QString("%1")
- .arg(string_escape(password)));
+ ControlCommand cmd("AUTHENTICATE", string_escape(password));
ControlReply reply;
QString str;
-
+
if (!send(cmd, reply, &str)) {
emit authenticationFailed(str);
return err(errmsg, str);
}
- onAuthenticated();
+ onAuthenticated();
return true;
}
@@ -262,7 +278,9 @@
getInfo("version", _torVersion);
/* We want to use verbose names in events and GETINFO results. */
useFeature("VERBOSE_NAMES");
-
+ /* We want to use extended events in all async events */
+ useFeature("EXTENDED_EVENTS");
+
emit authenticated();
}
@@ -284,11 +302,11 @@
foreach (ReplyLine line, reply.getLines()) {
if (line.getStatus() != "250")
continue;
-
+
msg = line.getMessage().trimmed();
idx = msg.indexOf(" ");
topic = msg.mid(0, idx).toUpper();
-
+
if (idx > 0) {
keyvals = string_parse_keyvals(msg.mid(idx+1), &ok);
if (!ok)
@@ -296,7 +314,7 @@
} else {
keyvals = QHash<QString,QString>();
}
-
+
if (topic == "AUTH") {
if (keyvals.contains("METHODS"))
pi.setAuthMethods(keyvals.value("METHODS"));
@@ -317,7 +335,7 @@
TorControl::useFeature(const QString &feature, QString *errmsg)
{
ControlCommand cmd("USEFEATURE", feature);
- return send(cmd, errmsg);
+ return send(cmd, errmsg);
}
BootstrapStatus
@@ -325,14 +343,14 @@
{
QString str = getInfo("status/bootstrap-phase").toString();
if (!str.isEmpty()) {
- tc::Severity severity = tc::toSeverity(str.section(' ', 0, 0));
+ tc::Severity severity = tc::severityFromString(str.section(' ', 0, 0));
QHash<QString,QString> args = string_parse_keyvals(str);
return BootstrapStatus(severity,
BootstrapStatus::statusFromString(args.value("TAG")),
args.value("PROGRESS").toInt(),
args.value("SUMMARY"),
args.value("WARNING"),
- tc::toConnectionStatusReason(args.value("REASON")),
+ tc::connectionStatusReasonFromString(args.value("REASON")),
BootstrapStatus::actionFromString(
args.value("RECOMMENDATION")));
}
@@ -342,7 +360,7 @@
/** Returns true if Tor either has an open circuit or (on Tor >=
* 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
bool
-TorControl::circuitEstablished()
+TorControl::isCircuitEstablished()
{
/* If Tor is recent enough, we can 'getinfo status/circuit-established' to
* see if Tor has an open circuit */
@@ -364,8 +382,8 @@
/** Sends a GETINFO message to Tor based on the given map of keyvals. The
* syntax is:
- *
- * "GETINFO" 1*(SP keyword) CRLF
+ *
+ * "GETINFO" 1*(SP keyword) CRLF
*/
bool
TorControl::getInfo(QHash<QString,QString> &map, QString *errmsg)
@@ -377,7 +395,7 @@
foreach (QString key, map.keys()) {
cmd.addArgument(key);
}
-
+
/* Ask Tor for the specified info values */
if (send(cmd, reply, errmsg)) {
/* Parse the response for the returned values */
@@ -412,7 +430,7 @@
int index = msg.indexOf("=");
QString key = msg.mid(0, index);
QStringList val;
-
+
if (index > 0 && index < msg.length()-1)
val << msg.mid(index+1);
if (line.hasData())
@@ -465,7 +483,7 @@
* asking it to stop running, so don't try to get a response. */
return _controlConn->send(cmd, errmsg);
}
- return send(cmd, errmsg);
+ return send(cmd, errmsg);
}
/** Returns an address on which Tor is listening for application
@@ -479,7 +497,7 @@
if (getSocksPort() == 0) {
return QHostAddress::Null;
}
-
+
/* Get a list of SocksListenAddress lines and return the first valid IP
* address parsed from the list. */
QStringList addrList = getSocksAddressList(errmsg);
@@ -493,7 +511,7 @@
return QHostAddress::LocalHost;
}
-/** Returns a (possibly empty) list of all currently configured
+/** Returns a (possibly empty) list of all currently configured
* SocksListenAddress entries. */
QStringList
TorControl::getSocksAddressList(QString *errmsg)
@@ -526,8 +544,8 @@
quint16 port, socksPort;
QString portString;
QList<quint16> portList;
-
- /* Get the value of the SocksPort configuration variable */
+
+ /* Get the value of the SocksPort configuration variable */
if (getConf("SocksPort", portString, errmsg)) {
socksPort = (quint16)portString.toUInt(&valid);
if (valid) {
@@ -597,72 +615,35 @@
* otherwise it is removed. If set is true, then the given event will be
* registered with Tor. */
bool
-TorControl::setEvent(TorEvents::TorEvent e, QObject *obj,
- bool add, bool set, QString *errmsg)
+TorControl::setEvent(TorEvents::Event e, bool add, bool set, QString *errmsg)
{
- if (add) {
- _torEvents.add(e, obj);
- } else {
- _torEvents.remove(e, obj);
- }
- if (set && isConnected()) {
+ _events = (add ? (_events | e) : (_events & ~e));
+ if (set && isConnected())
return setEvents(errmsg);
- }
return true;
}
-/** Registers for a set of logging events according to the given filter. If
- * the control socket is currently connected, this method will try to register
- * the log events with Tor, otherwise it will simply return true. */
-bool
-TorControl::setLogEvents(uint filter, QObject *obj, QString *errmsg)
-{
- setEvent(TorEvents::LogError , obj, filter & LogEvent::Error , false);
- setEvent(TorEvents::LogWarn , obj, filter & LogEvent::Warn , false);
- setEvent(TorEvents::LogNotice, obj, filter & LogEvent::Notice, false);
- setEvent(TorEvents::LogInfo , obj, filter & LogEvent::Info , false);
- setEvent(TorEvents::LogDebug , obj, filter & LogEvent::Debug , false);
-
- if (isConnected()) {
- bool rc = setEvents(errmsg);
- if (rc && _torProcess)
- /* The control socket is connected and the request for log events from
- * the control port was successful, so we can stop reading from stdout. */
- _torProcess->closeStdout();
- return rc;
- }
- return true;
-}
-
/** Register for the events currently in the event list */
bool
TorControl::setEvents(QString *errmsg)
{
- ControlCommand cmd("SETEVENTS");
- quint32 torVersion = getTorVersion();
+ ControlCommand cmd("SETEVENTS");
- /* Add each event to the argument list */
- foreach (TorEvents::TorEvent e, _torEvents.eventList()) {
- if (torVersion < 0x010203
- && (e == TorEvents::GeneralStatus
- || e == TorEvents::ClientStatus
- || e == TorEvents::ServerStatus)) {
- /* Tor < 0.1.2.3-alpha does not support STATUS_GENERAL, STATUS_CLIENT
- * and STATUS_SERVER events. */
- continue;
- }
- cmd.addArgument(TorEvents::toString(e));
+ for (TorEvents::Event e = TorEvents::EVENT_MIN; e <= TorEvents::EVENT_MAX;) {
+ if (_events & e)
+ cmd.addArgument(TorEvents::toString(e));
+ e = static_cast<TorEvents::Event>(e << 1);
}
return send(cmd, errmsg);
}
-/** Sets each configuration key in <b>map</b> to the value associated
+/** Sets each configuration key in <b>map</b> to the value associated
* with its key. */
bool
TorControl::setConf(QHash<QString,QString> map, QString *errmsg)
{
ControlCommand cmd("SETCONF");
-
+
/* Add each keyvalue to the argument list */
foreach (QString key, map.uniqueKeys()) {
/* If a key has multiple values (e.g., a QMultiHash), they are stored
@@ -679,7 +660,7 @@
cmd.addArgument(key);
}
}
- return send(cmd, errmsg);
+ return send(cmd, errmsg);
}
/** Sets a single configuration key to the given value. */
@@ -741,7 +722,7 @@
QStringList keyval = line.getMessage().split("=");
if (keyval.size() == 2) {
confKey = keyval.at(0);
-
+
if (map.contains(confKey)) {
/* This configuration key has multiple values, so add this one to
* the list. */
@@ -801,7 +782,7 @@
int index = msg.indexOf("=");
QString key = msg.mid(0, index);
QString val;
-
+
if (index > 0 && index < msg.length()-1)
val = msg.mid(index+1);
@@ -811,7 +792,7 @@
confMap.insert(key, values);
} else {
confMap.insert(key, val);
- }
+ }
}
return confMap;
}
@@ -910,14 +891,14 @@
QList<RouterStatus> networkStatus;
int len = networkStatusLines.size();
int i = 0;
-
+
while (i < len) {
/* Extract the "r", "s", and whatever other status lines */
QStringList routerStatusLines;
do {
routerStatusLines << networkStatusLines.at(i);
} while (++i < len && ! networkStatusLines.at(i).startsWith("r "));
-
+
/* Create a new RouterStatus object and add it to the network status, if
* it's valid. */
RouterStatus routerStatus(routerStatusLines);
@@ -940,12 +921,12 @@
foreach (QString line, lines) {
int idx = line.indexOf(" ");
-
+
/* Extract the annotation key */
- key = line.mid(0, idx);
+ key = line.mid(0, idx);
if (key.startsWith("@"))
key = key.remove(0, 1);
-
+
/* Extract the annotation value (if present) */
if (idx > 0 && idx < line.length()-1)
annotations.insert(key, line.mid(idx + 1).trimmed());
@@ -962,7 +943,7 @@
ControlCommand cmd("GETINFO", "circuit-status");
ControlReply reply;
CircuitList circuits;
-
+
if (!send(cmd, reply, errmsg))
return CircuitList();
@@ -995,14 +976,14 @@
ControlReply reply;
QList<Stream> streams;
Stream s;
-
+
if (send(cmd, reply, errmsg)) {
/* Sometimes there is a stream on the first message line */
QString msg = reply.getMessage();
s = Stream::fromString(msg.mid(msg.indexOf("=")+1));
if (s.isValid())
streams << s;
-
+
/* The rest of the streams just come as data, one per line */
foreach (QString line, reply.getData()) {
s = Stream::fromString(line);
Modified: vidalia/trunk/src/torcontrol/TorControl.h
===================================================================
--- vidalia/trunk/src/torcontrol/TorControl.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/TorControl.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -17,6 +17,7 @@
#ifndef _TORCONTROL_H
#define _TORCONTROL_H
+#include "tcglobal.h"
#include "ControlConnection.h"
#include "TorProcess.h"
#include "TorEvents.h"
@@ -24,8 +25,9 @@
#include "RouterDescriptor.h"
#include "RouterStatus.h"
#include "BootstrapStatus.h"
+#include "Circuit.h"
+#include "Stream.h"
#include "AddressMap.h"
-#include "ProtocolInfo.h"
#if defined(Q_OS_WIN32)
#include "TorService.h"
@@ -35,8 +37,9 @@
#include <QHash>
#include <QList>
#include <QStringList>
-#include <QVariant>
+#include <QVariantMap>
+class ProtocolInfo;
/** DescriptorAnnotations stores a map of annotation keys to (possibly empty)
* annotation values. */
@@ -74,7 +77,7 @@
/** Sends an authentication cookie to Tor. */
bool authenticate(const QByteArray cookie, QString *errmsg = 0);
/** Sends an authentication password to Tor. */
- bool authenticate(const QString password = QString(), QString *errmsg = 0);
+ bool authenticate(const QString &password = QString(), QString *errmsg = 0);
/** Sends a PROTOCOLINFO command to Tor and parses the response. */
ProtocolInfo protocolInfo(QString *errmsg = 0);
@@ -84,7 +87,7 @@
/** Returns true if Tor either has an open circuit or (on Tor >=
* 0.2.0.1-alpha) has previously decided it's able to establish a circuit. */
- bool circuitEstablished();
+ bool isCircuitEstablished();
/** Sends a GETINFO message to Tor based on the given keys */
bool getInfo(QHash<QString,QString> &map, QString *errmsg = 0);
@@ -100,7 +103,6 @@
* constructed QVariant on failure. */
QVariant getInfo(const QString &key, QString *errmsg = 0);
-
/** Sends a signal to Tor */
bool signal(TorSignal::Signal sig, QString *errmsg = 0);
@@ -125,13 +127,12 @@
/** Sets an event and its handler. If add is true, then the event is added,
* otherwise it is removed. If set is true, then the given event will be
* registered with Tor. */
- bool setEvent(TorEvents::TorEvent e, QObject *obj,
- bool add, bool set = true, QString *errmsg = 0);
+ bool setEvent(TorEvents::Event e, bool add = true, bool set = true,
+ QString *errmsg = 0);
/** Registers for a set of logging events according to the given filter. */
- bool setLogEvents(uint filter, QObject *obj, QString *errmsg = 0);
+ bool setLogEventFilter(uint filter, QString *errmsg = 0);
/** Register events of interest with Tor */
bool setEvents(QString *errmsg = 0);
-
/** Sets each configuration key in <b>map</b> to the value associated with its key. */
bool setConf(QHash<QString,QString> map, QString *errmsg = 0);
@@ -231,13 +232,81 @@
/** Emitted when Tor rejects our authentication attempt. */
void authenticationFailed(QString errmsg);
+ /** Emitted when Tor writes the message <b>msg</b> to the control port
+ * with message severity <b>level</b>.
+ */
+ void logMessage(tc::Severity level, const QString &msg);
+
+ /** Emitted when Tor sends a bandwidth usage update (roughly once every
+ * second). <b>bytesReceived</b> is the number of bytes read by Tor over
+ * the previous second and <b>bytesWritten</b> is the number of bytes
+ * sent over the same interval.
+ */
+ void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent);
+
+ /** Emitted when the stream status of <b>stream</b> has changed.
+ */
+ void streamStatusChanged(const Stream &stream);
+
+ /** Emitted when the circuit status of <b>circuit</b> has changed.
+ */
+ void circuitStatusChanged(const Circuit &circuit);
+
+ /** Emitted when Tor has mapped the address <b>from</b> to the address
+ * <b>to</b>. <b>expires</b> indicates the time at which when the address
+ * mapping will no longer be considered valid.
+ */
+ void addressMapped(const QString &from, const QString &to,
+ const QDateTime &expires);
+
+ /** Emitted when Tor has received one or more new router descriptors.
+ * <b>ids</b> contains a list of digests of the new descriptors.
+ */
+ void newDescriptors(const QStringList &ids);
+
+ /** Indicates Tor has been able to successfully establish one or more
+ * circuits.
+ */
+ void circuitEstablished();
+
+ /** Indicates that Tor has decided the user's Tor software <b>version</b>
+ * is no longer recommended for some <b>reason</b>. <b>recommended</b> is
+ * a list of Tor software versions that are considered current.
+ */
+ void dangerousTorVersion(tc::TorVersionStatus reason,
+ const QString &version,
+ const QStringList &recommended);
+
+ /** Emitted during Tor's startup process to indicate how far in its
+ * bootstrapping process it has progressed. <b>status</b> may indicate
+ * the current bootstrapping stage or an error during bootstrapping.
+ */
+ void bootstrapStatusChanged(const BootstrapStatus &status);
+
+ /** Emitted when the user attempts to establish a connection to some
+ * destination on port <b>port</b>, which is a port known to use
+ * plaintext connections (as determined by Tor's WarnPlaintextPorts and
+ * RejectPlaintextPorts torrc options). <b>rejected</b> indicates whether
+ * Tor rejected the connection or permitted it to connect anyway.
+ */
+ void dangerousPort(quint16 port, bool rejected);
+
+ /** Emitted when Tor detects a problem with a SOCKS connection from the
+ * user, such as a bad hostname, dangerous SOCKS protocol type, or a bad
+ * hostname. <b>type</b> indicates the type of error encountered and
+ * <b>destination</b> (if non-empty) specifies the attempted connection
+ * destination address or hostname.
+ */
+ void socksError(tc::SocksError type, const QString &destination);
+
private:
/** Instantiates a connection used to talk to Tor's control port */
ControlConnection* _controlConn;
/** Manages and monitors the Tor process */
TorProcess* _torProcess;
/** Keep track of which events we're interested in */
- TorEvents _torEvents;
+ TorEvents* _eventHandler;
+ TorEvents::Events _events;
/** The version of Tor we're currently talking to. */
QString _torVersion;
#if defined(Q_OS_WIN32)
@@ -258,7 +327,7 @@
private slots:
void onStopped(int exitCode, QProcess::ExitStatus exitStatus);
void onDisconnected();
- void onLogStdout(QString severity, QString message);
+ void onLogStdout(const QString &severity, const QString &message);
void onAuthenticated();
};
Modified: vidalia/trunk/src/torcontrol/TorEvents.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/TorEvents.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/TorEvents.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -16,81 +16,36 @@
#include "TorEvents.h"
+#include "ControlReply.h"
+#include "ReplyLine.h"
#include "Circuit.h"
#include "Stream.h"
-#include "UnrecognizedServerStatusEvent.h"
-#include "UnrecognizedClientStatusEvent.h"
-#include "UnrecognizedGeneralStatusEvent.h"
-#include "CircuitEstablishedEvent.h"
-#include "DangerousVersionEvent.h"
-#include "DangerousPortEvent.h"
-#include "BootstrapStatusEvent.h"
+#include "BootstrapStatus.h"
#include "stringutil.h"
-#include <QApplication>
+#include <QMetaType>
/** Format of expiry times in address map events. */
#define DATE_FMT "\"yyyy-MM-dd HH:mm:ss\""
/** Default constructor */
-TorEvents::TorEvents()
+TorEvents::TorEvents(QObject *parent)
+ : QObject(parent)
{
-}
+ qRegisterMetaType<tc::Severity>();
+ qRegisterMetaType<tc::SocksError>();
+ qRegisterMetaType<tc::TorVersionStatus>();
-/** Adds an event and interested object to the list */
-void
-TorEvents::add(TorEvent e, QObject *obj)
-{
- if (!_eventList.values(e).contains(obj)) {
- _eventList.insert(e, obj);
- }
+ qRegisterMetaType<BootstrapStatus>("BootstrapStatus");
+ qRegisterMetaType<Circuit>("Circuit");
+ qRegisterMetaType<Stream>("Stream");
}
-/** Removes <b>obj</b> from the list of target objects for event <b>e</b>. */
-void
-TorEvents::remove(TorEvent e, QObject *obj)
-{
- QMultiHash<TorEvent,QObject*>::iterator i = _eventList.find(e);
- while (i != _eventList.end() && i.key() == e) {
- if (i.value() == obj) {
- _eventList.erase(i);
- break;
- }
- i++;
- }
-}
-
-/** Returns true if an event has any registered handlers */
-bool
-TorEvents::contains(TorEvent event)
-{
- if (_eventList.contains(event)) {
- return (_eventList.values(event).count() > 0);
- }
- return false;
-}
-
-/** Returns the list of events in which we're interested */
-QList<TorEvents::TorEvent>
-TorEvents::eventList()
-{
- return _eventList.keys();
-}
-
-/** Dispatches a given event to all its handler targets. */
-void
-TorEvents::dispatch(TorEvent e, QEvent *event)
-{
- foreach (QObject *obj, _eventList.values(e)) {
- QApplication::postEvent(obj, event);
- }
-}
-
/** Converts an event type to a string Tor understands */
QString
-TorEvents::toString(TorEvent e)
+TorEvents::toString(Event e)
{
QString event;
switch (e) {
@@ -102,7 +57,6 @@
case LogError: event = "ERR"; break;
case CircuitStatus: event = "CIRC"; break;
case StreamStatus: event = "STREAM"; break;
- case OrConnStatus: event = "ORCONN"; break;
case NewDescriptor: event = "NEWDESC"; break;
case AddressMap: event = "ADDRMAP"; break;
case GeneralStatus: event = "STATUS_GENERAL"; break;
@@ -113,27 +67,11 @@
return event;
}
-/** Converts a log severity to its related Tor event */
-TorEvents::TorEvent
-TorEvents::toTorEvent(LogEvent::Severity severity)
-{
- TorEvent e;
- switch (severity) {
- case LogEvent::Debug: e = LogDebug; break;
- case LogEvent::Info: e = LogInfo; break;
- case LogEvent::Notice: e = LogNotice; break;
- case LogEvent::Warn: e = LogWarn; break;
- case LogEvent::Error: e = LogError; break;
- default: e = Unknown; break;
- }
- return e;
-}
-
/** Converts an event in the string form sent by Tor to its enum value */
-TorEvents::TorEvent
+TorEvents::Event
TorEvents::toTorEvent(const QString &event)
{
- TorEvent e;
+ Event e;
if (event == "BW") {
e = Bandwidth;
} else if (event == "CIRC") {
@@ -160,8 +98,6 @@
e = ClientStatus;
} else if (event == "STATUS_SERVER") {
e = ServerStatus;
- } else if (event == "ORCONN") {
- e = OrConnStatus;
} else {
e = Unknown;
}
@@ -170,7 +106,7 @@
/** Parse the event type out of a message line and return the corresponding
* Event enum value */
-TorEvents::TorEvent
+TorEvents::Event
TorEvents::parseEventType(const ReplyLine &line)
{
QString msg = line.getMessage();
@@ -189,7 +125,6 @@
case Bandwidth: handleBandwidthUpdate(line); break;
case CircuitStatus: handleCircuitStatus(line); break;
case StreamStatus: handleStreamStatus(line); break;
- case OrConnStatus: handleOrConnStatus(line); break;
case NewDescriptor: handleNewDescriptor(line); break;
case AddressMap: handleAddressMap(line); break;
@@ -227,7 +162,7 @@
quint64 bytesOut = (quint64)msg.at(2).toULongLong();
/* Post the event to each of the interested targets */
- dispatch(Bandwidth, new BandwidthEvent(bytesIn, bytesOut));
+ emit bandwidthUpdate(bytesIn, bytesOut);
}
}
@@ -251,7 +186,7 @@
/* Post the event to each of the interested targets */
Circuit circ(msg.mid(i));
if (circ.isValid())
- dispatch(CircuitStatus, new CircuitEvent(circ));
+ emit circuitStatusChanged(circ);
}
}
@@ -277,8 +212,9 @@
QString msg = line.getMessage().trimmed();
int i = msg.indexOf(" ") + 1;
if (i > 0) {
- /* Post the event to each of the interested targets */
- dispatch(StreamStatus, new StreamEvent(Stream::fromString(msg.mid(i))));
+ Stream stream = Stream::fromString(msg.mid(i));
+ if (stream.isValid())
+ emit streamStatusChanged(stream);
}
}
@@ -295,37 +231,13 @@
{
QString msg = line.getMessage();
int i = msg.indexOf(" ");
- LogEvent::Severity severity = LogEvent::toSeverity(msg.mid(0, i));
+ tc::Severity severity = tc::severityFromString(msg.mid(0, i));
QString logLine = (line.getData().size() > 0 ? line.getData().join("\n") :
msg.mid(i+1));
- dispatch(toTorEvent(severity), new LogEvent(severity, logLine));
+ emit logMessage(severity, logLine);
}
-/** Handle an OR Connection Status event. The syntax is:
- * "650" SP "ORCONN" SP (ServerID / Target) SP ORStatus
- *
- * ORStatus = "NEW" / "LAUNCHED" / "CONNECTED" / "FAILED" / "CLOSED"
- *
- * NEW is for incoming connections, and LAUNCHED is for outgoing
- * connections. CONNECTED means the TLS handshake has finished (in
- * either direction). FAILED means a connection is being closed
- * that hasn't finished its handshake, and CLOSED is for connections
- * that have handshaked.
- *
- * A ServerID is specified unless it's a NEW connection, in which
- * case we don't know what server it is yet, so we use Address:Port.
- */
-void
-TorEvents::handleOrConnStatus(const ReplyLine &line)
-{
- QStringList msg = line.getMessage().split(" ");
- if (msg.size() >= 3) {
- dispatch(OrConnStatus,
- new OrConnEvent(OrConnEvent::toStatus(msg.at(2)), msg.at(1)));
- }
-}
-
/** Handles a new descriptor event. The format for event messages of this type
* is:
*
@@ -336,9 +248,7 @@
{
QString descs = line.getMessage();
QStringList descList = descs.mid(descs.indexOf(" ")+1).split(" ");
- if (descList.size() > 0) {
- dispatch(NewDescriptor, new NewDescriptorEvent(descList));
- }
+ emit newDescriptors(descList);
}
/** Handles a new or updated address mapping event. The format for event
@@ -357,7 +267,7 @@
QDateTime expires;
if (msg.size() >= 5 && msg.at(3) != "NEVER")
expires = QDateTime::fromString(msg.at(3) + " " + msg.at(4), DATE_FMT);
- dispatch(AddressMap, new AddressMapEvent(msg.at(1), msg.at(2), expires));
+ emit addressMapped(msg.at(1), msg.at(2), expires);
}
}
@@ -375,102 +285,95 @@
* StatusValue = 1*(ALNUM / '_') / QuotedString
*/
void
-TorEvents::handleStatusEvent(TorEvent type, const ReplyLine &line)
+TorEvents::handleStatusEvent(Event e, const ReplyLine &line)
{
QString status;
tc::Severity severity;
QHash<QString,QString> args;
QString msg = line.getMessage();
- severity = tc::toSeverity(msg.section(' ', 1, 1));
+ severity = tc::severityFromString(msg.section(' ', 1, 1));
status = msg.section(' ', 2, 2);
args = string_parse_keyvals(msg.section(' ', 3));
- switch (type) {
+ switch (e) {
case ClientStatus:
- dispatchClientStatusEvent(severity, status, args); break;
- case ServerStatus:
- dispatchServerStatusEvent(severity, status, args); break;
- default:
- dispatchGeneralStatusEvent(severity, status, args);
- }
-}
+ handleClientStatusEvent(severity, status, args);
+ break;
-/** Parses and posts a Tor client status event. */
-void
-TorEvents::dispatchClientStatusEvent(tc::Severity severity,
- const QString &action,
- const QHash<QString,QString> &args)
-{
- ClientStatusEvent *event;
- ClientStatusEvent::Status status
- = ClientStatusEvent::statusFromString(action);
-
- switch (status) {
- case ClientStatusEvent::CircuitEstablished:
- event = new CircuitEstablishedEvent(severity);
+ case ServerStatus:
+ handleServerStatusEvent(severity, status, args);
break;
-
- case ClientStatusEvent::DangerousPort:
- event = new DangerousPortEvent(severity, args.value("PORT").toUInt(),
- DangerousPortEvent::resultFromString(args.value("RESULT")));
- break;
-
- case ClientStatusEvent::Bootstrap:
- event = new BootstrapStatusEvent(BootstrapStatus(severity,
- BootstrapStatus::statusFromString(args.value("TAG")),
- args.value("PROGRESS").toInt(),
- args.value("SUMMARY"),
- args.value("WARNING"),
- tc::toConnectionStatusReason(args.value("REASON")),
- BootstrapStatus::actionFromString(
- args.value("RECOMMENDATION"))));
+ case GeneralStatus:
+ handleGeneralStatusEvent(severity, status, args);
break;
default:
- event = new UnrecognizedClientStatusEvent(severity, action, args);
+ break;
}
- dispatch(ClientStatus, event);
}
-/** Parses and posts a Tor server status event. */
+/** Parses and emits a general Tor status event. */
void
-TorEvents::dispatchServerStatusEvent(tc::Severity severity,
- const QString &action,
- const QHash<QString,QString> &args)
+TorEvents::handleGeneralStatusEvent(tc::Severity severity,
+ const QString &action,
+ const QHash<QString,QString> &args)
{
- ServerStatusEvent *event;
- ServerStatusEvent::Status status
- = ServerStatusEvent::statusFromString(action);
-
- switch (status) {
- default:
- event = new UnrecognizedServerStatusEvent(severity, action, args);
+ if (! action.compare("DANGEROUS_TOR_VERSION", Qt::CaseInsensitive)) {
+ QString reason = args.value("REASON");
+ QString current = args.value("CURRENT");
+ QStringList recommended = args.value("RECOMMENDED")
+ .split(",", QString::SkipEmptyParts);
+ if (! reason.compare("NEW", Qt::CaseInsensitive))
+ emit dangerousTorVersion(tc::NewTorVersion, current, recommended);
+ else if (! reason.compare("UNRECOMMENDED", Qt::CaseInsensitive))
+ emit dangerousTorVersion(tc::UnrecommendedTorVersion, current, recommended);
+ else if (! reason.compare("OBSOLETE", Qt::CaseInsensitive)
+ || ! reason.compare("OLD", Qt::CaseInsensitive))
+ emit dangerousTorVersion(tc::ObsoleteTorVersion, current, recommended);
}
- dispatch(ServerStatus, event);
}
-/** Parses and posts a general Tor status event. */
+/** Parses and emits a Tor client status event. */
void
-TorEvents::dispatchGeneralStatusEvent(tc::Severity severity,
- const QString &action,
- const QHash<QString,QString> &args)
+TorEvents::handleClientStatusEvent(tc::Severity severity,
+ const QString &action,
+ const QHash<QString,QString> &args)
{
- GeneralStatusEvent *event;
- GeneralStatusEvent::Status status
- = GeneralStatusEvent::statusFromString(action);
-
- switch (status) {
- case GeneralStatusEvent::DangerousTorVersion:
- /* Dangerous Tor version ("DANGEROUS_VERSION") */
- event = new DangerousVersionEvent(severity,
- DangerousVersionEvent::reasonFromString(args.value("REASON")),
- args.value("CURRENT"),
- args.value("RECOMMENDED").split(",", QString::SkipEmptyParts));
- break;
- default:
- event = new UnrecognizedGeneralStatusEvent(severity, action, args);
+ if (! action.compare("CIRCUIT_ESTABLISHED", Qt::CaseInsensitive)) {
+ emit circuitEstablished();
+ } else if (! action.compare("DANGEROUS_PORT", Qt::CaseInsensitive)) {
+ bool reject = ! args.value("RESULT").compare("REJECT", Qt::CaseInsensitive);
+ emit dangerousPort(args.value("PORT").toUInt(), reject);
+ } else if (! action.compare("DANGEROUS_SOCKS", Qt::CaseInsensitive)) {
+ emit socksError(tc::DangerousSocksTypeError, args.value("ADDRESS"));
+ } else if (! action.compare("SOCKS_UNKNOWN_PROTOCOL", Qt::CaseInsensitive)) {
+ emit socksError(tc::UnknownSocksProtocolError, QString());
+ } else if (! action.compare("SOCKS_BAD_HOSTNAME", Qt::CaseInsensitive)) {
+ emit socksError(tc::BadSocksHostnameError, args.value("HOSTNAME"));
+ } else if (! action.compare("BOOTSTRAP", Qt::CaseInsensitive)) {
+ BootstrapStatus status
+ = BootstrapStatus(severity,
+ BootstrapStatus::statusFromString(args.value("TAG")),
+ args.value("PROGRESS").toInt(),
+ args.value("SUMMARY"),
+ args.value("WARNING"),
+ tc::connectionStatusReasonFromString(args.value("REASON")),
+ BootstrapStatus::actionFromString(
+ args.value("RECOMMENDATION")));
+ emit bootstrapStatusChanged(status);
}
- dispatch(GeneralStatus, event);
}
+/** Parses and emits a Tor server status event. */
+void
+TorEvents::handleServerStatusEvent(tc::Severity severity,
+ const QString &action,
+ const QHash<QString,QString> &args)
+{
+ Q_UNUSED(severity);
+ Q_UNUSED(action);
+ Q_UNUSED(args);
+}
+
+
Modified: vidalia/trunk/src/torcontrol/TorEvents.h
===================================================================
--- vidalia/trunk/src/torcontrol/TorEvents.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/TorEvents.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -1,6 +1,6 @@
/*
** This file is part of Vidalia, and is subject to the license terms in the
-** LICENSE file, found in the top level directory of this distribution. If
+** LICENSE file, found in the top level directory of this distribution. If
** you did not receive the LICENSE file with this file, you may obtain it
** from the Vidalia source package distributed by the Vidalia Project at
** http://www.vidalia-project.net/. No part of Vidalia, including this file,
@@ -8,7 +8,7 @@
** the terms described in the LICENSE file.
*/
-/*
+/*
** \file TorEvents.h
** \version $Id$
** \brief Parses and dispatches events from Tor
@@ -17,77 +17,134 @@
#ifndef _TOREVENTS_H
#define _TOREVENTS_H
-#include "LogEvent.h"
-#include "BandwidthEvent.h"
-#include "CircuitEvent.h"
-#include "StreamEvent.h"
-#include "OrConnEvent.h"
-#include "NewDescriptorEvent.h"
-#include "AddressMapEvent.h"
-#include "StatusEvent.h"
-#include "ControlReply.h"
-#include "eventtype.h"
+#include "tcglobal.h"
#include <QObject>
#include <QMultiHash>
#include <QList>
+#include <QFlags>
+class Circuit;
+class Stream;
+class BootstrapStatus;
+class ControlReply;
+class ReplyLine;
+class QString;
+class QDateTime;
+class QHostAddress;
+
+
class TorEvents : public QObject
{
Q_OBJECT
public:
/** Asynchronous events sent from Tor to the controller */
- enum TorEvent {
- Unknown,
- Bandwidth,
- LogDebug, LogInfo, LogNotice, LogWarn, LogError,
- CircuitStatus,
- StreamStatus,
- OrConnStatus,
- NewDescriptor,
- AddressMap,
- GeneralStatus,
- ClientStatus,
- ServerStatus
+ enum Event {
+ Unknown = 0,
+ Bandwidth = (1u << 0),
+ LogDebug = (1u << 1),
+ LogInfo = (1u << 2),
+ LogNotice = (1u << 3),
+ LogWarn = (1u << 4),
+ LogError = (1u << 5),
+ CircuitStatus = (1u << 6),
+ StreamStatus = (1u << 7),
+ OrConnStatus = (1u << 8),
+ NewDescriptor = (1u << 9),
+ AddressMap = (1u << 10),
+ GeneralStatus = (1u << 11),
+ ClientStatus = (1u << 12),
+ ServerStatus = (1u << 13)
};
-
+ static const Event EVENT_MIN = TorEvents::Bandwidth;
+ static const Event EVENT_MAX = TorEvents::ServerStatus;
+ Q_DECLARE_FLAGS(Events, Event);
+
/** Default Constructor */
- TorEvents();
+ TorEvents(QObject *parent = 0);
- /** Adds an event and interested object to the event list */
- void add(TorEvent event, QObject *obj);
- /** Removes <b>obj</b> from the list of target objects for event
- * <b>e</b>. */
- void remove(TorEvent event, QObject *obj);
- /** Returns true if an event has any registered handlers */
- bool contains(TorEvent event);
- /** Returns the list of events in which we're interested */
- QList<TorEvent> eventList();
-
/** Parses an event message and emits the proper signal */
void handleEvent(const ControlReply &reply);
- /** Dispatches a given event to all its handler targets. */
- void dispatch(TorEvent e, QEvent *event);
-
/** Converts an Event to a string */
- static QString toString(TorEvents::TorEvent e);
- /** Converts a log severity to an event */
- static TorEvent toTorEvent(LogEvent::Severity severity);
+ static QString toString(TorEvents::Event e);
+signals:
+ /** Emitted when Tor writes the message <b>msg</b> to the control port
+ * with message severity <b>level</b>.
+ */
+ void logMessage(tc::Severity level, const QString &msg);
+ /** Emitted when Tor sends a bandwidth usage update (roughly once every
+ * second). <b>bytesReceived</b> is the number of bytes read by Tor over
+ * the previous second and <b>bytesWritten</b> is the number of bytes
+ * sent over the same interval.
+ */
+ void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent);
+
+ /** Emitted when the stream status of <b>stream</b> has changed.
+ */
+ void streamStatusChanged(const Stream &stream);
+
+ /** Emitted when the circuit status of <b>circuit</b> has changed.
+ */
+ void circuitStatusChanged(const Circuit &circuit);
+
+ /** Emitted when Tor has mapped the address <b>from</b> to the address
+ * <b>to</b>. <b>expires</b> indicates the time at which when the address
+ * mapping will no longer be considered valid.
+ */
+ void addressMapped(const QString &from, const QString &to,
+ const QDateTime &expires);
+
+ /** Emitted when Tor has received one or more new router descriptors.
+ * <b>ids</b> contains a list of digests of the new descriptors.
+ */
+ void newDescriptors(const QStringList &ids);
+
+ /** Indicates Tor has been able to successfully establish one or more
+ * circuits.
+ */
+ void circuitEstablished();
+
+ /** Indicates that Tor has decided the user's Tor software <b>version</b>
+ * is no longer recommended for some <b>reason</b>. <b>recommended</b> is
+ * a list of Tor software versions that are considered current.
+ */
+ void dangerousTorVersion(tc::TorVersionStatus reason,
+ const QString &version,
+ const QStringList &recommended);
+
+ /** Emitted during Tor's startup process to indicate how far in its
+ * bootstrapping process it has progressed. <b>status</b> may indicate
+ * the current bootstrapping stage or an error during bootstrapping.
+ */
+ void bootstrapStatusChanged(const BootstrapStatus &status);
+
+ /** Emitted when the user attempts to establish a connection to some
+ * destination on port <b>port</b>, which is a port known to use
+ * plaintext connections (as determined by Tor's WarnPlaintextPorts and
+ * RejectPlaintextPorts torrc options). <b>rejected</b> indicates whether
+ * Tor rejected the connection or permitted it to connect anyway.
+ */
+ void dangerousPort(quint16 port, bool rejected);
+
+ /** Emitted when Tor detects a problem with a SOCKS connection from the
+ * user, such as a bad hostname, dangerous SOCKS protocol type, or a bad
+ * hostname. <b>type</b> indicates the type of error encountered and
+ * <b>destination</b> (if non-empty) specifies the attempted connection
+ * destination address or hostname.
+ */
+ void socksError(tc::SocksError error, const QString &destination);
+
private:
- /** Stores a mapping of Tor events to a list of the objects interested in
- * hearing about those events. */
- QMultiHash<TorEvent, QObject*> _eventList;
-
/** Parses the event type from the event message */
- static TorEvent parseEventType(const ReplyLine &line);
+ static Event parseEventType(const ReplyLine &line);
/** Converts a string to an Event */
- static TorEvent toTorEvent(const QString &event);
-
+ static Event toTorEvent(const QString &event);
+
/** Handle a bandwidth update event */
void handleBandwidthUpdate(const ReplyLine &line);
/** Handle a circuit status event */
@@ -102,22 +159,24 @@
void handleNewDescriptor(const ReplyLine &line);
/** Handles a new or updated address map event. */
void handleAddressMap(const ReplyLine &line);
+
/** Handles a Tor status event. */
- void handleStatusEvent(TorEvent type, const ReplyLine &line);
-
+ void handleStatusEvent(Event type, const ReplyLine &line);
+ /** Parses and posts a general Tor status event. */
+ void handleGeneralStatusEvent(tc::Severity severity,
+ const QString &action,
+ const QHash<QString,QString> &args);
/** Parses and posts a Tor client status event. */
- void dispatchClientStatusEvent(tc::Severity severity,
- const QString &action,
- const QHash<QString,QString> &args);
+ void handleClientStatusEvent(tc::Severity severity,
+ const QString &action,
+ const QHash<QString,QString> &args);
/** Parses and posts a Tor server status event. */
- void dispatchServerStatusEvent(tc::Severity severity,
- const QString &action,
- const QHash<QString,QString> &args);
- /** Parses and posts a general Tor status event. */
- void dispatchGeneralStatusEvent(tc::Severity severity,
- const QString &action,
- const QHash<QString,QString> &args);
+ void handleServerStatusEvent(tc::Severity severity,
+ const QString &action,
+ const QHash<QString,QString> &args);
};
+Q_DECLARE_OPERATORS_FOR_FLAGS(TorEvents::Events)
+
#endif
Modified: vidalia/trunk/src/torcontrol/tcglobal.cpp
===================================================================
--- vidalia/trunk/src/torcontrol/tcglobal.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/tcglobal.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -53,7 +53,7 @@
/* Converts <b>str</b> to a ConnectionStatusReason enum value. */
ConnectionStatusReason
-toConnectionStatusReason(const QString &str)
+connectionStatusReasonFromString(const QString &str)
{
if (str.isEmpty())
return UnrecognizedReason;
@@ -80,18 +80,18 @@
/* Converts <b>str</b> to a Severity enum value. */
Severity
-toSeverity(const QString &str)
+severityFromString(const QString &str)
{
if (!str.compare("DEBUG", Qt::CaseInsensitive))
- return SeverityDebug;
+ return DebugSeverity;
if (!str.compare("INFO", Qt::CaseInsensitive))
- return SeverityInfo;
+ return InfoSeverity;
if (!str.compare("NOTICE", Qt::CaseInsensitive))
- return SeverityNotice;
+ return NoticeSeverity;
if (!str.compare("WARN", Qt::CaseInsensitive))
- return SeverityWarn;
+ return WarnSeverity;
if (!str.compare("ERR", Qt::CaseInsensitive))
- return SeverityError;
+ return ErrorSeverity;
return UnrecognizedSeverity;
}
Modified: vidalia/trunk/src/torcontrol/tcglobal.h
===================================================================
--- vidalia/trunk/src/torcontrol/tcglobal.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/torcontrol/tcglobal.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -18,8 +18,8 @@
#define _TCGLOBAL_H
#include <QString>
+#include <QMetaType>
-
namespace tc {
/** Helper class to handle formatting log messages with arguments. */
class DebugMessage {
@@ -68,19 +68,33 @@
};
/** Severity values used in log message and status events. */
enum Severity {
- UnrecognizedSeverity, /**< An unrecognized severity value. */
- SeverityDebug, /**< Hyper-verbose events used for debugging. */
- SeverityInfo, /**< Verbose events that can occur frequently. */
- SeverityNotice, /**< A not-so-bad event. */
- SeverityWarn, /**< An important, but non-fatal event. */
- SeverityError /**< A critical event. */
+ UnrecognizedSeverity = 0, /**< An unrecognized severity value. */
+ DebugSeverity = (1u<<4), /**< Hyper-verbose events used for debugging. */
+ InfoSeverity = (1u<<3), /**< Verbose events that can occur frequently. */
+ NoticeSeverity = (1u<<2), /**< A not-so-bad event. */
+ WarnSeverity = (1u<<1), /**< An important, but non-fatal event. */
+ ErrorSeverity = (1u<<0) /**< A critical event. */
};
+ /** SOCKS error types used by Tor status event notifications. These are
+ * emitted in the TorControl::socksError() signal. */
+ enum SocksError {
+ DangerousSocksTypeError, /**< The SOCKS type uses only IP addresses. */
+ UnknownSocksProtocolError, /**< Unknown SOCKS protocol type. */
+ BadSocksHostnameError /**< Application provided an invalid hostname. */
+ };
+ /** Reasons that use of the user's current Tor version would be
+ * discouraged. */
+ enum TorVersionStatus {
+ ObsoleteTorVersion,
+ UnrecommendedTorVersion,
+ NewTorVersion
+ };
/** Converts <b>str</b> to a Severity enum value. */
- Severity toSeverity(const QString &str);
+ Severity severityFromString(const QString &str);
/** Converts <b>str</b> to a ConnectionStatusReason enum value. */
- ConnectionStatusReason toConnectionStatusReason(const QString &str);
+ ConnectionStatusReason connectionStatusReasonFromString(const QString &str);
/** Creates a new message using <b>fmt</b> and a severity level of
* QtDebugMsg. */
@@ -99,5 +113,9 @@
DebugMessage fatal(const QString &fmt);
}
+Q_DECLARE_METATYPE(tc::Severity)
+Q_DECLARE_METATYPE(tc::SocksError)
+Q_DECLARE_METATYPE(tc::TorVersionStatus)
+
#endif
Modified: vidalia/trunk/src/vidalia/MainWindow.cpp
===================================================================
--- vidalia/trunk/src/vidalia/MainWindow.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/MainWindow.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -28,9 +28,7 @@
#include "UpdatesAvailableDialog.h"
#endif
-#include "ClientStatusEvent.h"
-#include "DangerousVersionEvent.h"
-#include "DangerousPortEvent.h"
+#include "ProtocolInfo.h"
#include "net.h"
#include "file.h"
@@ -130,24 +128,36 @@
_status = Unset;
_isVidaliaRunningTor = false;
updateTorStatus(Stopped);
-
+
/* Create a new TorControl object, used to communicate with Tor */
_torControl = Vidalia::torControl();
connect(_torControl, SIGNAL(started()), this, SLOT(started()));
connect(_torControl, SIGNAL(startFailed(QString)),
- this, SLOT(startFailed(QString)));
+ this, SLOT(startFailed(QString)));
connect(_torControl, SIGNAL(stopped(int, QProcess::ExitStatus)),
- this, SLOT(stopped(int, QProcess::ExitStatus)));
+ this, SLOT(stopped(int, QProcess::ExitStatus)));
connect(_torControl, SIGNAL(connected()), this, SLOT(connected()));
connect(_torControl, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(_torControl, SIGNAL(connectFailed(QString)),
- this, SLOT(connectFailed(QString)));
+ this, SLOT(connectFailed(QString)));
connect(_torControl, SIGNAL(authenticated()), this, SLOT(authenticated()));
connect(_torControl, SIGNAL(authenticationFailed(QString)),
- this, SLOT(authenticationFailed(QString)));
- _torControl->setEvent(TorEvents::ClientStatus, this, true);
- _torControl->setEvent(TorEvents::GeneralStatus, this, true);
+ this, SLOT(authenticationFailed(QString)));
+ _torControl->setEvent(TorEvents::GeneralStatus);
+ connect(_torControl, SIGNAL(dangerousTorVersion(tc::TorVersionStatus,
+ QString, QStringList)),
+ this, SLOT(dangerousTorVersion(tc::TorVersionStatus,
+ QString, QStringList)));
+
+ _torControl->setEvent(TorEvents::ClientStatus);
+ connect(_torControl, SIGNAL(bootstrapStatusChanged(BootstrapStatus)),
+ this, SLOT(bootstrapStatusChanged(BootstrapStatus)));
+ connect(_torControl, SIGNAL(circuitEstablished()),
+ this, SLOT(circuitEstablished()));
+ connect(_torControl, SIGNAL(dangerousPort(quint16, bool)),
+ this, SLOT(warnDangerousPort(quint16, bool)));
+
/* Create a new HelperProcess object, used to start the web browser */
_browserProcess = new HelperProcess(this);
connect(_browserProcess, SIGNAL(finished(int, QProcess::ExitStatus)),
@@ -266,47 +276,6 @@
#endif
}
-/** Catches and processes Tor client and general status events. */
-void
-MainWindow::customEvent(QEvent *event)
-{
- if (event->type() == CustomEventType::ClientStatusEvent) {
- ClientStatusEvent *cse = dynamic_cast<ClientStatusEvent *>(event);
- if (!cse)
- return;
-
- if (cse->status() == ClientStatusEvent::CircuitEstablished) {
- circuitEstablished();
- cse->accept();
- } else if (cse->status() == ClientStatusEvent::Bootstrap) {
- BootstrapStatusEvent *bse = dynamic_cast<BootstrapStatusEvent *>(cse);
- if (bse)
- bootstrapStatusChanged(bse->status());
- cse->accept();
- } else if (cse->status() == ClientStatusEvent::DangerousPort) {
- DangerousPortEvent *dpe = dynamic_cast<DangerousPortEvent *>(cse);
- if (dpe) {
- bool rejected = (dpe->result() == DangerousPortEvent::Reject);
- warnDangerousPort(dpe->port(), rejected);
- }
- cse->accept();
- }
- } else if (event->type() == CustomEventType::GeneralStatusEvent) {
- GeneralStatusEvent *gse = dynamic_cast<GeneralStatusEvent *>(event);
- if (!gse)
- return;
-
- if (gse->status() == GeneralStatusEvent::DangerousTorVersion) {
- DangerousVersionEvent *dve = dynamic_cast<DangerousVersionEvent *>(gse);
- if (dve && (dve->reason() == DangerousVersionEvent::ObsoleteVersion
- || dve->reason() == DangerousVersionEvent::UnrecommendedVersion)) {
- dangerousTorVersion();
- }
- gse->accept();
- }
- }
-}
-
/** Called when the application has started and the main event loop is
* running. */
void
@@ -340,7 +309,7 @@
if (settings.isAutoUpdateEnabled()) {
QDateTime lastCheckedAt = settings.lastCheckedForUpdates();
if (UpdateProcess::shouldCheckForUpdates(lastCheckedAt)) {
- if (settings.runTorAtStart() && ! _torControl->circuitEstablished()) {
+ if (settings.runTorAtStart() && ! _torControl->isCircuitEstablished()) {
/* We started Tor but it hasn't bootstrapped yet, so give it a bit
* before we decide to check for updates. If Tor manages to build a
* circuit before this timer times out, we will stop the timer and
@@ -785,7 +754,7 @@
MainWindow::bootstrapStatusChanged(const BootstrapStatus &bs)
{
int percentComplete = STARTUP_PROGRESS_BOOTSTRAPPING + bs.percentComplete();
- bool warn = (bs.severity() == tc::SeverityWarn &&
+ bool warn = (bs.severity() == tc::WarnSeverity &&
bs.recommendedAction() != BootstrapStatus::RecommendIgnore);
QString description;
@@ -1370,7 +1339,7 @@
serverSettings.configurePortForwarding();
/* Check if Tor has a circuit established */
- if (_torControl->circuitEstablished())
+ if (_torControl->isCircuitEstablished())
circuitEstablished();
/* Check the status of Tor's version */
if (_torControl->getTorVersion() >= 0x020001)
@@ -1541,15 +1510,30 @@
if (!status.compare("old", Qt::CaseInsensitive)
|| !status.compare("unrecommended", Qt::CaseInsensitive)
|| !status.compare("obsolete", Qt::CaseInsensitive)) {
- dangerousTorVersion();
+ displayTorVersionWarning();
}
}
}
+/** Called when Tor thinks its version is old or unrecommended, and displays
+ * a message notifying the user. */
+void
+MainWindow::dangerousTorVersion(tc::TorVersionStatus reason,
+ const QString ¤t,
+ const QStringList &recommended)
+{
+ Q_UNUSED(current);
+ Q_UNUSED(recommended);
+
+ if (reason == tc::ObsoleteTorVersion
+ || reason == tc::UnrecommendedTorVersion)
+ displayTorVersionWarning();
+}
+
/** Called when Tor thinks its version is old or unrecommended, and displays a
* message notifying the user. */
void
-MainWindow::dangerousTorVersion()
+MainWindow::displayTorVersionWarning()
{
static bool alreadyWarned = false;
Modified: vidalia/trunk/src/vidalia/MainWindow.h
===================================================================
--- vidalia/trunk/src/vidalia/MainWindow.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/MainWindow.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -31,7 +31,6 @@
#include "NetViewer.h"
#include "TorControl.h"
-#include "BootstrapStatusEvent.h"
#if defined(USE_AUTOUPDATE)
#include "UpdateProcess.h"
@@ -60,8 +59,6 @@
virtual void setVisible(bool visible);
protected:
- /** Catches and processes Tor client status events. */
- virtual void customEvent(QEvent *event);
/** Called when the user changes the UI translation. */
virtual void retranslateUi();
@@ -128,6 +125,21 @@
/** Called when the proxy server fails to start */
void onProxyFailed(QString errmsg);
+ /** Called when Tor has successfully established a circuit. */
+ void circuitEstablished();
+ /** Called when Tor thinks the user has tried to connect to a port that
+ * typically is used for unencrypted applications. Warns the user and allows
+ * them to ignore future warnings on <b>port</b>. */
+ void warnDangerousPort(quint16 port, bool rejected);
+ /** Called when Tor's bootstrapping status changes. <b>bse</b> represents
+ * Tor's current estimate of its bootstrapping progress. */
+ void bootstrapStatusChanged(const BootstrapStatus &bs);
+ /** Called when Tor thinks its version is old or unrecommended, and displays
+ * a message notifying the user. */
+ void dangerousTorVersion(tc::TorVersionStatus reason,
+ const QString &version,
+ const QStringList &recommended);
+
#if defined(USE_AUTOUPDATE)
/** Called when the user clicks the 'Check Now' button in the General
* settings page. */
@@ -138,7 +150,8 @@
/** Called when the check for software updates fails. */
void checkForUpdatesFailed(const QString &errmsg);
/** Called when there is an update available for installation. */
- void updatesAvailable(UpdateProcess::BundleInfo bi, const PackageList &packageList);
+ void updatesAvailable(UpdateProcess::BundleInfo bi,
+ const PackageList &packageList);
/** Stops Tor (if necessary), installs any available for <b>bi</b>, and
* restarts Tor (if necessary). */
void installUpdates(UpdateProcess::BundleInfo bi);
@@ -194,21 +207,13 @@
* depending on the current platform. <b>cookiePath</b> can point to either
* a cookie file or a directory containing the cookie file. */
QByteArray loadControlCookie(QString cookiePath = QString());
- /** Called when Tor has successfully established a circuit. */
- void circuitEstablished();
/** Checks the status of the current version of Tor to see if it's old,
* unrecommended, or obsolete. */
void checkTorVersion();
- /** Called when Tor thinks its version is old or unrecommended, and displays
- * a message notifying the user. */
- void dangerousTorVersion();
- /** Called when Tor thinks the user has tried to connect to a port that
- * typically is used for unencrypted applications. Warns the user and allows
- * them to ignore future warnings on <b>port</b>. */
- void warnDangerousPort(quint16 port, bool rejected);
- /** Called when Tor's bootstrapping status changes. <b>bse</b> represents
- * Tor's current estimate of its bootstrapping progress. */
- void bootstrapStatusChanged(const BootstrapStatus &bs);
+ /** Alerts the user that their current Tor version is either obsolete or
+ * no longer recommended. If Vidalia was built with auto-update support,
+ * they will be given the option to check for available updates. */
+ void displayTorVersionWarning();
/** Sets the visibility of the startup status description and progress bar
* to <b>visible</b>. */
void setStartupProgressVisible(bool visible);
Modified: vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.cpp
===================================================================
--- vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -15,7 +15,6 @@
*/
#include "BandwidthGraph.h"
-#include "BandwidthEvent.h"
#include "Vidalia.h"
#define BWGRAPH_LINE_SEND (1u<<0)
@@ -46,6 +45,11 @@
/* Invoke Qt Designer generated QObject setup routine */
ui.setupUi(this);
+ /* Ask Tor to notify us about bandwidth updates */
+ Vidalia::torControl()->setEvent(TorEvents::Bandwidth);
+ connect(Vidalia::torControl(), SIGNAL(bandwidthUpdate(quint64,quint64)),
+ this, SLOT(updateGraph(quint64,quint64)));
+
/* Pressing 'Esc' or 'Ctrl+W' will close the window */
setShortcut("Esc", SLOT(close()));
setShortcut("Ctrl+W", SLOT(close()));
@@ -53,10 +57,6 @@
/* Bind events to actions */
createActions();
- /* Ask Tor to notify us about bandwidth updates */
- _torControl = Vidalia::torControl();
- _torControl->setEvent(TorEvents::Bandwidth, this, true);
-
/* Initialize Sent/Receive data counters */
reset();
/* Hide Bandwidth Graph Settings frame */
@@ -84,35 +84,24 @@
ui.retranslateUi(this);
}
-/** Custom event handler. Checks if the event is a bandwidth update event. If it
- * is, it will add the data point to the history and updates the graph. */
-void
-BandwidthGraph::customEvent(QEvent *event)
-{
- if (event->type() == CustomEventType::BandwidthEvent) {
- BandwidthEvent *bw = (BandwidthEvent *)event;
- updateGraph(bw->bytesRead(), bw->bytesWritten());
- }
-}
-
/** Binds events to actions. */
void
BandwidthGraph::createActions()
{
connect(ui.btnToggleSettings, SIGNAL(toggled(bool)),
- this, SLOT(showSettingsFrame(bool)));
+ this, SLOT(showSettingsFrame(bool)));
connect(ui.btnReset, SIGNAL(clicked()),
- this, SLOT(reset()));
+ this, SLOT(reset()));
connect(ui.btnSaveSettings, SIGNAL(clicked()),
- this, SLOT(saveChanges()));
+ this, SLOT(saveChanges()));
connect(ui.btnCancelSettings, SIGNAL(clicked()),
- this, SLOT(cancelChanges()));
-
+ this, SLOT(cancelChanges()));
+
connect(ui.sldrOpacity, SIGNAL(valueChanged(int)),
- this, SLOT(setOpacity(int)));
+ this, SLOT(setOpacity(int)));
}
/** Adds new data to the graph. */
@@ -164,8 +153,8 @@
{
/* Set to current time */
ui.statusbar->showMessage(tr("Since:") + " " +
- QDateTime::currentDateTime()
- .toString(DATETIME_FMT));
+ QDateTime::currentDateTime()
+ .toString(DATETIME_FMT));
/* Reset the graph */
ui.frmGraph->resetGraph();
}
Modified: vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.h
===================================================================
--- vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/bwgraph/BandwidthGraph.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -42,8 +42,6 @@
void showWindow();
protected:
- /** Called to deliver a bandwidth update event from Tor. */
- void customEvent(QEvent *event);
/** Called when the user changes the UI translation. */
virtual void retranslateUi();
Modified: vidalia/trunk/src/vidalia/log/LogTreeItem.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/LogTreeItem.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/log/LogTreeItem.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -30,8 +30,8 @@
/** Default constructor. */
-LogTreeItem::LogTreeItem(LogEvent::Severity type, QString message,
- QDateTime timestamp)
+LogTreeItem::LogTreeItem(tc::Severity type, const QString &message,
+ const QDateTime ×tamp)
: QTreeWidgetItem()
{
static quint32 seqnum = 0;
@@ -57,7 +57,7 @@
/** Sets the item's log time. */
void
-LogTreeItem::setTimestamp(QDateTime timestamp)
+LogTreeItem::setTimestamp(const QDateTime ×tamp)
{
QString strtime = timestamp.toString(DATETIME_FMT);
setText(COL_TIME, strtime);
@@ -66,16 +66,16 @@
/** Sets the item's severity and the appropriate background color. */
void
-LogTreeItem::setSeverity(LogEvent::Severity type)
+LogTreeItem::setSeverity(tc::Severity type)
{
/* Change row and text color for serious warnings and errors. */
- if (type == LogEvent::Error) {
+ if (type == tc::ErrorSeverity) {
/* Critical messages are red with white text. */
for (int i = 0; i < 3; i++) {
setBackgroundColor(i, Qt::red);
setTextColor(i, Qt::white);
}
- } else if (type == LogEvent::Warn) {
+ } else if (type == tc::WarnSeverity) {
/* Warning messages are yellow with black text. */
for (int i = 0; i < 3; i++) {
setBackgroundColor(i, Qt::yellow);
@@ -83,23 +83,23 @@
}
setTextAlignment(COL_TYPE, Qt::AlignCenter);
- setText(COL_TYPE, LogEvent::severityToString(type));
+ setText(COL_TYPE, severityToString(type));
setData(COL_TYPE, ROLE_TYPE, (uint)type);
}
/** Sets the item's message text. */
void
-LogTreeItem::setMessage(QString message)
+LogTreeItem::setMessage(const QString &message)
{
setText(COL_MESG, message);
setToolTip(COL_MESG, string_wrap(message, 80, " ", "\r\n"));
}
/** Returns the severity associated with this log item. */
-LogEvent::Severity
+tc::Severity
LogTreeItem::severity() const
{
- return (LogEvent::Severity)data(COL_TYPE, ROLE_TYPE).toUInt();
+ return (tc::Severity)data(COL_TYPE, ROLE_TYPE).toUInt();
}
/** Returns the timestamp for this log message. */
@@ -116,6 +116,22 @@
return text(COL_MESG);
}
+/** Converts a tc::Severity enum value to a localized string description. */
+QString
+LogTreeItem::severityToString(tc::Severity severity)
+{
+ QString str;
+ switch (severity) {
+ case tc::DebugSeverity: str = tr("Debug"); break;
+ case tc::InfoSeverity: str = tr("Info"); break;
+ case tc::NoticeSeverity: str = tr("Notice"); break;
+ case tc::WarnSeverity: str = tr("Warning"); break;
+ case tc::ErrorSeverity: str = tr("Error"); break;
+ default: str = tr("Unknown"); break;
+ }
+ return str;
+}
+
/** Compares <b>other</b> to this log message item based on the current sort
* column. */
bool
Modified: vidalia/trunk/src/vidalia/log/LogTreeItem.h
===================================================================
--- vidalia/trunk/src/vidalia/log/LogTreeItem.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/log/LogTreeItem.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -17,7 +17,7 @@
#ifndef _LOGTREEITEM_H
#define _LOGTREEITEM_H
-#include "LogEvent.h"
+#include "TorControl.h"
#include <QTreeWidgetItem>
#include <QDateTime>
@@ -26,24 +26,26 @@
class LogTreeItem : public QTreeWidgetItem
{
+ Q_DECLARE_TR_FUNCTIONS(LogTreeItem)
+
public:
/** Default constructor. */
- LogTreeItem(LogEvent::Severity type, QString message,
- QDateTime timestamp = QDateTime::currentDateTime());
+ LogTreeItem(tc::Severity type, const QString &message,
+ const QDateTime ×tamp = QDateTime::currentDateTime());
/** Sets the item's log time. */
- void setTimestamp(QDateTime timestamp);
+ void setTimestamp(const QDateTime ×tamp);
/** Sets the item's severity and appropriate background color. */
- void setSeverity(LogEvent::Severity type);
+ void setSeverity(tc::Severity type);
/** Sets the item's message text. */
- void setMessage(QString message);
+ void setMessage(const QString &message);
/** Returns this message's sequence number. */
quint32 id() const { return _seqnum; }
/** Returns the timestamp for this log message. */
QDateTime timestamp() const;
/** Returns the severity associated with this log item. */
- LogEvent::Severity severity() const;
+ tc::Severity severity() const;
/** Returns the message associated with this log item. */
QString message() const;
@@ -53,6 +55,9 @@
* column and order. */
virtual bool operator<(const QTreeWidgetItem &other) const;
+ /** Converts a tc::Severity enum value to a localized string description.*/
+ static QString severityToString(tc::Severity severity);
+
private:
quint32 _seqnum; /**< Sequence number used to disambiguate messages with
the same timestamp. */
Modified: vidalia/trunk/src/vidalia/log/LogTreeWidget.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/LogTreeWidget.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/log/LogTreeWidget.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -167,7 +167,7 @@
/** Adds a log item to the tree and returns a pointer to the new item. */
LogTreeItem*
-LogTreeWidget::log(LogEvent::Severity type, QString message)
+LogTreeWidget::log(tc::Severity type, const QString &message)
{
int oldScrollValue;
QScrollBar *scrollBar = verticalScrollBar();
Modified: vidalia/trunk/src/vidalia/log/LogTreeWidget.h
===================================================================
--- vidalia/trunk/src/vidalia/log/LogTreeWidget.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/log/LogTreeWidget.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -18,8 +18,9 @@
#define _LOGTREEWIDGET_H
#include "LogTreeItem.h"
-#include "LogEvent.h"
+#include "TorControl.h"
+
#include <QList>
#include <QString>
#include <QStringList>
@@ -58,7 +59,7 @@
void filter(uint filter);
/** Adds a log item to the tree. */
- LogTreeItem* log(LogEvent::Severity type, QString message);
+ LogTreeItem* log(tc::Severity severity, const QString &message);
/** Searches the log for entries that contain the given text. */
QList<LogTreeItem *> find(QString text, bool highlight = true);
Modified: vidalia/trunk/src/vidalia/log/MessageLog.cpp
===================================================================
--- vidalia/trunk/src/vidalia/log/MessageLog.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/log/MessageLog.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -32,7 +32,7 @@
#define SETTING_ENABLE_LOGFILE "EnableLogFile"
#define SETTING_LOGFILE "LogFile"
#define DEFAULT_MSG_FILTER \
- (LogEvent::Error|LogEvent::Warn|LogEvent::Notice)
+ (tc::ErrorSeverity|tc::WarnSeverity|tc::NoticeSeverity)
#define DEFAULT_MAX_MSG_COUNT 50
#define DEFAULT_ENABLE_LOGFILE false
#if defined(Q_OS_WIN32)
@@ -49,10 +49,10 @@
/** Constructor. The constructor will load the message log's settings from
* VidaliSettings and register for log events according to the most recently
- * set severity filter.
+ * set severity filter.
* \param torControl A TorControl object used to register for log events.
* \param parent The parent widget of this MessageLog object.
- * \param flags Any desired window creation flags.
+ * \param flags Any desired window creation flags.
*/
MessageLog::MessageLog(QWidget *parent, Qt::WFlags flags)
: VidaliaWindow("MessageLog", parent, flags)
@@ -62,26 +62,27 @@
/* Create necessary Message Log QObjects */
_torControl = Vidalia::torControl();
-
+ connect(_torControl, SIGNAL(logMessage(tc::Severity, QString)),
+ this, SLOT(log(tc::Severity, QString)));
+
/* Bind events to actions */
createActions();
/* Set tooltips for necessary widgets */
setToolTips();
-
+
/* Load the message log's stored settings */
loadSettings();
- /* Sort in ascending chronological order */
- ui.lstMessages->sortItems(LogTreeWidget::TimeColumn,
- Qt::AscendingOrder);
+ /* Sort in ascending chronological order */
+ ui.lstMessages->sortItems(LogTreeWidget::TimeColumn,
+ Qt::AscendingOrder);
}
/** Default Destructor. Simply frees up any memory allocated for member
* variables. */
MessageLog::~MessageLog()
{
- _torControl->setLogEvents(0, this);
_logFile.close();
}
@@ -89,29 +90,29 @@
void
MessageLog::createActions()
{
- connect(ui.actionSave_Selected, SIGNAL(triggered()),
- this, SLOT(saveSelected()));
-
- connect(ui.actionSave_All, SIGNAL(triggered()),
- this, SLOT(saveAll()));
-
+ connect(ui.actionSave_Selected, SIGNAL(triggered()),
+ this, SLOT(saveSelected()));
+
+ connect(ui.actionSave_All, SIGNAL(triggered()),
+ this, SLOT(saveAll()));
+
connect(ui.actionCopy, SIGNAL(triggered()),
- this, SLOT(copy()));
+ this, SLOT(copy()));
connect(ui.actionFind, SIGNAL(triggered()),
- this, SLOT(find()));
+ this, SLOT(find()));
connect(ui.actionHelp, SIGNAL(triggered()),
- this, SLOT(help()));
-
+ this, SLOT(help()));
+
connect(ui.btnSaveSettings, SIGNAL(clicked()),
- this, SLOT(saveSettings()));
+ this, SLOT(saveSettings()));
connect(ui.btnCancelSettings, SIGNAL(clicked()),
- this, SLOT(cancelChanges()));
+ this, SLOT(cancelChanges()));
connect(ui.btnBrowse, SIGNAL(clicked()),
- this, SLOT(browse()));
+ this, SLOT(browse()));
#if defined(Q_WS_MAC)
ui.actionHelp->setShortcut(QString("Ctrl+?"));
@@ -136,7 +137,7 @@
ui.chkTorInfo->setToolTip(tr("Messages that appear frequently \n"
"during normal Tor operation."));
ui.chkTorDebug->setToolTip(tr("Hyper-verbose messages primarily of \n"
- "interest to Tor developers."));
+ "interest to Tor developers."));
}
/** Called when the user changes the UI translation. */
@@ -168,13 +169,13 @@
/* Set the checkboxes accordingly */
_filter = getSetting(SETTING_MSG_FILTER, DEFAULT_MSG_FILTER).toUInt();
- ui.chkTorErr->setChecked(_filter & LogEvent::Error);
- ui.chkTorWarn->setChecked(_filter & LogEvent::Warn);
- ui.chkTorNote->setChecked(_filter & LogEvent::Notice);
- ui.chkTorInfo->setChecked(_filter & LogEvent::Info);
- ui.chkTorDebug->setChecked(_filter & LogEvent::Debug);
+ ui.chkTorErr->setChecked(_filter & tc::ErrorSeverity);
+ ui.chkTorWarn->setChecked(_filter & tc::WarnSeverity);
+ ui.chkTorNote->setChecked(_filter & tc::NoticeSeverity);
+ ui.chkTorInfo->setChecked(_filter & tc::InfoSeverity);
+ ui.chkTorDebug->setChecked(_filter & tc::DebugSeverity);
registerLogEvents();
-
+
/* Filter the message log */
QApplication::setOverrideCursor(Qt::WaitCursor);
ui.lstMessages->filter(_filter);
@@ -186,9 +187,20 @@
void
MessageLog::registerLogEvents()
{
- QString errmsg;
_filter = getSetting(SETTING_MSG_FILTER, DEFAULT_MSG_FILTER).toUInt();
- if (!_torControl->setLogEvents(_filter, this, &errmsg)) {
+ _torControl->setEvent(TorEvents::LogDebug,
+ _filter & tc::DebugSeverity, false);
+ _torControl->setEvent(TorEvents::LogInfo,
+ _filter & tc::InfoSeverity, false);
+ _torControl->setEvent(TorEvents::LogNotice,
+ _filter & tc::NoticeSeverity, false);
+ _torControl->setEvent(TorEvents::LogWarn,
+ _filter & tc::WarnSeverity, false);
+ _torControl->setEvent(TorEvents::LogError,
+ _filter & tc::ErrorSeverity, false);
+
+ QString errmsg;
+ if (_torControl->isConnected() && !_torControl->setEvents(&errmsg)) {
VMessageBox::warning(this, tr("Error Setting Filter"),
p(tr("Vidalia was unable to register for Tor's log events.")) + p(errmsg),
VMessageBox::Ok);
@@ -200,7 +212,7 @@
* file will be rotated to the new filename. In the case that the new filename
* can not be openend, the old file will remain open and writable. */
bool
-MessageLog::rotateLogFile(QString filename)
+MessageLog::rotateLogFile(const QString &filename)
{
QString errmsg;
if (_enableLogging) {
@@ -242,29 +254,29 @@
/* Update the maximum displayed item count */
saveSetting(SETTING_MAX_MSG_COUNT, ui.spnbxMaxCount->value());
ui.lstMessages->setMaximumMessageCount(ui.spnbxMaxCount->value());
-
+
/* Save message filter and refilter the list */
uint filter = 0;
- ADD_TO_FILTER(filter, LogEvent::Error, ui.chkTorErr->isChecked());
- ADD_TO_FILTER(filter, LogEvent::Warn, ui.chkTorWarn->isChecked());
- ADD_TO_FILTER(filter, LogEvent::Notice, ui.chkTorNote->isChecked());
- ADD_TO_FILTER(filter, LogEvent::Info, ui.chkTorInfo->isChecked());
- ADD_TO_FILTER(filter, LogEvent::Debug, ui.chkTorDebug->isChecked());
+ ADD_TO_FILTER(filter, tc::ErrorSeverity, ui.chkTorErr->isChecked());
+ ADD_TO_FILTER(filter, tc::WarnSeverity, ui.chkTorWarn->isChecked());
+ ADD_TO_FILTER(filter, tc::NoticeSeverity, ui.chkTorNote->isChecked());
+ ADD_TO_FILTER(filter, tc::InfoSeverity, ui.chkTorInfo->isChecked());
+ ADD_TO_FILTER(filter, tc::DebugSeverity, ui.chkTorDebug->isChecked());
saveSetting(SETTING_MSG_FILTER, filter);
registerLogEvents();
-
+
/* Filter the message log */
QApplication::setOverrideCursor(Qt::WaitCursor);
ui.lstMessages->filter(_filter);
QApplication::restoreOverrideCursor();
-
+
/* Hide the settings frame and reset toggle button*/
- ui.actionSettings->toggle();
+ ui.actionSettings->toggle();
}
/** Simply restores the previously saved settings and hides the settings
* frame. */
-void
+void
MessageLog::cancelChanges()
{
/* Hide the settings frame and reset toggle button */
@@ -287,10 +299,10 @@
}
/** Saves the given list of items to a file.
- * \param items A list of log message items to save.
+ * \param items A list of log message items to save.
*/
void
-MessageLog::save(QStringList messages)
+MessageLog::save(const QStringList &messages)
{
if (!messages.size()) {
return;
@@ -298,15 +310,15 @@
QString fileName = QFileDialog::getSaveFileName(this,
tr("Save Log Messages"),
- "VidaliaLog-" +
+ "VidaliaLog-" +
QDateTime::currentDateTime().toString("MM.dd.yyyy")
+ ".txt", tr("Text Files (*.txt)"));
-
+
/* If the choose to save */
if (!fileName.isEmpty()) {
LogFile logFile;
QString errmsg;
-
+
/* If can't write to file, show error message */
if (!logFile.open(fileName, &errmsg)) {
VMessageBox::warning(this, tr("Vidalia"),
@@ -316,7 +328,7 @@
VMessageBox::Ok);
return;
}
-
+
/* Write out the message log to the file */
QApplication::setOverrideCursor(Qt::WaitCursor);
foreach (QString msg, messages) {
@@ -353,7 +365,7 @@
/** Prompts the user for a search string. If the search string is not found in
* any of the currently displayed log entires, then a message will be
- * displayed for the user informing them that no matches were found.
+ * displayed for the user informing them that no matches were found.
* \sa search()
*/
void
@@ -362,13 +374,13 @@
bool ok;
QString text = QInputDialog::getText(this, tr("Find in Message Log"),
tr("Find:"), QLineEdit::Normal, QString(), &ok);
-
+
if (ok && !text.isEmpty()) {
/* Search for the user-specified text */
QList<LogTreeItem *> results = ui.lstMessages->find(text);
if (!results.size()) {
- VMessageBox::information(this, tr("Not Found"),
- p(tr("Search found 0 matches.")),
+ VMessageBox::information(this, tr("Not Found"),
+ p(tr("Search found 0 matches.")),
VMessageBox::Ok);
} else {
/* Set the focus to the first match */
@@ -382,14 +394,14 @@
* \param type The message's severity type.
* \param message The log message to be added.
*/
-void
-MessageLog::log(LogEvent::Severity type, QString message)
+void
+MessageLog::log(tc::Severity type, const QString &message)
{
/* Only add the message if it's not being filtered out */
if (_filter & (uint)type) {
/* Add the message to the list and scroll to it if necessary. */
- LogTreeItem *item = ui.lstMessages->log(type, message);
-
+ LogTreeItem *item = ui.lstMessages->log(type, message);
+
/* This is a workaround to force Qt to update the statusbar text (if any
* is currently displayed) to reflect the new message added. */
QString currStatusTip = ui.statusbar->currentMessage();
@@ -397,7 +409,7 @@
currStatusTip = ui.lstMessages->statusTip();
ui.statusbar->showMessage(currStatusTip);
}
-
+
/* If we're saving log messages to a file, go ahead and do that now */
if (_enableLogging) {
_logFile << item->toString();
@@ -405,20 +417,6 @@
}
}
-/** Custom event handler. Checks if the event is a log event. If it is, then
- * it will write the message to the message log.
- * \param event The custom log event.
- */
-void
-MessageLog::customEvent(QEvent *event)
-{
- if (event->type() == CustomEventType::LogEvent) {
- LogEvent *e = (LogEvent *)event;
- log(e->severity(), e->message());
- e->accept();
- }
-}
-
/** Displays help information about the message log. */
void
MessageLog::help()
Modified: vidalia/trunk/src/vidalia/log/MessageLog.h
===================================================================
--- vidalia/trunk/src/vidalia/log/MessageLog.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/log/MessageLog.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -20,15 +20,12 @@
#include "ui_MessageLog.h"
#include "VidaliaWindow.h"
#include "LogFile.h"
-#include "LogTreeItem.h"
#include "TorControl.h"
#include "VidaliaSettings.h"
-#include <QMainWindow>
-#include <QStringList>
-#include <QResizeEvent>
+class LogTreeItem;
+class QStringList;
-
class MessageLog : public VidaliaWindow
{
Q_OBJECT
@@ -40,12 +37,12 @@
~MessageLog();
protected:
- /** Called to deliver custom event types */
- void customEvent(QEvent *event);
/** Called when the user changes the UI translation. */
virtual void retranslateUi();
private slots:
+ /** Adds the passed message to the message log as the specified type **/
+ void log(tc::Severity severity, const QString &msg);
/** Called when the user triggers the save all action **/
void saveAll();
/** Called when the user triggers save selected action **/
@@ -75,11 +72,9 @@
/** Registers the current message filter with Tor */
void registerLogEvents();
/** Saves the given list of items to a file */
- void save(QStringList messages);
- /** Adds the passed message to the message log as the specified type **/
- void log(LogEvent::Severity, QString msg);
+ void save(const QStringList &messages);
/** Rotates the log file based on the filename and the current logging status. */
- bool rotateLogFile(QString filename);
+ bool rotateLogFile(const QString &filename);
/** A pointer to a TorControl object, used to register for log events */
TorControl* _torControl;
Modified: vidalia/trunk/src/vidalia/network/NetViewer.cpp
===================================================================
--- vidalia/trunk/src/vidalia/network/NetViewer.cpp 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/network/NetViewer.cpp 2009-08-17 02:25:08 UTC (rev 4054)
@@ -55,11 +55,27 @@
/* Get the TorControl object */
_torControl = Vidalia::torControl();
- _torControl->setEvent(TorEvents::NewDescriptor, this, true);
- _torControl->setEvent(TorEvents::CircuitStatus, this, true);
- _torControl->setEvent(TorEvents::StreamStatus, this, true);
- _torControl->setEvent(TorEvents::AddressMap, this, true);
+ connect(_torControl, SIGNAL(authenticated()),
+ this, SLOT(onAuthenticated()));
+ connect(_torControl, SIGNAL(disconnected()),
+ this, SLOT(onDisconnected()));
+ _torControl->setEvent(TorEvents::CircuitStatus);
+ connect(_torControl, SIGNAL(circuitStatusChanged(Circuit)),
+ this, SLOT(addCircuit(Circuit)));
+
+ _torControl->setEvent(TorEvents::StreamStatus);
+ connect(_torControl, SIGNAL(streamStatusChanged(Stream)),
+ this, SLOT(addStream(Stream)));
+
+ _torControl->setEvent(TorEvents::AddressMap);
+ connect(_torControl, SIGNAL(addressMapped(QString, QString, QDateTime)),
+ this, SLOT(addressMapped(QString, QString, QDateTime)));
+
+ _torControl->setEvent(TorEvents::NewDescriptor);
+ connect(_torControl, SIGNAL(newDescriptors(QStringList)),
+ this, SLOT(newDescriptors(QStringList)));
+
/* Change the column widths of the tree widgets */
ui.treeRouterList->header()->
resizeSection(RouterListWidget::StatusColumn, 25);
@@ -120,10 +136,6 @@
connect(ui.treeCircuitList, SIGNAL(closeStream(StreamId)),
_torControl, SLOT(closeStream(StreamId)));
- /* Respond to changes in the status of the control connection */
- connect(_torControl, SIGNAL(authenticated()), this, SLOT(onAuthenticated()));
- connect(_torControl, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
-
/* Connect the slot to find out when geoip information has arrived */
connect(&_geoip, SIGNAL(resolved(int, QList<GeoIp>)),
this, SLOT(resolved(int, QList<GeoIp>)));
@@ -188,35 +200,6 @@
ui.actionRefresh->setEnabled(false);
}
-/** Custom event handler. Catches the new descriptor events. */
-void
-NetViewer::customEvent(QEvent *event)
-{
- int type = event->type();
-
- if (type == CustomEventType::NewDescriptorEvent) {
- /* New router descriptor, so load it and add it to the list */
- NewDescriptorEvent *nde = (NewDescriptorEvent *)event;
- newDescriptors(nde->descriptorIDs());
- } else if (type == CustomEventType::CircuitEvent) {
- /* New or updated circuit information */
- CircuitEvent *ce = (CircuitEvent *)event;
- addCircuit(ce->circuit());
- } else if (type == CustomEventType::StreamEvent) {
- /* New or updated stream information */
- StreamEvent *se = (StreamEvent *)event;
- addStream(se->stream());
- } else if (type == CustomEventType::AddressMapEvent) {
- /* New or updated address mapping. We store the reverse of the new
- * mapping, so we can go from an IP address back to a hostname. */
- AddressMapEvent *ae = (AddressMapEvent *)event;
- _addressMap.add(ae->to(), ae->from(), ae->expires());
- }
-
- /* Update the world map */
- _map->update();
-}
-
/** Reloads the lists of routers, circuits that Tor knows about */
void
NetViewer::refresh()
@@ -314,6 +297,13 @@
}
}
+void
+NetViewer::addressMapped(const QString &from, const QString &to,
+ const QDateTime &expires)
+{
+ _addressMap.add(to, from, expires);
+}
+
/** Called when the user selects the "Help" action from the toolbar. */
void
NetViewer::help()
Modified: vidalia/trunk/src/vidalia/network/NetViewer.h
===================================================================
--- vidalia/trunk/src/vidalia/network/NetViewer.h 2009-08-16 20:59:49 UTC (rev 4053)
+++ vidalia/trunk/src/vidalia/network/NetViewer.h 2009-08-17 02:25:08 UTC (rev 4054)
@@ -36,7 +36,9 @@
#include <QTimer>
#include <QHash>
+class QDateTime;
+
class NetViewer : public VidaliaWindow
{
Q_OBJECT
@@ -55,12 +57,24 @@
/** Adds <b>stream</b> to the list of circuits, under the appropriate
* circuit. */
void addStream(const Stream &stream);
+
+ /** Called when a NEWDESC event arrives. Retrieves new router descriptors
+ * for the router identities given in <b>ids</b> and updates the router list
+ * and network map.
+ */
+ void newDescriptors(const QStringList &ids);
+
+ /** Called when Tor has mapped the address <b>from</b> to the address
+ * <b>to</b>. <b>expires</b> indicates the time at which when the address
+ * mapping will no longer be considered valid.
+ */
+ void addressMapped(const QString &from, const QString &to,
+ const QDateTime &expires);
+
/** Clears all known information */
void clear();
protected:
- /** Called to deliver a NEWDESC event from Tor. */
- void customEvent(QEvent *event);
/** Called when the user changes the UI translation. */
void retranslateUi();
@@ -104,10 +118,6 @@
/** Adds a router to our list of servers and retrieves geographic location
* information for the server. */
void addRouter(const RouterDescriptor &rd);
- /** Called when a NEWDESC event arrives. Retrieves new router descriptors
- * for the router identities given in <b>ids</b> and updates the router list
- * and network map. */
- void newDescriptors(const QStringList &ids);
/** TorControl object used to talk to Tor. */
TorControl* _torControl;