diff options
author | Nick Mathewson <nickm@torproject.org> | 2004-11-22 22:24:10 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2004-11-22 22:24:10 +0000 |
commit | d4754b334c1780db1dff77c96c68e2f6883a44b3 (patch) | |
tree | 39c58f653da2090126b2dcb65e82b09e4097250c /src/or/hibernate.c | |
parent | b9cdb142c90755a12b84d7f656c7c1fab72f8055 (diff) | |
download | tor-d4754b334c1780db1dff77c96c68e2f6883a44b3.tar.gz tor-d4754b334c1780db1dff77c96c68e2f6883a44b3.zip |
Compile cleanly on windows; prevent some insane bandwidth cases (e.g., "BandwidthBurst 1000 TB" from occuring.
svn:r2941
Diffstat (limited to 'src/or/hibernate.c')
-rw-r--r-- | src/or/hibernate.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/or/hibernate.c b/src/or/hibernate.c index 8f2183f1c7..394bf4ff0d 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -336,8 +336,8 @@ configure_accounting(time_t now) static void update_expected_bandwidth(void) { - uint64_t used; - uint32_t max_configured = (get_options()->BandwidthRate * 60); + uint64_t used, expected; + uint64_t max_configured = (get_options()->BandwidthRate * 60); if (n_seconds_active_in_interval < 1800) { /* If we haven't gotten enough data last interval, guess that @@ -346,15 +346,17 @@ update_expected_bandwidth(void) * up until we send Max bytes. Next interval, we'll choose * our starting time based on how much we sent this interval. */ - expected_bandwidth_usage = max_configured; + expected = max_configured; } else { used = n_bytes_written_in_interval < n_bytes_read_in_interval ? n_bytes_read_in_interval : n_bytes_written_in_interval; - expected_bandwidth_usage = (uint32_t) - (used / (n_seconds_active_in_interval / 60)); - if (expected_bandwidth_usage > max_configured) - expected_bandwidth_usage = max_configured; + expected = (used / (n_seconds_active_in_interval / 60)); + if (expected > max_configured) + expected = max_configured; } + if (expected > UINT32_MAX) + expected = UINT32_MAX; + expected_bandwidth_usage = (uint32_t) expected; } /** Called at the start of a new accounting interval: reset our @@ -440,7 +442,7 @@ accounting_set_wakeup_time(void) crypto_free_digest_env(d_env); if (expected_bandwidth_usage) - time_to_exhaust_bw = + time_to_exhaust_bw = (int) (get_options()->AccountingMax/expected_bandwidth_usage)*60; else time_to_exhaust_bw = 24*60*60; |