aboutsummaryrefslogtreecommitdiff
path: root/src/or/hibernate.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2006-03-13 01:06:55 +0000
committerNick Mathewson <nickm@torproject.org>2006-03-13 01:06:55 +0000
commitdad60905a814de9aad55fb824a5315673b9e13f9 (patch)
treeeb2748453733ed2ab1fa04a1e36b0ca79e69f8c9 /src/or/hibernate.c
parentdaea6b21a536ff1d60310c35bd89844614ec9d7f (diff)
downloadtor-dad60905a814de9aad55fb824a5315673b9e13f9.tar.gz
tor-dad60905a814de9aad55fb824a5315673b9e13f9.zip
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
Diffstat (limited to 'src/or/hibernate.c')
-rw-r--r--src/or/hibernate.c23
1 files 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<interval_end_time?down_time:interval_end_time);
+ format_local_iso_time(buf3, down_time);
format_local_iso_time(buf4, interval_end_time);
log_notice(LD_ACCT,