[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2941: The geoip parts now function with either async downloads fro (in vidalia/branches/exit-country/src/vidalia: . config geoip network)
Author: cviecco
Date: 2008-08-05 14:17:57 -0400 (Tue, 05 Aug 2008)
New Revision: 2941
Added:
vidalia/branches/exit-country/src/vidalia/geoip/README
Modified:
vidalia/branches/exit-country/src/vidalia/CMakeLists.txt
vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h
vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp
vidalia/branches/exit-country/src/vidalia/network/netviewer.h
vidalia/branches/exit-country/src/vidalia/vidalia.cpp
vidalia/branches/exit-country/src/vidalia/vidalia.h
Log:
The geoip parts now function with either async downloads from vidalia's geoip db or the internal DB.
Added description of API. Next step: tor based geoip(tor gives us the country not lat-long).
Modified: vidalia/branches/exit-country/src/vidalia/CMakeLists.txt
===================================================================
--- vidalia/branches/exit-country/src/vidalia/CMakeLists.txt 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/CMakeLists.txt 2008-08-05 18:17:57 UTC (rev 2941)
@@ -125,6 +125,7 @@
geoip/geoiprequest.cpp
geoip/geoipresponse.cpp
geoip/webgeoipresolver.cpp
+ geoip/geoipresolver.cpp
)
qt4_wrap_cpp(vidalia_SRCS
# geoip/geoip.h
@@ -134,6 +135,7 @@
geoip/geoiprequest.h
geoip/geoipresponse.h
geoip/webgeoipresolver.h
+ geoip/geoipresolver.h
)
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-08-05 18:17:57 UTC (rev 2941)
@@ -77,7 +77,7 @@
//file based geoip resolver
_geoIpResolver=Vidalia::geoIpResolver();
-
+ connect(_geoIpResolver, SIGNAL(geoResolved()), this, SLOT(refresh()));
}
@@ -253,6 +253,10 @@
QList<int> saved_excluded_index;
QStringList saved_excluded=_settings->getExcludeNodeCountry();
+ //clear the boxes!
+ ui.cmboExitNodesbyCountry->clear();
+ ui.listWidgetExcludedCountries->clear();
+
foreach (QString country, by_country_exit_nodes2.keys()) {
/*Get the count of exit nodes for this country*/
count=QString("%1").arg(by_country_exit_nodes2.value(country).count(),0,10);
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h 2008-08-05 18:17:57 UTC (rev 2941)
@@ -26,6 +26,7 @@
#include <torcontrol.h>
#include <routerstatus.h>
#include <filegeoipresolver.h>
+#include <geoipresolver.h>
//#include <torsettings.h>
#include "configpage.h"
@@ -93,7 +94,7 @@
QMap<QString,QString> country_long;
TorControl* _torControl;
- FileGeoIpResolver* _geoIpResolver;
+ GeoIpResolver* _geoIpResolver;
/** Timer that fires once an hour to update the QMaps list. */
QTimer _refreshTimer;
Added: vidalia/branches/exit-country/src/vidalia/geoip/README
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/README (rev 0)
+++ vidalia/branches/exit-country/src/vidalia/geoip/README 2008-08-05 18:17:57 UTC (rev 2941)
@@ -0,0 +1,35 @@
+All geoip modules MUST have the following functions:
+
+//-----------
+QString get_country(QHostAddress ip);
+
+GeoIp search(QHostAddress ip);
+
+void geoResolved();
+
+//--------
+If the modules uses a remote entitity for
+any part of the requests, the module MUST
+cache the answers. The cache MUST be at
+least 3000 entries in size.
+
+//-------------------
+Their functionality and api is:
+
+get_country -> gets the current known country of an ip address Syncronous.
+ this function can open files, but should have
+ a small bound on its termination time.
+ If the module uses external resolving, the
+ ip address should be added to the queue of unkown
+ ip addresses.
+search -> gets the current known geoip info. Syncronous.
+ this function can open files, but should have
+ a small bound on its termination time.
+ If the module uses external resolving, the
+ ip address should be added to the queue of unkown
+ ip addresses.
+geoResolved -> this function is called when the module has completed
+ a new batch of requests, if the module has any
+ remote resolving.
+
+
Modified: vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp 2008-08-05 18:17:57 UTC (rev 2941)
@@ -32,7 +32,10 @@
/** Page that we request the geo ip information from. */
#define GEOIP_PAGE "/cgi-bin/geoip"
+/*20 seconds*/
+#define RESOLVE_QUEUE_DELAY (15*1000)
+
/** Default constructor. */
WebGeoIpResolver::WebGeoIpResolver()
{
@@ -44,6 +47,12 @@
vWarn("Failed to add the GeoIP CA certificate to the default CA "
"certificate database.");
#endif
+ //_ResolveQueueTimer.setSingleShot(true);
+ _ResolveQueueTimer.setSingleShot(true);
+ // _ResolveQueueTimer.setInterval(10*1000);
+ connect(&_ResolveQueueTimer, SIGNAL(timeout()), this, SLOT(resolveInternalQueue()));
+ // QTimer::singleShot(5000, this, SLOT(resolveInternalQueue()));
+ mutex =new QMutex(QMutex::Recursive);
}
/** Sets the address and port of Tor, through which GeoIP requests will be
@@ -51,6 +60,8 @@
void
WebGeoIpResolver::setSocksHost(QHostAddress addr, quint16 port)
{
+ QMutexLocker locker(mutex);
+
_socksAddr = addr;
_socksPort = port;
}
@@ -61,6 +72,8 @@
bool
WebGeoIpResolver::resolveFromCache(QHostAddress ip)
{
+ QMutexLocker locker(mutex);
+
if (_cache.contains(ip)) {
emit resolved(-1, QList<GeoIp>() << _cache.geoip(ip));
return true;
@@ -73,7 +86,10 @@
QList<QHostAddress>
WebGeoIpResolver::resolveFromCache(QList<QHostAddress> ips)
{
+
+
QList<GeoIp> cached;
+ QMutexLocker locker(mutex);
/* Build a list of which IPs have cached GeoIp information */
foreach (QHostAddress ip, ips) {
@@ -102,6 +118,8 @@
void
WebGeoIpResolver::connected()
{
+ QMutexLocker locker(mutex);
+
/* Find the socket and request for whoever called this slot */
QAbstractSocket *socket = dynamic_cast<QAbstractSocket *>(sender());
if (!_requestList.contains(socket)) {
@@ -119,6 +137,8 @@
void
WebGeoIpResolver::disconnected()
{
+ QMutexLocker locker(mutex);
+
/* Find the socket and request for whoever called this slot */
QAbstractSocket *socket = dynamic_cast<QAbstractSocket *>(sender());
if (!_requestList.contains(socket)) {
@@ -165,6 +185,8 @@
vInfo("Parsed %1 entries from the GeoIP response. (request id %2)")
.arg(geoips.size()).arg(request->id());
emit resolved(request->id(), geoips);
+ fprintf(stderr,"web resolved!\n");
+ emit geoResolved();
} else {
/* We failed to get the Geo IP information, so emit resolveFailed and
* include the HTTP status message. */
@@ -182,6 +204,8 @@
void
WebGeoIpResolver::socketError(QString errorString)
{
+ QMutexLocker locker(mutex);
+
/* Find the socket and request for whoever called this slot */
QAbstractSocket *socket = dynamic_cast<QAbstractSocket *>(sender());
if (!_requestList.contains(socket)) {
@@ -206,6 +230,8 @@
GeoIpRequest*
WebGeoIpResolver::createRequest(QList<QHostAddress> ips)
{
+ QMutexLocker locker(mutex);
+
static int id = -1;
GeoIpRequest *request = new GeoIpRequest(++id);
request->setHost(GEOIP_HOST);
@@ -218,6 +244,9 @@
int
WebGeoIpResolver::resolve(QList<QHostAddress> ips)
{
+
+ QMutexLocker locker(mutex);
+
/* Resolve the cached IPs and get a list of IPs that still need to be
* resolved to a lat and long. */
QList<QHostAddress> uncached = resolveFromCache(ips);
@@ -261,3 +290,57 @@
return request->id();
}
+/*cviecco*/
+QString
+WebGeoIpResolver::get_country(QHostAddress ip){
+ QString unknown("??");
+ //return unknown;
+ GeoIp resolv=search(ip);
+
+ if (resolv.isEmpty() || resolv.isUnknown())
+ return unknown;
+ else
+ return resolv.country();
+}
+
+GeoIp
+WebGeoIpResolver::search(QHostAddress ip){
+
+ GeoIp invalid;
+ GeoIp rvalue;
+
+ QMutexLocker locker(mutex);
+
+ fprintf(stderr,"{");
+ if (_cache.contains(ip)) {
+ rvalue=_cache.geoip(ip);
+ return rvalue;
+ }
+ fprintf(stderr,"}");
+ //add to queue and return invalid!
+ //is this operation atomic?
+ queueMutex.lock();
+ _resolveQueue.append(ip);
+ queueMutex.unlock();
+ if(_resolveQueue.size()==1){
+ fprintf(stderr,"starting timer!\n");
+ _ResolveQueueTimer.start(15*1000);
+ }
+ //_ResolveQueueTimer.start(5*1000);
+
+ return invalid;
+
+}
+
+
+void
+WebGeoIpResolver::resolveInternalQueue(){
+
+ queueMutex.lock();
+ fprintf(stderr,"resolving internal queue! size=%d\n",_resolveQueue.size());
+ resolve(_resolveQueue);
+ //this is bad, as operations on the queue are NOT atomic
+ _resolveQueue.clear();
+ queueMutex.unlock();
+}
+
Modified: vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h 2008-08-05 18:17:57 UTC (rev 2941)
@@ -22,6 +22,9 @@
#include <QHash>
#include <QString>
#include <QHostAddress>
+#include <QTimer>
+#include <QMutex>
+#include <QMutexLocker>
#include <geoip.h>
#include "geoipcache.h"
@@ -50,12 +53,21 @@
* are cached. Returns a list of which IPs were not cached. */
QList<QHostAddress> resolveFromCache(QList<QHostAddress> ips);
+ /*can we build this?*/
+ GeoIp search(QHostAddress ip);
+ QString get_country(QHostAddress ip);
+
+
signals:
/** Emitted when a list of IPs have been resolved to lat/long. */
void resolved(int id, QList<GeoIp> geoips);
/** Emitted when a resolve has failed. */
void resolveFailed(int id, QString errorString);
+ /** Emitted when a list of IPs have been resolved to lat/long. */
+ void geoResolved();
+
+
private slots:
/** Called when the socket has connected to the Geo IP host. */
void connected();
@@ -64,18 +76,32 @@
/** Called when an error has occurred getting the Geo IP information. */
void socketError(QString errorString);
+ /**/
+ void resolveInternalQueue();
+
+
private:
+ /*Since this thing can be called from several threads*/
+ QMutex *mutex;
+
+
/** Creates an HTTP request for Geo IP information. */
GeoIpRequest* createRequest(QList<QHostAddress> ips);
/**< Cached GeoIp objects. */
GeoIpCache _cache;
+
/**< List of sockets used for requests. */
QHash<QAbstractSocket *,GeoIpRequest*> _requestList;
/** Tor's SocksListenAddress. */
QHostAddress _socksAddr;
/** Tor's SocksPort. */
quint16 _socksPort;
+
+ /*Internal queue stuff*/
+ QMutex queueMutex;
+ QList<QHostAddress> _resolveQueue;
+ QTimer _ResolveQueueTimer;
};
#endif
Modified: vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp 2008-08-05 18:17:57 UTC (rev 2941)
@@ -114,8 +114,8 @@
//file based geoip resolver
_geoIpResolver=Vidalia::geoIpResolver();
+ connect(_geoIpResolver, SIGNAL(geoResolved()), this, SLOT(refresh()));
-
}
/** Display the network map window. If there are geoip requests waiting in the
@@ -317,6 +317,10 @@
RouterListItem *router;
router = ui.treeRouterList->findRouterById(rd.id());
GeoIp geoip=_geoIpResolver->search(rd.ip());
+
+ //now test!
+ //webGeoResolver.search(rd.ip());
+
router->setLocation(geoip );
// Plot the router on the map
_map->addRouter(router->id(), geoip.latitude(), geoip.longitude());
Modified: vidalia/branches/exit-country/src/vidalia/network/netviewer.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/network/netviewer.h 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/network/netviewer.h 2008-08-05 18:17:57 UTC (rev 2941)
@@ -24,7 +24,9 @@
#include <QHash>
#include <torcontrol.h>
#include <vidaliawindow.h>
+#include <geoipresolver.h>
#include <filegeoipresolver.h>
+#include <webgeoipresolver.h>
//#include "geoipresolver.h"
#include "tormapwidget.h"
@@ -114,8 +116,8 @@
QTimer _maxResolveQueueTimer;
/*cviecco's*/
- FileGeoIpResolver* _geoIpResolver;
-
+ GeoIpResolver* _geoIpResolver;
+ WebGeoIpResolver webGeoResolver;
/** Qt Designer generated object **/
Ui::NetViewer ui;
Modified: vidalia/branches/exit-country/src/vidalia/vidalia.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/vidalia.cpp 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/vidalia.cpp 2008-08-05 18:17:57 UTC (rev 2941)
@@ -44,7 +44,9 @@
QString Vidalia::_style; /**< The current GUI style. */
QString Vidalia::_language; /**< The current language. */
TorControl* Vidalia::_torControl = 0; /**< Main TorControl object. */
-FileGeoIpResolver *Vidalia::_geoipResolver= NULL;
+GeoIpResolver *Vidalia::_geoipResolver= NULL;
+FileGeoIpResolver *Vidalia::_filegeoipResolver= NULL;
+
Log Vidalia::_log;
/** Catches debugging messages from Qt and sends them to Vidalia's logs. If Qt
@@ -111,7 +113,8 @@
_torControl = new TorControl();
// Creates a filegeoi resolver object;
- _geoipResolver= new FileGeoIpResolver();
+ _filegeoipResolver= new FileGeoIpResolver();
+ _geoipResolver= new GeoIpResolver();
}
Modified: vidalia/branches/exit-country/src/vidalia/vidalia.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/vidalia.h 2008-08-05 13:18:56 UTC (rev 2940)
+++ vidalia/branches/exit-country/src/vidalia/vidalia.h 2008-08-05 18:17:57 UTC (rev 2941)
@@ -31,6 +31,7 @@
#include <vidaliasettings.h>
#include <torcontrol.h>
#include <filegeoipresolver.h>
+#include <geoipresolver.h>
#include "config.h"
@@ -98,7 +99,8 @@
static void createShortcut(const QKeySequence &key, QWidget *sender,
QWidget *receiver, const char *slot);
- static FileGeoIpResolver* geoIpResolver(){return _geoipResolver; };
+ static FileGeoIpResolver* fileGeoIpResolver(){return _filegeoipResolver; };
+ static GeoIpResolver* geoIpResolver(){return _geoipResolver; };
signals:
/** Emitted when the application is running and the main event loop has
@@ -136,7 +138,8 @@
static Log _log; /**< Logs debugging messages to file or stdout. */
//ok I dont like this.. All this trouble for OO to have static stuff?
- static FileGeoIpResolver* _geoipResolver;
+ static FileGeoIpResolver* _filegeoipResolver;
+ static GeoIpResolver* _geoipResolver;
};
#endif