Vidalia
0.2.15
|
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.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 RouterDescriptor.cpp 00013 ** \brief Parses a blob of router descriptor text from Tor 00014 */ 00015 00016 #include "RouterDescriptor.h" 00017 00018 #include <QtGlobal> 00019 00020 00021 /** Constructor. Just assigns the ID and determines whether the router is 00022 * responsive or not based on the presence of a "!" at the start of the ID. 00023 * See tor-spec.txt for details. */ 00024 RouterDescriptor::RouterDescriptor(QStringList descriptor) 00025 { 00026 _status = Online; 00027 parseDescriptor(descriptor); 00028 } 00029 00030 /** Parses this router's descriptor for relevant information. */ 00031 void 00032 RouterDescriptor::parseDescriptor(QStringList descriptor) 00033 { 00034 foreach (QString line, descriptor) { 00035 if (line.startsWith("router ")) { 00036 QStringList parts = line.remove(0,qstrlen("router ")).split(" "); 00037 _name = parts.at(0); 00038 _ip = QHostAddress(parts.at(1)); 00039 _orPort = (quint16)parts.at(2).toUInt(); 00040 _dirPort = (quint16)parts.at(4).toUInt(); 00041 } else if (line.startsWith("platform ")) { 00042 _platform = line.remove(0,qstrlen("platform ")); 00043 } else if (line.startsWith("published ")) { 00044 _published = QDateTime::fromString( 00045 line.remove(0,qstrlen("published ")), 00046 "yyyy-MM-dd HH:mm:ss"); 00047 _published.setTimeSpec(Qt::UTC); 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