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

[vidalia-svn] r3018: Added sorting of displayed nodes. Fixed behaviour of exlucde (vidalia/branches/exit-country/src/vidalia/config)



Author: cviecco
Date: 2008-08-29 13:38:01 -0400 (Fri, 29 Aug 2008)
New Revision: 3018

Modified:
   vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp
   vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h
Log:
Added sorting of displayed nodes. Fixed behaviour of exlucde nodes. It was excluding only exit nodes in the selected countries, not all other nodes.
Needs cleaunup 


Modified: vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp	2008-08-29 16:03:27 UTC (rev 3017)
+++ vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.cpp	2008-08-29 17:38:01 UTC (rev 3018)
@@ -18,6 +18,8 @@
 #include "nodepolicypage.h"
 #include <nodepolicysettings.h>
 
+
+
 /** Default Constructor */
 NodePolicyPage::NodePolicyPage(QWidget *parent)
 : ConfigPage(parent, tr("Networkout"))
@@ -71,6 +73,9 @@
   delete _settings;
 }
 
+
+
+
 /** Saves the changes on this page */
 bool
 NodePolicyPage::save(QString &errmsg)
@@ -149,6 +154,7 @@
   QString short_country_name;
   QString ip_addr;
   QString count;
+  QString all_count;
   int flags;
   QString uniqueRouterName;
   quint32 torVersion = Vidalia::torControl()->getTorVersion();
@@ -159,8 +165,9 @@
   
   vInfo("Network out refresh!\n"); 
 
-  /*Fill up the internal structure*/
+  /*Fill up the internal structures*/
   by_country_exit_nodes2.clear();
+  by_country_all_nodes.clear();
   foreach( RouterStatus router, networkStatus){
 
      //Get the country!
@@ -170,17 +177,6 @@
      //test with file!
      short_country_name=_geoIpResolver->get_country(router.ipAddress()).toLower();
     
- 
-     /*Only continue (insert into struct)
-      * if the router is running,valid,isexit and is NOT badexit*/
-     if (!router.isRunning())
-      continue;
-     if (!router.isValid())
-      continue;
-     flags=router.flags();
-     //Must be exit AND not badexit
-     if((router.Exit) !=((router.Exit | router.BadExit) & flags) ) 
-      continue;
 
      /*Get a unique name, if unnamed use the full descriptor id*/
      uniqueRouterName=router.name();
@@ -189,7 +185,32 @@
      if(uniqueRouterName=="Unnamed" || (0x00== (flags & router.Named))){
          uniqueRouterName=router.id().prepend("$");
      }
+     /* Now insert it into the all country list*/
+      
+    /*Now insert the information into the HAsh/MAp*/
+     if (by_country_all_nodes.contains(short_country_name)){
+        by_country_all_nodes.insert(short_country_name,
+                 QList<RouterStatus>(by_country_all_nodes.value(short_country_name))<<router);
 
+     }
+     else{
+        by_country_all_nodes.insert(short_country_name,QList<RouterStatus>()<<router);
+     }
+
+
+     /*Only continue if this is a valid exit node!
+      * if the router is running,valid,isexit and is NOT badexit*/
+/*
+     if (!router.isRunning())
+      continue;
+     if (!router.isValid())
+      continue;
+*/
+     flags=router.flags();
+     //Must be exit AND not badexit
+     if((router.Exit) ==((router.Exit | router.BadExit) & flags) ){
+
+
      /*Now insert the information into the HAsh/MAp*/
      if (by_country_exit_nodes2.contains(short_country_name)){
         by_country_exit_nodes2.insert(short_country_name,
@@ -199,8 +220,41 @@
      else{
         by_country_exit_nodes2.insert(short_country_name,QList<RouterStatus>()<<router);
      }
+     }
+     
   }
-  
+  //now sort the interal structs!
+  QMap<QString,RouterStatus> sortMap;
+  QMap<QString,RouterStatus> sortMap2;
+  foreach (QString country,  by_country_exit_nodes2.keys()){
+      sortMap.clear();
+      sortMap2.clear();
+      foreach(RouterStatus router, by_country_exit_nodes2.value(country)){
+         sortMap.insert(router.name().toLower(),router);
+      }
+      foreach(RouterStatus router, by_country_all_nodes.value(country)){
+         sortMap2.insert(router.name().toLower(),router);
+      }
+      by_country_exit_nodes2.insert(country,sortMap.values()); 
+/*
+      if(sortMap2.size()==sortMap.size()){
+        fprintf(stderr,"*");
+      }else{
+        fprintf(stderr,"!");
+      }
+*/
+      by_country_all_nodes.insert(country,sortMap2.values()); 
+      
+  } 
+  //QMap<QString,RouterStatus> sortMap2;
+  //RouterStatus router2;
+  foreach (QString country,  by_country_all_nodes.keys()){
+      sortMap2.clear();
+      foreach(RouterStatus router2, by_country_all_nodes.value(country)){
+         sortMap2.insert(router2.name().toLower(),router2);
+      }
+      //by_country_all_nodes.insert(country,sortMap2.values());
+  }
 
   //* now fill the combo boxes!*/  
   QListWidgetItem *countryListItem;
@@ -225,7 +279,8 @@
   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);
- 
+    all_count=QString("%1").arg(by_country_all_nodes.value(country).count(),0,10);
+
     /*now do de icon for the country*/
     QIcon country_flag;
     if(country!="??"){
@@ -249,6 +304,13 @@
     if(country.toAscii()==saved_country){
       saved_index=itemcount; 
     }
+    //now repeat for exclude countries
+    if(country_long.contains(country)){
+        longCountryCount=country_long[country];
+    }
+    longCountryCount.append(" (").append(country);
+    longCountryCount.append(")(").append(all_count).append(")");
+ 
 
     /*Also add it on the exclude node list*/    
     ui.listWidgetExcludedCountries->addItem(longCountryCount);
@@ -341,7 +403,8 @@
   int itemcount=0;
   foreach(QString country, invalidCountries){
      //fprintf(stderr) 
-     foreach (RouterStatus router, by_country_exit_nodes2.value(country)){
+     //foreach (RouterStatus router, by_country_exit_nodes2.value(country)){
+     foreach (RouterStatus router, by_country_all_nodes.value(country)){
         QString displayname(router.name());
         if( router.Named!= (router.flags() & router.Named)){
             displayname.append(" ($").append(router.id()).append(")");
@@ -441,7 +504,7 @@
        QStringList excludedCountries=getExcludeCountries();
        
         foreach(QString country, excludedCountries){
-          foreach (RouterStatus router, by_country_exit_nodes2.value(country)){
+          foreach (RouterStatus router, by_country_all_nodes.value(country)){
             QString id(router.name());
             if( router.Named!= (router.flags() & router.Named)){
                //displayname.append(" ($").append(router.id()).append(")");

Modified: vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h
===================================================================
--- vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h	2008-08-29 16:03:27 UTC (rev 3017)
+++ vidalia/branches/exit-country/src/vidalia/config/nodepolicypage.h	2008-08-29 17:38:01 UTC (rev 3018)
@@ -95,6 +95,7 @@
   /*struct to hold the country-exit-node-mappings */
   //QMap<QString,QStringList> by_country_exit_nodes;
   QMap<QString,QList<RouterStatus> > by_country_exit_nodes2;
+  QMap<QString,QList<RouterStatus> > by_country_all_nodes;
   QMap<QString,QString> country_long;
 
   /*pointers to the global torControl and geoResolver objects*/