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

[vidalia-svn] r2943: Now with tor as resolver. Next step -> clean up, next select (in vidalia/branches/exit-country/src/vidalia: . geoip res)



Author: cviecco
Date: 2008-08-05 17:09:10 -0400 (Tue, 05 Aug 2008)
New Revision: 2943

Added:
   vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp
   vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h
   vidalia/branches/exit-country/src/vidalia/res/country_loc.csv
Modified:
   vidalia/branches/exit-country/src/vidalia/CMakeLists.txt
   vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.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/res/vidalia_common.qrc
Log:
Now with tor as resolver. Next step -> clean up, next selection logic.


Modified: vidalia/branches/exit-country/src/vidalia/CMakeLists.txt
===================================================================
--- vidalia/branches/exit-country/src/vidalia/CMakeLists.txt	2008-08-05 18:19:36 UTC (rev 2942)
+++ vidalia/branches/exit-country/src/vidalia/CMakeLists.txt	2008-08-05 21:09:10 UTC (rev 2943)
@@ -126,6 +126,7 @@
   geoip/geoipresponse.cpp
   geoip/webgeoipresolver.cpp
   geoip/geoipresolver.cpp
+  geoip/torgeoipresolver.cpp
 )
 qt4_wrap_cpp(vidalia_SRCS
 #  geoip/geoip.h
@@ -136,6 +137,7 @@
   geoip/geoipresponse.h
   geoip/webgeoipresolver.h
   geoip/geoipresolver.h
+  geoip/torgeoipresolver.h
 )
 
 

Modified: vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.h	2008-08-05 18:19:36 UTC (rev 2942)
+++ vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.h	2008-08-05 21:09:10 UTC (rev 2943)
@@ -102,6 +102,8 @@
 
 public:
   GeoIp search(QHostAddress ip);
+  static uint32_t string2intloc(const char *);
+  bool isReady(){return ready;};
 
 private:
   //provides locking during db access/updates to guarantee thread safety
@@ -113,7 +115,7 @@
   //QHash<QString,FileGeoIpResolverGeoLocation> location;
   QHash<uint32_t,FileGeoIpResolverGeoLocation> location;
   QVector<FileGeoIpResolverIpRange> ipRange;
-  uint32_t string2intloc(const char *);
+  //uint32_t string2intloc(const char *);
 };
 
 #endif

Modified: vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp	2008-08-05 18:19:36 UTC (rev 2942)
+++ vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.cpp	2008-08-05 21:09:10 UTC (rev 2943)
@@ -49,7 +49,8 @@
 GeoIpResolver::search(QHostAddress ip){
   GeoIp invalid;
 
-  return webGeoResolver.search(ip);
+   return torGeoResolver.search(ip);
+  //return webGeoResolver.search(ip);
   //return _fileGeoIpResolver->search(ip);
 
   //return invalid;

Modified: vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h	2008-08-05 18:19:36 UTC (rev 2942)
+++ vidalia/branches/exit-country/src/vidalia/geoip/geoipresolver.h	2008-08-05 21:09:10 UTC (rev 2943)
@@ -31,6 +31,7 @@
 #include "geoipresponse.h"
 #include <filegeoipresolver.h>
 #include <webgeoipresolver.h>
+#include <torgeoipresolver.h>
 #include <torcontrol.h>
 
 
@@ -65,7 +66,7 @@
   /*In Private we actually keep what makes the resolving */
   FileGeoIpResolver* _fileGeoIpResolver;
   WebGeoIpResolver webGeoResolver;
-
+  TorGeoIpResolver torGeoResolver;
 };
 
 #endif

