diff options
author | Sebastian Hahn <sebastian@torproject.org> | 2011-01-25 16:45:27 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-01-10 09:59:36 -0500 |
commit | 50a50392b7d65409de4416eb604bec6339670a2c (patch) | |
tree | 0788dbf5f0bab5cb41cc57c0f9b7c53c24374663 /src/or/hibernate.c | |
parent | 2a9b279163da4ba0d870dd5e9b7fc1ae9591127c (diff) | |
download | tor-50a50392b7d65409de4416eb604bec6339670a2c.tar.gz tor-50a50392b7d65409de4416eb604bec6339670a2c.zip |
Advertise dirport if accountingmax is large enough
When we have an effective bandwidthrate configured so that we cannot
exceed our bandwidth limit in one accounting interval, don't disable
advertising the dirport. Implements ticket 2434.
Diffstat (limited to 'src/or/hibernate.c')
-rw-r--r-- | src/or/hibernate.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/or/hibernate.c b/src/or/hibernate.c index ce64581d1c..803f7f5764 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -242,6 +242,14 @@ accounting_is_enabled(const or_options_t *options) return 0; } +/** If accounting is enabled, return how long (in seconds) this + * interval lasts. */ +int +accounting_get_interval_length(void) +{ + return (int)(interval_end_time - interval_start_time); +} + /** Called from main.c to tell us that <b>seconds</b> seconds have * passed, <b>n_read</b> bytes have been read, and <b>n_written</b> * bytes have been written. */ @@ -504,7 +512,6 @@ accounting_set_wakeup_time(void) { char digest[DIGEST_LEN]; crypto_digest_env_t *d_env; - int time_in_interval; uint64_t time_to_exhaust_bw; int time_to_consider; @@ -538,22 +545,21 @@ accounting_set_wakeup_time(void) interval_wakeup_time = interval_start_time; log_notice(LD_ACCT, - "Configured hibernation. This interval begins at %s " - "and ends at %s. We have no prior estimate for bandwidth, so " + "Configured hibernation. This interval begins at %s " + "and ends at %s. We have no prior estimate for bandwidth, so " "we will start out awake and hibernate when we exhaust our quota.", buf1, buf2); return; } - time_in_interval = (int)(interval_end_time - interval_start_time); - time_to_exhaust_bw = (get_options()->AccountingMax/expected_bandwidth_usage)*60; if (time_to_exhaust_bw > INT_MAX) { time_to_exhaust_bw = INT_MAX; time_to_consider = 0; } else { - time_to_consider = time_in_interval - (int)time_to_exhaust_bw; + time_to_consider = accounting_get_interval_length() - + (int)time_to_exhaust_bw; } if (time_to_consider<=0) { |