Commit 28a297eb authored by Roger Dingledine's avatar Roger Dingledine
Browse files

only play the accounting game if it's possible you'll choose to hibernate


svn:r2694
parent 865f3417
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1173,6 +1173,7 @@ getconfig(int argc, char **argv)
  static char **backup_argv;
  static int backup_argc;

  /* we don't use get_options() here, since it's null on the first call */
  oldoptions = global_options;

  if (argv) { /* first time we're called. save commandline args */
+3 −6
Original line number Diff line number Diff line
@@ -169,7 +169,6 @@ reset_accounting(time_t now) {
  n_seconds_active_in_interval = 0;
}


static INLINE int time_to_record_bandwidth_usage(time_t now)
{
  /* Note every 5 minutes */
@@ -180,11 +179,6 @@ static INLINE int time_to_record_bandwidth_usage(time_t now)
  static uint64_t last_written_bytes_noted = 0;
  static time_t last_time_noted = 0;

  /* ???? Maybe only do this if accountingmaxkb is set ?
  if (!get_options()->AccountingMaxKB)
    return 0;
  */

  if (last_time_noted + NOTE_INTERVAL <= now ||
      last_read_bytes_noted + NOTE_BYTES <= n_bytes_read_in_interval ||
      last_written_bytes_noted + NOTE_BYTES <= n_bytes_written_in_interval ||
@@ -240,6 +234,9 @@ accounting_set_wakeup_time(void)

  n_days_to_consider = n_days_in_interval - n_days_to_exhaust_bw;

  /* XXX can we simplify this just by picking a random (non-deterministic)
   * time to be up? If we go down and come up, then we pick a new one. Is
   * that good enough? -RD */
  while (((unsigned char)digest[0]) > n_days_to_consider)
    crypto_digest(digest, digest, DIGEST_LEN);

+8 −5
Original line number Diff line number Diff line
@@ -529,7 +529,7 @@ static void run_scheduled_events(time_t now) {
    last_rotated_certificate = now;
  if (last_rotated_certificate+MAX_SSL_KEY_LIFETIME < now) {
    log_fn(LOG_INFO,"Rotating tls context.");
    if (tor_tls_context_new(get_identity_key(), 1, get_options()->Nickname,
    if (tor_tls_context_new(get_identity_key(), 1, options->Nickname,
                            MAX_SSL_KEY_LIFETIME) < 0) {
      log_fn(LOG_WARN, "Error reinitializing TLS context");
    }
@@ -540,6 +540,7 @@ static void run_scheduled_events(time_t now) {

  /** 1c. If we have to change the accounting interval or record
   * bandwidth used in this accounting interval, do so. */
  if (options->AccountingMaxKB)
    accounting_run_housekeeping(now);

  /** 2. Every DirFetchPostPeriod seconds, we get a new directory and upload
@@ -576,7 +577,7 @@ static void run_scheduled_events(time_t now) {
    }
    rend_cache_clean(); /* should this go elsewhere? */

    time_to_fetch_directory = now + get_options()->DirFetchPostPeriod;
    time_to_fetch_directory = now + options->DirFetchPostPeriod;
  }

  /** 3a. Every second, we examine pending circuits and prune the
@@ -657,6 +658,7 @@ static int prepare_for_poll(void) {
    seconds_elapsed = current_second ? (now.tv_sec - current_second) : 0;
    stats_n_bytes_read += bytes_read;
    stats_n_bytes_written += bytes_written;
    if (get_options()->AccountingMaxKB)
      accounting_add_bytes(bytes_read, bytes_written, seconds_elapsed);
    control_event_bandwidth_used((uint32_t)bytes_read,(uint32_t)bytes_written);

@@ -818,6 +820,7 @@ static int do_main_loop(void) {
  }

  /* Set up accounting */
  if (get_options()->AccountingMaxKB)
    configure_accounting(time(NULL));

  /* load the routers file, or assign the defaults. */