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

[vidalia-svn] r2753: Minimal support to avoid certain countries via Exclude Nodes (vidalia/branches/exit-country/src/vidalia/config)



Author: cviecco
Date: 2008-06-18 17:51:08 -0400 (Wed, 18 Jun 2008)
New Revision: 2753

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/config/networkoutpage.ui
   vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
   vidalia/branches/exit-country/src/vidalia/config/networksettings.h
   vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp
   vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h
Log:
Minimal support to avoid certain countries via Exclude Nodes. This setting works, but which countries are avoided is not saved.


Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.cpp	2008-06-18 21:51:08 UTC (rev 2753)
@@ -55,13 +55,20 @@
 
 */
   connect(ui.pButtonApplyCountry,SIGNAL(clicked()),
-          this, SLOT( copyCountryToText() ));
+          this, SLOT( copyExitCountryToText() ));
 
+  connect(ui.pButtonApplyExcludedCountry,SIGNAL(clicked()),
+          this, SLOT( copyExcludedCountryToText() ));
+
+
   connect(ui.chkNodePolicy,SIGNAL(clicked()),
           this, SLOT( HideUnhide() ));
   connect(ui.chkExitNodePolicy,SIGNAL(clicked()),
           this, SLOT( HideUnhide() ));
+  connect(ui.chkExcludeNodePolicy,SIGNAL(clicked()),
+          this, SLOT( HideUnhide() ));
 
+
   //file based geoip resolver
   _geoIpResolver=Vidalia::geoIpResolver();
 }
@@ -94,6 +101,10 @@
 
         _settings->setExitNodeCountry(current);
     }
+    if(ui.chkExcludeNodePolicy->isChecked()){
+         QStringList excluded=getExcludeCountries();
+        _settings->setExcludeNodeCountry(excluded);
+    }
   }
 
   //now apply tor settings
@@ -125,6 +136,7 @@
   */
   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(","));
@@ -222,6 +234,9 @@
   memset(saved_country,0x00,4);  
   memcpy(saved_country,_settings->getExitNodeCountry().toAscii(),2);  
 
+  QList<int> saved_excluded_index;
+  QStringList saved_excluded=_settings->getExcludeNodeCountry();
+
   foreach (QString country, by_country_exit_nodes2.keys()) {
     /*Get the count of exit nodes for this country*/
     count=QString("%1").arg(by_country_exit_nodes2.value(country).count(),0,10);
@@ -243,17 +258,18 @@
       saved_index=itemcount; 
     }
 
-    /*
-    ui.listWidgetExitCountry->addItem(countryCount);
-    countryListItem=ui.listWidgetExitCountry->item(itemcount);
+    
+    ui.listWidgetExcludedCountries->addItem(countryCount);
+    
+    countryListItem=ui.listWidgetExcludedCountries->item(itemcount);
     countryListItem->setIcon(country_flag);
-    */
     itemcount++;
   }
   
   
   //and enable multiple selections?
-  //ui.listWidgetExitCountry->setSelectionMode(QAbstractItemView::MultiSelection);
+  //ui.listWidgetInvalidCountries->setSelectionMode(QAbstractItemView::MultiSelection);
+  ui.listWidgetExcludedCountries->setSelectionMode(QAbstractItemView::ExtendedSelection);
  
   //Now load settings for country
   ui.cmboExitNodesbyCountry->setCurrentIndex(saved_index);
@@ -268,14 +284,14 @@
      QString err;
      //save(err);
      ui.cmboExitNodesbyCountry->setCurrentIndex(saved_index);
-     copyCountryToText();
+     copyExitCountryToText();
      applyTorSettings();
   }
 
 }
 
 void 
-NetworkoutPage::copyCountryToText()
+NetworkoutPage::copyExitCountryToText()
 {
   QString current=ui.cmboExitNodesbyCountry->currentText();
     
@@ -304,7 +320,37 @@
   ui.chkCloseAllActiveCircuits->setChecked(true);
 }
 
