Vidalia 0.3.1
Circuit.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 Circuit.h
13** \brief Object representing a Tor circuit
14*/
15
16#ifndef _CIRCUIT_H
17#define _CIRCUIT_H
18
19#include <QCoreApplication>
20#include <QStringList>
21#include <QMetaType>
22
23/** Circuit IDs contains 1-16 alphanumeric ASCII characters. */
24typedef QString CircuitId;
25
26
28{
29 Q_DECLARE_TR_FUNCTIONS(Circuit)
30
31public:
32 /** Circuit status events */
33 enum Status {
34 Unknown, /**< Unknown circuit status */
35 Launched, /**< Circuit ID assigned to new circuit */
36 Built, /**< All hops finished */
37 Extended, /**< Circuit extended by one hop */
38 Failed, /**< Circuit closed (was not built) */
39 Closed /**< Circuit closed (was built) */
40 };
41
42 /** Default constructor. */
43 Circuit();
44 /** Constructor. */
45 Circuit(const CircuitId &circuit);
46
47 /** Returns true if this circuit is valid. */
48 bool isValid() const { return _isValid; }
49
50 /** Returns the ID for this circuit */
51 CircuitId id() const { return _circId; }
52 /** Returns the status of this circuit */
53 Status status() const { return _status; }
54 /** Returns a string representation of the status of this circuit. */
55 QString statusString() const;
56 /** Returns the length of the circuit's path. */
57 uint length() const { return _ids.size(); }
58 /** Returns the circuit's path as an ordered list of router nicknames. */
59 QStringList routerNames() const { return _names; }
60 /** Returns the circuit's path as an ordered list of router fingerprints. */
61 QStringList routerIDs() const { return _ids; }
62
63 /** Converts a string description of a circuit's status to an enum value */
64 static Status toStatus(const QString &strStatus);
65
66 /** Returns true iff <b>circId</b> consists of only between 1 and 16
67 * (inclusive) ASCII-encoded letters and numbers. */
68 static bool isValidCircuitId(const CircuitId &circId);
69
70private:
71 CircuitId _circId; /**< Circuit ID. */
72 Status _status; /**< Circuit status. */
73 QStringList _names; /**< Nicknames of the routers in the circuit. */
74 QStringList _ids; /**< IDs of the routers in the circuit. */
76};
77
79
80/** A collection of circuits. */
81typedef QList<Circuit> CircuitList;
82
83#endif
84
QList< Circuit > CircuitList
Definition: Circuit.h:81
QString CircuitId
Definition: Circuit.h:24
Q_DECLARE_METATYPE(Circuit)
bool isValid() const
Definition: Circuit.h:48
QStringList _ids
Definition: Circuit.h:74
static bool isValidCircuitId(const CircuitId &circId)
Definition: Circuit.cpp:74
Status _status
Definition: Circuit.h:72
CircuitId id() const
Definition: Circuit.h:51
QStringList routerIDs() const
Definition: Circuit.h:61
Circuit()
Definition: Circuit.cpp:24
QStringList _names
Definition: Circuit.h:73
uint length() const
Definition: Circuit.h:57
QStringList routerNames() const
Definition: Circuit.h:59
bool _isValid
Definition: Circuit.h:75
static Status toStatus(const QString &strStatus)
Definition: Circuit.cpp:90
CircuitId _circId
Definition: Circuit.h:71
QString statusString() const
Definition: Circuit.cpp:107
Status
Definition: Circuit.h:33
@ Failed
Definition: Circuit.h:38
@ Launched
Definition: Circuit.h:35
@ Closed
Definition: Circuit.h:39
@ Unknown
Definition: Circuit.h:34
@ Built
Definition: Circuit.h:36
@ Extended
Definition: Circuit.h:37
Status status() const
Definition: Circuit.h:53