[or-cvs] bump default pathlen to 3; clean up surrounding code

Roger Dingledine arma at seul.org
Thu Nov 13 23:01:58 UTC 2003


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/home2/arma/work/onion/cvs/src/or

Modified Files:
	config.c onion.c or.h 
Log Message:
bump default pathlen to 3; clean up surrounding code


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.67
retrieving revision 1.68
diff -u -d -r1.67 -r1.68
--- config.c	13 Nov 2003 06:49:25 -0000	1.67
+++ config.c	13 Nov 2003 23:01:55 -0000	1.68
@@ -153,8 +153,6 @@
     /* string options */
     config_compare(list, "Address",        CONFIG_TYPE_STRING, &options->Address) ||
 
-    config_compare(list, "CoinWeight",     CONFIG_TYPE_DOUBLE, &options->CoinWeight) ||
-
     config_compare(list, "DebugLogFile",   CONFIG_TYPE_STRING, &options->DebugLogFile) ||
     config_compare(list, "DataDirectory",  CONFIG_TYPE_STRING, &options->DataDirectory) ||
     config_compare(list, "DirPort",        CONFIG_TYPE_INT, &options->DirPort) ||
@@ -187,10 +185,11 @@
     config_compare(list, "OnionRouter",    CONFIG_TYPE_BOOL, &options->OnionRouter) ||
 
     config_compare(list, "PidFile",        CONFIG_TYPE_STRING, &options->PidFile) ||
+    config_compare(list, "PathlenCoinWeight",CONFIG_TYPE_DOUBLE, &options->PathlenCoinWeight) ||
 
     config_compare(list, "RouterFile",     CONFIG_TYPE_STRING, &options->RouterFile) ||
     config_compare(list, "RunAsDaemon",    CONFIG_TYPE_BOOL, &options->RunAsDaemon) ||
-    config_compare(list, "RecommendedVersions", CONFIG_TYPE_STRING, &options->RecommendedVersions) ||
+    config_compare(list, "RecommendedVersions",CONFIG_TYPE_STRING, &options->RecommendedVersions) ||
 
     config_compare(list, "SocksPort",      CONFIG_TYPE_INT, &options->SocksPort) ||
     config_compare(list, "SocksBindAddress",CONFIG_TYPE_STRING,&options->SocksBindAddress) ||
@@ -262,7 +261,7 @@
   options->loglevel = LOG_INFO;
   options->PidFile = tor_strdup("tor.pid");
   options->DataDirectory = NULL;
-  options->CoinWeight = 0.1;
+  options->PathlenCoinWeight = 0.3;
   options->MaxConn = 900;
   options->DirFetchPostPeriod = 600;
   options->KeepalivePeriod = 300;
@@ -338,7 +337,7 @@
 
 /* Validate options */
 
-  /* first check if some of the previous options have changed but aren't allowed to */
+  /* first check if any of the previous options have changed but aren't allowed to */
   if(previous_pidfile && strcmp(previous_pidfile,options->PidFile)) {
     log_fn(LOG_WARN,"During reload, PidFile changed from %s to %s. Failing.",
            previous_pidfile, options->PidFile);
@@ -412,8 +411,8 @@
   }
 
   if(options->SocksPort > 1 &&
-     (options->CoinWeight < 0.0 || options->CoinWeight >= 1.0)) {
-    log(LOG_WARN,"CoinWeight option must be >=0.0 and <1.0.");
+     (options->PathlenCoinWeight < 0.0 || options->PathlenCoinWeight >= 1.0)) {
+    log(LOG_WARN,"PathlenCoinWeight option must be >=0.0 and <1.0.");
     result = -1;
   }
 

Index: onion.c
===================================================================
RCS file: /home/or/cvsroot/src/or/onion.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -d -r1.81 -r1.82
--- onion.c	12 Nov 2003 19:34:34 -0000	1.81
+++ onion.c	13 Nov 2003 23:01:55 -0000	1.82
@@ -187,34 +187,15 @@
   return out;  
 }
 
-/* uses a weighted coin with weight cw to choose a route length */
-static int chooselen(double cw) {
-  int len = 2;
-  
-  if ((cw < 0) || (cw >= 1)) /* invalid parameter */
-    return -1;
-  
-  while(1)
-  {
-    if (crypto_pseudo_rand_int(255) > cw*255) /* don't extend */
-      break;
-    else
-      len++;
-  }
-  
-  return len;
-}
-
 static int new_route_len(double cw, routerinfo_t **rarray, int rarray_len) {
   int num_acceptable_routers;
   int routelen;
 
-  assert((cw >= 0) && (cw < 1) && (rarray) ); /* valid parameters */
+  assert((cw >= 0) && (cw < 1) && rarray); /* valid parameters */
 
-  routelen = chooselen(cw);
-  if (routelen == -1) {
-    log_fn(LOG_WARN,"Choosing route length failed.");
-    return -1;
+  for(routelen=3; ; routelen++) { /* 3, increment until coinflip says we're done */
+    if (crypto_pseudo_rand_int(255) >= cw*255) /* don't extend */
+      break;
   }
   log_fn(LOG_DEBUG,"Chosen route length %d (%d routers available).",routelen, rarray_len);
 
@@ -242,7 +223,7 @@
   directory_t *dir;
 
   router_get_directory(&dir);
-  return new_route_len(options.CoinWeight, dir->routers, dir->n_routers);
+  return new_route_len(options.PathlenCoinWeight, dir->routers, dir->n_routers);
 }
 
 static int count_acceptable_routers(routerinfo_t **rarray, int rarray_len) {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.183
retrieving revision 1.184
diff -u -d -r1.183 -r1.184
--- or.h	13 Nov 2003 06:49:25 -0000	1.183
+++ or.h	13 Nov 2003 23:01:56 -0000	1.184
@@ -439,7 +439,7 @@
   char *RecommendedVersions;
   char *User;
   char *Group;
-  double CoinWeight;
+  double PathlenCoinWeight;
   int ORPort;
   int SocksPort;
   int DirPort;



More information about the tor-commits mailing list