[or-cvs] split the token bucket into "rate" and "burst" params

Roger Dingledine arma at seul.org
Sat Jan 10 23:40:42 UTC 2004


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

Modified Files:
	config.c connection_edge.c cpuworker.c dns.c main.c or.h 
	router.c routerlist.c 
Log Message:
split the token bucket into 'rate' and 'burst' params
we're not entirely migrated to burst yet, for backward compatibility

note some win32 probable-bugs

clean up routerlist.c


Index: config.c
===================================================================
RCS file: /home/or/cvsroot/src/or/config.c,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -d -r1.78 -r1.79
--- config.c	17 Dec 2003 21:09:31 -0000	1.78
+++ config.c	10 Jan 2004 23:40:38 -0000	1.79
@@ -153,6 +153,9 @@
     /* string options */
     config_compare(list, "Address",        CONFIG_TYPE_STRING, &options->Address) ||
 
+    config_compare(list, "BandwidthRate",  CONFIG_TYPE_INT, &options->BandwidthRate) ||
+    config_compare(list, "BandwidthBurst", CONFIG_TYPE_INT, &options->BandwidthBurst) ||
+
     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) ||
@@ -194,7 +197,6 @@
     config_compare(list, "SocksPort",      CONFIG_TYPE_INT, &options->SocksPort) ||
     config_compare(list, "SocksBindAddress",CONFIG_TYPE_STRING,&options->SocksBindAddress) ||
 
-    config_compare(list, "TotalBandwidth", CONFIG_TYPE_INT, &options->TotalBandwidth) ||
     config_compare(list, "TrafficShaping", CONFIG_TYPE_BOOL, &options->TrafficShaping) ||
 
     config_compare(list, "User",           CONFIG_TYPE_STRING, &options->User)
@@ -211,10 +213,11 @@
 /* prints the usage of tor. */
 void print_usage(void) {
   printf("tor -f <torrc> [args]\n"
+         "See man page for more options.\n\n"
+         "-b <bandwidth>\t\tbytes/second rate limiting\n"
          "-d <file>\t\tDebug file\n"
          "-m <max>\t\tMax number of connections\n"
          "-l <level>\t\tLog level\n"
-         "-t <bandwidth>\t\tTotal bandwidth\n"
          "-r <file>\t\tList of known routers\n");
   printf("\nClient options:\n"
          "-e \"nick1 nick2 ...\"\t\tExit nodes\n"
@@ -269,7 +272,8 @@
   options->KeepalivePeriod = 300;
   options->MaxOnionsPending = 100;
   options->NewCircuitPeriod = 60; /* once a minute */
-  options->TotalBandwidth = 800000; /* at most 800kB/s total sustained incoming */
+  options->BandwidthRate = 800000; /* at most 800kB/s total sustained incoming */
+  options->BandwidthBurst = 10000000; /* max burst on the token bucket */
   options->NumCpus = 1;
 }
 

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/src/or/connection_edge.c,v
retrieving revision 1.85
retrieving revision 1.86
diff -u -d -r1.85 -r1.86
--- connection_edge.c	2 Jan 2004 09:03:38 -0000	1.85
+++ connection_edge.c	10 Jan 2004 23:40:38 -0000	1.86
@@ -290,6 +290,7 @@
             return 0;
         }
       }
+/* XXX add to this log_fn the exit node's nickname? */
       log_fn(LOG_INFO,"end cell (%s) for stream %d. Removing stream.",
         connection_edge_end_reason(cell->payload+RELAY_HEADER_SIZE, rh.length),
         conn->stream_id);
@@ -880,7 +881,8 @@
          exit->nickname, conn->socks_request->address,
          conn->socks_request->port);
   addr = client_dns_lookup_entry(conn->socks_request->address);
-  return router_supports_exit_address(addr, conn->socks_request->port, exit);
+  return router_compare_addr_to_exit_policy(addr,
+           conn->socks_request->port, exit->exit_policy);
 }
 
 /* ***** Client DNS code ***** */