Added: vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp	                        (rev 0)
+++ vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp	2008-08-05 21:09:10 UTC (rev 2943)
@@ -0,0 +1,127 @@
+/*
+**  This file is part of Vidalia, and is subject to the license terms in the
+**  LICENSE file, found in the top level directory of this distribution. If you
+**  did not receive the LICENSE file with this file, you may obtain it from the
+**  Vidalia source package distributed by the Vidalia Project at
+**  http://www.vidalia-project.net/. No part of Vidalia, including this file,
+**  may be copied, modified, propagated, or distributed except according to the
+**  terms described in the LICENSE file.
+*/
+
+/*
+** \file geoipresolver.cpp
+** \version $Id: geoipresolver.cpp 2429 2008-03-21 02:27:36Z edmanm $
+** \brief Requests GeoIP information and caches the result
+*/
+
+//#include <torsocket.h>
+#include <vidalia.h>
+#include <torcontrol.h>
+
+#include "torgeoipresolver.h"
+#include "config.h"
+
+#include <time.h>
+
+
+/** Default constructor. */
+TorGeoIpResolver::TorGeoIpResolver()
+{
+  /*Define the connection*/
+  _torControl = Vidalia::torControl();
+
+  /*now we load the map!!*/
+
+  FileGeoIpResolverGeoLocation newlocation;
+  QFile file(":/geoip/country_loc.csv");
+  QString line;
+  QStringList list;
+  QTextStream in(&file);
+  if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+     fprintf (stderr,"cannot open geoip data file!\n");
+     return;
+  }
+  //fprintf(stderr,"using default geoip file!\n");
+  while (!in.atEnd()) {
+     line = in.readLine();
+     list=line.split(",");
+     //list=in.readLine().split(',');
+
+     switch (list.size()){
+         case 5:
+         case 4: //is location;
+               
+                 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(FileGeoIpResolver::string2intloc(list.at(0).toLower().toAscii()),newlocation);
+                 break;
+         default:
+                 break;
+
+     }
+
+  }//closes while
+
+  fprintf(stderr,"tor geo: file loaded! location_size=%d\n",location.size());
+   
+}
+
+
+QString 
+TorGeoIpResolver::get_country(QHostAddress ip){
+
+  QString unknown("??");
+  //GeoIp resolv=search(ip);
+  QString ip_addr;
+  ip_addr=ip.toString();
+
+ //short_country_name=_torControl->getIPCountry(ip_addr);
+  
+  return _torControl->getIPCountry(ip_addr);
+/*
+  if (resolv.isEmpty() || resolv.isUnknown())
+    return unknown;
+  else 
+    return resolv.country();
+*/
+}
+
+
+//Search for a geoip address given a host ip
+GeoIp 
+TorGeoIpResolver::search(QHostAddress ip){
+  GeoIp invalid;
+  FileGeoIpResolverGeoLocation iploc;
+  QString ip_addr;
+  QHash<uint32_t,FileGeoIpResolverGeoLocation>::const_iterator iter;// = hash.find("HDR");
+
+
+  ip_addr=ip.toString();
+
+  QString country_name=_torControl->getIPCountry(ip_addr);
+  iter=location.find(FileGeoIpResolver::string2intloc(country_name.toAscii()));
+  if(iter == location.end()){
+    //fprintf(stderr,"cannot find tor geoiploc!\n");
+    return invalid;
+  }
+
+
+  iploc=location[FileGeoIpResolver::string2intloc(country_name.toAscii())];
+  //now convert
+  GeoIp rvalue(ip, iploc.latitude, iploc.longitude,
+        iploc.extra_info, "", iploc.country_short);
+
+  return rvalue;
+}
+
+
+
+void
+TorGeoIpResolver::resolved(){
+//GeoIpResolver::resolved(){
+   fprintf(stderr,"georeslved signal!\n");
+   emit geoResolved();
+};
+

Added: vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h	                        (rev 0)
+++ vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h	2008-08-05 21:09:10 UTC (rev 2943)
@@ -0,0 +1,64 @@
+/*
+**  This file is part of Vidalia, and is subject to the license terms in the
+**  LICENSE file, found in the top level directory of this distribution. If you
+**  did not receive the LICENSE file with this file, you may obtain it from the
+**  Vidalia source package distributed by the Vidalia Project at
+**  http://www.vidalia-project.net/. No part of Vidalia, including this file,
+**  may be copied, modified, propagated, or distributed except according to the
+**  terms described in the LICENSE file.
+*/
+
+/*
+** \file geoipresolver.h
+** \version $Id: geoipresolver.h 2429 2008-03-21 02:27:36Z edmanm $
+** \brief Requests GeoIP information and caches the result
+*/
+
+#ifndef _TORGEOIPRESOLVER_H
+#define _TORGEOIPRESOLVER_H
+
+#include <QObject>
+#include <QList>
+#include <QHash>
+#include <QString>
+#include <QHostAddress>
+#include <QTimer>
+#include <QMutex>
+
+#include <geoip.h>
+#include <torcontrol.h>
+#include <QMap>
+#include <QHash>
+#include <filegeoipresolver.h>
+
+
+class TorGeoIpResolver : public QObject
+{
+  Q_OBJECT
+
+public:
+  /** Default constructor. */
+  TorGeoIpResolver();
+  
+
+  /*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 geoResolved();
+
+
+private slots:
+  void resolved();
+
+private:
+  /*In Private we actually keep what makes the resolving */
+  TorControl* _torControl;
+  QHash<uint32_t,FileGeoIpResolverGeoLocation> location;
+};
+
+#endif
+

