Vidalia  0.2.21
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 #include "RouterStatus.h"
26 
28 {
29  Q_DECLARE_TR_FUNCTIONS(RouterDescriptor)
30 
31 public:
32  /** Possible router states. */
34  Online, /**< Router is online and reachable. */
35  Hibernating, /**< Router is currently hibernating. */
36  Offline /**< Router is unresponsive. */
37  };
38 
39  /** Default constructor. */
40  RouterDescriptor(bool microdesc = false) : _microdesc(microdesc) {}
41  /** Constructor. */
42  RouterDescriptor(QStringList descriptor, bool microdesc = false);
43 
44  /** Returns the router's name. */
45  QString name() const { return _name; }
46  /** Returns the router's IP address. */
47  QHostAddress ip() const { return _ip; }
48  /** Returns the router's ORPort. */
49  quint16 orPort() const { return _orPort; }
50  /** Returns the router's DirPort. */
51  quint16 dirPort() const { return _dirPort; }
52  /** Returns the router's ID. */
53  QString id() const { return _id; }
54  /** Returns the platform on which this router is running. */
55  QString platform() const { return _platform; }
56  /** Returns the length of time this router has been up. */
57  quint64 uptime() const { return _uptime; }
58  /** Returns the router's contact information. */
59  QString contact() const { return _contact; }
60  /** Returns the date and time the router was published. */
61  QDateTime published() const { return _published; }
62  /** Returns the fingerprint for this router. */
63  QString fingerprint() const { return _fingerprint; }
64  /** Returns the average bandwidth for this router. */
65  quint64 averageBandwidth() const { return _avgBandwidth; }
66  /** Returns the burst bandwidth for this router. */
67  quint64 burstBandwidth() const { return _burstBandwidth; }
68  /** Returns the observed bandwidth for this router. */
69  quint64 observedBandwidth() const { return _observedBandwidth; }
70  /** Returns true if this router is online and responsive. */
71  bool online() const { return _status == Online; }
72  /** Returns true if this router is unresponsive. */
73  bool offline() const { return _status == Offline; }
74  /** Returns true if this router is hibernating. */
75  bool hibernating() const { return _status == Hibernating; }
76  /** Returns true if the router has neither a nickname or an ID. */
77  bool isEmpty() { return (_id.isEmpty() && _name.isEmpty()); }
78  /** Returns a string representation of the status of this router. */
79  QString status();
80 
81  /** Returns geographic location information for this router. Note that this
82  * information is NOT part of the Tor directory protocol, but can be
83  * determined out of band and set using setLocation(). */
84  QString location() const { return _location; }
85  /** Sets geographic location information for this router. */
86  void setLocation(QString location) { _location = location; }
87  /** Sets the descriptors status to Offline if <b>offline</b> is true. */
88  void setOffline(bool offline) { _status = (offline ? Offline : Online); }
89 
90  /** Microdescriptor */
91  /** Returns the onion key for this router */
92  QString onionKey() const { return _onionKey; }
93  /** Returns this router's family */
94  QString family() const { return _family; }
95  /** Returns this router's exit policy */
96  QString exitPolicy() const { return _exitPolicy; }
97 
98  /** Uses the RouterStatus information to update key elements of the
99  * descriptor */
100  void appendRouterStatusInfo(const RouterStatus &rs);
101 
102 private:
103  /** Parses this router's descriptor for relevant information. */
104  void parseDescriptor(QStringList descriptor);
105 
106  RouterStatusEnum _status;/**< Availability status of this router. */
107  QString _id; /**< Router's descriptor ID. */
108  QString _name; /**< The router's name. */
109  QString _fingerprint; /**< Router's fingerprint. */
110  QString _platform; /**< Platform on which router is running. */
111  QString _contact; /**< Router operator contact information. */
112  QHostAddress _ip; /**< Router's IP address. */
113  quint16 _orPort; /**< Router's ORPort. */
114  quint16 _dirPort; /**< Router's DirPort. */
115  QDateTime _published; /**< Date router descriptor was published. */
116  quint64 _uptime; /**< Time the router has been online. */
117  quint64 _avgBandwidth; /**< Average bandwidth. */
118  quint64 _burstBandwidth; /**< Burst bandwidth. */
119  quint64 _observedBandwidth; /**< Observed bandwidth. */
120  QString _location; /**< Geographic location information. */
121 
122  /** Microdescriptor info */
123  bool _microdesc; /** */
124  QString _onionKey; /** Router SSL key */
125  QString _exitPolicy; /** Exit policy */
126  QString _family; /** Family */
127 };
128 
129 #endif
130