routerdescriptor.cpp

Go to the documentation of this file.
00001 /****************************************************************
00002  *  Vidalia is distributed under the following license:
00003  *
00004  *  Copyright (C) 2006,  Matt Edman, Justin Hipple
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; either version 2
00009  *  of the License, or (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, 
00019  *  Boston, MA  02110-1301, USA.
00020  ****************************************************************/
00021 
00022 /** 
00023  * \file routerdescriptor.cpp
00024  * \version $Id: routerdescriptor.cpp 1266 2006-10-03 18:39:50Z edmanm $
00025  * \brief Parses a blob of router descriptor text from Tor
00026  */
00027 
00028 #include <QtGlobal>
00029 
00030 #include "routerdescriptor.h"
00031 
00032 
00033 /** Constructor. Just assigns the ID and determines whether the router is
00034  * responsive or not based on the presence of a "!" at the start of the ID.
00035  * See tor-spec.txt for details. */
00036 RouterDescriptor::RouterDescriptor(QStringList descriptor)
00037 {
00038   _status = Online;
00039   parseDescriptor(descriptor);
00040 }
00041 
00042 /** Parses this router's descriptor for relevant information. */
00043 void
00044 RouterDescriptor::parseDescriptor(QStringList descriptor)
00045 {
00046   foreach (QString line, descriptor) {
00047     if (line.startsWith("router ")) {
00048       QStringList parts = line.remove(0,qstrlen("router ")).split(" ");
00049       _name    = parts.at(0);
00050       _ip      = parts.at(1);
00051       _orPort  = (quint16)parts.at(2).toUInt();
00052       _dirPort = (quint16)parts.at(4).toUInt();
00053     } else if (line.startsWith("platform ")) {
00054       _platform = line.remove(0,qstrlen("platform "));
00055     } else if (line.startsWith("published ")) {
00056       _published = QDateTime::fromString(
00057                                line.remove(0,qstrlen("published ")),
00058                                "yyyy-MM-dd HH:mm:ss");
00059     } else if (line.startsWith("opt fingerprint ")) {
00060       _fingerprint = line.remove(0,qstrlen("opt fingerprint "));
00061       _id = _fingerprint.remove(" ");
00062     } else if (line.startsWith("fingerprint ")) {
00063       _fingerprint = line.remove(0,qstrlen("fingerprint "));
00064       _id = _fingerprint.remove(" ");
00065     } else if (line.startsWith("uptime ")) {
00066       _uptime = (quint64)line.remove(0,qstrlen("uptime ")).toULongLong();
00067     } else if (line.startsWith("bandwidth ")) {
00068       QStringList bw = line.remove(0,qstrlen("bandwidth ")).split(" ");
00069       _avgBandwidth      = (quint64)bw.at(0).toULongLong();
00070       _burstBandwidth    = (quint64)bw.at(1).toULongLong();
00071       _observedBandwidth = (quint64)bw.at(2).toULongLong();
00072     } else if (line.startsWith("contact ")) {
00073       _contact = line.remove(0,qstrlen("contact "));
00074     } else if (line.startsWith("hibernating ")) {
00075       if (line.remove(0,qstrlen("hibernating ")).trimmed() == "1") {
00076         _status = Hibernating;
00077       }
00078     }
00079   }
00080 }
00081 
00082 /** Returns a string representation of the status of this router. */
00083 QString
00084 RouterDescriptor::status()
00085 {
00086   if (_status == Online) {
00087     return tr("Online");
00088   } else if (_status == Hibernating) {
00089     return tr("Hibernating");
00090   }
00091   return tr("Offline");
00092 }
00093 

Generated on Mon Oct 23 20:08:16 2006 for Vidalia by  doxygen 1.5.0