Vidalia  0.3.1
RouterStatus.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 RouterStatus.h
13 ** \brief Parses a blob of router status text from Tor
14 */
15 
16 #ifndef _ROUTERSTATUS_H
17 #define _ROUTERSTATUS_H
18 
19 #include <QFlags>
20 #include <QStringList>
21 #include <QHostAddress>
22 #include <QDateTime>
23 
24 
26 {
27 public:
28  /** Possible router status flags. */
29  enum Flag {
30  Unknown = 0x0000,
31  Authority = 0x0001,
32  BadExit = 0x0002,
33  BadDirectory = 0x0004,
34  Exit = 0x0008,
35  Fast = 0x0010,
36  Guard = 0x0020,
37  HSDir = 0x0040,
38  Named = 0x0080,
39  Stable = 0x0100,
40  Running = 0x0200,
41  Valid = 0x0400,
42  V2Dir = 0x0800,
43  V3Dir = 0x1000
44  };
45  Q_DECLARE_FLAGS(Flags, Flag)
46 
47  /** Constructor. */
48  RouterStatus(const QStringList &status);
49 
50  /** Returns the router's hexadecimal-encoded router identity key digest. */
51  QString id() const { return _id; }
52  /** Returns the router's nickname. */
53  QString name() const { return _name; }
54  /** Returns the hexadecimal-encoded digest of the router's most recent
55  * descriptor. */
56  QString descriptorDigest() const { return _digest; }
57  /** Returns the router's most recent IP address. */
58  QHostAddress ipAddress() const { return _ipAddress; }
59  /** Returns the publication time of the router's most recent descriptor. */
60  QDateTime published() const { return _published; }
61  /** Returns the router's OR port number. */
62  quint16 orPort() const { return _orPort; }
63  /** Returns the router's directory port number. */
64  quint16 dirPort() const { return _dirPort; }
65 
66  /** Returns an OR-ed field of the router's current status flags. */
67  Flags flags() const { return _flags; }
68  /** Returns true if this router is currently listed as Running. */
69  bool isRunning() const { return (flags() & Running); }
70 
71  /** Returns true if this router status object is valid. This method should
72  * be called to verify that the QStringList given in this object's
73  * constructor contained properly formatted router status lines. */
74  bool isValid() const { return _valid; }
75 
76 private:
77  /** Returns a Flags enum value for the given router status <b>flag</b>. If
78  * <b>flag</b> is not recognized, then <i>Unknown</i> is returned. */
79  Flag flagValue(const QString &flag);
80 
81  bool _valid; /**< True if this object is a valid RouterStatus. */
82  QString _name; /**< Router nickname. */
83  QString _id; /**< Hexadecimal-encoded router identity digest. */
84  QString _digest; /**< Hexadecimal-encoded hash of the router's most recent
85  descriptor. */
86  QDateTime _published; /**< The publication time of the router's most recent
87  descriptor. */
88  QHostAddress _ipAddress; /**< Current IP address. */
89  quint16 _orPort; /**< Current OR port. */
90  quint16 _dirPort; /**< Current directory port. */
91  Flags _flags; /**< OR-ed field of the router's current status flags. */
92 };
93 
94 Q_DECLARE_OPERATORS_FOR_FLAGS(RouterStatus::Flags)
95 
96 /** A collection of RouterStatus objects. */
97 typedef QList<RouterStatus> NetworkStatus;
98 
99 #endif
100 
QString descriptorDigest() const
Definition: RouterStatus.h:56
quint16 orPort() const
Definition: RouterStatus.h:62
QString name() const
Definition: RouterStatus.h:53
Flags flags() const
Definition: RouterStatus.h:67
QString _name
Definition: RouterStatus.h:82
QHostAddress ipAddress() const
Definition: RouterStatus.h:58
Flag flagValue(const QString &flag)
QString _digest
Definition: RouterStatus.h:84
QDateTime _published
Definition: RouterStatus.h:86
QHostAddress _ipAddress
Definition: RouterStatus.h:88
quint16 dirPort() const
Definition: RouterStatus.h:64
bool isRunning() const
Definition: RouterStatus.h:69
quint16 _dirPort
Definition: RouterStatus.h:90
QString _id
Definition: RouterStatus.h:83
QList< RouterStatus > NetworkStatus
Definition: RouterStatus.h:97
bool isValid() const
Definition: RouterStatus.h:74
QDateTime published() const
Definition: RouterStatus.h:60
quint16 _orPort
Definition: RouterStatus.h:89