+void
+NetworkoutPage::copyExcludedCountryToText()
+{
+  //step 1 get countries
+  //step 2 iterate to insert stuff into display.
+  //step 3 enable close active circuits
+  QStringList invalidCountries;
+  invalidCountries=getExcludeCountries();
+  fprintf(stderr,"invalid_count=%d\n",invalidCountries.count());
+  //now step2
+  ui.listWidgetExcludedNodes->clear();
+  int itemcount=0;
+  foreach(QString country, invalidCountries){
+     //fprintf(stderr) 
+     foreach (RouterStatus router, by_country_exit_nodes2.value(country)){
+        QString displayname(router.name());
+        if( router.Named!= (router.flags() & router.Named)){
+            displayname.append(" ($").append(router.id()).append(")");
+        }
+       ui.listWidgetExcludedNodes->addItem(displayname); 
+       itemcount++;
+      }
+  }
 
+  ui.chkCloseAllActiveCircuits->setEnabled(true);
+  ui.chkCloseAllActiveCircuits->setChecked(true);
+
+}
+
+
+
   /** Handles when we get disconnected from Tor network */
  void
 NetworkoutPage::onDisconnected(){
@@ -321,7 +367,7 @@
       //enable all other stuff!
    ui.chkExitNodePolicy->setEnabled(ui.chkNodePolicy->isChecked());
    ui.grpExitNodeSettings->setVisible(ui.chkExitNodePolicy->isChecked() & ui.chkNodePolicy->isChecked()); 
-    
+   ui.grpExcludeNodeSettings->setVisible(ui.chkExcludeNodePolicy->isChecked() & ui.chkNodePolicy->isChecked());
    /*
       //disable all other stuff!
        ui.chkExitNodePolicy->setEnabled(false);
@@ -356,6 +402,8 @@
  /*Now save only is settings have been enabled*/
   if((ui.chkNodePolicy->isChecked())){
     settings.setUseExitNodePolicy(ui.chkExitNodePolicy->isChecked());
+    settings.setUseExcludeNodePolicy(ui.chkExcludeNodePolicy->isChecked());
+
     /*Only save if we have enabled saving exit policies!*/
     if(ui.chkExitNodePolicy->isChecked()){
         /*Need to add validation?*/
@@ -380,13 +428,47 @@
         } 
         settings.setExitNodeList(exitList);     
     }
+    if (ui.chkExcludeNodePolicy->isChecked()){
+       QStringList excludedList;
+       QStringList excludedCountries=getExcludeCountries();
+       
+        foreach(QString country, excludedCountries){
+          foreach (RouterStatus router, by_country_exit_nodes2.value(country)){
+            QString id(router.name());
+            if( router.Named!= (router.flags() & router.Named)){
+               //displayname.append(" ($").append(router.id()).append(")");
+               id=router.id();
+               id.prepend("$");
+               }
+            //ui.listWidgetExcludedNodes->addItem(displayname);
+            excludedList<<id;
+          }
+        }
+        //apply here
+        //settings.setExitNodeList(exitList);
+        settings.setExcludeNodeList(excludedList);
+    }
   }
   /*if clear connections is set, clear them up!*/
   if(ui.chkCloseAllActiveCircuits->isChecked()){
      closeAllCircuits();
   }
 
+}
 
+QStringList 
+NetworkoutPage::getExcludeCountries(){
+  QStringList excludeCountries;
+  QList<QListWidgetItem *> selectedCountries;
+  selectedCountries=ui.listWidgetExcludedCountries->selectedItems ();
 
+  foreach(QListWidgetItem *selected,selectedCountries){
+      QString current=selected->text();
+      QStringList countrylist=current.split("(");
+      current=countrylist.at(0);
+      excludeCountries<<current;
+  }
+  return excludeCountries;
 }
 
+

Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.h	2008-06-18 21:51:08 UTC (rev 2753)
@@ -52,7 +52,10 @@
   void HideUnhide();
 
   /*copies country nodes into exit node text*/
-  void copyCountryToText();
+  void copyExitCountryToText();
+  /**/
+  void copyExcludedCountryToText();
+
   /*Do stuff once authenticated*/
   void onAuthenticated();  
   /** Handles when we get disconnected from Tor network */
@@ -66,6 +69,9 @@
   /*Apply tor gui settings*/
   void applyTorSettings();
 
