mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-09-21 13:34:59 +02:00
only play the accounting game if it's possible you'll choose to hibernate
svn:r2694
This commit is contained in:
parent
865f341708
commit
28a297ebe7
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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()) {
|
||||
|
Loading…
Reference in New Issue
Block a user