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 you 00004 ** did not receive the LICENSE file with this file, you may obtain it from the 00005 ** 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 the 00008 ** terms described in the LICENSE file. 00009 */ 00010 00011 /* 00012 ** \file bootstrapstatus.h 00013 ** \version $Id: bootstrapstatus.h 2782 2008-06-21 21:52:15Z edmanm $ 00014 ** \brief Describes the Tor software's current bootstrap status 00015 */ 00016 00017 #ifndef _BOOTSTRAPSTATUS_H 00018 #define _BOOTSTRAPSTATUS_H 00019 00020 #include <QString> 00021 #include "tcglobal.h" 00022 00023 00024 class BootstrapStatus 00025 { 00026 public: 00027 /** Currently enumerated bootstrapping states defined by Tor's control 00028 * protocol (Tor >= 0.2.1.0-alpha-dev. */ 00029 enum Status { 00030 UnrecognizedStatus, 00031 ConnectingToDirMirror, 00032 HandshakingWithDirMirror, 00033 CreatingOneHopCircuit, 00034 RequestingNetworkStatus, 00035 LoadingNetworkStatus, 00036 LoadingAuthorityCertificates, 00037 RequestingDescriptors, 00038 LoadingDescriptors, 00039 ConnectingToEntryGuard, 00040 HandshakingWithEntryGuard, 00041 EstablishingCircuit, 00042 BootstrappingDone 00043 }; 00044 /** Actions the Tor software might recommend controllers take in response to 00045 * a bootstrap status problem event. */ 00046 enum Recommendation { 00047 UnrecognizedRecommendation, 00048 RecommendIgnore, 00049 RecommendWarn 00050 }; 00051 00052 /** Default constructor. */ 00053 BootstrapStatus(); 00054 00055 /** Constructor. */ 00056 BootstrapStatus(tc::Severity severity, 00057 Status status, int percentComplete, 00058 const QString &description, 00059 const QString &warning = QString(), 00060 tc::ConnectionStatusReason reason = tc::UnrecognizedReason, 00061 Recommendation action = UnrecognizedRecommendation); 00062 00063 /** Returns the severity of this bootstrap status event. */ 00064 tc::Severity severity() const { return _severity; } 00065 00066 /** Returns the BootstrapStatus enum value indicated by this bootstrap 00067 * status event. */ 00068 Status status() const { return _status; } 00069 00070 /** Returns an integer between 0 and 100 representing an estimate of how 00071 * much of Tor's bootstrapping process it has completed. */ 00072 int percentComplete() const { return _percentComplete; } 00073 00074 /** Returns a description of Tor's current bootstrapping status. */ 00075 QString description() const { return _description; } 00076 00077 /** Returns a description of the most recent error Tor encountered while 00078 * attempting to bootstrap, if this event's severity is 'warn'. Otherwise, 00079 * this returns a default-constructed QString. */ 00080 QString warning() const { return _warning; } 00081 00082 /** Returns a ConnectionStatusReason enum value describing the most recent 00083 * error Tor encountered while attempting to bootstrap, if this event's 00084 * severity is 'warn'. Otherwise, this simply returns 00085 * tc::UnrecognizedReason. */ 00086 tc::ConnectionStatusReason reason() const { return _reason; } 00087 00088 /** Returns the action that the Tor software recommended be taken in 00089 * response to this bootstrap status event. */ 00090 Recommendation recommendedAction() const { return _action; } 00091 00092 /** Returns true if this object represents a valid bootstrap status 00093 * phase. */ 00094 bool isValid() const; 00095 00096 /** Converts a string TAG value to a BootstrapStatus enum value. */ 00097 static Status statusFromString(const QString &tag); 00098 /** Converts a string RECOMMENDATION value to a RecommendAction enum 00099 * value. */ 00100 static Recommendation actionFromString(const QString &str); 00101 00102 private: 00103 /** Severity of the current bootstrap status. 00104 * \sa severity 00105 */ 00106 tc::Severity _severity; 00107 00108 /** Current bootstrapping status value. 00109 * \sa status 00110 */ 00111 Status _status; 00112 00113 /** Approximate percentage of Tor's bootstrapping process that is complete. 00114 * \sa percentComplete 00115 */ 00116 int _percentComplete; 00117 00118 /** Description of Tor's current bootstrapping status. 00119 * \sa description 00120 */ 00121 QString _description; 00122 00123 /** Description of the most recent error Tor encountered while attempting to 00124 * bootstrap. 00125 * \sa warning 00126 */ 00127 QString _warning; 00128 00129 /** ConnectionStatusReason enum value describing the most recent error Tor 00130 * encountered while attempting to bootstrap. 00131 * \sa reason 00132 */ 00133 tc::ConnectionStatusReason _reason; 00134 00135 /** Recommendation enum value describing Tor's suggested response to this 00136 * bootstrap status event. 00137 * \sa recommendedAction 00138 */ 00139 Recommendation _action; 00140 }; 00141 00142 #endif 00143