[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2946: Stylisti changes to accomodate to vidalia coding/commenting (in vidalia/branches/exit-country/src/vidalia: config geoip network)
Author: cviecco
Date: 2008-08-06 15:59:49 -0400 (Wed, 06 Aug 2008)
New Revision: 2946
Modified:
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/filegeoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp
vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h
vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp
vidalia/branches/exit-country/src/vidalia/network/netviewer.h
Log:
Stylisti changes to accomodate to vidalia coding/commenting conventions
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-08-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-08-06 19:59:49 UTC (rev 2946)
@@ -33,21 +33,10 @@
_torControl = Vidalia::torControl();
NetworkStatus networkStatus = _torControl->getNetworkStatus();
- /* Populate combo boxes */
- /*
- foreach (QString code, LanguageSupport::languageCodes()) {
- ui.cmboLanguage->addItem(LanguageSupport::languageName(code),
- code);
- }
- foreach (QString style, QStyleFactory::keys()) {
- ui.cmboStyle->addItem(style, style.toLower());
- }
- */
/* Create the timer that will be used to update the internal ans displays once
- every hour */
- //_refreshTimer.setInterval(60*60*1000);
- _refreshTimer.setInterval(60*2*1000);
+ every 30 minutes */
+ _refreshTimer.setInterval(60*30*1000);
connect(&_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
@@ -124,28 +113,11 @@
NetworkSettings settings(Vidalia::torControl());
- //ok the next three lines can be simiplified.. talk to edmanm
- /*
- TorControl *tc ;
- tc=Vidalia::torControl();
- NetworkStatus networkstatus=(*tc).getNetworkStatus(NULL);
-*/
-/*
- int index = ui.cmboLanguage->findData(_settings->getLanguageCode());
- ui.cmboLanguage->setCurrentIndex(index);
-
- index = ui.cmboStyle->findData(Vidalia::style().toLower());
- ui.cmboStyle->setCurrentIndex(index);
- */
-
+ //load saved GUIsettings and apply
ui.chkNodePolicy->setChecked(_settings->getUseNodePolicy());
ui.chkExitNodePolicy->setChecked(settings.getUseExitNodePolicy());
ui.chkExcludeNodePolicy->setChecked(settings.getUseExcludeNodePolicy());
- //QStringList exit_nodes = settings.getExitNodeList();
- //ui.lineEditExitNodes->setText(exit_nodes.join(","));
-
- //cmboExitNodesbyCountry->ui.cmboStyle("")
ui.chkCloseAllActiveCircuits->setChecked(false);
//ui.chkCloseAllActiveCircuits->setEnabled(false);
@@ -162,11 +134,15 @@
_refreshTimer.start();
}
+
+/* The monster function! does:
+ a. reload the internal strucuter
+ b. fills the combo boxes
+*/
+
void
NetworkoutPage::refresh()
{
- //_geoip.setSocksHost(_torControl->getSocksAddress(),
- // _torControl->getSocksPort());
NetworkStatus networkStatus = _torControl->getNetworkStatus();
QString short_country_name;
@@ -180,7 +156,7 @@
//initialize the window.. just in case it has not been initialized yet.
load();
- fprintf(stderr,"refresh!\n");
+ vInfo("Network out refresh!\n");
/*Fill up the internal structure*/
//by_country_exit_nodes.clear();
@@ -263,12 +239,9 @@
QString longCountryCount;
if(country_long.contains(country)){
longCountryCount=country_long[country];
- // longCountryCount.append(" (").append(country);
- // longCountryCount.append(")(").append(count).append(")");
}
longCountryCount.append(" (").append(country);
longCountryCount.append(")(").append(count).append(")");
- //countryCount.append("(").append(count).append(")");
ui.cmboExitNodesbyCountry->addItem(country_flag,longCountryCount,
country);
if(country.toAscii()==saved_country){
@@ -292,12 +265,8 @@
ui.cmboExitNodesbyCountry->setCurrentIndex(saved_index);
//now apply changes if something was saved!
- //char saved[20];
- //memset(saved,0x00,20);
- //memcpy(saved,_settings->getExitNodeCountry().toAscii(),2);
- fprintf(stderr,"saved_index=%d saved_country=%s\n",saved_index,saved_country);
if(0!=saved_index){
- //fprintf(stderr,"applying save!\n");
+ vInfo("Network out: applying save!\n");
//apply a save!
QString err;
//save(err);
@@ -308,6 +277,8 @@
}
+/*copy the names of routers in the exit
+* country to the appropiate place in the GUI*/
void
NetworkoutPage::copyExitCountryToText()
{
@@ -321,9 +292,6 @@
current=countrylist.at(0);
current=getExitCountry();
- //fprintf(stderr,"nqlen=%d",current.length());
- //ui.lineEditExitNodes->setText(by_country_exit_nodes.value(current).join(","));
- //ui.textEditExitNodes->setText(by_country_exit_nodes.value(current).join(","));
//copy to list listwidget!
ui.listWidgetExitNodes->clear();
@@ -337,11 +305,14 @@
}
- //alsoe enable
+ /*Enable ans set the close all active circutuis*/
ui.chkCloseAllActiveCircuits->setEnabled(true);
ui.chkCloseAllActiveCircuits->setChecked(true);
}
+
+/*copy the names of routers in the excluded
+* country list to the appropiate place in the GUI*/
void
NetworkoutPage::copyExcludedCountryToText()
{
@@ -350,7 +321,7 @@
//step 3 enable close active circuits
QStringList invalidCountries;
invalidCountries=getExcludeCountries();
- fprintf(stderr,"invalid_count=%d\n",invalidCountries.count());
+ //fprintf(stderr,"invalid_count=%d\n",invalidCountries.count());
//now step2
ui.listWidgetExcludedNodes->clear();
int itemcount=0;
@@ -376,14 +347,15 @@
/** Handles when we get disconnected from Tor network */
void
NetworkoutPage::onDisconnected(){
- //erase data structure
+ /*clear the internal data structure data structure*/
by_country_exit_nodes2.clear();
- //remove data from the country combo box?
+ /*stio the refresh timed*/
_refreshTimer.stop();
}
+/*Hide/Undide stuff in the GUI accordint to selections*/
void
NetworkoutPage::HideUnhide(){
// if(ui.chkNodePolicy->isChecked()){
@@ -392,16 +364,12 @@
ui.grpExitNodeSettings->setVisible(ui.chkExitNodePolicy->isChecked() & ui.chkNodePolicy->isChecked());
ui.chkExcludeNodePolicy->setEnabled(ui.chkNodePolicy->isChecked());
ui.grpExcludeNodeSettings->setVisible(ui.chkExcludeNodePolicy->isChecked() & ui.chkNodePolicy->isChecked());
- /*
- //disable all other stuff!
- ui.chkExitNodePolicy->setEnabled(false);
- ui.grpExitNodeSettings->setVisible(ui.chkExitNodePolicy->isChecked());
- */
}
+/*close all circuits*/
void
NetworkoutPage::closeAllCircuits(){
//get list of circuits
@@ -411,13 +379,13 @@
foreach(Circuit circuit, circuitList){
//for each do close!
/* * true, then the circuit will not be closed unless it is unused. */
- //bool closeCircuit(quint64 circid, bool ifUnused = false, QString *errmsg = 0);
_torControl->closeCircuit(circuit.id());
}
}
+/*Apply GUI settings if any to tor*/
void
NetworkoutPage::applyTorSettings(){
@@ -451,7 +419,7 @@
}
exitList<<id;
}
- fprintf(stderr,"exit_size=%d\n",exitList.size());
+ //fprintf(stderr,"exit_size=%d\n",exitList.size());
settings.setExitNodeList(exitList);
}
if (ui.chkExcludeNodePolicy->isChecked()){
@@ -482,6 +450,7 @@
}
+/*Get the list of selected exclude countryies from the gui*/
QStringList
NetworkoutPage::getExcludeCountries(){
QStringList excludeCountries;
@@ -499,7 +468,7 @@
return excludeCountries;
}
-
+/*Get the current select country from the GUI*/
QString
NetworkoutPage::getExitCountry(){
QString current=ui.cmboExitNodesbyCountry->currentText();
@@ -514,29 +483,11 @@
void
NetworkoutPage::load_longnames(){
-
+
+ /*clear the db*/
country_long.clear();
-/*
- QFile file(":/geoip/country_names.txt");
- QString line;
- QStringList list;
- QTextStream in(&file);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
- fprintf (stderr,"cannot open geoip data file!\n");
- return;
- }
- while (!in.atEnd()) {
- line = in.readLine();
- list=line.split(",");
- switch (list.size()){
- case 2:
- country_long.insert(list.at(0),list.at(1));
- }
-
- }
-*/
-//
+ /*fill in the values*/
country_long.insert("af",tr("Afghanistan"));
country_long.insert("al",tr("Albania "));
country_long.insert("dz",tr("Algeria "));
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h 2008-08-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h 2008-08-06 19:59:49 UTC (rev 2946)
@@ -76,10 +76,10 @@
/*Get the countries from the excludelist*/
QStringList getExcludeCountries();
- /**/
+ /*Get the selectec gui exit node*/
QString getExitCountry();
- /**/
+ /*load the short to long country name mapping*/
void load_longnames();
/** A VidaliaSettings object used for saving/loading settings */
@@ -93,10 +93,11 @@
QMap<QString,QList<RouterStatus> > by_country_exit_nodes2;
QMap<QString,QString> country_long;
+ /*pointers to the global torControl and geoResolver objects*/
TorControl* _torControl;
GeoIpResolver* _geoIpResolver;
- /** Timer that fires once an hour to update the QMaps list. */
+ /** Timer that fires once an hour to update the combo boxes. */
QTimer _refreshTimer;
};
Modified: vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.cpp 2008-08-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/geoip/filegeoipresolver.cpp 2008-08-06 19:59:49 UTC (rev 2946)
@@ -110,57 +110,10 @@
} //closes while
fclose(file2);
+ } else{
+ /*cannot open file, close here before is considered 'ready'*/
+ return;
}
- else{
- //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;
- QTextStream in(&file);
- if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
- fprintf (stderr,"cannot open builtin 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 0:
- case 1:
- case 2:
- //invalid options
- break;
-
- case 3: //is range
- newrange.low_net=list.at(0).toUInt();
- newrange.high_net=list.at(1).toUInt();
- //newrange.location=list.at(2);
- //memcpy(tmpline3,list.at(0).toAscii(),2);
- newrange.location2=string2intloc(list.at(2).toAscii());
- ipRange.append(newrange);
- break;
-
- //now some magic, beware of fallthrough
- default:
- newlocation.extra_info=list.at(4);
- 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(string2intloc(list.at(0).toAscii()),newlocation);
- break;
-
- }
-
- }//closes while
-
-
- }
end=time(NULL);
@@ -193,15 +146,6 @@
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;
Modified: vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp 2008-08-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.cpp 2008-08-06 19:59:49 UTC (rev 2946)
@@ -65,7 +65,7 @@
}
-
+/*Get the short country name*/
QString
TorGeoIpResolver::get_country(QHostAddress ip){
@@ -78,7 +78,7 @@
}
-//Search for a geoip address given a host ip
+/*Get the geoip information for a host ip*/
GeoIp
TorGeoIpResolver::search(QHostAddress ip){
GeoIp invalid;
@@ -96,7 +96,7 @@
return invalid;
}
-
+
iploc=location[FileGeoIpResolver::string2intloc(country_name.toAscii())];
//now convert
GeoIp rvalue(ip, iploc.latitude, iploc.longitude,
Modified: vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h 2008-08-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/geoip/torgeoipresolver.h 2008-08-06 19:59:49 UTC (rev 2946)
@@ -31,7 +31,13 @@
#include <QHash>
#include <filegeoipresolver.h>
+/*The Purpose of this class is to do
+ * geoip resolutions based on Tor's
+ * geoip information. Never checks
+ if this capability is even possible
+*/
+
class TorGeoIpResolver : public QObject
{
Q_OBJECT
Modified: vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp 2008-08-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/network/netviewer.cpp 2008-08-06 19:59:49 UTC (rev 2946)
@@ -78,13 +78,6 @@
_refreshTimer.setInterval(60*60*1000);
connect(&_refreshTimer, SIGNAL(timeout()), this, SLOT(refresh()));
- /* Set up the timers used to group together GeoIP requests for new
- * descriptors arriving within MIN_RESOLVE_QUEUE_DELAY milliseconds, but no
- * more than MAX_RESOLVE_QUEUE_DELAY milliseconds of each other. */
- //_minResolveQueueTimer.setSingleShot(true);
- //connect(&_minResolveQueueTimer, SIGNAL(timeout()), this, SLOT(resolve()));
- //_maxResolveQueueTimer.setSingleShot(true);
- //connect(&_maxResolveQueueTimer, SIGNAL(timeout()), this, SLOT(resolve()));
/* Connect the necessary slots and signals */
connect(ui.actionHelp, SIGNAL(triggered()), this, SLOT(help()));
@@ -108,25 +101,19 @@
connect(_torControl, SIGNAL(authenticated()), this, SLOT(onAuthenticated()));
connect(_torControl, SIGNAL(disconnected()), this, SLOT(onDisconnected()));
- /* Connect the slot to find out when geoip information has arrived */
- //connect(&_geoip, SIGNAL(resolved(int, QList<GeoIp>)),
- // this, SLOT(resolved(int, QList<GeoIp>)));
-
- //file based geoip resolver
+ /*attach our pointer to the 'global' geoip resolver*/
_geoIpResolver=Vidalia::geoIpResolver();
+ /*Connect the geoipresolver to our refresh signal so that
+ of the resolutin is async we refresh when the georesolvers
+ are done*/
connect(_geoIpResolver, SIGNAL(geoResolved()), this, SLOT(refresh()));
}
-/** Display the network map window. If there are geoip requests waiting in the
- * queue, start the queue timers now. */
+/** Display the network map window.*/
void
NetViewer::showWindow()
{
- if (!_resolveQueue.isEmpty()) {
- _minResolveQueueTimer.start(MIN_RESOLVE_QUEUE_DELAY);
- _maxResolveQueueTimer.start(MAX_RESOLVE_QUEUE_DELAY);
- }
VidaliaWindow::showWindow();
}
@@ -206,7 +193,7 @@
{
/* Clear the resolve queue and map */
_resolveMap.clear();
- _resolveQueue.clear();
+ // _resolveQueue.clear();
/* Clear the network map */
_map->clear();
_map->update();
@@ -299,30 +286,25 @@
}
}
-/** Adds a router to our list of servers and retrieves geographic location
- * information for the server. */
+/** Adds a router to our list of servers and plots with
+* the current known geographic location for the server. */
void
NetViewer::addRouter(const RouterDescriptor &rd)
{
/* Add the descriptor to the list of server */
ui.treeRouterList->addRouter(rd);
- /* Add this IP to a list whose geographic location we'd like to find. */
- //addToResolveQueue(rd.ip(), rd.id());
+ /*get the router from the ui */
- //cviecco--->what to do!
- // Save the location information in the descriptor
- // router->setLocation(geoip);
RouterListItem *router;
router = ui.treeRouterList->findRouterById(rd.id());
- GeoIp geoip=_geoIpResolver->search(rd.ip());
- //now test!
- //webGeoResolver.search(rd.ip());
-
+ /**find the geolocation and assign it to the router */
+ GeoIp geoip=_geoIpResolver->search(rd.ip());
router->setLocation(geoip );
- // Plot the router on the map
+
+ /* 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-06 15:32:19 UTC (rev 2945)
+++ vidalia/branches/exit-country/src/vidalia/network/netviewer.h 2008-08-06 19:59:49 UTC (rev 2946)
@@ -25,10 +25,7 @@
#include <torcontrol.h>
#include <vidaliawindow.h>
#include <geoipresolver.h>
-//#include <filegeoipresolver.h>
-//#include <webgeoipresolver.h>
-//#include "geoipresolver.h"
#include "tormapwidget.h"
#include "ui_netviewer.h"
@@ -99,23 +96,11 @@
QTimer _refreshTimer;
/** TorMapWidget that displays the map. */
TorMapWidget* _map;
- /** GeoIpResolver used to geolocate routers by IP address. */
- //GeoIpResolver _geoip;
- /** Queue for IPs pending resolution to geographic information. */
- QList<QHostAddress> _resolveQueue;
/** Maps pending GeoIP requests to server IDs. */
QHash<QString, QString> _resolveMap;
/** Stores a list of address mappings from Tor. */
AddressMap _addressMap;
- /** Timer used to delay GeoIP requests for MIN_RESOLVE_QUEUE_DELAY
- * milliseconds after we've inserted the last item into the queue. */
- QTimer _minResolveQueueTimer;
- /** Timer used to limit the delay of GeoIP requests to
- * MAX_RESOLVE_QUEUE_DELAY milliseconds after inserting the first item
- * into the queue. */
- QTimer _maxResolveQueueTimer;
-
- /*The Geoipresolver object*/
+ /*The Geoipresolver used to geolocate routers*/
GeoIpResolver* _geoIpResolver;
/** Qt Designer generated object **/