Vidalia  0.3.1
BootstrapStatus.cpp
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 you
4 ** did not receive the LICENSE file with this file, you may obtain it from the
5 ** 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 BootstrapStatus.cpp
13 ** \brief Describes the Tor software's current bootstrapping status
14 */
15 
16 #include "BootstrapStatus.h"
17 
18 
20 {
25  _percentComplete = -1;
26 }
27 
28 /** Constructor. */
30  int percentComplete,
31  const QString &description,
32  const QString &warning,
34  Recommendation action)
35 {
37  _status = status;
38  _percentComplete = qBound(0, percentComplete, 100);
40  _warning = warning;
41  _reason = reason;
42  _action = action;
43 }
44 
45 /** Converts a string TAG value to a BootstrapStatus enum value. */
48 {
49  if (!str.compare("CONN_DIR", Qt::CaseInsensitive))
50  return ConnectingToDirMirror;
51  if (!str.compare("HANDSHAKE_DIR", Qt::CaseInsensitive))
53  if (!str.compare("ONEHOP_CREATE", Qt::CaseInsensitive))
54  return CreatingOneHopCircuit;
55  if (!str.compare("REQUESTING_STATUS", Qt::CaseInsensitive))
57  if (!str.compare("LOADING_STATUS", Qt::CaseInsensitive))
58  return LoadingNetworkStatus;
59  if (!str.compare("LOADING_KEYS", Qt::CaseInsensitive))
61  if (!str.compare("REQUESTING_DESCRIPTORS", Qt::CaseInsensitive))
62  return RequestingDescriptors;
63  if (!str.compare("LOADING_DESCRIPTORS", Qt::CaseInsensitive))
64  return LoadingDescriptors;
65  if (!str.compare("CONN_OR", Qt::CaseInsensitive))
67  if (!str.compare("HANDSHAKE_OR", Qt::CaseInsensitive))
69  if (!str.compare("CIRCUIT_CREATE", Qt::CaseInsensitive))
70  return EstablishingCircuit;
71  if (!str.compare("DONE", Qt::CaseInsensitive))
72  return BootstrappingDone;
73  return UnrecognizedStatus;
74 }
75 
76 /** Returns the action that the Tor software recommended be taken in response
77  * to this bootstrap status. */
80 {
81  if (!str.compare("WARN", Qt::CaseInsensitive))
82  return RecommendWarn;
83  if (!str.compare("IGNORE", Qt::CaseInsensitive))
84  return RecommendIgnore;
86 }
87 
88 /** Returns true if this object represents a valid bootstrap status phase. */
89 bool
91 {
94  && _percentComplete >= 0);
95 }
96 
tc::ConnectionStatusReason _reason
static Status statusFromString(const QString &tag)
static Recommendation actionFromString(const QString &str)
ConnectionStatusReason
Definition: tcglobal.h:56
tc::Severity severity() const
bool isValid() const
tc::Severity _severity
Status status() const
Severity
Definition: tcglobal.h:69
QString description() const
tc::ConnectionStatusReason reason() const
QString warning() const
Recommendation _action