routerdescriptor.h

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  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 routerdescriptor.h
00024  * \version $Id: routerdescriptor.h 1238 2006-09-25 17:50:57Z edmanm $
00025  * \brief Parses a blob of router descriptor text from Tor
00026  */
00027 
00028 #ifndef _ROUTERDESCRIPTOR_H
00029 #define _ROUTERDESCRIPTOR_H
00030 
00031 #include <QCoreApplication>
00032 #include <QStringList>
00033 #include <QDateTime>
00034 #include <QList>
00035 
00036 
00037 class RouterDescriptor
00038 {
00039   Q_DECLARE_TR_FUNCTIONS(RouterDescriptor)
00040 
00041 public:
00042   /** Possible router states. */
00043   enum RouterStatus {
00044     Online,       /**< Router is online and reachable. */
00045     Hibernating,  /**< Router is currently hibernating. */
00046     Offline       /**< Router is unresponsive. */
00047   };
00048 
00049   /** Default constructor. */
00050   RouterDescriptor() {}
00051   /** Constructor. */ 
00052   RouterDescriptor(QStringList descriptor);
00053   
00054   /** Returns the router's name. */
00055   QString name() const { return _name; }
00056   /** Returns the router's IP address. */
00057   QString ip() const { return _ip; }
00058   /** Returns the router's ORPort. */
00059   quint16 orPort() const { return _orPort; }
00060   /** Returns the router's DirPort. */
00061   quint16 dirPort() const { return _dirPort; }
00062   /** Returns the router's ID. */
00063   QString id() const { return _id; }
00064   /** Returns the platform on which this router is running. */
00065   QString platform() const { return _platform; }
00066   /** Returns the length of time this router has been up. */
00067   quint64 uptime() const { return _uptime; }
00068   /** Returns the router's contact information. */
00069   QString contact() const { return _contact; }
00070   /** Returns the date and time the router was published. */
00071   QDateTime published() const { return _published; }
00072   /** Returns the fingerprint for this router. */
00073   QString fingerprint() const { return _fingerprint; }
00074   /** Returns the average bandwidth for this router. */
00075   quint64 averageBandwidth() const { return _avgBandwidth; }
00076   /** Returns the burst bandwidth for this router. */
00077   quint64 burstBandwidth() const { return _burstBandwidth; }
00078   /** Returns the observed bandwidth for this router. */
00079   quint64 observedBandwidth() const { return _observedBandwidth; }
00080   /** Returns true if this router is online and responsive. */
00081   bool online() const { return _status == Online; }
00082   /** Returns true if this router is unresponsive. */
00083   bool offline() const { return _status == Offline; }
00084   /** Returns true if this router is hibernating. */
00085   bool hibernating() const { return _status == Hibernating; }
00086   /** Returns true if the router has neither a nickname or an ID. */
00087   bool isEmpty() { return (_id.isEmpty() && _name.isEmpty()); }
00088   /** Returns a string representation of the status of this router. */
00089   QString status();
00090   
00091   /** Returns geographic location information for this router. Note that this
00092    * information is NOT part of the Tor directory protocol, but can be
00093    * determined out of band and set using setLocation(). */
00094   QString location() const { return _location; }
00095   /** Sets geographic location information for this router. */
00096   void setLocation(QString location) { _location = location; }
00097   /** Sets the descriptors status to Offline if <b>offline</b> is true. */
00098   void setOffline(bool offline) { _status = (offline ? Offline : Online); }
00099 
00100 private:
00101   /** Parses this router's descriptor for relevant information. */
00102   void parseDescriptor(QStringList descriptor);
00103 
00104   RouterStatus _status;    /**< Availability status of this router. */
00105   QString _id;             /**< Router's descriptor ID. */
00106   QString _name;           /**< The router's name. */
00107   QString _fingerprint;    /**< Router's fingerprint. */
00108   QString _platform;       /**< Platform on which router is running. */
00109   QString _contact;        /**< Router operator contact information. */
00110   QString _ip;             /**< Router's IP address. */
00111   quint16 _orPort;         /**< Router's ORPort. */
00112   quint16 _dirPort;        /**< Router's DirPort. */
00113   QDateTime _published;    /**< Date router descriptor was published. */
00114   quint64 _uptime;         /**< Time the router has been online. */
00115   quint64 _avgBandwidth;   /**< Average bandwidth. */
00116   quint64 _burstBandwidth; /**< Burst bandwidth. */
00117   quint64 _observedBandwidth; /**< Observed bandwidth. */
00118   QString _location;       /**< Geographic location information. */
00119 };
00120 
00121 #endif
00122 

Generated on Mon Oct 23 20:08:16 2006 for Vidalia by  doxygen 1.5.0