[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[vidalia-svn] r1262: Key the network map server points based on keyid instead of (in trunk/src: control gui/network)



Author: edmanm
Date: 2006-10-03 03:16:16 -0400 (Tue, 03 Oct 2006)
New Revision: 1262

Modified:
   trunk/src/control/circuit.cpp
   trunk/src/control/circuit.h
   trunk/src/gui/network/circuitlistwidget.cpp
   trunk/src/gui/network/circuitlistwidget.h
   trunk/src/gui/network/netviewer.cpp
   trunk/src/gui/network/netviewer.h
   trunk/src/gui/network/tormapwidget.cpp
   trunk/src/gui/network/tormapwidget.h
Log:
Key the network map server points based on keyid instead of name, which means we
now have to get ids for every hop in a circuit to be able to plot a path on
the map. This is not a problem with Tor >= 0.1.2.2-alpha, but we're still
screwed with older Tors when it comes to knowing which of the servers named 
"anonymous" we're really using.


Modified: trunk/src/control/circuit.cpp
===================================================================
--- trunk/src/control/circuit.cpp	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/control/circuit.cpp	2006-10-03 07:16:16 UTC (rev 1262)
@@ -46,6 +46,14 @@
   _path   = path;
 }
 
+/** Constructor */
+Circuit::Circuit(quint64 circId, Status status, QStringList hops)
+{
+  _circId = circId;
+  _status = status;
+  _path   = hops.join(",");
+}
+
 /** Parses the string given in Tor control protocol format for a circuit. The
  * format is:
  * 

Modified: trunk/src/control/circuit.h
===================================================================
--- trunk/src/control/circuit.h	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/control/circuit.h	2006-10-03 07:16:16 UTC (rev 1262)
@@ -52,6 +52,8 @@
   Circuit();
   /** Constructor */
   Circuit(quint64 circId, Status status, QString path);
+  /** Constructor */
+  Circuit(quint64 circId, Status status, QStringList hops);
 
   /** Parses the given string (in Tor's control protocol format) */
   static Circuit fromString(QString circuit);

Modified: trunk/src/gui/network/circuitlistwidget.cpp
===================================================================
--- trunk/src/gui/network/circuitlistwidget.cpp	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/gui/network/circuitlistwidget.cpp	2006-10-03 07:16:16 UTC (rev 1262)
@@ -130,7 +130,7 @@
     CircuitItem *circuitItem = _circuitRemovalList.takeFirst();
     Circuit circuit = circuitItem->circuit();
     removeCircuit(circuitItem);
-    emit circuitRemoved(circuit);
+    emit circuitRemoved(circuit.id());
   }
 }
 

Modified: trunk/src/gui/network/circuitlistwidget.h
===================================================================
--- trunk/src/gui/network/circuitlistwidget.h	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/gui/network/circuitlistwidget.h	2006-10-03 07:16:16 UTC (rev 1262)
@@ -67,7 +67,7 @@
   /** Emitted when a circuit item is selected. */
   void circuitSelected(Circuit circuit);
   /** Emitted when a circuit is removed from the list. */
-  void circuitRemoved(Circuit circuit);
+  void circuitRemoved(quint64 circid);
 
 public slots:
   /** Clears all circuits and streams from the list. */

Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/gui/network/netviewer.cpp	2006-10-03 07:16:16 UTC (rev 1262)
@@ -99,8 +99,8 @@
 	  this, SLOT(routerSelected(RouterDescriptor)));
   connect(ui.treeCircuitList, SIGNAL(circuitSelected(Circuit)),
           this, SLOT(circuitSelected(Circuit)));
-  connect(ui.treeCircuitList, SIGNAL(circuitRemoved(Circuit)),
-          _map, SLOT(removeCircuit(Circuit)));
+  connect(ui.treeCircuitList, SIGNAL(circuitRemoved(quint64)),
+          _map, SLOT(removeCircuit(quint64)));
 
   /* Respond to changes in the status of the control connection */
   connect(_torControl, SIGNAL(connected(bool)), ui.actionRefresh, SLOT(setEnabled(bool)));
