00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include <QtGlobal>
00018
00019 #include "routerdescriptor.h"
00020
00021
00022
00023
00024
00025 RouterDescriptor::RouterDescriptor(QStringList descriptor)
00026 {
00027 _status = Online;
00028 parseDescriptor(descriptor);
00029 }
00030
00031
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
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