Vidalia  0.3.1
RouterDescriptor.h
Go to the documentation of this file.
1 /*
2 ** This file is part of Vidalia, and is subject to the license terms in the
3 ** LICENSE file, found in the top level directory of this distribution. If
4 ** you did not receive the LICENSE file with this file, you may obtain it
5 ** from the Vidalia source package distributed by the Vidalia Project at
6 ** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7 ** including this file, may be copied, modified, propagated, or distributed
8 ** except according to the terms described in the LICENSE file.
9 */
10 
11 /*
12 ** \file RouterDescriptor.h
13 ** \brief Parses a blob of router descriptor text from Tor
14 */
15 
16 #ifndef _ROUTERDESCRIPTOR_H
17 #define _ROUTERDESCRIPTOR_H
18 
19 #include <QCoreApplication>
20 #include <QStringList>
21 #include <QDateTime>
22 #include <QList>
23 #include <QHostAddress>
24 
25 
27 {
28  Q_DECLARE_TR_FUNCTIONS(RouterDescriptor)
29 
30 public:
31  /** Possible router states. */
32  enum RouterStatus {
33  Online, /**< Router is online and reachable. */
34  Hibernating, /**< Router is currently hibernating. */
35  Offline /**< Router is unresponsive. */
36  };
37 
38  /** Default constructor. */
40  /** Constructor. */
41  RouterDescriptor(QStringList descriptor);
42 
43  /** Returns the router's name. */
44  QString name() const { return _name; }
45  /** Returns the router's IP address. */
46  QHostAddress ip() const { return _ip; }
47  /** Returns the router's ORPort. */
48  quint16 orPort() const { return _orPort; }
49  /** Returns the router's DirPort. */
50  quint16 dirPort() const { return _dirPort; }
51  /** Returns the router's ID. */
52  QString id() const { return _id; }
53  /** Returns the platform on which this router is running. */
54  QString platform() const { return _platform; }
55  /** Returns the length of time this router has been up. */
56  quint64 uptime() const { return _uptime; }
57  /** Returns the router's contact information. */
58  QString contact() const { return _contact; }
59  /** Returns the date and time the router was published. */
60  QDateTime published() const { return _published; }
61  /** Returns the fingerprint for this router. */
62  QString fingerprint() const { return _fingerprint; }
63  /** Returns the average bandwidth for this router. */
64  quint64 averageBandwidth() const { return _avgBandwidth; }
65  /** Returns the burst bandwidth for this router. */
66  quint64 burstBandwidth() const { return _burstBandwidth; }
67  /** Returns the observed bandwidth for this router. */
68  quint64 observedBandwidth() const { return _observedBandwidth; }
69  /** Returns true if this router is online and responsive. */
70  bool online() const { return _status == Online; }
71  /** Returns true if this router is unresponsive. */
72  bool offline() const { return _status == Offline; }
73  /** Returns true if this router is hibernating. */
74  bool hibernating() const { return _status == Hibernating; }
75  /** Returns true if the router has neither a nickname or an ID. */
76  bool isEmpty() { return (_id.isEmpty() && _name.isEmpty()); }
77  /** Returns a string representation of the status of this router. */
78  QString status();
79 
80  /** Returns geographic location information for this router. Note that this
81  * information is NOT part of the Tor directory protocol, but can be
82  * determined out of band and set using setLocation(). */
83  QString location() const { return _location; }
84  /** Sets geographic location information for this router. */
85  void setLocation(QString location) { _location = location; }
86  /** Sets the descriptors status to Offline if <b>offline</b> is true. */
87  void setOffline(bool offline) { _status = (offline ? Offline : Online); }
88 
89 private:
90  /** Parses this router's descriptor for relevant information. */
91  void parseDescriptor(QStringList descriptor);
92 
93  RouterStatus _status; /**< Availability status of this router. */
94  QString _id; /**< Router's descriptor ID. */
95  QString _name; /**< The router's name. */
96  QString _fingerprint; /**< Router's fingerprint. */
97  QString _platform; /**< Platform on which router is running. */
98  QString _contact; /**< Router operator contact information. */
99  QHostAddress _ip; /**< Router's IP address. */
100  quint16 _orPort; /**< Router's ORPort. */
101  quint16 _dirPort; /**< Router's DirPort. */
102  QDateTime _published; /**< Date router descriptor was published. */
103  quint64 _uptime; /**< Time the router has been online. */
104  quint64 _avgBandwidth; /**< Average bandwidth. */
105  quint64 _burstBandwidth; /**< Burst bandwidth. */
106  quint64 _observedBandwidth; /**< Observed bandwidth. */
107  QString _location; /**< Geographic location information. */
108 };
109 
110 #endif
111