[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r1548: If we get a valid geoip response telling us the geoip databa (in trunk/src: gui/network util/geoip)
Author: edmanm
Date: 2006-12-23 04:03:55 -0500 (Sat, 23 Dec 2006)
New Revision: 1548
Modified:
trunk/src/gui/network/netviewer.cpp
trunk/src/util/geoip/geoip.cpp
trunk/src/util/geoip/geoip.h
trunk/src/util/geoip/geoipcacheitem.cpp
Log:
If we get a valid geoip response telling us the geoip database doesn't have a
location for the requested IP address, cache that response for one week so we
don't keep sending requests that are likely to fail anyway.
Modified: trunk/src/gui/network/netviewer.cpp
===================================================================
--- trunk/src/gui/network/netviewer.cpp 2006-12-23 06:53:57 UTC (rev 1547)
+++ trunk/src/gui/network/netviewer.cpp 2006-12-23 09:03:55 UTC (rev 1548)
@@ -306,11 +306,11 @@
/* 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;
-
+
/* Wait MIN_RESOLVE_QUEUE_DELAY after the last item inserted into the
* queue, before sending the resolve request. */
_minResolveQueueTimer.start(MIN_RESOLVE_QUEUE_DELAY);
@@ -392,7 +392,10 @@
/* Find all routers that are at this IP address */
ip = geoip.ip().toString();
QList<QString> ids = _resolveMap.values(ip);
-
+ _resolveMap.remove(ip);
+ if (geoip.isUnknown())
+ continue; /* We don't know where this router is */
+
/* Update their geographic location information with the results of this
* GeoIP query. */
foreach (QString id, ids) {
@@ -404,7 +407,6 @@
_map->addRouter(router->id(), geoip.latitude(), geoip.longitude());
}
}
- _resolveMap.remove(ip);
}
/* Update the circuit lines */
Modified: trunk/src/util/geoip/geoip.cpp
===================================================================
--- trunk/src/util/geoip/geoip.cpp 2006-12-23 06:53:57 UTC (rev 1547)
+++ trunk/src/util/geoip/geoip.cpp 2006-12-23 09:03:55 UTC (rev 1548)
@@ -29,6 +29,12 @@
#include "geoip.h"
+/** Constructor */
+GeoIp::GeoIp(QHostAddress ip)
+{
+ _ip = ip;
+ _latitude = _longitude = 0.0;
+}
/** Constructor. */
GeoIp::GeoIp(QHostAddress ip, float latitude, float longitude,
@@ -52,7 +58,10 @@
{
/* Split comma-delimited data fields */
QStringList data = geoip.split(",");
- if (data.size() < 6) {
+
+ if (data.size() == 2 && data.at(1).toLower() == "unknown") {
+ return GeoIp(QHostAddress(data.at(0)));
+ } else if (data.size() < 6) {
return GeoIp();
}
@@ -90,6 +99,14 @@
return (_ip.isNull() && !_latitude && !_longitude);
}
+/** Returns true if the GeoIp object is valid, but no location information
+ * is known for the associated IP address. */
+bool
+GeoIp::isUnknown() const
+{
+ return (!_ip.isNull() && !_latitude && !_longitude);
+}
+
/** Returns a human-readable string of GeoIp location information. */
QString
GeoIp::toLocation() const
Modified: trunk/src/util/geoip/geoip.h
===================================================================
--- trunk/src/util/geoip/geoip.h 2006-12-23 06:53:57 UTC (rev 1547)
+++ trunk/src/util/geoip/geoip.h 2006-12-23 09:03:55 UTC (rev 1548)
@@ -37,6 +37,8 @@
public:
/** Default constructor */
GeoIp() : _latitude(0), _longitude(0) {}
+ /** Constructor. */
+ GeoIp(QHostAddress ip);
/** Constructor */
GeoIp(QHostAddress ip, float latitude, float longitude,
@@ -64,6 +66,9 @@
/** Returns true if the GeoIp object is invalid. */
bool isEmpty() const;
+ /** Returns true if the GeoIp object is valid, but no location information
+ * is known for the associated IP address. */
+ bool isUnknown() const;
private:
QHostAddress _ip; /**< IP address for this location. */
Modified: trunk/src/util/geoip/geoipcacheitem.cpp
===================================================================
--- trunk/src/util/geoip/geoipcacheitem.cpp 2006-12-23 06:53:57 UTC (rev 1547)
+++ trunk/src/util/geoip/geoipcacheitem.cpp 2006-12-23 09:03:55 UTC (rev 1548)
@@ -77,11 +77,15 @@
return GeoIpCacheItem();
}
-/** Returns true if the cache item is too old to be considered valid. */
+/** Returns true if the cache item is too old to be considered valid. Normal
+ * cached responses are valid for one month. Cached UNKNOWN responses are
+ * considered valid for one week. */
bool
GeoIpCacheItem::isExpired() const
{
- /* Consider cache entries to be valid for one month. */
+ if (_geoip.isUnknown()) {
+ return (_timestamp.addDays(7) < QDateTime::currentDateTime());
+ }
return (_timestamp.addMonths(1) < QDateTime::currentDateTime());
}