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
26class Circuit;
27class Stream;
28class BootstrapStatus;
29class ControlReply;
30class ReplyLine;
31
32class QString;
33class QDateTime;
34class QHostAddress;
35
36
37class TorEvents : public QObject
38{
39 Q_OBJECT
40
41public:
42 /** Asynchronous events sent from Tor to the controller */
43 enum Event {
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 };
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
73signals:
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 */
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 */
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 */
162
163 /** Emitted when Tor determines that the user's DNS provider is providing
164 * a hijacked address even for well-known websites.
165 */
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
210private:
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
251Q_DECLARE_OPERATORS_FOR_FLAGS(TorEvents::Events)
252
253#endif
254
Definition: Stream.h:32
@ OrConnStatus
Definition: TorEvents.h:53
@ GeneralStatus
Definition: TorEvents.h:56
@ LogError
Definition: TorEvents.h:50
@ ServerStatus
Definition: TorEvents.h:58
@ Bandwidth
Definition: TorEvents.h:45
@ LogDebug
Definition: TorEvents.h:46
@ ClientStatus
Definition: TorEvents.h:57
@ StreamStatus
Definition: TorEvents.h:52
@ NewDescriptor
Definition: TorEvents.h:54
@ CircuitStatus
Definition: TorEvents.h:51
@ LogNotice
Definition: TorEvents.h:48
void serverDescriptorRejected(const QHostAddress &ip, quint16 port, const QString &reason)
void handleEvent(const ControlReply &reply)
Definition: TorEvents.cpp:124
void streamStatusChanged(const Stream &stream)
void handleAddressMap(const ReplyLine &line)
Definition: TorEvents.cpp:266
void handleGeneralStatusEvent(tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
Definition: TorEvents.cpp:321
void dangerousPort(quint16 port, bool rejected)
void orPortReachabilityFinished(const QHostAddress &ip, quint16 port, bool reachable)
void serverDescriptorAccepted(const QHostAddress &ip, quint16 port)
void logMessage(tc::Severity level, const QString &msg)
void handleClientStatusEvent(tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
Definition: TorEvents.cpp:353
void circuitEstablished()
static const Event EVENT_MAX
Definition: TorEvents.h:61
void externalAddressChanged(const QHostAddress &ip, const QString &hostname)
void addressMapped(const QString &from, const QString &to, const QDateTime &expires)
static QPair< QHostAddress, quint16 > splitAddress(const QString &address)
Definition: TorEvents.cpp:443
void clockSkewed(int skew, const QString &source)
static Event parseEventType(const ReplyLine &line)
Definition: TorEvents.cpp:113
static const Event EVENT_MIN
Definition: TorEvents.h:60
void serverDescriptorAccepted()
TorEvents(QObject *parent=0)
Definition: TorEvents.cpp:34
void bootstrapStatusChanged(const BootstrapStatus &status)
void handleBandwidthUpdate(const ReplyLine &line)
Definition: TorEvents.cpp:160
void dangerousTorVersion(tc::TorVersionStatus reason, const QString &version, const QStringList &recommended)
void socksError(tc::SocksError error, const QString &destination)
void handleNewDescriptor(const ReplyLine &line)
Definition: TorEvents.cpp:250
void checkingOrPortReachability(const QHostAddress &ip, quint16 port)
static QString toString(TorEvents::Event e)
Definition: TorEvents.cpp:51
void bug(const QString &reason)
void handleStreamStatus(const ReplyLine &line)
Definition: TorEvents.cpp:213
void dnsHijacked()
static Event toTorEvent(const QString &event)
Definition: TorEvents.cpp:75
Q_DECLARE_FLAGS(Events, Event)
void newDescriptors(const QStringList &ids)
void dnsUseless()
void circuitStatusChanged(const Circuit &circuit)
void checkingDirPortReachability(const QHostAddress &ip, quint16 port)
void dirPortReachabilityFinished(const QHostAddress &ip, quint16 port, bool reachable)
void handleCircuitStatus(const ReplyLine &line)
Definition: TorEvents.cpp:184
void handleLogMessage(const ReplyLine &line)
Definition: TorEvents.cpp:233
void handleStatusEvent(Event type, const ReplyLine &line)
Definition: TorEvents.cpp:291
void bandwidthUpdate(quint64 bytesReceived, quint64 bytesSent)
void handleServerStatusEvent(tc::Severity severity, const QString &action, const QHash< QString, QString > &args)
Definition: TorEvents.cpp:384
void handleOrConnStatus(const ReplyLine &line)
TorVersionStatus
Definition: tcglobal.h:86
DebugMessage error(const QString &fmt)
Definition: tcglobal.cpp:40
SocksError
Definition: tcglobal.h:79
Severity
Definition: tcglobal.h:69