From dad60905a814de9aad55fb824a5315673b9e13f9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 13 Mar 2006 01:06:55 +0000 Subject: [PATCH] Be a little more careful when our calculated bandwidth is so high that we could never ever exhaust our bandwidth limit. This should resolve bug 130. svn:r6146 --- src/or/hibernate.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/or/hibernate.c b/src/or/hibernate.c index a8128f45e9..1c734a96ea 100644 --- a/src/or/hibernate.c +++ b/src/or/hibernate.c @@ -443,7 +443,7 @@ accounting_set_wakeup_time(void) char digest[DIGEST_LEN]; crypto_digest_env_t *d_env; int time_in_interval; - int time_to_exhaust_bw; + uint64_t time_to_exhaust_bw; int time_to_consider; if (! identity_key_is_set()) { @@ -478,10 +478,16 @@ accounting_set_wakeup_time(void) return; } - time_to_exhaust_bw = (int) - (get_options()->AccountingMax/expected_bandwidth_usage)*60; time_in_interval = interval_end_time - interval_start_time; - time_to_consider = time_in_interval - time_to_exhaust_bw; + + time_to_exhaust_bw = + (get_options()->AccountingMax/expected_bandwidth_usage)*60; + if (time_to_exhaust_bw > TIME_MAX) { + time_to_exhaust_bw = TIME_MAX; + time_to_consider = 0; + } else { + time_to_consider = time_in_interval - (int)time_to_exhaust_bw; + } if (time_to_consider<=0) { interval_wakeup_time = interval_start_time; @@ -504,13 +510,16 @@ accounting_set_wakeup_time(void) char buf2[ISO_TIME_LEN+1]; char buf3[ISO_TIME_LEN+1]; char buf4[ISO_TIME_LEN+1]; - time_t down_time = interval_wakeup_time+time_to_exhaust_bw; + time_t down_time; + if (interval_wakeup_time+time_to_exhaust_bw > TIME_MAX) + down_time = TIME_MAX; + else + down_time = (time_t)(interval_wakeup_time+time_to_exhaust_bw); if (down_time>interval_end_time) down_time = interval_end_time; format_local_iso_time(buf1, interval_start_time); format_local_iso_time(buf2, interval_wakeup_time); - format_local_iso_time(buf3, - down_time