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