circuit.h

Go to the documentation of this file.
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 2977 2008-08-17 01:28:25Z 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 
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 /** A collection of circuits. */
00079 typedef QList<Circuit> CircuitList;
00080 
00081 #endif
00082 

Generated on Tue Jul 7 16:58:11 2009 for Vidalia by  doxygen 1.4.7