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

Generated on Mon Aug 30 19:14:02 2010 for Vidalia by  doxygen 1.5.9