Index: cpuworker.c
===================================================================
RCS file: /home/or/cvsroot/src/or/cpuworker.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -d -r1.20 -r1.21
--- cpuworker.c	6 Jan 2004 07:53:40 -0000	1.20
+++ cpuworker.c	10 Jan 2004 23:40:38 -0000	1.21
@@ -127,6 +127,7 @@
   close(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
   connection_free_all(); /* so the child doesn't hold the parent's fd's open */
+/* XXX probably don't close all the fd's on MS_WINDOWS? */
 
   for(;;) {
 

Index: dns.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dns.c,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -d -r1.47 -r1.48
--- dns.c	6 Jan 2004 07:53:40 -0000	1.47
+++ dns.c	10 Jan 2004 23:40:38 -0000	1.48
@@ -396,6 +396,7 @@
   close(fdarray[0]); /* this is the side of the socketpair the parent uses */
   fd = fdarray[1]; /* this side is ours */
   connection_free_all(); /* so the child doesn't hold the parent's fd's open */
+/* XXX probably don't close all the fd's on MS_WINDOWS? */
 
   for(;;) {
 

Index: main.c
===================================================================
RCS file: /home/or/cvsroot/src/or/main.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- main.c	5 Jan 2004 05:22:04 -0000	1.162
+++ main.c	10 Jan 2004 23:40:38 -0000	1.163
@@ -347,8 +347,8 @@
    *    increment global_read_bucket.
    */
   stats_n_bytes_read += stats_prev_global_read_bucket-global_read_bucket;
-  if(global_read_bucket < 9*options.TotalBandwidth) {
-    global_read_bucket += options.TotalBandwidth;
+  if(global_read_bucket < options.BandwidthBurst) {
+    global_read_bucket += options.BandwidthRate;
     log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
   }
   stats_prev_global_read_bucket = global_read_bucket;
@@ -418,7 +418,7 @@
     log_fn(LOG_DEBUG, "Successfully opened DebugLogFile '%s'.", options.DebugLogFile);
   }
 
-  global_read_bucket = options.TotalBandwidth; /* start it at 1 second of traffic */
+  global_read_bucket = options.BandwidthBurst; /* start it at max traffic */
   stats_prev_global_read_bucket = global_read_bucket;
 
   if(options.User || options.Group) {

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/src/or/or.h,v
retrieving revision 1.218
retrieving revision 1.219
diff -u -d -r1.218 -r1.219
--- or.h	6 Jan 2004 07:53:40 -0000	1.218
+++ or.h	10 Jan 2004 23:40:38 -0000	1.219
@@ -389,7 +389,8 @@
   int is_running;
 
   /* link info */
-  uint32_t bandwidth;
+  uint32_t bandwidthrate;
+  uint32_t bandwidthburst;
   struct exit_policy_t *exit_policy;
 } routerinfo_t;
 
@@ -505,7 +506,8 @@
   int KeepalivePeriod;
   int MaxOnionsPending;
   int NewCircuitPeriod;
-  int TotalBandwidth;
+  int BandwidthRate;
+  int BandwidthBurst;
   int NumCpus;
   int loglevel;
 } or_options_t;
@@ -800,8 +802,6 @@
 int router_set_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey);
 routerinfo_t *router_get_entry_from_string(const char **s);
 int router_add_exit_policy_from_string(routerinfo_t *router, const char *s);
-int router_supports_exit_address(uint32_t addr, uint16_t port,
-                                 routerinfo_t *router);
 int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
                                        struct exit_policy_t *policy);
 int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port);

Index: router.c
===================================================================
RCS file: /home/or/cvsroot/src/or/router.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- router.c	17 Dec 2003 21:09:31 -0000	1.6
+++ router.c	10 Jan 2004 23:40:38 -0000	1.7
@@ -338,7 +338,8 @@
   ri->onion_pkey = crypto_pk_dup_key(get_onion_key());
   ri->link_pkey = crypto_pk_dup_key(get_link_key());
   ri->identity_pkey = crypto_pk_dup_key(get_identity_key());
-  ri->bandwidth = options.TotalBandwidth;
+  ri->bandwidthrate = options.BandwidthRate;
+  ri->bandwidthburst = options.BandwidthBurst;
   ri->exit_policy = NULL; /* zero it out first */
   router_add_exit_policy_from_config(ri);
   if (desc_routerinfo)
@@ -421,7 +422,8 @@
     router->or_port,
     router->socks_port,
     router->dir_port,
-    (int) router->bandwidth,
+    (int) router->bandwidthrate,
+/* XXXBC also write bandwidthburst */
     platform,
     published,
     onion_pkey, link_pkey, identity_pkey);

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- routerlist.c	19 Dec 2003 19:55:02 -0000	1.13
+++ routerlist.c	10 Jan 2004 23:40:38 -0000	1.14
@@ -22,7 +22,7 @@
 /****************************************************************************/
 
 /* Enumeration of possible token types.  The ones starting with K_ correspond
- * to directory 'keywords'.  _SIGNATURE and _PUBLIC_KEY are self-explanitory.
+ * to directory 'keywords'.  _SIGNATURE and _PUBLIC_KEY are self-explanatory.
  * _ERR is an error in the tokenizing process, _EOF is an end-of-file marker,
  * and _NIL is used to encode not-a-token.
  */
@@ -64,10 +64,9 @@
 
 /****************************************************************************/
 
-
-
 /* static function prototypes */