@@ -213,8 +213,13 @@
 void
 NetViewer::addCircuit(Circuit circuit)
 {
-  ui.treeCircuitList->addCircuit(circuit);
-  _map->addCircuit(circuit);
+  /* Circuits displayed to the user always use nicknames */
+  Circuit circNames = circuitPathNames(circuit);
+  /* Circuits on the map always use keyids */
+  Circuit circIds   = circuitPathIDs(circuit);
+
+  ui.treeCircuitList->addCircuit(circNames);
+  _map->addCircuit(circuit.id(), circIds.hops());
 }
 
 /** Called when the user selects the "Help" action from the toolbar. */
@@ -266,7 +271,7 @@
   _map->deselectAll();
 
   /* Select the items on the map and in the list */
-  _map->selectCircuit(circuit);
+  _map->selectCircuit(circuit.id());
 
   QList<RouterDescriptor> routers;
 
@@ -330,10 +335,85 @@
 
   /* Update the circuit lines */
   foreach (Circuit circuit, ui.treeCircuitList->circuits()) {
-    _map->addCircuit(circuit);
+    _map->addCircuit(circuit.id(), circuit.hops());
   }
   
   /* Repaint the map */
   _map->update();
 }
 
+/** Convert all hops in <b>circ</b>'s path to server identities. <b>circ</b>'s
+ * status and circuit ID will be preserved. If no ID can be found for a
+ * router name, the name will be left in the circuit's path. */
+Circuit
+NetViewer::circuitPathIDs(Circuit circ)
+{
+  QStringList path = circ.hops();
+  QStringList ids;
+  RouterDescriptor rd;
+  quint32 torVersion;
+
+  torVersion = _torControl->getTorVersion();
+  foreach (QString hop, path) {
+    if (!hop.startsWith("$")) {
+      if (torVersion < 0x00010202) {
+        /* Tor versions earlier than 0.1.2.2 have a bug where they will tell
+         * you a server's nickname in a circuit, even if that server is
+         * non-Named. If we requested the descriptor by name for a non-Named server
+         * from Tor, the user's log could be filled with warnings. So, just
+         * try to look it up from our own router list first. */
+        RouterListItem *item = ui.treeRouterList->findRouterByName(hop);
+        if (item) {
+          rd = item->descriptor();
+        } else {
+          /* We don't know about the router, so try to get it by name even
+           * though Tor will probably yell at us. We can't help it. */
+          rd = _torControl->getDescriptorByName(hop);
+          if (!rd.isEmpty()) {
+            /* Add this router to the list of those we know about */
+            ui.treeRouterList->addRouter(rd);
+          }
+        }
+      } else {
+        /* Ask Tor for the descriptor for the given router name */
+        rd = _torControl->getDescriptorByName(hop);
+      }
+      hop = (rd.isEmpty() ? hop : rd.id());
+    }
+    ids << hop;
+  }
+  return Circuit(circ.id(), circ.status(), ids);
+}
+
+/** Convert all hops in <b>circ</b>'s path to server names. <b>circ</b>'s
+ * status and circuit ID will be preserved. If no name can be found for a
+ * server identity, the ID will be left in the circuit's path. */
+Circuit
+NetViewer::circuitPathNames(Circuit circ)
+{
+  QStringList path = circ.hops();
+  QStringList names;
+  RouterDescriptor rd;
+  
+  foreach (QString hop, path) {
+    if (hop.startsWith("$")) {
+      /* Check if we already have a descriptor for this server identity. */
+      RouterListItem *item =  ui.treeRouterList->findRouterById(hop.mid(1));
+      if (item) {
+        rd = item->descriptor();
+      } else {
+        /* A router with the current hop ID does not exist in our router list,
+         * so ask Tor for its descriptor */
+        rd = _torControl->getDescriptorById(hop);
+        if (!rd.isEmpty()) {
+          /* This is a fine time to add this new router to our list */
+          ui.treeRouterList->addRouter(rd);
+        }
+      }
+      hop = (rd.isEmpty() ? hop : rd.name());
+    }
+    names << hop;
+  }
+  return Circuit(circ.id(), circ.status(), names);
+}
+

