[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2736: Code cleanup. Removed unncecesary functions. Fixed typeo on (vidalia/branches/exit-country/src/vidalia/config)
Author: cviecco
Date: 2008-06-15 16:17:04 -0400 (Sun, 15 Jun 2008)
New Revision: 2736
Modified:
vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.h
vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
Log:
Code cleanup. Removed unncecesary functions. Fixed typeo on node list control. Made
allmost all nodes be selected by descripor id instead of name as I dont know
a way to query which names are registered.
Modified: vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.cpp 2008-06-15 19:40:10 UTC (rev 2735)
+++ vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.cpp 2008-06-15 20:17:04 UTC (rev 2736)
@@ -21,8 +21,21 @@
#include <time.h>
-#define GEOIP_FILENAME (Vidalia::defaultDataDirectory() + "/geoip.data")
+#define GEOIP_FILENAME (Vidalia::dataDirectory() + "/geoip.data")
+inline
+uint32_t
+FileGeoIpResolver::string2intloc(const char *in){
+ //long internal;
+ uint32_t rval;
+ rval=atoi(in);
+ if(0==rval){
+ rval=0xFF000000 | (in[0]<<8) | (in[1]);
+ }
+ return rval;
+}
+
+
/** Default constructor. */
FileGeoIpResolver::FileGeoIpResolver()
{
@@ -50,7 +63,7 @@
if(3==sscanf(tmpline,"%u,%u,%s",&newrange.low_net,&newrange.high_net,tmpline3)){
if(0==block_count){
- ipRange.reserve(location.size()*location.size()/3);
+ ipRange.reserve((location.size()*location.size())/10);
}
block_count++;
//token = strtok(line, search);
@@ -62,7 +75,8 @@
//newrange.low_net=list2.at(0).toUInt();
//newrange.high_net=list2.at(1).toUInt();
//newrange.location=list2.at(2);
- newrange.location=newline;
+ newrange.location2=string2intloc(tmpline3);
+ //newrange.location=newline;
ipRange.append(newrange);
@@ -79,7 +93,10 @@
newlocation.latitude=list2.at(2).toFloat();
newlocation.longitude=list2.at(3).toFloat();
//fprintf(stderr,"%s",tmpline2);
- location.insert(list2.at(0),newlocation);
+ //location.insert(list2.at(0),newlocation);
+ //memcpy(tmpline3,list2.at(0).toAscii(),2);
+ //location.insert(string2intloc(tmpline3),newlocation);
+ location.insert(string2intloc(list2.at(0).toAscii()),newlocation);
break;
case 0:
case 1:
@@ -96,9 +113,8 @@
fclose(file2);
}
else{
- //user geoip file not found or cannot be opened
- //use the default, built in file!
- //QFile file(":geoip.data");
+ //This branche when user geoip file not found or cannot be opened
+ //therefore, use the default, built in file!
QFile file(":/geoip/geoip.data");
QString line;
QStringList list;
@@ -107,7 +123,7 @@
fprintf (stderr,"cannot open geoip data file!\n");
return;
}
- fprintf(stderr,"using default geoip file!\n");
+ //fprintf(stderr,"using default geoip file!\n");
while (!in.atEnd()) {
line = in.readLine();
list=line.split(",");
@@ -123,7 +139,9 @@
case 3: //is range
newrange.low_net=list.at(0).toUInt();
newrange.high_net=list.at(1).toUInt();
- newrange.location=list.at(2);
+ //newrange.location=list.at(2);
+ //memcpy(tmpline3,list.at(0).toAscii(),2);
+ newrange.location2=string2intloc(list.at(2).toAscii());
ipRange.append(newrange);
break;
@@ -134,7 +152,8 @@
newlocation.country_short=list.at(1);
newlocation.latitude=list.at(2).toFloat();
newlocation.longitude=list.at(3).toFloat();
- location.insert(list.at(0),newlocation);
+ //location.insert(list.at(0),newlocation);
+ location.insert(string2intloc(list.at(0).toAscii()),newlocation);
break;
}
@@ -150,101 +169,8 @@
}
-/** Sets the address and port of Tor, through which GeoIP requests will be
- * made. */
-void
-FileGeoIpResolver::setSocksHost(QHostAddress addr, quint16 port)
-{
- //do nothing here, kept for easy backwards compatibility.
-
-}
-/** 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
-FileGeoIpResolver::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>
-FileGeoIpResolver::resolveFromCache(QList<QHostAddress> ips)
-{
- QList<GeoIp> cached;
-
- foreach (QHostAddress ip, ips) {
- if (_cache.contains(ip)) {
- ips.removeAt(ips.indexOf(ip));
- cached << _cache.geoip(ip);
- }
- }
-
- if (cached.size() > 0) {
- vInfo("Resolved %1 GeoIP entries from cache.").arg(ips.size());
- emit resolved(-1, cached);
- }
- return ips;
-}
-*/
-
-
-/** Resolves a single IP to a geographic location. */
-int
-FileGeoIpResolver::resolve(QHostAddress ip)
-{
- return resolve(QList<QHostAddress>() << ip);
-}
-
-/** Called when the socket has connected to the Geo IP host. */
-void
-FileGeoIpResolver::connected()
-{
-}
-
-/** Called when the socket has disconnected from the Geo IP host. */
-void
-FileGeoIpResolver::disconnected()
-{
-}
-
-/** Called when an error has occurred requesting Geo IP information. */
-void
-FileGeoIpResolver::socketError(QString errorString)
-{
-}
-
-/** Creates an HTTP request for Geo IP information. */
-
-/** Resolves a list of IPs to a geographic location. */
-int
-FileGeoIpResolver::resolve(QList<QHostAddress> ips)
-{
- //return request->id();
- return 0;
-}
-
-
-QList<GeoIp>
-FileGeoIpResolver::resolve_sync(QHostAddress ip){
- return resolve_sync(QList<QHostAddress>() << ip);
-}
-
-
-QList<GeoIp>
-FileGeoIpResolver::resolve_sync(QList<QHostAddress> ips){
- QList<GeoIp> rlist;
- return rlist;
-}
-
+//returns an country given an ip.
QString
FileGeoIpResolver::get_country(QHostAddress ip){
QString unknown("??");
@@ -257,9 +183,10 @@
return resolv.country();
}
+
+//Search for a geoip address given a host ip
GeoIp
FileGeoIpResolver::search(QHostAddress ip){
- // for easy of code do a linear search....
int i;
int found=-1;
FileGeoIpResolverGeoLocation iploc;
@@ -267,23 +194,21 @@
int high=ipRange.size();
GeoIp invalid;
-/*
+
+ /*
+ //old code.. simple linear search..
for(i=0;i<ipRange.size();i++){
if(ipRange[i].low_net<=ip.toIPv4Address() && ipRange[i].high_net>=ip.toIPv4Address() ){
found=i;
break;
}
}
-*/
-
+ */
+
+ //new code.. combo binary search + linear (linear on near found)
low=0;
high=ipRange.size();
while(low+1<high){
- // if(ipRange[low].low_net>ip.toIPv4Address() || ipRange[high].high_net<ip.toIPv4Address()){
- // low=0;
- // high=0;
- // break;
- // }
//now compare with middle!
mid=(low+high)/2;
if(ipRange[mid].low_net>ip.toIPv4Address()){
@@ -294,7 +219,8 @@
}
}
for(i=low;i<high+1;i++){
- if(ipRange[i].low_net<=ip.toIPv4Address() && ipRange[i].high_net>=ip.toIPv4Address() ){
+ if(ipRange[i].low_net<=ip.toIPv4Address() &&
+ ipRange[i].high_net>=ip.toIPv4Address() ){
found=i;
break;
}
@@ -306,7 +232,8 @@
//now get location
- iploc=location[ipRange[found].location];
+ //iploc=location[ipRange[found].location];
+ iploc=location[ipRange[found].location2];
//now convert
GeoIp rvalue(ip, iploc.latitude, iploc.longitude,
iploc.extra_info, "", iploc.country_short);
Modified: vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.h 2008-06-15 19:40:10 UTC (rev 2735)
+++ vidalia/branches/exit-country/src/vidalia/config/filegeoipresolver.h 2008-06-15 20:17:04 UTC (rev 2736)
@@ -36,6 +36,8 @@
//#include "geoiprequest.h"
//#include "geoipresponse.h"
+
+//Two classes for internal storage!
class FileGeoIpResolverGeoLocation
{
public:
@@ -50,10 +52,13 @@
public:
uint32_t low_net;
uint32_t high_net;
- QString location;
+ //QString location;
+ uint32_t location2;
};
+//now the actual class
+
class FileGeoIpResolver : public QObject
{
Q_OBJECT
@@ -64,14 +69,14 @@
/** Sets the address and port of Tor, through which GeoIP requests will be
* made. */
- void setSocksHost(QHostAddress addr, quint16 port);
+ //void setSocksHost(QHostAddress addr, quint16 port);
/** Resolves a single IP to a geographic location. */
- int resolve(QHostAddress ip);
+ //int resolve(QHostAddress ip);
/** Resolves a list of IPs to a geographic location. */
- int resolve(QList<QHostAddress> ips);
+ //int resolve(QList<QHostAddress> ips);
- QList<GeoIp> resolve_sync(QHostAddress ip);
- QList<GeoIp> resolve_sync(QList<QHostAddress> ips);
+ //QList<GeoIp> resolve_sync(QHostAddress ip);
+ //List<GeoIp> resolve_sync(QList<QHostAddress> ips);
/** Resolves <b>ip</b> to geographic information only if it is cached. */
//bool resolveFromCache(QHostAddress ip);
@@ -81,44 +86,34 @@
QString get_country(QHostAddress ip);
-
-signals:
+//signals:
/** Emitted when a list of IPs have been resolved to lat/long. */
- void resolved(int id, QList<GeoIp> geoips);
+ //void resolved(int id, QList<GeoIp> geoips);
/** Emitted when a resolve has failed. */
- void resolveFailed(int id, QString errorString);
+ //void resolveFailed(int id, QString errorString);
-private slots:
+//private slots:
/** Called when the socket has connected to the Geo IP host. */
- void connected();
+ //void connected();
/** Called when the socket has disconnected from the Geo IP host. */
- void disconnected();
+ //void disconnected();
/** Called when an error has occurred getting the Geo IP information. */
- void socketError(QString errorString);
+ //void socketError(QString errorString);
public:
GeoIp search(QHostAddress ip);
private:
- /** 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;
-
//provides locking during db access/updates to guarantee thread safety
+ // not used now since we do not update the DB on realtime
QMutex mutex;
bool ready;
//now the internal data structs
- QHash<QString,FileGeoIpResolverGeoLocation> location;
+ //QHash<QString,FileGeoIpResolverGeoLocation> location;
+ QHash<uint32_t,FileGeoIpResolverGeoLocation> location;
QVector<FileGeoIpResolverIpRange> ipRange;
+ uint32_t string2intloc(const char *);
};
#endif
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-06-15 19:40:10 UTC (rev 2735)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-06-15 20:17:04 UTC (rev 2736)
@@ -189,13 +189,17 @@
if (!router.isValid())
continue;
flags=router.flags();
- if(0x08 !=((0x08 | 0x02) & flags) ) //must be exit and not badexit!
+ if(0x0408 !=((0x08 | 0x02 | 0x0400) & flags) ) //must be exit,valid and not badexit!
continue;
//fprintf(stderr,"%x\n",flags);
/*Get a unique name, if unnamed use the full descriptor id*/
uniqueRouterName=router.name();
- if(uniqueRouterName=="Unnamed"){
+
+ //Since I dont know a way to determine if a router name is registered
+ // Will use FULL id for now.. This really sucks
+ // I am wrongly assuming here that stable,guard nodes are registered!
+ if(uniqueRouterName=="Unnamed" || (0x00== (flags & 0x0120))){
uniqueRouterName=router.id().prepend("$");
}
Modified: vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp 2008-06-15 19:40:10 UTC (rev 2735)
+++ vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp 2008-06-15 20:17:04 UTC (rev 2736)
@@ -30,7 +30,7 @@
#define SETTING_TUNNEL_DIR_CONNS "TunnelDirConns"
#define SETTING_PREFER_TUNNELED_DIR_CONNS "PreferTunneledDirConns"
#define SETTING_USE_EXIT_NODE_POLICY "UseExitNodePolicy"
-#define SETTING_EXIT_NODE_LIST "ExitNode"
+#define SETTING_EXIT_NODE_LIST "ExitNodes"
/** Default constructor */