Vidalia 0.3.1
RouterDescriptor.cpp
Go to the documentation of this file.
1/*
2** This file is part of Vidalia, and is subject to the license terms in the
3** LICENSE file, found in the top level directory of this distribution. If
4** you did not receive the LICENSE file with this file, you may obtain it
5** from the Vidalia source package distributed by the Vidalia Project at
6** http://www.torproject.org/projects/vidalia.html. No part of Vidalia,
7** including this file, may be copied, modified, propagated, or distributed
8** except according to the terms described in the LICENSE file.
9*/
10
11/*
12** \file RouterDescriptor.cpp
13** \brief Parses a blob of router descriptor text from Tor
14*/
15
16#include "RouterDescriptor.h"
17
18#include <QtGlobal>
19
20
21/** Constructor. Just assigns the ID and determines whether the router is
22 * responsive or not based on the presence of a "!" at the start of the ID.
23 * See tor-spec.txt for details. */
25{
27 parseDescriptor(descriptor);
28}
29
30/** Parses this router's descriptor for relevant information. */
31void
32RouterDescriptor::parseDescriptor(QStringList descriptor)
33{
34 foreach (QString line, descriptor) {
35 if (line.startsWith("router ")) {
36 QStringList parts = line.remove(0,qstrlen("router ")).split(" ");
37 _name = parts.at(0);
38 _ip = QHostAddress(parts.at(1));
39 _orPort = (quint16)parts.at(2).toUInt();
40 _dirPort = (quint16)parts.at(4).toUInt();
41 } else if (line.startsWith("platform ")) {
42 _platform = line.remove(0,qstrlen("platform "));
43 } else if (line.startsWith("published ")) {
44 _published = QDateTime::fromString(
45 line.remove(0,qstrlen("published ")),
46 "yyyy-MM-dd HH:mm:ss");
47 _published.setTimeSpec(Qt::UTC);
48 } else if (line.startsWith("opt fingerprint ")) {
49 _fingerprint = line.remove(0,qstrlen("opt fingerprint "));
50 _id = _fingerprint.remove(" ");
51 } else if (line.startsWith("fingerprint ")) {
52 _fingerprint = line.remove(0,qstrlen("fingerprint "));
53 _id = _fingerprint.remove(" ");
54 } else if (line.startsWith("uptime ")) {
55 _uptime = (quint64)line.remove(0,qstrlen("uptime ")).toULongLong();
56 } else if (line.startsWith("bandwidth ")) {
57 QStringList bw = line.remove(0,qstrlen("bandwidth ")).split(" ");
58 _avgBandwidth = (quint64)bw.at(0).toULongLong();
59 _burstBandwidth = (quint64)bw.at(1).toULongLong();
60 _observedBandwidth = (quint64)bw.at(2).toULongLong();
61 } else if (line.startsWith("contact ")) {
62 _contact = line.remove(0,qstrlen("contact "));
63 } else if (line.startsWith("hibernating ")) {
64 if (line.remove(0,qstrlen("hibernating ")).trimmed() == "1") {
66 }
67 }
68 }
69}
70
71/** Returns a string representation of the status of this router. */
72QString
74{
75 if (_status == Online) {
76 return tr("Online");
77 } else if (_status == Hibernating) {
78 return tr("Hibernating");
79 }
80 return tr("Offline");
81}
82
QHostAddress _ip
void parseDescriptor(QStringList descriptor)
RouterStatus _status