Vidalia
0.2.17
|
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.torproject.org/projects/vidalia.html. No part of Vidalia, 00007 ** including this file, may be copied, modified, propagated, or distributed 00008 ** except according to the terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file Circuit.h 00013 ** \brief Object representing a Tor circuit 00014 */ 00015 00016 #ifndef _CIRCUIT_H 00017 #define _CIRCUIT_H 00018 00019 #include <QCoreApplication> 00020 #include <QStringList> 00021 #include <QMetaType> 00022 00023 /** Circuit IDs contains 1-16 alphanumeric ASCII characters. */ 00024 typedef QString CircuitId; 00025 00026 00027 class Circuit 00028 { 00029 Q_DECLARE_TR_FUNCTIONS(Circuit) 00030 00031 public: 00032 /** Circuit status events */ 00033 enum Status { 00034 Unknown, /**< Unknown circuit status */ 00035 Launched, /**< Circuit ID assigned to new circuit */ 00036 Built, /**< All hops finished */ 00037 Extended, /**< Circuit extended by one hop */ 00038 Failed, /**< Circuit closed (was not built) */ 00039 Closed /**< Circuit closed (was built) */ 00040 }; 00041 00042 /** Default constructor. */ 00043 Circuit(); 00044 /** Constructor. */ 00045 Circuit(const CircuitId &circuit); 00046 00047 /** Returns true if this circuit is valid. */ 00048 bool isValid() const { return _isValid; } 00049 00050 /** Returns the ID for this circuit */ 00051 CircuitId id() const { return _circId; } 00052 /** Returns the status of this circuit */ 00053 Status status() const { return _status; } 00054 /** Returns a string representation of the status of this circuit. */ 00055 QString statusString() const; 00056 /** Returns the length of the circuit's path. */ 00057 uint length() const { return _ids.size(); } 00058 /** Returns the circuit's path as an ordered list of router nicknames. */ 00059 QStringList routerNames() const { return _names; } 00060 /** Returns the circuit's path as an ordered list of router fingerprints. */ 00061 QStringList routerIDs() const { return _ids; } 00062 00063 /** Converts a string description of a circuit's status to an enum value */ 00064 static Status toStatus(const QString &strStatus); 00065 00066 /** Returns true iff <b>circId</b> consists of only between 1 and 16 00067 * (inclusive) ASCII-encoded letters and numbers. */ 00068 static bool isValidCircuitId(const CircuitId &circId); 00069 00070 private: 00071 CircuitId _circId; /**< Circuit ID. */ 00072 Status _status; /**< Circuit status. */ 00073 QStringList _names; /**< Nicknames of the routers in the circuit. */ 00074 QStringList _ids; /**< IDs of the routers in the circuit. */ 00075 bool _isValid; 00076 }; 00077 00078 Q_DECLARE_METATYPE(Circuit); 00079 00080 /** A collection of circuits. */ 00081 typedef QList<Circuit> CircuitList; 00082 00083 #endif 00084