Added: vidalia/branches/exit-country/src/vidalia/res/country_loc.csv
===================================================================
--- vidalia/branches/exit-country/src/vidalia/res/country_loc.csv	                        (rev 0)
+++ vidalia/branches/exit-country/src/vidalia/res/country_loc.csv	2008-08-05 21:09:10 UTC (rev 2943)
@@ -0,0 +1,249 @@
+O1,O1,0.0000,0.0000,
+AP,AP,35.0000,105.0000,
+EU,EU,47.0000,8.0000,
+AD,AD,42.5000,1.5000,
+AE,AE,24.0000,54.0000,
+AF,AF,33.0000,65.0000,
+AG,AG,17.0500,-61.8000,
+AI,AI,18.2500,-63.1667,
+AL,AL,41.0000,20.0000,
+AM,AM,40.0000,45.0000,
+AN,AN,12.2500,-68.7500,
+AO,AO,12.5000,18.5000,
+AQ,AQ,90.0000,0.0000,
+AR,AR,34.0000,-64.0000,
+AS,AS,14.3333,-170.0000,
+AT,AT,47.3333,13.3333,
+AU,AU,27.0000,133.0000,
+AW,AW,12.5000,-69.9667,
+AZ,AZ,40.5000,47.5000,
+BA,BA,44.0000,18.0000,
+BB,BB,13.1667,-59.5333,
+BD,BD,24.0000,90.0000,
+BE,BE,50.8333,4.0000,
+BF,BF,13.0000,-2.0000,
+BG,BG,43.0000,25.0000,
+BH,BH,26.0000,50.5500,
+BI,BI,3.5000,30.0000,
+BJ,BJ,9.5000,2.2500,
+BM,BM,32.3333,-64.7500,
+BN,BN,4.5000,114.6667,
+BO,BO,17.0000,-65.0000,
+BR,BR,10.0000,-55.0000,
+BS,BS,24.2500,-76.0000,
+BT,BT,27.5000,90.5000,
+BV,BV,54.4333,3.4000,
+BW,BW,22.0000,24.0000,
+BY,BY,53.0000,28.0000,
+BZ,BZ,17.2500,-88.7500,
+CA,CA,60.0000,-95.0000,
+CC,CC,12.5000,96.8333,
+CD,CD,0.0000,25.0000,
+CF,CF,7.0000,21.0000,
+CG,CG,1.0000,15.0000,
+CH,CH,47.0000,8.0000,
+CI,CI,8.0000,-5.0000,
+CK,CK,21.2333,-159.7667,
+CL,CL,30.0000,-71.0000,
+CM,CM,6.0000,12.0000,
+CN,CN,35.0000,105.0000,
+CO,CO,4.0000,-72.0000,
+CR,CR,10.0000,-84.0000,
+CU,CU,21.5000,-80.0000,
+CV,CV,16.0000,-24.0000,
+CX,CX,10.5000,105.6667,
+CY,CY,35.0000,33.0000,
+CZ,CZ,49.7500,15.5000,
+DE,DE,51.0000,9.0000,
+DJ,DJ,11.5000,43.0000,
+DK,DK,56.0000,10.0000,
+DM,DM,15.4167,-61.3333,
+DO,DO,19.0000,-70.6667,
+DZ,DZ,28.0000,3.0000,
+EC,EC,2.0000,-77.5000,
+EE,EE,59.0000,26.0000,
+EG,EG,27.0000,30.0000,
+EH,EH,24.5000,-13.0000,
+ER,ER,15.0000,39.0000,
+ES,ES,40.0000,-4.0000,
+ET,ET,8.0000,38.0000,
+FI,FI,64.0000,26.0000,
+FJ,FJ,18.0000,175.0000,
+FK,FK,51.7500,-59.0000,
+FM,FM,6.9167,158.2500,
+FO,FO,62.0000,-7.0000,
+FR,FR,46.0000,2.0000,
+GA,GA,1.0000,11.7500,
+GB,GB,54.0000,-2.0000,
+GD,GD,12.1167,-61.6667,
+GE,GE,42.0000,43.5000,
+GF,GF,4.0000,-53.0000,
+GH,GH,8.0000,-2.0000,
+GI,GI,36.1833,-5.3667,
+GL,GL,72.0000,-40.0000,
+GM,GM,13.4667,-16.5667,
+GN,GN,11.0000,-10.0000,
+GP,GP,16.2500,-61.5833,
+GQ,GQ,2.0000,10.0000,
+GR,GR,39.0000,22.0000,
+GS,GS,54.5000,-37.0000,
+GT,GT,15.5000,-90.2500,
+GU,GU,13.4667,144.7833,
+GW,GW,12.0000,-15.0000,
+GY,GY,5.0000,-59.0000,
+HK,HK,22.2500,114.1667,
+HM,HM,53.1000,72.5167,
+HN,HN,15.0000,-86.5000,
+HR,HR,45.1667,15.5000,
+HT,HT,19.0000,-72.4167,
+HU,HU,47.0000,20.0000,
+ID,ID,5.0000,120.0000,
+IE,IE,53.0000,-8.0000,
+IL,IL,31.5000,34.7500,
+IN,IN,20.0000,77.0000,
+IO,IO,6.0000,71.5000,
+IQ,IQ,33.0000,44.0000,
+IR,IR,32.0000,53.0000,
+IS,IS,65.0000,-18.0000,
+IT,IT,42.8333,12.8333,
+JM,JM,18.2500,-77.5000,
+JO,JO,31.0000,36.0000,
+JP,JP,36.0000,138.0000,
+KE,KE,1.0000,38.0000,
+KG,KG,41.0000,75.0000,
+KH,KH,13.0000,105.0000,
+KI,KI,1.4167,173.0000,
+KM,KM,12.1667,44.2500,
+KN,KN,17.3333,-62.7500,
+KP,KP,40.0000,127.0000,
+KR,KR,37.0000,127.5000,
+KW,KW,29.3375,47.6581,
+KY,KY,19.5000,-80.5000,
+KZ,KZ,48.0000,68.0000,
+LA,LA,18.0000,105.0000,
+LB,LB,33.8333,35.8333,
+LC,LC,13.8833,-61.1333,
+LI,LI,47.1667,9.5333,
+LK,LK,7.0000,81.0000,
+LR,LR,6.5000,-9.5000,
+LS,LS,29.5000,28.5000,
+LT,LT,56.0000,24.0000,
+LU,LU,49.7500,6.1667,
+LV,LV,57.0000,25.0000,
+LY,LY,25.0000,17.0000,
+MA,MA,32.0000,-5.0000,
+MC,MC,43.7333,7.4000,
+MD,MD,47.0000,29.0000,
+MG,MG,20.0000,47.0000,
+MH,MH,9.0000,168.0000,
+MK,MK,41.8333,22.0000,
+ML,ML,17.0000,-4.0000,
+MM,MM,22.0000,98.0000,
+MN,MN,46.0000,105.0000,
+MO,MO,22.1667,113.5500,
+MP,MP,15.2000,145.7500,
+MQ,MQ,14.6667,-61.0000,
+MR,MR,20.0000,-12.0000,
+MS,MS,16.7500,-62.2000,
+MT,MT,35.8333,14.5833,
+MU,MU,20.2833,57.5500,
+MV,MV,3.2500,73.0000,
+MW,MW,13.5000,34.0000,
+MX,MX,23.0000,-102.0000,
+MY,MY,2.5000,112.5000,
+MZ,MZ,18.2500,35.0000,
+NA,NA,22.0000,17.0000,
+NC,NC,21.5000,165.5000,
+NE,NE,16.0000,8.0000,
+NF,NF,29.0333,167.9500,
+NG,NG,10.0000,8.0000,
+NI,NI,13.0000,-85.0000,
+NL,NL,52.5000,5.7500,
+NO,NO,62.0000,10.0000,
+NP,NP,28.0000,84.0000,
+NR,NR,0.5333,166.9167,
+NU,NU,19.0333,-169.8667,
+NZ,NZ,41.0000,174.0000,
+OM,OM,21.0000,57.0000,
+PA,PA,9.0000,-80.0000,
+PE,PE,10.0000,-76.0000,
+PF,PF,15.0000,-140.0000,
+PG,PG,6.0000,147.0000,
+PH,PH,13.0000,122.0000,
+PK,PK,30.0000,70.0000,
+PL,PL,52.0000,20.0000,
+PM,PM,46.8333,-56.3333,
+PR,PR,18.2500,-66.5000,
+PS,PS,32.0000,35.2500,
+PT,PT,39.5000,-8.0000,
+PW,PW,7.5000,134.5000,
+PY,PY,23.0000,-58.0000,
+QA,QA,25.5000,51.2500,
+RE,RE,21.1000,55.6000,
+RO,RO,46.0000,25.0000,
+RU,RU,60.0000,100.0000,
+RW,RW,2.0000,30.0000,
+SA,SA,25.0000,45.0000,
+SB,SB,8.0000,159.0000,
+SC,SC,4.5833,55.6667,
+SD,SD,15.0000,30.0000,
+SE,SE,62.0000,15.0000,
+SG,SG,1.3667,103.8000,
+SH,SH,15.9333,-5.7000,
+SI,SI,46.0000,15.0000,
+SJ,SJ,78.0000,20.0000,
+SK,SK,48.6667,19.5000,
+SL,SL,8.5000,-11.5000,
+SM,SM,43.7667,12.4167,
+SN,SN,14.0000,-14.0000,
+SO,SO,10.0000,49.0000,
+SR,SR,4.0000,-56.0000,
+ST,ST,1.0000,7.0000,
+SV,SV,13.8333,-88.9167,
+SY,SY,35.0000,38.0000,
+SZ,SZ,26.5000,31.5000,
+TC,TC,21.7500,-71.5833,
+TD,TD,15.0000,19.0000,
+TF,TF,43.0000,67.0000,
+TG,TG,8.0000,1.1667,
+TH,TH,15.0000,100.0000,
+TJ,TJ,39.0000,71.0000,
+TK,TK,9.0000,-172.0000,
+TM,TM,40.0000,60.0000,
+TN,TN,34.0000,9.0000,
+TO,TO,20.0000,-175.0000,
+TR,TR,39.0000,35.0000,
+TT,TT,11.0000,-61.0000,
+TV,TV,8.0000,178.0000,
+TW,TW,23.5000,121.0000,
+TZ,TZ,6.0000,35.0000,
+UA,UA,49.0000,32.0000,
+UG,UG,1.0000,32.0000,
+UM,UM,19.2833,166.6000,
+US,US,38.0000,-97.0000,
+UY,UY,33.0000,-56.0000,
+UZ,UZ,41.0000,64.0000,
+VA,VA,41.9000,12.4500,
+VC,VC,13.2500,-61.2000,
+VE,VE,8.0000,-66.0000,
+VG,VG,18.5000,-64.5000,
+VI,VI,18.3333,-64.8333,
+VN,VN,16.0000,106.0000,
+VU,VU,16.0000,167.0000,
+WF,WF,13.3000,-176.2000,
+WS,WS,13.5833,-172.3333,
+YE,YE,15.0000,48.0000,
+YT,YT,12.8333,45.1667,
+RS,RS,44.0000,21.0000,
+ZA,ZA,29.0000,24.0000,
+ZM,ZM,15.0000,30.0000,
+ME,ME,42.0000,19.0000,
+ZW,ZW,20.0000,30.0000,
+A1,A1,0.0000,0.0000,
+A2,A2,0.0000,0.0000,
+AX,AX,60.1200,19.9000,
+GG,GG,49.4300,2.5800,
+IM,IM,54.2300,-4.5700,
+JE,JE,49.1800,2.1000,
+GG,GG,49.4300,-2.5800,
+JE,JE,49.1800,-2.1000,

Modified: vidalia/branches/exit-country/src/vidalia/res/vidalia_common.qrc
===================================================================
--- vidalia/branches/exit-country/src/vidalia/res/vidalia_common.qrc	2008-08-05 18:19:36 UTC (rev 2942)
+++ vidalia/branches/exit-country/src/vidalia/res/vidalia_common.qrc	2008-08-05 21:09:10 UTC (rev 2943)
@@ -285,5 +285,6 @@
         <file>cacert_root.crt</file>
         <file>geoip.data</file>
         <file>country_names.txt</file>
+        <file>country_loc.csv</file>
     </qresource>
 </RCC>