Modified: trunk/src/gui/network/netviewer.h
===================================================================
--- trunk/src/gui/network/netviewer.h	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/gui/network/netviewer.h	2006-10-03 07:16:16 UTC (rev 1262)
@@ -82,6 +82,12 @@
 private:
   /** Loads a list of router descriptors from the list of IDs. */
   void loadDescriptors(QStringList ids);
+  /** Convert all hops in <b>circ</b>'s path to server identities.
+  * <b>circ</b>'s status and circuit ID will be preserved. */
+  Circuit circuitPathIDs(Circuit circ);
+  /** Convert all hops in <b>circ</b>'s path to server names. <b>circ</b>'s
+   * status and circuit ID will be preserved. */
+  Circuit circuitPathNames(Circuit circ);
 
   /** TorControl object used to talk to Tor. */
   TorControl* _torControl;

Modified: trunk/src/gui/network/tormapwidget.cpp
===================================================================
--- trunk/src/gui/network/tormapwidget.cpp	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/gui/network/tormapwidget.cpp	2006-10-03 07:16:16 UTC (rev 1262)
@@ -89,25 +89,24 @@
 
 /** Adds a router to the map. */
 void
-TorMapWidget::addRouter(QString name, float latitude, float longitude)
+TorMapWidget::addRouter(QString id, float latitude, float longitude)
 {
   QPointF routerCoord = toMapSpace(latitude, longitude);
   
   /* Add data the hash of known routers, and plot the point on the map */
-  _routers.insert(name, new QPair<QPointF,bool>(routerCoord, false));
+  _routers.insert(id, new QPair<QPointF,bool>(routerCoord, false));
 }
 
-/** Adds a circuit to the map using the given ordered list of routers. */
+/** Adds a circuit to the map using the given ordered list of router IDs. */
 void
