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

[vidalia-svn] r1519: When adding addresses to the geoip request queue, try to res (in trunk/src: gui/network util/geoip)



Author: edmanm
Date: 2006-12-10 13:16:52 -0500 (Sun, 10 Dec 2006)
New Revision: 1519

Modified:
   trunk/src/gui/network/netviewer.cpp
   trunk/src/util/geoip/geoipresolver.cpp
   trunk/src/util/geoip/geoipresolver.h
Log:
When adding addresses to the geoip request queue, try to resolve them from
cache first instead of waiting for the queue timers to time out.


Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp	2006-12-10 18:13:16 UTC (rev 1518)
+++ trunk/src/gui/network/netviewer.cpp	2006-12-10 18:16:52 UTC (rev 1519)
@@ -301,7 +301,12 @@
 NetViewer::addToResolveQueue(QHostAddress ip, QString id)
 {
   QString ipstr = ip.toString();
-  if (!_resolveQueue.contains(ip)) {
+  if (!_resolveMap.values(ipstr).contains(id)) {
+    /* Remember which server ids belong to which IP addresses */
+    _resolveMap.insertMulti(ipstr, id);
+  }
+  
+  if (!_resolveQueue.contains(ip) && !_geoip.resolveFromCache(ip)) {
     /* Add the IP to the queue of IPs waiting for geographic information  */
     _resolveQueue << ip;
     
@@ -316,10 +321,6 @@
       _maxResolveQueueTimer.start(MAX_RESOLVE_QUEUE_DELAY);
     }
   }
-  if (!_resolveMap.values(ipstr).contains(id)) {
-    /* Remember which server ids belog to which IP addresses */
-    _resolveMap.insertMulti(ipstr, id);
-  }
 }
 
 /** Called when the user selects a circuit from the circuit and streams
@@ -363,10 +364,6 @@
 NetViewer::resolve()
 {
   if (!_resolveQueue.isEmpty()) {
-    /* Get geoip information for addresses that are cached. Returns a list of
-     * IP addresses that were not cached. */
-    _resolveQueue = _geoip.resolveFromCache(_resolveQueue);
-    
     /* Send the request now if either the network map is visible, or the
      * request is for more than a quarter of the servers in the list. */
     if (isVisible() || 

Modified: trunk/src/util/geoip/geoipresolver.cpp
===================================================================
--- trunk/src/util/geoip/geoipresolver.cpp	2006-12-10 18:13:16 UTC (rev 1518)
+++ trunk/src/util/geoip/geoipresolver.cpp	2006-12-10 18:16:52 UTC (rev 1519)
@@ -44,6 +44,19 @@
   _socksPort = port;
 }
 
+/** Resolves <b>ip</b> to geographic information if it is cached. A resolved()
+ * signal will be emitted and true returned if we have cached geographic
+ * information for <b>ip</b>. Otherwise, this returns false. */
+bool
+GeoIpResolver::resolveFromCache(QHostAddress ip)
+{
+  if (_cache.contains(ip)) {
+    emit resolved(-1, QList<GeoIp>() << _cache.geoip(ip));
+    return true;
+  }
+  return false;
+}
+
 /** Resolves a list of IPs to a geographic location, but only those which are
  * cached. Returns a list of IPs that were not in the cache. */
 QList<QHostAddress>

Modified: trunk/src/util/geoip/geoipresolver.h
===================================================================
--- trunk/src/util/geoip/geoipresolver.h	2006-12-10 18:13:16 UTC (rev 1518)
+++ trunk/src/util/geoip/geoipresolver.h	2006-12-10 18:16:52 UTC (rev 1519)
@@ -57,6 +57,8 @@
   int resolve(QHostAddress ip);
   /** Resolves a list of IPs to a geographic location. */
   int resolve(QList<QHostAddress> ips);
+  /** Resolves <b>ip</b> to geographic information only if it is cached. */
+  bool resolveFromCache(QHostAddress ip);
   /** Resolves a list of IPs to a geographic location, but only those which
    * are cached. Returns a list of which IPs were not cached. */
   QList<QHostAddress> resolveFromCache(QList<QHostAddress> ips);