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

[vidalia-svn] r1799: Maintain a list of address mappings, so we can try to replac (trunk/src/gui/network)



Author: edmanm
Date: 2007-07-02 21:32:39 -0400 (Mon, 02 Jul 2007)
New Revision: 1799

Modified:
   trunk/src/gui/network/netviewer.cpp
   trunk/src/gui/network/netviewer.h
Log:
Maintain a list of address mappings, so we can try to replace IP addresses in
stream targets with host names. (Suggested by phobos.)


Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp	2007-07-03 01:31:17 UTC (rev 1798)
+++ trunk/src/gui/network/netviewer.cpp	2007-07-03 01:32:39 UTC (rev 1799)
@@ -64,7 +64,8 @@
   _torControl->setEvent(TorEvents::NewDescriptor, this, true);
   _torControl->setEvent(TorEvents::CircuitStatus, this, true);
   _torControl->setEvent(TorEvents::StreamStatus,  this, true);
-  
+  _torControl->setEvent(TorEvents::AddressMap,    this, true);
+
   /* Change the column widths of the tree widgets */
   ui.treeRouterList->header()->
     resizeSection(RouterListWidget::StatusColumn, 25);
@@ -164,19 +165,22 @@
     /* New router descriptor, so load it and add it to the list */
     NewDescriptorEvent *nde = (NewDescriptorEvent *)event;
     loadDescriptors(nde->descriptorIDs());
-  
   } else if (type == CustomEventType::CircuitEvent) {
     /* New or updated circuit information */
     CircuitEvent *ce = (CircuitEvent *)event;
     addCircuit(ce->circuit());
-  
   } else if (type == CustomEventType::StreamEvent) {
     /* New or updated stream information */
     StreamEvent *se = (StreamEvent *)event;
-    ui.treeCircuitList->addStream(se->stream());
+    addStream(se->stream());
+  } else if (type == CustomEventType::AddressMapEvent) {
+    /* New or updated address mapping. We store the reverse of the new
+     * mapping, so we can go from an IP address back to a hostname. */
+    AddressMapEvent *ae = (AddressMapEvent *)event;
+    _addressMap.add(ae->to(), ae->from(), ae->expires());
   }
 
-  /** Update the map */
+  /* Update the world map */
   _map->update();
 }
 
@@ -192,7 +196,8 @@
 
   /* Load router information */
   loadDescriptors(_torControl->getRouterIDList());
-
+  /* Load existing address mappings */
+  loadAddressMap();
   /* Load Circuits and Streams information */
   loadConnections();
 
@@ -210,12 +215,23 @@
   /* Clear the network map */
   _map->clear();
   _map->update();
+  /* Clear the address map */
+  _addressMap.clear();
   /* Clear the lists of routers, circuits, and streams */
   ui.treeRouterList->clearRouters();
   ui.treeCircuitList->clearCircuits();
   ui.textRouterInfo->clear();
 }
 
+/** Loads a list of all current address mappings. */
+void
+NetViewer::loadAddressMap()
+{
+  /* We store the reverse address mappings, so we can go from a numeric value
+   * back to a likely more meaningful hostname to display for the user. */
+  _addressMap = _torControl->getAddressMap().reverse();
+}
+
 /** Loads a list of all current circuits and streams. */
 void
 NetViewer::loadConnections()
@@ -228,14 +244,14 @@
   /* Now load all streams */
   QList<Stream> streams = _torControl->getStreams();
   foreach (Stream stream, streams) {
-    ui.treeCircuitList->addStream(stream);
+    addStream(stream);
   }
 
   /* Update the map */
   _map->update();
 }
 
-/** Adds a circuit to the map and the list */
+/** Adds <b>circuit</b> to the map and the list */
 void
 NetViewer::addCircuit(Circuit circuit)
 {
@@ -248,6 +264,24 @@
   _map->addCircuit(circuit.id(), circIds.hops());
 }
 
+/** Adds <b>stream</b> to its associated circuit on the list of all circuits. */
+void
+NetViewer::addStream(Stream stream)
+{
+  QString target = stream.targetAddress();
+  QHostAddress addr(target);
+  
+  /* If the stream's target has an IP address instead of a host name,
+   * check our cache for an existing reverse address mapping. */
+  if (!addr.isNull() && _addressMap.isMapped(target)) {
+    /* Replace the IP address in the stream event with the original 
+     * hostname */
+    stream = Stream(stream.id(), stream.status(), stream.circuitId(),
+                    _addressMap.mappedTo(target), stream.targetPort());
+  }
+  ui.treeCircuitList->addStream(stream);
+}
+
 /** Called when the user selects the "Help" action from the toolbar. */
 void
 NetViewer::help()

Modified: trunk/src/gui/network/netviewer.h
===================================================================
--- trunk/src/gui/network/netviewer.h	2007-07-03 01:31:17 UTC (rev 1798)
+++ trunk/src/gui/network/netviewer.h	2007-07-03 01:32:39 UTC (rev 1799)
@@ -54,8 +54,11 @@
   void showWindow();
   /** Loads a list of current circuits and streams. */
   void loadConnections();
-  /** Adds a circuit to the list and the map */
+  /** Adds <b>circuit</b> to the list and the map */
   void addCircuit(Circuit circuit);
+  /** Adds <b>stream</b> to the list of circuits, under the appropriate
+   * circuit. */
+  void addStream(Stream stream);
   /** Clears all known information */
   void clear();
 
@@ -86,6 +89,8 @@
   void addToResolveQueue(QHostAddress ip, QString id);
   /** Loads a list of router descriptors from the list of IDs. */
   void loadDescriptors(QStringList ids);
+  /** Loads a list of address mappings from Tor. */
+  void loadAddressMap();
   /** Adds a router to our list of servers and retrieves geographic location
    * information for the server. */
   void addRouter(RouterDescriptor rd);
@@ -108,6 +113,8 @@
   QList<QHostAddress> _resolveQueue;
   /** Maps pending GeoIP requests to server IDs. */
   QHash<QString, QString> _resolveMap;
+  /** Stores a list of address mappings from Tor. */
+  AddressMap _addressMap;
   /** Timer used to delay GeoIP requests for MIN_RESOLVE_QUEUE_DELAY
    * milliseconds after we've inserted the last item into the queue. */
   QTimer _minResolveQueueTimer;