-TorMapWidget::addCircuit(Circuit circuit)
+TorMapWidget::addCircuit(quint64 circid, QStringList path)
 {
   QPainterPath *circPainterPath = new QPainterPath;
-  QStringList hops = circuit.hops();
   
   /* Build the new circuit */
-  for (int i = 0; i < hops.size()-1; i++) {
-    QString fromNode = hops.at(i);
-    QString toNode = hops.at(i+1);
+  for (int i = 0; i < path.size()-1; i++) {
+    QString fromNode = path.at(i);
+    QString toNode = path.at(i+1);
    
     /* Add the coordinates of the hops to the circuit */
     if (_routers.contains(fromNode) && _routers.contains(toNode)) {
@@ -123,7 +122,6 @@
   }
   
   /** Add the data to the hash of known circuits and plot the circuit on the map */
-  int circid = circuit.id();
   if (_circuits.contains(circid)) {
     /* This circuit is being updated, so just update the path, making sure we
      * free the memory allocated to the old one. */
@@ -138,32 +136,31 @@
 
 /** Removes a circuit from the map. */
 void
-TorMapWidget::removeCircuit(Circuit circuit)
+TorMapWidget::removeCircuit(quint64 circid)
 {
-  int key = circuit.id();
-  QPair<QPainterPath*,bool> *circ = _circuits.take(key);
+  QPair<QPainterPath*,bool> *circ = _circuits.take(circid);
   QPainterPath *circpath = circ->first;
   if (circpath) {
     delete circpath;
   }
 }
 
-/** Selects and highlights a router on the map. */
+/** Selects and highlights the router on the map. */
 void
-TorMapWidget::selectRouter(QString name)
+TorMapWidget::selectRouter(QString id)
 {
-  if (_routers.contains(name)) {
-    QPair<QPointF, bool> *routerPair = _routers.value(name);
+  if (_routers.contains(id)) {
+    QPair<QPointF, bool> *routerPair = _routers.value(id);
     routerPair->second = true;
   }
   repaint();
 }
 
-/** Selects and highlights a circuit on the map. */
+/** Selects and highlights the circuit with the id <b>circid</b> 
+ * on the map. */
 void
-TorMapWidget::selectCircuit(Circuit circuit)
+TorMapWidget::selectCircuit(quint64 circid)
 {
-  int circid = circuit.id();
   if (_circuits.contains(circid)) {
     QPair<QPainterPath*, bool> *circuitPair = _circuits.value(circid);
     circuitPair->second = true;
@@ -181,7 +178,7 @@
     routerPair->second = false;
   }
   /* Deselect all circuit paths */
-  foreach (int circid, _circuits.keys()) {
+  foreach (quint64 circid, _circuits.keys()) {
     QPair<QPainterPath*,bool> *circuitPair = _circuits.value(circid);
     circuitPair->second = false;
   }
@@ -196,7 +193,7 @@
     delete _routers.take(router);
   }
   /* Clear out all the circuit paths and free their memory */
-  foreach (int circid, _circuits.keys()) {
+  foreach (quint64 circid, _circuits.keys()) {
     QPair<QPainterPath*,bool> *circuitPair = _circuits.take(circid);
     delete circuitPair->first;
     delete circuitPair;
@@ -216,7 +213,7 @@
     painter->drawPoint(routerPair->first);
   }
   /* Draw the circuit paths */
-  foreach(int circid, _circuits.keys()) {
+  foreach(quint64 circid, _circuits.keys()) {
     QPair<QPainterPath*,bool> *circuitPair = _circuits.value(circid);
     painter->setPen((circuitPair->second ? PEN_SELECTED : PEN_CIRCUIT));
     painter->drawPath(*(circuitPair->first));
@@ -295,7 +292,7 @@
   QRectF rect;
 
   /* Compute the union of bounding rectangles for all circuit paths */
-  foreach (int circid, _circuits.keys()) {
+  foreach (quint64 circid, _circuits.keys()) {
     QPair<QPainterPath*,bool> *pair = _circuits.value(circid);
     QPainterPath *circuit = pair->first;
     rect = rect.unite(circuit->boundingRect());

Modified: trunk/src/gui/network/tormapwidget.h
===================================================================
--- trunk/src/gui/network/tormapwidget.h	2006-10-03 06:29:35 UTC (rev 1261)
+++ trunk/src/gui/network/tormapwidget.h	2006-10-03 07:16:16 UTC (rev 1262)
@@ -32,7 +32,6 @@
 #include <QPair>
 #include <QPainter>
 #include <QPainterPath>
-#include <control/circuit.h>
 
 #include "zimageview.h"
 
@@ -48,19 +47,19 @@
   ~TorMapWidget();
 
   /** Plots the given router on the map using the given coordinates. */
-  void addRouter(QString name, float latitude, float longitude);
+  void addRouter(QString id, float latitude, float longitude);
   /** Plots the given circuit on the map. */
-  void addCircuit(Circuit circuit);
+  void addCircuit(quint64 circid, QStringList path);
   /** Selects and hightlights a router on the map. */
-  void selectRouter(QString name);
+  void selectRouter(QString id);
   /** Selects and highlights a circuit on the map. */
-  void selectCircuit(Circuit circuit);
+  void selectCircuit(quint64 circid);
   /** Returns the minimum size of the widget */
   QSize minimumSizeHint() const;
 
 public slots:
   /** Removes a circuit from the map. */
-  void removeCircuit(Circuit circuit);
+  void removeCircuit(quint64 circid);
   /** Deselects all the highlighted circuits and routers */
   void deselectAll();
   /** Clears the known routers and removes all the data from the map */
@@ -84,7 +83,7 @@
   /** Stores map locations for tor routers */
   QHash<QString, QPair<QPointF,bool>* > _routers;
   /** Stores circuit information */
-  QHash<int, QPair<QPainterPath *,bool>* > _circuits;
+  QHash<quint64, QPair<QPainterPath *,bool>* > _circuits;
 };
 
 #endif