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 RouterStatus.h 00013 ** \version $Id: RouterStatus.h 3735 2009-04-28 20:28:01Z edmanm $ 00014 ** \brief Parses a blob of router status text from Tor 00015 */ 00016 00017 #ifndef _ROUTERSTATUS_H 00018 #define _ROUTERSTATUS_H 00019 00020 #include <QFlags> 00021 #include <QStringList> 00022 #include <QHostAddress> 00023 #include <QDateTime> 00024 00025 00026 class RouterStatus 00027 { 00028 public: 00029 /** Possible router status flags. */ 00030 enum Flag { 00031 Unknown = 0x0000, 00032 Authority = 0x0001, 00033 BadExit = 0x0002, 00034 BadDirectory = 0x0004, 00035 Exit = 0x0008, 00036 Fast = 0x0010, 00037 Guard = 0x0020, 00038 HSDir = 0x0040, 00039 Named = 0x0080, 00040 Stable = 0x0100, 00041 Running = 0x0200, 00042 Valid = 0x0400, 00043 V2Dir = 0x0800, 00044 V3Dir = 0x1000 00045 }; 00046 Q_DECLARE_FLAGS(Flags, Flag) 00047 00048 /** Constructor. */ 00049 RouterStatus(const QStringList &status); 00050 00051 /** Returns the router's hexadecimal-encoded router identity key digest. */ 00052 QString id() const { return _id; } 00053 /** Returns the router's nickname. */ 00054 QString name() const { return _name; } 00055 /** Returns the hexadecimal-encoded digest of the router's most recent 00056 * descriptor. */ 00057 QString descriptorDigest() const { return _digest; } 00058 /** Returns the router's most recent IP address. */ 00059 QHostAddress ipAddress() const { return _ipAddress; } 00060 /** Returns the publication time of the router's most recent descriptor. */ 00061 QDateTime published() const { return _published; } 00062 /** Returns the router's OR port number. */ 00063 quint16 orPort() const { return _orPort; } 00064 /** Returns the router's directory port number. */ 00065 quint16 dirPort() const { return _dirPort; } 00066 00067 /** Returns an OR-ed field of the router's current status flags. */ 00068 Flags flags() const { return _flags; } 00069 /** Returns true if this router is currently listed as Running. */ 00070 bool isRunning() const { return (flags() & Running); } 00071 00072 /** Returns true if this router status object is valid. This method should 00073 * be called to verify that the QStringList given in this object's 00074 * constructor contained properly formatted router status lines. */ 00075 bool isValid() const { return _valid; } 00076 00077 private: 00078 /** Returns a Flags enum value for the given router status <b>flag</b>. If 00079 * <b>flag</b> is not recognized, then <i>Unknown</i> is returned. */ 00080 Flag flagValue(const QString &flag); 00081 00082 bool _valid; /**< True if this object is a valid RouterStatus. */ 00083 QString _name; /**< Router nickname. */ 00084 QString _id; /**< Hexadecimal-encoded router identity digest. */ 00085 QString _digest; /**< Hexadecimal-encoded hash of the router's most recent 00086 descriptor. */ 00087 QDateTime _published; /**< The publication time of the router's most recent 00088 descriptor. */ 00089 QHostAddress _ipAddress; /**< Current IP address. */ 00090 quint16 _orPort; /**< Current OR port. */ 00091 quint16 _dirPort; /**< Current directory port. */ 00092 Flags _flags; /**< OR-ed field of the router's current status flags. */ 00093 }; 00094 00095 Q_DECLARE_OPERATORS_FOR_FLAGS(RouterStatus::Flags) 00096 00097 /** A collection of RouterStatus objects. */ 00098 typedef QList<RouterStatus> NetworkStatus; 00099 00100 #endif 00101