diff options
author | Roger Dingledine <arma@torproject.org> | 2004-11-06 06:56:28 +0000 |
---|---|---|
committer | Roger Dingledine <arma@torproject.org> | 2004-11-06 06:56:28 +0000 |
commit | 28a297ebe7058308922812adc9d874ef4c7aa630 (patch) | |
tree | a79900d128fa5c202cc33646a77c52e1f4b5375d /src | |
parent | 865f3417082e2362af3be3fab5cc41fd3e1a7299 (diff) | |
download | tor-28a297ebe7058308922812adc9d874ef4c7aa630.tar.gz tor-28a297ebe7058308922812adc9d874ef4c7aa630.zip |
only play the accounting game if it's possible you'll choose to hibernate
svn:r2694
Diffstat (limited to 'src')
-rw-r--r-- | src/or/config.c | 1 | ||||
-rw-r--r-- | src/or/hibernate.c | 9 | ||||
-rw-r--r-- | src/or/main.c | 13 |
3 files changed, 12 insertions, 11 deletions
diff --git a/src/or/config.c b/src/or/config.c index e553dc9695..98af9518ba 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -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 */ diff --git a/src/or/hibernate.c b/src/or/hibernate.c index f4efd89f6a..68fe34cfdb 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -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); diff --git a/src/or/main.c b/src/or/main.c index ec1b66c4ef..d5823220d0 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -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,7 +540,8 @@ 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. */ - accounting_run_housekeeping(now); + if (options->AccountingMaxKB) + accounting_run_housekeeping(now); /** 2. Every DirFetchPostPeriod seconds, we get a new directory and upload * our descriptor (if we've passed our internal checks). */ @@ -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,7 +658,8 @@ 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; - accounting_add_bytes(bytes_read, bytes_written, seconds_elapsed); + 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); connection_bucket_refill(&now); @@ -818,7 +820,8 @@ static int do_main_loop(void) { } /* Set up accounting */ - configure_accounting(time(NULL)); + if (get_options()->AccountingMaxKB) + configure_accounting(time(NULL)); /* load the routers file, or assign the defaults. */ if(router_reload_router_list()) { |