routerdescriptor.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 
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 routerdescriptor.cpp
00013 ** \version $Id: routerdescriptor.cpp 2362 2008-02-29 04:30:11Z edmanm $
00014 ** \brief Parses a blob of router descriptor text from Tor
00015 */
00016 
00017 #include <QtGlobal>
00018 
00019 #include "routerdescriptor.h"
00020 
00021 
00022 /** Constructor. Just assigns the ID and determines whether the router is
00023  * responsive or not based on the presence of a "!" at the start of the ID.
00024  * See tor-spec.txt for details. */
00025 RouterDescriptor::RouterDescriptor(QStringList descriptor)
00026 {
00027   _status = Online;
00028   parseDescriptor(descriptor);
00029 }
00030 
00031 /** Parses this router's descriptor for relevant information. */
00032 void
00033 RouterDescriptor::parseDescriptor(QStringList descriptor)
00034 {
00035   foreach (QString line, descriptor) {
00036     if (line.startsWith("router ")) {
00037       QStringList parts = line.remove(0,qstrlen("router ")).split(" ");
00038       _name    = parts.at(0);
00039       _ip      = QHostAddress(parts.at(1));
00040       _orPort  = (quint16)parts.at(2).toUInt();
00041       _dirPort = (quint16)parts.at(4).toUInt();
00042     } else if (line.startsWith("platform ")) {
00043       _platform = line.remove(0,qstrlen("platform "));
00044     } else if (line.startsWith("published ")) {
00045       _published = QDateTime::fromString(
00046                                line.remove(0,qstrlen("published ")),
00047                                "yyyy-MM-dd HH:mm:ss");
00048     } else if (line.startsWith("opt fingerprint ")) {
00049       _fingerprint = line.remove(0,qstrlen("opt fingerprint "));
00050       _id = _fingerprint.remove(" ");
00051     } else if (line.startsWith("fingerprint ")) {
00052       _fingerprint = line.remove(0,qstrlen("fingerprint "));
00053       _id = _fingerprint.remove(" ");
00054     } else if (line.startsWith("uptime ")) {
00055       _uptime = (quint64)line.remove(0,qstrlen("uptime ")).toULongLong();
00056     } else if (line.startsWith("bandwidth ")) {
00057       QStringList bw = line.remove(0,qstrlen("bandwidth ")).split(" ");
00058       _avgBandwidth      = (quint64)bw.at(0).toULongLong();
00059       _burstBandwidth    = (quint64)bw.at(1).toULongLong();
00060       _observedBandwidth = (quint64)bw.at(2).toULongLong();
00061     } else if (line.startsWith("contact ")) {
00062       _contact = line.remove(0,qstrlen("contact "));
00063     } else if (line.startsWith("hibernating ")) {
00064       if (line.remove(0,qstrlen("hibernating ")).trimmed() == "1") {
00065         _status = Hibernating;
00066       }
00067     }
00068   }
00069 }
00070 
00071 /** Returns a string representation of the status of this router. */
00072 QString
00073 RouterDescriptor::status()
00074 {
00075   if (_status == Online) {
00076     return tr("Online");
00077   } else if (_status == Hibernating) {
00078     return tr("Hibernating");
00079   }
00080   return tr("Offline");
00081 }
00082 

Generated on 28 Dec 2009 for Vidalia by  doxygen 1.6.1