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