Vidalia 0.2.10
|
00001 /* 00002 ** This file is part of Vidalia, and is subject to the license terms in the 00003 ** LICENSE file, found in the top level directory of this distribution. If 00004 ** you did not receive the LICENSE file with this file, you may obtain it 00005 ** from the Vidalia source package distributed by the Vidalia Project at 00006 ** http://www.vidalia-project.net/. No part of Vidalia, including this file, 00007 ** may be copied, modified, propagated, or distributed except according to 00008 ** the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file TorEvents.h 00013 ** \version $Id: TorEvents.h 4060 2009-08-20 03:41:13Z edmanm $ 00014 ** \brief Parses and dispatches events from Tor 00015 */ 00016 00017 #ifndef _TOREVENTS_H 00018 #define _TOREVENTS_H 00019 00020 #include "tcglobal.h" 00021 00022 #include <QObject> 00023 #include <QMultiHash> 00024 #include <QList> 00025 #include <QFlags> 00026 00027 class Circuit; 00028 class Stream; 00029 class BootstrapStatus; 00030 class ControlReply; 00031 class ReplyLine; 00032 00033 class QString; 00034 class QDateTime; 00035 class QHostAddress; 00036 00037 00038 class TorEvents : public QObject 00039 { 00040 Q_OBJECT 00041 00042 public: 00043 /** Asynchronous events sent from Tor to the controller */ 00044 enum Event { 00045 Unknown = 0, 00046 Bandwidth = (1u << 0), 00047 LogDebug = (1u << 1), 00048 LogInfo = (1u << 2), 00049 LogNotice = (1u << 3), 00050 LogWarn = (1u << 4), 00051 LogError = (1u << 5), 00052 CircuitStatus = (1u << 6), 00053 StreamStatus = (1u << 7), 00054 OrConnStatus = (1u << 8), 00055 NewDescriptor = (1u << 9), 00056 AddressMap = (1u << 10), 00057 GeneralStatus = (1u << 11), 00058 ClientStatus = (1u << 12), 00059 ServerStatus = (1u << 13) 00060 }; 00061 static const Event EVENT_MIN = TorEvents::Bandwidth; 00062 static const Event EVENT_MAX = TorEvents::ServerStatus; 00063 Q_DECLARE_FLAGS(Events, Event); 00064 00065 /** Default Constructor */ 00066 TorEvents(QObject *parent = 0); 00067 00068 /** Parses an event message and emits the proper signal */ 00069 void handleEvent(const ControlReply &reply); 00070 00071 /** Converts an Event to a string */ 00072 static QString toString(TorEvents::Event e); 00073 00074 signals: 00075 /** Emitted when Tor writes the message <b>msg</b> to the control port 00076 * with message severity <b>level</b>. 00077 */ 00078 void logMessage(tc::Severity level, const QString &msg); 00079 00080 /** Emitted when Tor sends a bandwidth usage update (roughly once every 00081 * second). <b>bytesReceived</b> is the number of bytes read by Tor over 00082 * the previous second and <b>bytesWritten</b> is the number of bytes 00083 * sent over the same interval. 00084 */ 00085 void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent); 00086 00087 /** Emitted when the stream status of <b>stream</b> has changed. 00088 */ 00089 void streamStatusChanged(const Stream &stream); 00090 00091 /** Emitted when the circuit status of <b>circuit</b> has changed. 00092 */ 00093 void circuitStatusChanged(const Circuit &circuit); 00094 00095 /** Emitted when Tor has mapped the address <b>from</b> to the address 00096 * <b>to</b>. <b>expires</b> indicates the time at which when the address 00097 * mapping will no longer be considered valid. 00098 */ 00099 void addressMapped(const QString &from, const QString &to, 00100 const QDateTime &expires); 00101 00102 /** Emitted when Tor has received one or more new router descriptors. 00103 * <b>ids</b> contains a list of digests of the new descriptors. 00104 */ 00105 void newDescriptors(const QStringList &ids); 00106 00107 /** Indicates Tor has been able to successfully establish one or more 00108 * circuits. 00109 */ 00110 void circuitEstablished(); 00111 00112 /** Indicates that Tor has decided the user's Tor software <b>version</b> 00113 * is no longer recommended for some <b>reason</b>. <b>recommended</b> is 00114 * a list of Tor software versions that are considered current. 00115 */ 00116 void dangerousTorVersion(tc::TorVersionStatus reason, 00117 const QString &version, 00118 const QStringList &recommended); 00119 00120 /** Emitted during Tor's startup process to indicate how far in its 00121 * bootstrapping process it has progressed. <b>status</b> may indicate 00122 * the current bootstrapping stage or an error during bootstrapping. 00123 */ 00124 void bootstrapStatusChanged(const BootstrapStatus &status); 00125 00126 /** Emitted when the user attempts to establish a connection to some 00127 * destination on port <b>port</b>, which is a port known to use 00128 * plaintext connections (as determined by Tor's WarnPlaintextPorts and 00129 * RejectPlaintextPorts torrc options). <b>rejected</b> indicates whether 00130 * Tor rejected the connection or permitted it to connect anyway. 00131 */ 00132 void dangerousPort(quint16 port, bool rejected); 00133 00134 /** Emitted when Tor detects a problem with a SOCKS connection from the 00135 * user, such as a bad hostname, dangerous SOCKS protocol type, or a bad 00136 * hostname. <b>type</b> indicates the type of error encountered and 00137 * <b>destination</b> (if non-empty) specifies the attempted connection 00138 * destination address or hostname. 00139 */ 00140 void socksError(tc::SocksError error, const QString &destination); 00141 00142 /** Emitted when Tor has encountered an internal bug. <b>reason</b> is 00143 * Tor's description of the bug. 00144 */ 00145 void bug(const QString &reason); 00146 00147 /** Emitted when Tor decides the client's external IP address has changed 00148 * to <b>ip</b>. If <b>hostname</b> is non-empty, Tor obtained the new 00149 * value for <b>ip</b> by resolving <b>hostname</b>. 00150 */ 00151 void externalAddressChanged(const QHostAddress &ip, const QString &hostname); 00152 00153 /** Indicates that Tor has determined the client's clock is potentially 00154 * skewed by <b>skew</b> seconds relative to <b>source</b>. 00155 */ 00156 void clockSkewed(int skew, const QString &source); 00157 00158 /** Emitted when Tor determines that the user's DNS provider is providing 00159 * an address for non-existent domains when it should really be saying 00160 * "NXDOMAIN". 00161 */ 00162 void dnsHijacked(); 00163 00164 /** Emitted when Tor determines that the user's DNS provider is providing 00165 * a hijacked address even for well-known websites. 00166 */ 00167 void dnsUseless(); 00168 00169 /** Indicates Tor has started testing the reachability of its OR port 00170 * using the IP address <b>ip</b> and port <b>port</b>. 00171 */ 00172 void checkingOrPortReachability(const QHostAddress &ip, quint16 port); 00173 00174 /** Tor has completed testing the reachability of its OR port using 00175 * the IP address <b>ip</b> and port <b>port</b>. If the user's OR port 00176 * was reachable, <b>reachable</b> will be set to true. 00177 */ 00178 void orPortReachabilityFinished(const QHostAddress &ip, quint16 port, 00179 bool reachable); 00180 00181 /** Indicates Tor has started testing the reachability of its directory 00182 * port using the IP address <b>ip</b> and port <b>port</b>. 00183 */ 00184 void checkingDirPortReachability(const QHostAddress &ip, quint16 port); 00185 00186 /** Tor has completed testing the reachability of its directory port using 00187 * the IP address <b>ip</b> and port <b>port</b>. If the user's directory 00188 * port was reachable, <b>reachable</b> will be set to true. 00189 */ 00190 void dirPortReachabilityFinished(const QHostAddress &ip, quint16 port, 00191 bool reachable); 00192 00193 /** Emitted when the directory authority with IP address <b>ip</b> and 00194 * port <b>port</b> rejected the user's server descriptor. <b>reason</b> 00195 * describes why the descriptor was rejected (e.g., malformed, skewed 00196 * clock, etc.). 00197 */ 00198 void serverDescriptorRejected(const QHostAddress &ip, quint16 port, 00199 const QString &reason); 00200 00201 /** Emitted when the directory authority with IP address <b>ip</b> and 00202 * port <b>port</b> accepted the user's server descriptor. 00203 */ 00204 void serverDescriptorAccepted(const QHostAddress &ip, quint16 port); 00205 00206 /** Emitted when at least one directory authority has accepted the user's 00207 * server descriptor. 00208 */ 00209 void serverDescriptorAccepted(); 00210 00211 private: 00212 /** Parses the event type from the event message */ 00213 static Event parseEventType(const ReplyLine &line); 00214 /** Converts a string to an Event */ 00215 static Event toTorEvent(const QString &event); 00216 /** Splits a string in the form "IP:PORT" into a QHostAddress and quint16 00217 * pair. If either portion is invalid, a default-constructed QPair() is 00218 * returned. */ 00219 static QPair<QHostAddress,quint16> splitAddress(const QString &address); 00220 00221 /** Handle a bandwidth update event */ 00222 void handleBandwidthUpdate(const ReplyLine &line); 00223 /** Handle a circuit status event */ 00224 void handleCircuitStatus(const ReplyLine &line); 00225 /** Handle a stream status event */ 00226 void handleStreamStatus(const ReplyLine &line); 00227 /** Handle a log message event */ 00228 void handleLogMessage(const ReplyLine &line); 00229 /** Handle an OR connection status event. */ 00230 void handleOrConnStatus(const ReplyLine &line); 00231 /** Handles a new list of descriptors event. */ 00232 void handleNewDescriptor(const ReplyLine &line); 00233 /** Handles a new or updated address map event. */ 00234 void handleAddressMap(const ReplyLine &line); 00235 00236 /** Handles a Tor status event. */ 00237 void handleStatusEvent(Event type, const ReplyLine &line); 00238 /** Parses and posts a general Tor status event. */ 00239 void handleGeneralStatusEvent(tc::Severity severity, 00240 const QString &action, 00241 const QHash<QString,QString> &args); 00242 /** Parses and posts a Tor client status event. */ 00243 void handleClientStatusEvent(tc::Severity severity, 00244 const QString &action, 00245 const QHash<QString,QString> &args); 00246 /** Parses and posts a Tor server status event. */ 00247 void handleServerStatusEvent(tc::Severity severity, 00248 const QString &action, 00249 const QHash<QString,QString> &args); 00250 }; 00251 00252 Q_DECLARE_OPERATORS_FOR_FLAGS(TorEvents::Events) 00253 00254 #endif 00255