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