+  /*Get the countries from the excludelist*/
+  QStringList getExcludeCountries();
+
   /** A VidaliaSettings object used for saving/loading settings */
   VidaliaSettings* _settings;
 

Modified: vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/networkoutpage.ui	2008-06-18 21:51:08 UTC (rev 2753)
@@ -5,124 +5,175 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>622</width>
-    <height>450</height>
+    <width>571</width>
+    <height>507</height>
    </rect>
   </property>
   <property name="contextMenuPolicy" >
    <enum>Qt::NoContextMenu</enum>
   </property>
-  <widget class="QCheckBox" name="chkNodePolicy" >
-   <property name="geometry" >
-    <rect>
-     <x>9</x>
-     <y>9</y>
-     <width>481</width>
-     <height>23</height>
-    </rect>
-   </property>
-   <property name="text" >
-    <string>Enable Vidalia Node Policy Management (Will reduce your anonymity)</string>
-   </property>
-  </widget>
-  <widget class="QCheckBox" name="chkExitNodePolicy" >
-   <property name="geometry" >
-    <rect>
-     <x>9</x>
-     <y>38</y>
-     <width>461</width>
-     <height>23</height>
-    </rect>
-   </property>
-   <property name="text" >
-    <string>Enable Strict Exit Node Management (Will change your exit node configuration)</string>
-   </property>
-  </widget>
-  <widget class="QGroupBox" name="grpExitNodeSettings" >
-   <property name="geometry" >
-    <rect>
-     <x>10</x>
-     <y>60</y>
-     <width>531</width>
-     <height>211</height>
-    </rect>
-   </property>
-   <property name="title" >
-    <string>Exit Node Selection Policy</string>
-   </property>
-   <widget class="QLabel" name="label_2" >
-    <property name="geometry" >
-     <rect>
-      <x>10</x>
-      <y>50</y>
-      <width>71</width>
-      <height>18</height>
-     </rect>
-    </property>
-    <property name="text" >
-     <string>Exit Nodes</string>
-    </property>
-   </widget>
-   <widget class="QComboBox" name="cmboExitNodesbyCountry" >
-    <property name="geometry" >
-     <rect>
-      <x>160</x>
-      <y>120</y>
-      <width>171</width>
-      <height>29</height>
-     </rect>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="pButtonApplyCountry" >
-    <property name="geometry" >
-     <rect>
-      <x>360</x>
-      <y>120</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>90</x>
-      <y>130</y>
-      <width>54</width>
-      <height>18</height>
-     </rect>
-    </property>
-    <property name="text" >
-     <string>Country</string>
-    </property>
-   </widget>
-   <widget class="QCheckBox" name="chkCloseAllActiveCircuits" >
-    <property name="geometry" >
-     <rect>
-      <x>80</x>
-      <y>160</y>
-      <width>171</width>
-      <height>23</height>
-     </rect>
-    </property>
-    <property name="text" >
-     <string>Close All Active Circuits</string>
-    </property>
-   </widget>
-   <widget class="QListWidget" name="listWidgetExitNodes" >
-    <property name="geometry" >
-     <rect>
-      <x>90</x>
-      <y>30</y>
-      <width>431</width>
-      <height>75</height>
-     </rect>
-    </property>
-   </widget>
-  </widget>
+  <layout class="QGridLayout" >
+   <item row="0" column="0" >
+    <widget class="QCheckBox" name="chkNodePolicy" >
+     <property name="text" >
+      <string>Enable Vidalia Node Policy Management (Will reduce your anonymity)</string>
+     </property>
+    </widget>
+   </item>
+   <item row="1" column="0" >
+    <widget class="QCheckBox" name="chkExitNodePolicy" >
+     <property name="text" >
+      <string>Enable Strict Exit Node Management (Will change your exit node configuration)</string>
+     </property>
+    </widget>
+   </item>
+   <item row="2" column="0" colspan="2" >
+    <widget class="QGroupBox" name="grpExitNodeSettings" >
+     <property name="title" >
+      <string>Exit Node Selection Policy</string>
+     </property>
+     <widget class="QLabel" name="label_2" >
+      <property name="geometry" >
+       <rect>
+        <x>20</x>
+        <y>50</y>
+        <width>71</width>
+        <height>18</height>
+       </rect>
+      </property>
+      <property name="text" >
+       <string>Exit Nodes</string>
+      </property>
+     </widget>
+     <widget class="QComboBox" name="cmboExitNodesbyCountry" >
+      <property name="geometry" >
+       <rect>
+        <x>160</x>
+        <y>110</y>
+        <width>171</width>
+        <height>29</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pButtonApplyCountry" >
+      <property name="geometry" >
+       <rect>
+        <x>360</x>
+        <y>110</y>
+        <width>141</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>90</x>
+        <y>120</y>
+        <width>54</width>
+        <height>18</height>
+       </rect>
+      </property>
+      <property name="text" >
+       <string>Country</string>
+      </property>
+     </widget>
+     <widget class="QListWidget" name="listWidgetExitNodes" >
+      <property name="geometry" >
+       <rect>
+        <x>110</x>
+        <y>30</y>
+        <width>431</width>
+        <height>75</height>
+       </rect>
+      </property>
+     </widget>
+    </widget>
+   </item>
+   <item row="3" column="0" >
+    <widget class="QCheckBox" name="chkExcludeNodePolicy" >
+     <property name="text" >
+      <string>Enable Exclude Node Management (Will change your invalid node configuration)</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="0" colspan="2" >
+    <widget class="QGroupBox" name="grpExcludeNodeSettings" >
+     <property name="title" >
+      <string>GroupBox</string>
+     </property>
+     <widget class="QListWidget" name="listWidgetExcludedNodes" >
+      <property name="geometry" >
+       <rect>
+        <x>110</x>
+        <y>20</y>
+        <width>431</width>
+        <height>75</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QLabel" name="label" >
+      <property name="geometry" >
+       <rect>
+        <x>10</x>
+        <y>50</y>
+        <width>90</width>
+        <height>18</height>
+       </rect>
+      </property>
+      <property name="text" >
+       <string>Excluded Nodes</string>
+      </property>
+     </widget>
+     <widget class="QListWidget" name="listWidgetExcludedCountries" >
+      <property name="geometry" >
+       <rect>
+        <x>150</x>
+        <y>100</y>
+        <width>181</width>
+        <height>75</height>
+       </rect>
+      </property>
+     </widget>
+     <widget class="QPushButton" name="pButtonApplyExcludedCountry" >
+      <property name="geometry" >
+       <rect>
+        <x>350</x>
+        <y>130</y>
+        <width>174</width>
+        <height>27</height>
+       </rect>
+      </property>
+      <property name="text" >
+       <string>Set Exclude Nodes by Country</string>
+      </property>
+     </widget>
+     <widget class="QLabel" name="label_4" >
+      <property name="geometry" >
+       <rect>
+        <x>80</x>
+        <y>130</y>
+        <width>54</width>
+        <height>18</height>
+       </rect>
+      </property>
+      <property name="text" >
+       <string>Countries</string>
+      </property>
+     </widget>
+    </widget>
+   </item>
+   <item row="5" column="0" >
+    <widget class="QCheckBox" name="chkCloseAllActiveCircuits" >
+     <property name="text" >
+      <string>Close All Active Circuits</string>
+     </property>
+    </widget>
+   </item>
+  </layout>
  </widget>
  <resources/>
  <connections/>

