[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2665: Selection of Exit nodes by country works (but does not autom (in vidalia/branches/exit-country/src: torcontrol vidalia/config)
Author: cviecco
Date: 2008-06-04 09:17:38 -0400 (Wed, 04 Jun 2008)
New Revision: 2665
Modified:
vidalia/branches/exit-country/src/torcontrol/torcontrol.cpp
vidalia/branches/exit-country/src/torcontrol/torcontrol.h
vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui
vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
Log:
Selection of Exit nodes by country works (but does not automatically close old circuits not conforming to the new policy).
Tested with only recent versions of tor.. requires GETINFO ip-to-country/
torcontrol.cpp, torcontrol.h -> Added function to get ip-to-country info
Modified: vidalia/branches/exit-country/src/torcontrol/torcontrol.cpp
===================================================================
--- vidalia/branches/exit-country/src/torcontrol/torcontrol.cpp 2008-06-04 13:17:30 UTC (rev 2664)
+++ vidalia/branches/exit-country/src/torcontrol/torcontrol.cpp 2008-06-04 13:17:38 UTC (rev 2665)
@@ -1007,3 +1007,24 @@
return addressMap;
}
+
+ /** Returns the Country code for an ipv4 address**/
+QString
+TorControl::getIPCountry(QString &ip_addr){
+ QString rvalue("bad");
+ QString com_arg("ip-to-country/");
+ QStringList message;
+
+ com_arg.append(ip_addr);
+ ControlCommand cmd("GETINFO", com_arg);
+ ControlReply reply;
+ if(send(cmd,reply,NULL)){
+ message=reply.getMessage().split("=");
+ return message.at(1);
+
+ }
+
+ return rvalue;
+
+}
+
Modified: vidalia/branches/exit-country/src/torcontrol/torcontrol.h
===================================================================
--- vidalia/branches/exit-country/src/torcontrol/torcontrol.h 2008-06-04 13:17:30 UTC (rev 2664)
+++ vidalia/branches/exit-country/src/torcontrol/torcontrol.h 2008-06-04 13:17:38 UTC (rev 2665)
@@ -169,6 +169,8 @@
* is returned. */
NetworkStatus getNetworkStatus(QString *errmsg = 0);
+ /** Returns the Country code for a n ipv4 address**/
+ QString getIPCountry(QString &ip_addr);
/** Gets a list of current circuits. */
CircuitList getCircuits(QString *errmsg = 0);
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-06-04 13:17:30 UTC (rev 2664)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp 2008-06-04 13:17:38 UTC (rev 2665)
@@ -30,6 +30,21 @@
/* Create VidaliaSettings object */
_settings = new VidaliaSettings();
+ /*Create a network status object ... is there one already?*/
+ TorControl *tc ;
+ tc=Vidalia::torControl();
+ QString error_str;
+ NetworkStatus networkstatus=(*tc).getNetworkStatus(&error_str);
+
+ _torControl = Vidalia::torControl();
+ NetworkStatus networkStatus = _torControl->getNetworkStatus();
+
+
+// QList<RouterStatus> testlist(networkstatus);
+// testlist=networkstatus;
+ QString short_country_name;
+ QString ip_addr;
+
/* Populate combo boxes */
foreach (QString code, LanguageSupport::languageCodes()) {
ui.cmboLanguage->addItem(LanguageSupport::languageName(code),
@@ -38,6 +53,17 @@
foreach (QString style, QStyleFactory::keys()) {
ui.cmboStyle->addItem(style, style.toLower());
}
+
+ /*do connections!*/
+ connect(_torControl, SIGNAL(authenticated()), this, SLOT(onAuthenticated()));
+
+ /*
+ connect(ui.lblBandwidthGraph, SIGNAL(clicked()),
+ _bandwidthGraph, SLOT(showWindow()));
+
+*/
+ connect(ui.pButtonApplyCountry,SIGNAL(clicked()),
+ this, SLOT( copyCountryToText() ));
}
/** Destructor */
@@ -75,16 +101,89 @@
NetworkoutPage::load()
{
- NetworkSettings settings(Vidalia::torControl());
+ 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);
+
+ ui.chkNodePolicy->setChecked(settings.getUseNodePolicy());
QStringList exit_nodes = settings.getExitNodeList();
ui.lineEditExitNodes->setText(exit_nodes.join(","));
+ //cmboExitNodesbyCountry->ui.cmboStyle("")
+
}
+void
+NetworkoutPage::onAuthenticated()
+{
+ //_geoip.setSocksHost(_torControl->getSocksAddress(),
+ // _torControl->getSocksPort());
+ //refresh();
+ //_refreshTimer.start();
+ //ui.actionRefresh->setEnabled(true);
+
+ NetworkStatus networkStatus = _torControl->getNetworkStatus();
+ QString short_country_name;
+ QString ip_addr;
+ QString count;
+ int flags;
+
+ fprintf(stderr,"hello2\n");
+ foreach( RouterStatus router, networkStatus){
+ fprintf(stderr,"*");
+ //Get the country!
+ ip_addr=router.ipAddress().toString();
+ short_country_name=_torControl->getIPCountry(ip_addr);
+
+ if (!router.isRunning())
+ continue;
+
+ if (!router.isValid())
+ continue;
+
+ flags=router.flags();
+ if(0x08 !=(0x08 & flags) )
+ continue;
+ fprintf(stderr,"%x\n",flags);
+
+
+ if (by_country_exit_nodes.contains(short_country_name)){
+ by_country_exit_nodes.insert(short_country_name, QStringList(by_country_exit_nodes.value(short_country_name))<<router.name());
+ }
+ else{
+ by_country_exit_nodes.insert(short_country_name,QStringList()<<router.name());
+ }
+ }
+ //* now fill the combo boxes!*/
+ foreach (QString country, by_country_exit_nodes.keys()) {
+ count=QString("%1").arg(by_country_exit_nodes.value(country).count(),0,10);
+ ui.cmboExitNodesbyCountry->addItem(country,
+ country.append("(").append(count).append(")"));
+ }
+
+
+}
+
+void
+NetworkoutPage::copyCountryToText()
+{
+ QString current=ui.cmboExitNodesbyCountry->currentText();
+
+ fprintf(stderr,"qlen=%d",current.length());
+ QStringList countrylist=current.split("(");
+
+ current=countrylist.at(0);
+ fprintf(stderr,"nqlen=%d",current.length());
+ ui.lineEditExitNodes->setText(by_country_exit_nodes.value(current).join(","));
+
+}
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h 2008-06-04 13:17:30 UTC (rev 2664)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h 2008-06-04 13:17:38 UTC (rev 2665)
@@ -22,6 +22,10 @@
#include <vidaliasettings.h>
#include <languagesupport.h>
+#include <routerdescriptor.h>
+#include <torcontrol.h>
+#include <routerstatus.h>
+//#include <torsettings.h>
#include "configpage.h"
#include "ui_networkoutpage.h"
@@ -40,6 +44,14 @@
/** Loads the settings for this page */
void load();
+private slots:
+ void copyCountryToText();
+
+ /*Do stuff once authenticated*/
+ void onAuthenticated();
+
+
+
private:
/** A VidaliaSettings object used for saving/loading settings */
@@ -47,6 +59,13 @@
/** Qt Designer generated object */
Ui::NetworkoutPage ui;
+
+ /*struct to hold the country-exit-node-mappings */
+ QHash<QString,QStringList> by_country_exit_nodes;
+
+ TorControl* _torControl;
+
+
};
#endif
Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui 2008-06-04 13:17:30 UTC (rev 2664)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui 2008-06-04 13:17:38 UTC (rev 2665)
@@ -1,11 +1,11 @@
<ui version="4.0" >
<class>NetworkoutPage</class>
- <widget class="QWidget" name="AppearancePage" >
+ <widget class="QWidget" name="NetworkoutPage" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
- <width>494</width>
+ <width>519</width>
<height>395</height>
</rect>
</property>
@@ -101,7 +101,7 @@
<rect>
<x>9</x>
<y>107</y>
- <width>476</width>
+ <width>471</width>
<height>68</height>
</rect>
</property>
@@ -114,58 +114,50 @@
<property name="title" >
<string>Style</string>
</property>
- <layout class="QGridLayout" >
- <property name="leftMargin" >
- <number>9</number>
+ <widget class="QWidget" name="layoutWidget" >
+ <property name="geometry" >
+ <rect>
+ <x>11</x>
+ <y>28</y>
+ <width>451</width>
+ <height>31</height>
+ </rect>
</property>
- <property name="topMargin" >
- <number>9</number>
- </property>
- <property name="rightMargin" >
- <number>9</number>
- </property>
- <property name="bottomMargin" >
- <number>9</number>
- </property>
- <property name="horizontalSpacing" >
- <number>6</number>
- </property>
- <property name="verticalSpacing" >
- <number>6</number>
- </property>
- <item row="0" column="1" >
- <spacer>
- <property name="orientation" >
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" >
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="0" >
- <widget class="QComboBox" name="cmboStyle" >
- <property name="minimumSize" >
- <size>
- <width>150</width>
- <height>0</height>
- </size>
- </property>
- <property name="contextMenuPolicy" >
- <enum>Qt::NoContextMenu</enum>
- </property>
- <property name="toolTip" >
- <string>Choose Vidalia's interface style</string>
- </property>
- <property name="editable" >
- <bool>false</bool>
- </property>
- </widget>
- </item>
- </layout>
+ <layout class="QHBoxLayout" >
+ <item>
+ <widget class="QComboBox" name="cmboStyle" >
+ <property name="minimumSize" >
+ <size>
+ <width>150</width>
+ <height>0</height>
+ </size>
+ </property>
+ <property name="contextMenuPolicy" >
+ <enum>Qt::NoContextMenu</enum>
+ </property>
+ <property name="toolTip" >
+ <string>Choose Vidalia's interface style</string>
+ </property>
+ <property name="editable" >
+ <bool>false</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer>
+ <property name="orientation" >
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" >
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </widget>
</widget>
<widget class="QCheckBox" name="chkNodePolicy" >
<property name="geometry" >
@@ -186,7 +178,7 @@
<x>10</x>
<y>200</y>
<width>471</width>
- <height>91</height>
+ <height>181</height>
</rect>
</property>
<property name="title" >
@@ -195,8 +187,8 @@
<widget class="QLineEdit" name="lineEditExitNodes" >
<property name="geometry" >
<rect>
- <x>90</x>
- <y>30</y>
+ <x>100</x>
+ <y>40</y>
<width>361</width>
<height>27</height>
</rect>
@@ -206,7 +198,7 @@
<property name="geometry" >
<rect>
<x>20</x>
- <y>30</y>
+ <y>50</y>
<width>71</width>
<height>18</height>
</rect>
@@ -215,6 +207,42 @@
<string>Exit Nodes</string>
</property>
</widget>
+ <widget class="QComboBox" name="cmboExitNodesbyCountry" >
+ <property name="geometry" >
+ <rect>
+ <x>140</x>
+ <y>90</y>
+ <width>171</width>
+ <height>29</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QPushButton" name="pButtonApplyCountry" >
+ <property name="geometry" >
+ <rect>
+ <x>326</x>
+ <y>90</y>
+ <width>131</width>
+ <height>27</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Set Exits by Country</string>
+ </property>
+ </widget>
+ <widget class="QLabel" name="label_3" >
+ <property name="geometry" >
+ <rect>
+ <x>80</x>
+ <y>100</y>
+ <width>54</width>
+ <height>18</height>
+ </rect>
+ </property>
+ <property name="text" >
+ <string>Country</string>
+ </property>
+ </widget>
</widget>
</widget>
<resources/>
Modified: vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp 2008-06-04 13:17:30 UTC (rev 2664)
+++ vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp 2008-06-04 13:17:38 UTC (rev 2665)
@@ -71,6 +71,9 @@
conf.insert(SETTING_EXIT_NODE_LIST,
localValue(SETTING_EXIT_NODE_LIST).toStringList().join(","));
conf.insert("StrictExitNodes","1");
+ }else{
+ //very bad!, need to find better way...
+ conf.insert("StrictExitNodes","0");
}
conf.insert(SETTING_HTTP_PROXY,