-static int router_set_routerlist_from_string(const char *s);
+static int
+router_set_routerlist_from_string(const char *s);
 static int
 router_get_list_from_string_impl(const char **s, routerlist_t **dest,
                                  int n_good_nicknames,
@@ -75,23 +74,24 @@
 static int
 router_get_routerlist_from_directory_impl(const char *s, routerlist_t **dest,
                                           crypto_pk_env_t *pkey);
-static int router_add_exit_policy(routerinfo_t *router,
-                                  directory_token_t *tok);
-static int router_resolve_routerlist(routerlist_t *dir);
-
-
+static int
+router_add_exit_policy(routerinfo_t *router, directory_token_t *tok);
+static int
+router_resolve_routerlist(routerlist_t *dir);
 
-static int _router_get_next_token(const char **s, directory_token_t *tok);
+static int
+_router_get_next_token(const char **s, directory_token_t *tok);
 #ifdef DEBUG_ROUTER_TOKENS
-static int router_get_next_token(const char **s, directory_token_t *tok);
+static int
+router_get_next_token(const char **s, directory_token_t *tok);
 #else
 #define router_get_next_token _router_get_next_token
 #endif
-static int router_get_hash_impl(const char *s, char *digest,
-                                const char *start_str,
-                                const char *end_str);
-static void router_release_token(directory_token_t *tok);
-
+static int
+router_get_hash_impl(const char *s, char *digest,
+                     const char *start_str, const char *end_str);
+static void
+router_release_token(directory_token_t *tok);
 
 /****************************************************************************/
 
@@ -262,7 +262,6 @@
   return 0;
 }
 
-
 /* Helper function: read routerinfo elements from s, and throw out the
  * ones that don't parse and resolve.  Replace the current
  * routerlist. */
@@ -296,8 +295,8 @@
                               "router ","router-signature");
 }
 
-/* return 0 if myversion is in versionlist. Else return -1.  (versionlist
- * contains a comma-separated list of versions.) */
+/* return 0 if myversion is in versionlist. Else return -1.
+ * (versionlist contains a comma-separated list of versions.) */
 int compare_recommended_versions(const char *myversion,
                                  const char *versionlist) {
   int len_myversion = strlen(myversion);
@@ -319,8 +318,7 @@
 }
 
 /* Replace the current routerlist with the routers stored in the directory
- * 's'.  If pkey is provided, make sure that 's' is signed with pkey.
- */
+ * 's'.  If pkey is provided, make sure that 's' is signed with pkey. */
 int router_set_routerlist_from_directory(const char *s, crypto_pk_env_t *pkey)
 {
   if (router_get_routerlist_from_directory_impl(s, &routerlist, pkey)) {
@@ -344,7 +342,6 @@
       exit(0);
     }
   }
-
   return 0;
 }
 
@@ -401,17 +398,6 @@
  * Returns -1 for 'rejected', 0 for accepted, 1 for 'maybe' (since IP is
  * unknown.
  */
-int router_supports_exit_address(uint32_t addr, uint16_t port,
-                                 routerinfo_t *router)
-{
-  return router_compare_addr_to_exit_policy(addr, port, router->exit_policy);
-}
-
-/* Addr is 0 for "IP unknown".
- *
- * Returns -1 for 'rejected', 0 for accepted, 1 for 'maybe' (since IP is
- * unknown.
- */
 int router_compare_addr_to_exit_policy(uint32_t addr, uint16_t port,
                                        struct exit_policy_t *policy)
 {
@@ -716,7 +702,8 @@
   router = tor_malloc_zero(sizeof(routerinfo_t));
   router->onion_pkey = router->identity_pkey = router->link_pkey = NULL;
 
-  if (N_ARGS != 6) {
+/* XXXBC move to <7 once we require bandwidthburst */
+  if (N_ARGS < 6) {
     log_fn(LOG_WARN,"Wrong # of arguments to \"router\"");
     goto err;
   }
@@ -749,12 +736,22 @@
   router->dir_port = atoi(ARGS[4]);
 
   /* Router->bandwidth */
-  router->bandwidth = atoi(ARGS[5]);
-  if (!router->bandwidth) {
-    log_fn(LOG_WARN,"bandwidth unreadable or 0. Failing.");
+  router->bandwidthrate = atoi(ARGS[5]);
+  if (!router->bandwidthrate) {
+    log_fn(LOG_WARN,"bandwidthrate unreadable or 0. Failing.");
     goto err;
   }
 
+#if XXXBC
+  router->bandwidthburst = atoi(ARGS[6]);
+  if (!router->bandwidthburst) {
+    log_fn(LOG_WARN,"bandwidthburst unreadable or 0. Failing.");
+    goto err;
+  }
+#else
+  router->bandwidthburst = 10*router->bandwidthrate;
+#endif
+
   log_fn(LOG_DEBUG,"or_port %d, socks_port %d, dir_port %d, bandwidth %u.",
     router->or_port, router->socks_port, router->dir_port,
     (unsigned) router->bandwidth);



More information about the tor-commits mailing list