Modified: vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/networksettings.cpp	2008-06-18 21:51:08 UTC (rev 2753)
@@ -31,6 +31,8 @@
 #define SETTING_PREFER_TUNNELED_DIR_CONNS "PreferTunneledDirConns"
 #define SETTING_USE_EXIT_NODE_POLICY "UseExitNodePolicy"
 #define SETTING_EXIT_NODE_LIST       "ExitNodes"
+#define SETTING_USE_EXCLUDE_NODE_POLICY "UseExcludeNodePolicy"
+#define SETTING_EXCLUDE_NODE_LIST    "ExcludeNodes"
 
 
 /** Default constructor */
@@ -53,6 +55,7 @@
   setDefault(SETTING_USE_EXIT_NODE_POLICY ,  false);
   setDefault(SETTING_EXIT_NODE_LIST, 
     QStringList() << "blutmagie" << "chaoscomputerclub23");
+  setDefault(SETTING_USE_EXCLUDE_NODE_POLICY ,  false);
 }
 
 /** Applies the current network configuration settings to Tor. If
@@ -77,6 +80,8 @@
     conf.insert("StrictExitNodes","0");
     conf.insert(SETTING_EXIT_NODE_LIST,"");
   }
+  conf.insert(SETTING_EXCLUDE_NODE_LIST,
+        localValue(SETTING_EXCLUDE_NODE_LIST).toStringList().join(","));
 
   conf.insert(SETTING_HTTP_PROXY,
     (getUseHttpProxy() ? localValue(SETTING_HTTP_PROXY).toString() : ""));
@@ -344,4 +349,33 @@
 }
 
 
+bool
+NetworkSettings::getUseExcludeNodePolicy(){
+  return value(SETTING_USE_EXCLUDE_NODE_POLICY).toBool();
+}
 
+/** Sets to <b>useNodePolicy</b> whether Tor should try
+ to use node policies to access the newtowk. */
+void
+NetworkSettings::setUseExcludeNodePolicy(bool useNodeExcludePolicy){
+  setValue(SETTING_USE_EXCLUDE_NODE_POLICY, useNodeExcludePolicy);
+}
+
+
+
+/** Returns a list of bridge nodes Tor should use. */
+QStringList
+NetworkSettings::getExcludeNodeList()
+{
+  return value(SETTING_EXCLUDE_NODE_LIST).toStringList();
+}
+
+/** Sets to <b>bridgeList</b> the list of bridge nodes Tor should use. */
+void
+NetworkSettings::setExcludeNodeList(const QStringList &excludeNodeList)
+{
+  setValue(SETTING_EXCLUDE_NODE_LIST, excludeNodeList);
+}
+
+
+

