Commit 50863008 authored by Roger Dingledine's avatar Roger Dingledine
Browse files

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


svn:r982
parent db0c27b3
Loading
Loading
Loading
Loading
+7 −3
Original line number Original line Diff line number Diff line
@@ -153,6 +153,9 @@ static void config_assign(or_options_t *options, struct config_line *list) {
    /* string options */
    /* string options */
    config_compare(list, "Address",        CONFIG_TYPE_STRING, &options->Address) ||
    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, "DebugLogFile",   CONFIG_TYPE_STRING, &options->DebugLogFile) ||
    config_compare(list, "DataDirectory",  CONFIG_TYPE_STRING, &options->DataDirectory) ||
    config_compare(list, "DataDirectory",  CONFIG_TYPE_STRING, &options->DataDirectory) ||
    config_compare(list, "DirPort",        CONFIG_TYPE_INT, &options->DirPort) ||
    config_compare(list, "DirPort",        CONFIG_TYPE_INT, &options->DirPort) ||
@@ -194,7 +197,6 @@ static void config_assign(or_options_t *options, struct config_line *list) {
    config_compare(list, "SocksPort",      CONFIG_TYPE_INT, &options->SocksPort) ||
    config_compare(list, "SocksPort",      CONFIG_TYPE_INT, &options->SocksPort) ||
    config_compare(list, "SocksBindAddress",CONFIG_TYPE_STRING,&options->SocksBindAddress) ||
    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, "TrafficShaping", CONFIG_TYPE_BOOL, &options->TrafficShaping) ||


    config_compare(list, "User",           CONFIG_TYPE_STRING, &options->User)
    config_compare(list, "User",           CONFIG_TYPE_STRING, &options->User)
@@ -211,10 +213,11 @@ static void config_assign(or_options_t *options, struct config_line *list) {
/* prints the usage of tor. */
/* prints the usage of tor. */
void print_usage(void) {
void print_usage(void) {
  printf("tor -f <torrc> [args]\n"
  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"
         "-d <file>\t\tDebug file\n"
         "-m <max>\t\tMax number of connections\n"
         "-m <max>\t\tMax number of connections\n"
         "-l <level>\t\tLog level\n"
         "-l <level>\t\tLog level\n"
         "-t <bandwidth>\t\tTotal bandwidth\n"
         "-r <file>\t\tList of known routers\n");
         "-r <file>\t\tList of known routers\n");
  printf("\nClient options:\n"
  printf("\nClient options:\n"
         "-e \"nick1 nick2 ...\"\t\tExit nodes\n"
         "-e \"nick1 nick2 ...\"\t\tExit nodes\n"
@@ -269,7 +272,8 @@ void init_options(or_options_t *options) {
  options->KeepalivePeriod = 300;
  options->KeepalivePeriod = 300;
  options->MaxOnionsPending = 100;
  options->MaxOnionsPending = 100;
  options->NewCircuitPeriod = 60; /* once a minute */
  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;
  options->NumCpus = 1;
}
}


+3 −1
Original line number Original line Diff line number Diff line
@@ -290,6 +290,7 @@ int connection_edge_process_relay_cell(cell_t *cell, circuit_t *circ, connection
            return 0;
            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.",
      log_fn(LOG_INFO,"end cell (%s) for stream %d. Removing stream.",
        connection_edge_end_reason(cell->payload+RELAY_HEADER_SIZE, rh.length),
        connection_edge_end_reason(cell->payload+RELAY_HEADER_SIZE, rh.length),
        conn->stream_id);
        conn->stream_id);
@@ -880,7 +881,8 @@ int connection_ap_can_use_exit(connection_t *conn, routerinfo_t *exit)
         exit->nickname, conn->socks_request->address,
         exit->nickname, conn->socks_request->address,
         conn->socks_request->port);
         conn->socks_request->port);
  addr = client_dns_lookup_entry(conn->socks_request->address);
  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 ***** */
/* ***** Client DNS code ***** */
+1 −0
Original line number Original line Diff line number Diff line
@@ -127,6 +127,7 @@ int cpuworker_main(void *data) {
  close(fdarray[0]); /* this is the side of the socketpair the parent uses */
  close(fdarray[0]); /* this is the side of the socketpair the parent uses */
  fd = fdarray[1]; /* this side is ours */
  fd = fdarray[1]; /* this side is ours */
  connection_free_all(); /* so the child doesn't hold the parent's fd's open */
  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(;;) {
  for(;;) {


+1 −0
Original line number Original line Diff line number Diff line
@@ -396,6 +396,7 @@ int dnsworker_main(void *data) {
  close(fdarray[0]); /* this is the side of the socketpair the parent uses */
  close(fdarray[0]); /* this is the side of the socketpair the parent uses */
  fd = fdarray[1]; /* this side is ours */
  fd = fdarray[1]; /* this side is ours */
  connection_free_all(); /* so the child doesn't hold the parent's fd's open */
  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(;;) {
  for(;;) {


+3 −3
Original line number Original line Diff line number Diff line
@@ -347,8 +347,8 @@ static void run_scheduled_events(time_t now) {
   *    increment global_read_bucket.
   *    increment global_read_bucket.
   */
   */
  stats_n_bytes_read += stats_prev_global_read_bucket-global_read_bucket;
  stats_n_bytes_read += stats_prev_global_read_bucket-global_read_bucket;
  if(global_read_bucket < 9*options.TotalBandwidth) {
  if(global_read_bucket < options.BandwidthBurst) {
    global_read_bucket += options.TotalBandwidth;
    global_read_bucket += options.BandwidthRate;
    log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
    log_fn(LOG_DEBUG,"global_read_bucket now %d.", global_read_bucket);
  }
  }
  stats_prev_global_read_bucket = global_read_bucket;
  stats_prev_global_read_bucket = global_read_bucket;
@@ -418,7 +418,7 @@ static int init_from_config(int argc, char **argv) {
    log_fn(LOG_DEBUG, "Successfully opened DebugLogFile '%s'.", options.DebugLogFile);
    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;
  stats_prev_global_read_bucket = global_read_bucket;


  if(options.User || options.Group) {
  if(options.User || options.Group) {
Loading