[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2952: Made more stuff compliant to the hacking document(doxygen). (in vidalia/branches/exit-country: . src/vidalia src/vidalia/config src/vidalia/geoip)
Author: cviecco
Date: 2008-08-11 14:43:05 -0400 (Mon, 11 Aug 2008)
New Revision: 2952
Added:
vidalia/branches/exit-country/README.exit-country
Modified:
vidalia/branches/exit-country/src/vidalia/CMakeLists.txt
vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp
vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h
vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h
vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h
vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h
Log:
Made more stuff compliant to the hacking document(doxygen).
Fixed a race condition.
Added documnetation on what was done, how and
what files were modified
Added: vidalia/branches/exit-country/README.exit-country
===================================================================
--- vidalia/branches/exit-country/README.exit-country (rev 0)
+++ vidalia/branches/exit-country/README.exit-country 2008-08-11 18:43:05 UTC (rev 2952)
@@ -0,0 +1,164 @@
+The Exit country branch was sponsored by Google as
+a 2008 Google summer of code project.
+The project Manager was: Matt Edman,
+the student: Camilo Viecco.
+
+The objective was to add some 'blossom' functionality to vidalia,
+that is the ability to select a desired country to view the
+'Internet' network from. The key assumtion is that the content
+of the network is different according to the users (ip address)
+country location. The second assumtion
+is that per country content views is pervasive while
+filtering on Tor exit nodes is not.
+
+
+2. Implementaiton Overview
+
+The functionality was implemented as an additional 'tab'
+in vidalia's settings window. The interface
+provides checks to prevent users from accidentaly enabling this
+functionality as it significantly reduces users anonymity.
+The selection of the country is done via a 'combo-box', followed
+by an 'apply country' button. Every time the country is changed,
+the system close all built circuits, so that next circuit
+construction follows the policy.
+Also an 'avoid the following countries' selector was
+implemented.
+
+
+The implementation created a centralized geoip resolver class with a new
+and simplier API for any vidalia subsystem that desires geoip location.
+All of the geoip resolvers conforming to the API must be thread safe
+(after initialization) in order to be called from any place in the
+vidalia codebase. All implemented geoip resolvers (Tor,web,file) follow
+this restriction. The geoip parts were moved into a single directory.
+
+A new window tab 'policy settings' was created with the vidalia
+style for them (3 sets of files: page, ui, and settings). The
+system uses the new geoip api. Vidalia's 'netviewer' was modified
+to use this new geoip resolver (simplifying the netviewer class)
+
+The system has been tested in windows XP and Linux using qt 4.3.5.
+
+3. Toughts and thigs to do.
+
+On the coding in general.
+The initial system implementaiton was straigtforward. However the
+need to build a unified API slowed down the coding.
+
+On things not implemented.
+A better way to detect if the current circuits satisfy the policy
+would be really handy, but is out of the scope for this summer.
+
+What I would do for a future student:
+Vidalia needs better documentation on its internal connectors.
+Reading the code is ok, but I found myself rebuilding some code
+to satisfy coding style that was not explicit.
+There is no need for students to be fluent in Qt, but
+c++ is really needed.
+
+What I would change in Vidalia.
+I disagree in the way comments are placed in the Hacking directives.
+I think that comments in /**/ are OK for .h files but are
+problematic for .cpp files as commenting large blocks of code
+for debugging/testing is cumbersome and leaves coders tempted
+to remove the comments. Otherwise I like it.
+
+
+
+//-------------------------------
+Appendix. GeoIP resolvers API.
+
+All Goip resolvers must implement 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.
+
+The functionality of the functions 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.
+
+
+
+//-------------------------
+Appendix. Code Details
+
+Modified files:
+ src/vidalia/vidalia.h
+ src/vidalia/vidalia.cpp
+ src/vidalia/network/netviewer.h
+ src/vidalia/network/netviewer.cpp
+ src/vidalia/config/configdialog.h
+ src/vidalia/config/configdialog.cpp
+ src/vidalia/CMakeLists.txt
+ src/vidalia/res/vidalia_common.qrc
+ src/torcontrol/torcontrol.h
+ src/torcontrol/torcontrol.cpp
+
+Moved/renamed/modified files:
+ src/vidalia/network/geoipresolver.h -> src/vidalia/geoip/webgeoipresolver.h
+ src/vidalia/network/geoipresolver.cpp -> src/vidalia/geoip/webgeoipresolver.cpp
+ src/vidalia/network/geoip.h -> src/vidalia/geoip/geoip.h
+ src/vidalia/network/geoip.cpp -> src/vidalia/geoip/geoip.cpp
+ src/vidalia/network/geoipcacheitem.h -> src/vidalia/geoip/geoipcacheitem.h
+ src/vidalia/network/geoipcacheitem.cpp -> src/vidalia/geoip/geoipcacheitem.cpp
+ src/vidalia/network/geoipcache.h -> src/vidalia/geoip/geoipcache.h
+ src/vidalia/network/geoipcache.cpp -> src/vidalia/geoip/geoipcache.cpp
+ src/vidalia/network/geoiprequest.h -> src/vidalia/geoip/geoiprequest.h
+ src/vidalia/network/geoiprequest.cpp -> src/vidalia/geoip/geoiprequest.cpp
+ src/vidalia/network/geoipresponse.h -> src/vidalia/geoip/geoipresponse.h
+ src/vidalia/network/geoipresponse.cpp -> src/vidalia/geoip/geoipresponse.cpp
+
+New files:
+ src/vidalia/geoip/torgeoipresolver.h
+ src/vidalia/geoip/torgeoipresolver.cpp
+ src/vidalia/geoip/geoipresolver.h
+ src/vidalia/geoip/geoipresolver.cpp
+ src/vidalia/geoip/README
+ src/vidalia/config/nodepolicypage.cpp
+ src/vidalia/config/nodepolicypage.h
+ src/vidalia/config/nodepolicypage.ui
+ src/vidalia/config/nodepolicysettings.cpp
+ src/vidalia/config/nodepolicysettings.h
+ src/vidalia/res/country_loc.csv
+
+changes:
+ -geoipresolver.*
+ The vidalia geoipresolver class was renamed
+ webgeoipresolver. The following chages were done:
+ -Locks were added to make it thread safe
+ -A new interface for querieng replaced the old one.
+ This simplifies the entities that make the queries
+ -Internal queues were inserted for the new interface.
+ -filegeoipresolver.*
+ A new geoiprsolver class that resolved geoip information
+ from a local file. After initialization is thread safe
+ -torgeoipresolver.*
+ A new class that resolves geoip information by asking the Tor
+ controller for information. After initialization is thread safe.
+ -geoipresolver.*
+ A new geoipresolver class, resolves via Tor, web or file depending
+ on the availability of the resolvers. Assumes websreolver always exists
+ but is the least prefereable way to do resolving.
+
+
+
Modified: vidalia/branches/exit-country/src/vidalia/CMakeLists.txt
===================================================================
--- vidalia/branches/exit-country/src/vidalia/CMakeLists.txt 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/CMakeLists.txt 2008-08-11 18:43:05 UTC (rev 2952)
@@ -132,10 +132,10 @@
qt4_wrap_cpp(vidalia_SRCS
# geoip/geoip.h
geoip/filegeoipresolver.h
- geoip/geoipcacheitem.h
- geoip/geoipcache.h
- geoip/geoiprequest.h
- geoip/geoipresponse.h
+ #geoip/geoipcacheitem.h
+ #geoip/geoipcache.h
+ #geoip/geoiprequest.h
+ #geoip/geoipresponse.h
geoip/webgeoipresolver.h
geoip/geoipresolver.h
geoip/torgeoipresolver.h
@@ -161,12 +161,6 @@
set(vidalia_SRCS ${vidalia_SRCS}
network/circuititem.cpp
network/circuitlistwidget.cpp
- #network/geoipcache.cpp
- #network/geoipcacheitem.cpp
- #network/geoip.cpp
- #network/geoiprequest.cpp
- #network/geoipresolver.cpp
- #network/geoipresponse.cpp
network/netviewer.cpp
network/routerdescriptorview.cpp
network/routerlistitem.cpp
@@ -177,7 +171,6 @@
)
qt4_wrap_cpp(vidalia_SRCS
network/circuitlistwidget.h
- #network/geoipresolver.h
network/netviewer.h
network/routerdescriptorview.h
network/routerlistwidget.h
Modified: vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp 2008-08-11 18:43:05 UTC (rev 2952)
@@ -126,7 +126,7 @@
load_longnames();
}
-
+/** run when the connection is lost*/
void
NodePolicyPage::onAuthenticated()
{
@@ -136,7 +136,8 @@
-/* The monster function! does:
+/** Implements the core functionality
+ The monster function! does:
a. reload the internal structures
b. fills the combo boxes
*/
@@ -273,7 +274,7 @@
}
-/*copy the names of routers in the exit
+/** copy the names of routers in the exit
* country to the appropiate place in the GUI*/
void
NodePolicyPage::copyExitCountryToText()
@@ -306,7 +307,7 @@
}
-/*copy the names of routers in the excluded
+/** copy the names of routers in the excluded
* country list to the appropiate place in the GUI*/
void
NodePolicyPage::copyExcludedCountryToText()
@@ -350,7 +351,7 @@
}
-/*Hide/Undide stuff in the GUI accordint to selections*/
+/** Hide/Undide stuff in the GUI accordint to selections*/
void
NodePolicyPage::HideUnhide(){
// if(ui.chkNodePolicy->isChecked()){
@@ -364,7 +365,7 @@
-/*close all circuits*/
+/** close all circuits*/
void
NodePolicyPage::closeAllCircuits(){
//get list of circuits
@@ -380,7 +381,7 @@
}
-/*Apply GUI settings if any to tor*/
+/** Apply GUI settings if any to tor*/
void
NodePolicyPage::applyTorSettings(){
@@ -446,7 +447,7 @@
_settings->apply();
}
-/*Get the list of selected exclude countryies from the gui*/
+/** Get the list of selected exclude countryies from the gui*/
QStringList
NodePolicyPage::getExcludeCountries(){
QStringList excludeCountries;
@@ -464,7 +465,7 @@
return excludeCountries;
}
-/*Get the current select country from the GUI*/
+/** Get the current select country from the GUI*/
QString
NodePolicyPage::getExitCountry(){
QString current=ui.cmboExitNodesbyCountry->currentText();
@@ -478,8 +479,8 @@
}
-/*Loads the internal map of short country names to
-full country names*/
+/** Loads the internal map of short country names to
+ *full country names*/
void
NodePolicyPage::load_longnames(){
Modified: vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h 2008-08-11 18:43:05 UTC (rev 2952)
@@ -32,7 +32,10 @@
#include "configpage.h"
#include "ui_networkoutpage.h"
-
+/**
+ This class contains the GUI functionality for the node popolicy page
+ ie. per country exit
+*/
class NodePolicyPage : public ConfigPage
{
Q_OBJECT
Modified: vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp 2008-08-11 18:43:05 UTC (rev 2952)
@@ -30,7 +30,7 @@
}
-
+/** resolves a the ip of a country */
QString
GeoIpResolver::get_country(QHostAddress ip){
QString unknown("??");
@@ -44,14 +44,15 @@
}
-//Search for a geoip address given a host ip
-// The order of authoritateveness is
-// 1. user file,
-// 2. Tor
-// 3. Vidalia-current geolocation
+/** Search for a geoip address given a host ip
+ * The order of authoritateveness is
+ * 1. user file,
+ * 2. Tor
+ * 3. Vidalia-current geolocation
+*/
GeoIp
GeoIpResolver::search(QHostAddress ip){
-
+ GeoIp torResolved;
quint32 torVersion = Vidalia::torControl()->getTorVersion();
//all the logic is defined here!
@@ -60,10 +61,16 @@
return _fileGeoIpResolver->search(ip);
}
if(torVersion>=0x020100){
- return torGeoResolver.search(ip);
+ //fprintf(stderr,"#");
+ torResolved=torGeoResolver.search(ip);
+ //next line, what do do on unknown
+ //current decision, never go web
+ if(!torResolved.isEmpty() || 1==1){
+ return torResolved;
+ }
+ vInfo("Tor cannot resolve, going via web interface!\n");
}
//and now the default
-
return webGeoResolver.search(ip);
}
@@ -78,7 +85,7 @@
void
GeoIpResolver::resolved(){
//GeoIpResolver::resolved(){
- fprintf(stderr,"georeslved signal!\n");
+ vInfo("georeolver signal!\n");
emit geoResolved();
};
Modified: vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h 2008-08-11 18:43:05 UTC (rev 2952)
@@ -34,8 +34,10 @@
#include <torgeoipresolver.h>
#include <torcontrol.h>
+/**
+ Geoip resolver. Solves Geoip information from the 'appropiate' resolvers :)
+*/
-
class GeoIpResolver : public QObject
{
Q_OBJECT
Modified: vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp 2008-08-11 18:43:05 UTC (rev 2952)
@@ -65,7 +65,7 @@
}
-/*Get the short country name*/
+/** Get the short country name for a given ip*/
QString
TorGeoIpResolver::get_country(QHostAddress ip){
@@ -78,7 +78,7 @@
}
-/*Get the geoip information for a host ip*/
+/** Get the geoip information for a host ip*/
GeoIp
TorGeoIpResolver::search(QHostAddress ip){
GeoIp invalid;
@@ -106,7 +106,7 @@
}
-
+/** async signal for delayed resolutions*/
void
TorGeoIpResolver::resolved(){
vInfo("georeslved signal!\n");
Modified: vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h 2008-08-11 18:43:05 UTC (rev 2952)
@@ -31,11 +31,12 @@
#include <QHash>
#include <filegeoipresolver.h>
-/*The Purpose of this class is to do
+/**
+ * The Purpose of this class is to do
* geoip resolutions based on Tor's
* geoip information. Never checks
- if this capability is even possible
-*/
+ * if this capability is even possible
+ */
class TorGeoIpResolver : public QObject
Modified: vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.cpp 2008-08-11 18:43:05 UTC (rev 2952)
@@ -185,7 +185,7 @@
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");
+ vInfo("web resolved!\n");
emit geoResolved();
} else {
/* We failed to get the Geo IP information, so emit resolveFailed and
@@ -290,7 +290,10 @@
return request->id();
}
-/*cviecco*/
+/** returns the current known country for a given ip
+ * if unkown/not in cache will queue the ip for
+ * async resolution
+*/
QString
WebGeoIpResolver::get_country(QHostAddress ip){
QString unknown("??");
@@ -303,27 +306,33 @@
return resolv.country();
}
+/** returns the known geoip information for a given ip
+ * if unkown/not in cache will queue the ip for
+ * async resolution
+*/
+
GeoIp
WebGeoIpResolver::search(QHostAddress ip){
GeoIp invalid;
GeoIp rvalue;
-
+ uint32_t queueSize;
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);
+ if(!_resolveQueue.contains(ip)){
+ _resolveQueue.append(ip);
+ }
+ queueSize=_resolveQueue.size();
queueMutex.unlock();
- if(_resolveQueue.size()==1){
- fprintf(stderr,"starting timer!\n");
+ if(1==queueSize){
+ vInfo("starting timer!\n");
_ResolveQueueTimer.start(15*1000);
}
//_ResolveQueueTimer.start(5*1000);
@@ -332,12 +341,13 @@
}
-
+/** async queue manager. Starts resolution of the current unkown ip queue
+*/
void
WebGeoIpResolver::resolveInternalQueue(){
queueMutex.lock();
- fprintf(stderr,"resolving internal queue! size=%d\n",_resolveQueue.size());
+ //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();
Modified: vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h 2008-08-11 13:04:22 UTC (rev 2951)
+++ vidalia/branches/exit-country/src/vidalia/geoip/webgeoipresolver.h 2008-08-11 18:43:05 UTC (rev 2952)
@@ -31,6 +31,10 @@
#include "geoiprequest.h"
#include "geoipresponse.h"
+/**
+ This class resolves geoip information using vidalia's online
+ geoip locator. Uses caching and asyncronous signals
+*/
class WebGeoIpResolver : public QObject
{