Vidalia  0.3.1
TorEvents.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If
4 ** you did not receive the LICENSE file with this file, you may obtain it
5 ** from the Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file TorEvents.h
13 ** \brief Parses and dispatches events from Tor
14 */
15 
16 #ifndef _TOREVENTS_H
17 #define _TOREVENTS_H
18 
19 #include "tcglobal.h"
20 
21 #include <QObject>
22 #include <QMultiHash>
23 #include <QList>
24 #include <QFlags>
25 
26 class Circuit;
27 class Stream;
28 class BootstrapStatus;
29 class ControlReply;
30 class ReplyLine;
31 
32 class QString;
33 class QDateTime;
34 class QHostAddress;
35 
36 
37 class TorEvents : public QObject
38 {
39  Q_OBJECT
40 
41 public:
42  /** Asynchronous events sent from Tor to the controller */
43  enum Event {
44  Unknown = 0,
45  Bandwidth = (1u << 0),
46  LogDebug = (1u << 1),
47  LogInfo = (1u << 2),
48  LogNotice = (1u << 3),
49  LogWarn = (1u << 4),
50  LogError = (1u << 5),
51  CircuitStatus = (1u << 6),
52  StreamStatus = (1u << 7),
53  OrConnStatus = (1u << 8),
54  NewDescriptor = (1u << 9),
55  AddressMap = (1u << 10),
56  GeneralStatus = (1u << 11),
57  ClientStatus = (1u << 12),
58  ServerStatus = (1u << 13)
59  };
62  Q_DECLARE_FLAGS(Events, Event);
63 
64  /** Default Constructor */
65  TorEvents(QObject *parent = 0);
66 
67  /** Parses an event message and emits the proper signal */
68  void handleEvent(const ControlReply &reply);
69 
70  /** Converts an Event to a string */
71  static QString toString(TorEvents::Event e);
72 
73 signals:
74  /** Emitted when Tor writes the message <b>msg</b> to the control port
75  * with message severity <b>level</b>.
76  */
77  void logMessage(tc::Severity level, const QString &msg);
78 
79  /** Emitted when Tor sends a bandwidth usage update (roughly once every
80  * second). <b>bytesReceived</b> is the number of bytes read by Tor over
81  * the previous second and <b>bytesWritten</b> is the number of bytes
82  * sent over the same interval.
83  */
84  void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent);
85 
86  /** Emitted when the stream status of <b>stream</b> has changed.
87  */
88  void streamStatusChanged(const Stream &stream);
89 
90  /** Emitted when the circuit status of <b>circuit</b> has changed.
91  */
92  void circuitStatusChanged(const Circuit &circuit);
93 
94  /** Emitted when Tor has mapped the address <b>from</b> to the address
95  * <b>to</b>. <b>expires</b> indicates the time at which when the address
96  * mapping will no longer be considered valid.
97  */
98  void addressMapped(const QString &from, const QString &to,
99  const QDateTime &expires);
100 
101  /** Emitted when Tor has received one or more new router descriptors.
102  * <b>ids</b> contains a list of digests of the new descriptors.
103  */
104  void newDescriptors(const QStringList &ids);
105 
106  /** Indicates Tor has been able to successfully establish one or more
107  * circuits.
108  */
109  void circuitEstablished();
110 
111  /** Indicates that Tor has decided the user's Tor software <b>version</b>
112  * is no longer recommended for some <b>reason</b>. <b>recommended</b> is
113  * a list of Tor software versions that are considered current.
114  */
116  const QString &version,
117  const QStringList &recommended);
118 
119  /** Emitted during Tor's startup process to indicate how far in its
120  * bootstrapping process it has progressed. <b>status</b> may indicate
121  * the current bootstrapping stage or an error during bootstrapping.
122  */
123  void bootstrapStatusChanged(const BootstrapStatus &status);
124 
125  /** Emitted when the user attempts to establish a connection to some
126  * destination on port <b>port</b>, which is a port known to use
127  * plaintext connections (as determined by Tor's WarnPlaintextPorts and
128  * RejectPlaintextPorts torrc options). <b>rejected</b> indicates whether
129  * Tor rejected the connection or permitted it to connect anyway.
130  */
131  void dangerousPort(quint16 port, bool rejected);
132 
133  /** Emitted when Tor detects a problem with a SOCKS connection from the
134  * user, such as a bad hostname, dangerous SOCKS protocol type, or a bad
135  * hostname. <b>type</b> indicates the type of error encountered and
136  * <b>destination</b> (if non-empty) specifies the attempted connection
137  * destination address or hostname.
138  */
139  void socksError(tc::SocksError error, const QString &destination);
140 
141  /** Emitted when Tor has encountered an internal bug. <b>reason</b> is
142  * Tor's description of the bug.
143  */
144  void bug(const QString &reason);
145 
146  /** Emitted when Tor decides the client's external IP address has changed
147  * to <b>ip</b>. If <b>hostname</b> is non-empty, Tor obtained the new
148  * value for <b>ip</b> by resolving <b>hostname</b>.
149  */
150  void externalAddressChanged(const QHostAddress &ip, const QString &hostname);
151 
152  /** Indicates that Tor has determined the client's clock is potentially
153  * skewed by <b>skew</b> seconds relative to <b>source</b>.
154  */
155  void clockSkewed(int skew, const QString &source);
156 
157  /** Emitted when Tor determines that the user's DNS provider is providing
158  * an address for non-existent domains when it should really be saying
159  * "NXDOMAIN".
160  */
161  void dnsHijacked();
162 
163  /** Emitted when Tor determines that the user's DNS provider is providing
164  * a hijacked address even for well-known websites.
165  */
166  void dnsUseless();
167 
168  /** Indicates Tor has started testing the reachability of its OR port
169  * using the IP address <b>ip</b> and port <b>port</b>.
170  */
171  void checkingOrPortReachability(const QHostAddress &ip, quint16 port);
172 
173  /** Tor has completed testing the reachability of its OR port using
174  * the IP address <b>ip</b> and port <b>port</b>. If the user's OR port
175  * was reachable, <b>reachable</b> will be set to true.
176  */
177  void orPortReachabilityFinished(const QHostAddress &ip, quint16 port,
178  bool reachable);
179 
180  /** Indicates Tor has started testing the reachability of its directory
181  * port using the IP address <b>ip</b> and port <b>port</b>.
182  */
183  void checkingDirPortReachability(const QHostAddress &ip, quint16 port);
184 
185  /** Tor has completed testing the reachability of its directory port using
186  * the IP address <b>ip</b> and port <b>port</b>. If the user's directory
187  * port was reachable, <b>reachable</b> will be set to true.
188  */
189  void dirPortReachabilityFinished(const QHostAddress &ip, quint16 port,
190  bool reachable);
191 
192  /** Emitted when the directory authority with IP address <b>ip</b> and
193  * port <b>port</b> rejected the user's server descriptor. <b>reason</b>
194  * describes why the descriptor was rejected (e.g., malformed, skewed
195  * clock, etc.).
196  */
197  void serverDescriptorRejected(const QHostAddress &ip, quint16 port,
198  const QString &reason);
199 
200  /** Emitted when the directory authority with IP address <b>ip</b> and
201  * port <b>port</b> accepted the user's server descriptor.
202  */
203  void serverDescriptorAccepted(const QHostAddress &ip, quint16 port);
204 
205  /** Emitted when at least one directory authority has accepted the user's
206  * server descriptor.
207  */
209 
210 private:
211  /** Parses the event type from the event message */
212  static Event parseEventType(const ReplyLine &line);
213  /** Converts a string to an Event */
214  static Event toTorEvent(const QString &event);
215  /** Splits a string in the form "IP:PORT" into a QHostAddress and quint16
216  * pair. If either portion is invalid, a default-constructed QPair() is
217  * returned. */
218  static QPair<QHostAddress,quint16> splitAddress(const QString &address);
219 
220  /** Handle a bandwidth update event */
221  void handleBandwidthUpdate(const ReplyLine &line);
222  /** Handle a circuit status event */
223  void handleCircuitStatus(const ReplyLine &line);
224  /** Handle a stream status event */
225  void handleStreamStatus(const ReplyLine &line);
226  /** Handle a log message event */
227  void handleLogMessage(const ReplyLine &line);
228  /** Handle an OR connection status event. */
229  void handleOrConnStatus(const ReplyLine &line);
230  /** Handles a new list of descriptors event. */
231  void handleNewDescriptor(const ReplyLine &line);
232  /** Handles a new or updated address map event. */
233  void handleAddressMap(const ReplyLine &line);
234 
235  /** Handles a Tor status event. */
236  void handleStatusEvent(Event type, const ReplyLine &line);
237  /** Parses and posts a general Tor status event. */
239  const QString &action,
240  const QHash<QString,QString> &args);
241  /** Parses and posts a Tor client status event. */
243  const QString &action,
244  const QHash<QString,QString> &args);
245  /** Parses and posts a Tor server status event. */
247  const QString &action,
248  const QHash<QString,QString> &args);
249 };
250 
251 Q_DECLARE_OPERATORS_FOR_FLAGS(TorEvents::Events)
252 
253 #endif
254 
TorEvents::circuitStatusChanged
void circuitStatusChanged(const Circuit &circuit)
TorEvents::checkingOrPortReachability
void checkingOrPortReachability(const QHostAddress &ip, quint16 port)
TorEvents::addressMapped
void addressMapped(const QString &from, const QString &to, const QDateTime &expires)
TorEvents::toTorEvent
static Event toTorEvent(const QString &event)
Definition: TorEvents.cpp:75
TorEvents::dnsHijacked
void dnsHijacked()
TorEvents::serverDescriptorAccepted
void serverDescriptorAccepted()
tcglobal.h
TorEvents::clockSkewed
void clockSkewed(int skew, const QString &source)
TorEvents::OrConnStatus
@ OrConnStatus
Definition: TorEvents.h:53
TorEvents::Bandwidth
@ Bandwidth
Definition: TorEvents.h:45
TorEvents::handleCircuitStatus
void handleCircuitStatus(const ReplyLine &line)
Definition: TorEvents.cpp:184
TorEvents::socksError
void socksError(tc::SocksError error, const QString &destination)
TorEvents::handleOrConnStatus
void handleOrConnStatus(const ReplyLine &line)
TorEvents::streamStatusChanged
void streamStatusChanged(const Stream &stream)
BootstrapStatus
Definition: BootstrapStatus.h:25
TorEvents::dangerousTorVersion
void dangerousTorVersion(tc::TorVersionStatus reason, const QString &version, const QStringList &recommended)
tc::Severity
Severity
Definition: tcglobal.h:69
TorEvents::ServerStatus
@ ServerStatus
Definition: TorEvents.h:58
TorEvents::LogInfo
@ LogInfo
Definition: TorEvents.h:47
TorEvents::bootstrapStatusChanged
void bootstrapStatusChanged(const BootstrapStatus &status)
TorEvents::Unknown
@ Unknown
Definition: TorEvents.h:44
TorEvents::splitAddress
static QPair< QHostAddress, quint16 > splitAddress(const QString &address)
Definition: TorEvents.cpp:443
TorEvents::NewDescriptor
@ NewDescriptor
Definition: TorEvents.h:54
Circuit
Definition: Circuit.h:27
TorEvents::LogWarn
@ LogWarn
Definition: TorEvents.h:49
TorEvents::LogDebug
@ LogDebug
Definition: TorEvents.h:46
TorEvents::bug
void bug(const QString &reason)
ReplyLine
Definition: ReplyLine.h:22
TorEvents::TorEvents
TorEvents(QObject *parent=0)
Definition: TorEvents.cpp:34
TorEvents::handleAddressMap
void handleAddressMap(const ReplyLine &line)
Definition: TorEvents.cpp:266
TorEvents::EVENT_MAX
static const Event EVENT_MAX
Definition: TorEvents.h:61
ControlReply
Definition: ControlReply.h:24
TorEvents
Definition: TorEvents.h:37
TorEvents::dnsUseless
void dnsUseless()
TorEvents::handleServerStatusEvent
void handleServerStatusEvent(tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
Definition: TorEvents.cpp:384
Stream
Definition: Stream.h:31
TorEvents::handleStreamStatus
void handleStreamStatus(const ReplyLine &line)
Definition: TorEvents.cpp:213
TorEvents::dangerousPort
void dangerousPort(quint16 port, bool rejected)
TorEvents::handleEvent
void handleEvent(const ControlReply &reply)
Definition: TorEvents.cpp:124
TorEvents::dirPortReachabilityFinished
void dirPortReachabilityFinished(const QHostAddress &ip, quint16 port, bool reachable)
TorEvents::LogNotice
@ LogNotice
Definition: TorEvents.h:48
TorEvents::logMessage
void logMessage(tc::Severity level, const QString &msg)
TorEvents::LogError
@ LogError
Definition: TorEvents.h:50
TorEvents::parseEventType
static Event parseEventType(const ReplyLine &line)
Definition: TorEvents.cpp:113
TorEvents::externalAddressChanged
void externalAddressChanged(const QHostAddress &ip, const QString &hostname)
TorEvents::EVENT_MIN
static const Event EVENT_MIN
Definition: TorEvents.h:60
TorEvents::StreamStatus
@ StreamStatus
Definition: TorEvents.h:52
tc::TorVersionStatus
TorVersionStatus
Definition: tcglobal.h:86
TorEvents::ClientStatus
@ ClientStatus
Definition: TorEvents.h:57
TorEvents::CircuitStatus
@ CircuitStatus
Definition: TorEvents.h:51
TorEvents::handleGeneralStatusEvent
void handleGeneralStatusEvent(tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
Definition: TorEvents.cpp:321
TorEvents::handleBandwidthUpdate
void handleBandwidthUpdate(const ReplyLine &line)
Definition: TorEvents.cpp:160
TorEvents::newDescriptors
void newDescriptors(const QStringList &ids)
TorEvents::handleStatusEvent
void handleStatusEvent(Event type, const ReplyLine &line)
Definition: TorEvents.cpp:291
TorEvents::orPortReachabilityFinished
void orPortReachabilityFinished(const QHostAddress &ip, quint16 port, bool reachable)
tc::error
DebugMessage error(const QString &fmt)
Definition: tcglobal.cpp:40
TorEvents::circuitEstablished
void circuitEstablished()
TorEvents::Event
Event
Definition: TorEvents.h:43
TorEvents::toString
static QString toString(TorEvents::Event e)
Definition: TorEvents.cpp:51
TorEvents::bandwidthUpdate
void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent)
TorEvents::handleNewDescriptor
void handleNewDescriptor(const ReplyLine &line)
Definition: TorEvents.cpp:250
TorEvents::Q_DECLARE_FLAGS
Q_DECLARE_FLAGS(Events, Event)
TorEvents::checkingDirPortReachability
void checkingDirPortReachability(const QHostAddress &ip, quint16 port)
tc::SocksError
SocksError
Definition: tcglobal.h:79
AddressMap
Definition: AddressMap.h:28
TorEvents::handleClientStatusEvent
void handleClientStatusEvent(tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
Definition: TorEvents.cpp:353
TorEvents::handleLogMessage
void handleLogMessage(const ReplyLine &line)
Definition: TorEvents.cpp:233
TorEvents::GeneralStatus
@ GeneralStatus
Definition: TorEvents.h:56
TorEvents::serverDescriptorRejected
void serverDescriptorRejected(const QHostAddress &ip, quint16 port, const QString &reason)