Modified: vidalia/branches/exit-country/src/vidalia/config/networksettings.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/networksettings.h	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/networksettings.h	2008-06-18 21:51:08 UTC (rev 2753)
@@ -134,6 +134,21 @@
   /** Sets to <b>bridgeList</b> the list of bridge nodes Tor should use. */
   void setExitNodeList(const QStringList &exitNodeList);
 
+    /** Returns true if vidalia should manage Tor's exit nodes
+   * network. */
+  bool getUseExcludeNodePolicy();
+  /** Sets to <b>useNodePolicy</b> whether Tor should try
+   to use node policies to access the newtowk. */
+  void setUseExcludeNodePolicy(bool useExcludeNodePolicy);
+
+
+
+  /** Returns Tor should use. */
+  QStringList getExcludeNodeList();
+  /** Sets to ould use. */
+  void setExcludeNodeList(const QStringList &excludeNodeList);
+
+
 };
 
 #endif

Modified: vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.cpp	2008-06-18 21:51:08 UTC (rev 2753)
@@ -261,5 +261,18 @@
 }
 
 
+QStringList
+VidaliaSettings::getExcludeNodeCountry()
+{
+  return value(SETTING_EXCLUDE_NODES_COUNTRY_LIST).toStringList();
+}
 
+void
+VidaliaSettings::setExcludeNodeCountry( QStringList
+                                             &excludeCountryList)
+{
+  setValue(SETTING_EXCLUDE_NODES_COUNTRY_LIST, excludeCountryList);
+}
 
+
+

Modified: vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h	2008-06-18 17:52:51 UTC (rev 2752)
+++ vidalia/branches/exit-country/src/vidalia/config/vidaliasettings.h	2008-06-18 21:51:08 UTC (rev 2753)
@@ -98,6 +98,13 @@
   // Saves the preferred exit country
   void setExitNodeCountry(QString exitCountry);
 
+  //getting the exit node country (last saved that is!)
+  QStringList getExcludeNodeCountry();
+  // Saves the preferred exit country
+  //void VidaliaSettings::setExcludeNodeCountry(QStringList&)
+  void setExcludeNodeCountry(QStringList &excludeCountry);
+
+
 };
 
 #endif