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