Vidalia  0.2.15
BootstrapStatus.cpp
Go to the documentation of this file.
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.torproject.org/projects/vidalia.html. No part of Vidalia, 
00007 **  including this file, may be copied, modified, propagated, or distributed 
00008 **  except according to the terms described in the LICENSE file.
00009 */
00010 
00011 /* 
00012 ** \file BootstrapStatus.cpp
00013 ** \brief  Describes the Tor software's current bootstrapping status
00014 */
00015 
00016 #include "BootstrapStatus.h"
00017 
00018 
00019 BootstrapStatus::BootstrapStatus()
00020 {
00021   _severity = tc::UnrecognizedSeverity;
00022   _reason   = tc::UnrecognizedReason;
00023   _status   = UnrecognizedStatus;
00024   _action   = UnrecognizedRecommendation;
00025   _percentComplete = -1;
00026 }
00027 
00028 /** Constructor. */
00029 BootstrapStatus::BootstrapStatus(tc::Severity severity, Status status, 
00030                                  int percentComplete,
00031                                  const QString &description,
00032                                  const QString &warning,
00033                                  tc::ConnectionStatusReason reason,
00034                                  Recommendation action)
00035 {
00036   _severity = severity;
00037   _status = status;
00038   _percentComplete = qBound(0, percentComplete, 100);
00039   _description = description;
00040   _warning = warning;
00041   _reason = reason;
00042   _action = action;
00043 }
00044 
00045 /** Converts a string TAG value to a BootstrapStatus enum value. */
00046 BootstrapStatus::Status
00047 BootstrapStatus::statusFromString(const QString &str)
00048 {
00049   if (!str.compare("CONN_DIR", Qt::CaseInsensitive))
00050     return ConnectingToDirMirror;
00051   if (!str.compare("HANDSHAKE_DIR", Qt::CaseInsensitive))
00052     return HandshakingWithDirMirror;
00053   if (!str.compare("ONEHOP_CREATE", Qt::CaseInsensitive))
00054     return CreatingOneHopCircuit;
00055   if (!str.compare("REQUESTING_STATUS", Qt::CaseInsensitive))
00056     return RequestingNetworkStatus;
00057   if (!str.compare("LOADING_STATUS", Qt::CaseInsensitive))
00058     return LoadingNetworkStatus;
00059   if (!str.compare("LOADING_KEYS", Qt::CaseInsensitive))
00060     return LoadingAuthorityCertificates;
00061   if (!str.compare("REQUESTING_DESCRIPTORS", Qt::CaseInsensitive))
00062     return RequestingDescriptors;
00063   if (!str.compare("LOADING_DESCRIPTORS", Qt::CaseInsensitive))
00064     return LoadingDescriptors;
00065   if (!str.compare("CONN_OR", Qt::CaseInsensitive))
00066     return ConnectingToEntryGuard;
00067   if (!str.compare("HANDSHAKE_OR", Qt::CaseInsensitive))
00068     return HandshakingWithEntryGuard;
00069   if (!str.compare("CIRCUIT_CREATE", Qt::CaseInsensitive))
00070     return EstablishingCircuit;
00071   if (!str.compare("DONE", Qt::CaseInsensitive))
00072     return BootstrappingDone;
00073   return UnrecognizedStatus;
00074 }
00075 
00076 /** Returns the action that the Tor software recommended be taken in response
00077  * to this bootstrap status. */
00078 BootstrapStatus::Recommendation
00079 BootstrapStatus::actionFromString(const QString &str)
00080 {
00081   if (!str.compare("WARN", Qt::CaseInsensitive))
00082     return RecommendWarn;
00083   if (!str.compare("IGNORE", Qt::CaseInsensitive))
00084     return RecommendIgnore;
00085   return UnrecognizedRecommendation;
00086 }
00087 
00088 /** Returns true if this object represents a valid bootstrap status phase. */
00089 bool
00090 BootstrapStatus::isValid() const
00091 {
00092   return (_severity != tc::UnrecognizedSeverity
00093             && _status != UnrecognizedStatus
00094             && _percentComplete >= 0);
00095 }
00096