circuit.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006-2007,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file circuit.h
00024  * \version $Id: circuit.h 1607 2007-01-21 00:11:35Z edmanm $
00025  * \brief Object representing a Tor circuit
00026  */
00027 
00028 #ifndef _CIRCUIT_H
00029 #define _CIRCUIT_H
00030 
00031 #include <QCoreApplication>
00032 #include <QStringList>
00033 #include <QString>
00034 
00035 
00036 class Circuit
00037 {
00038   Q_DECLARE_TR_FUNCTIONS(Circuit)
00039 
00040 public:
00041   /** Circuit status events */
00042   enum Status {
00043     Unknown,   /**< Unknown circuit status */
00044     Launched,  /**< Circuit ID assigned to new circuit */
00045     Built,     /**< All hops finished */
00046     Extended,  /**< Circuit extended by one hop */
00047     Failed,    /**< Circuit closed (was not built) */
00048     Closed     /**< Circuit closed (was built) */
00049   };
00050 
00051   /** Default constructor. */
00052   Circuit();
00053   /** Constructor */
00054   Circuit(quint64 circId, Status status, QString path);
00055   /** Constructor */
00056   Circuit(quint64 circId, Status status, QStringList hops);
00057 
00058   /** Parses the given string (in Tor's control protocol format) */
00059   static Circuit fromString(QString circuit);
00060   /** Converts a string description of a circuit's status to an enum value */
00061   static Status toStatus(QString strStatus);
00062   
00063   /** Returns true if all fields in this Circuit are empty. */
00064   bool isEmpty();
00065   
00066   /** Returns the ID for this circuit */
00067   quint64 id() { return _circId; }
00068   /** Returns the status of this circuit */
00069   Status status() { return _status; }
00070   /** Returns a string representation of the status of this circuit. */
00071   QString statusString();
00072   /** Returns the path chosen for this circuit */
00073   QString path() { return _path; }
00074   /** Returns the length of the circuit's path. */
00075   uint length() { return hops().size(); }
00076   /** Returns a list of hops on the path. */
00077   QStringList hops() { return _path.isEmpty() ? QStringList() 
00078                                               : _path.split(","); }
00079 
00080 private:
00081   quint64 _circId; /**< Circuit ID. */
00082   Status _status;  /**< Circuit status. */
00083   QString _path;   /**< Circuit path. */
00084 };
00085 
00086 #endif
00087 

Generated on Wed Sep 5 15:49:27 2007 for Vidalia by  doxygen 1.5.3