aboutsummaryrefslogtreecommitdiff
path: root/src/or/connection.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-02-06 18:21:16 +0000
committerNick Mathewson <nickm@torproject.org>2008-02-06 18:21:16 +0000
commit6e2946fb5d59595278bd0f0ef0aa4e092905dc97 (patch)
treeb15be8263a11c0f2ac3abdee4cb53729453eea90 /src/or/connection.c
parenta869574c564440c79a40b0d2019ad0a6c8b24174 (diff)
downloadtor-6e2946fb5d59595278bd0f0ef0aa4e092905dc97.tar
tor-6e2946fb5d59595278bd0f0ef0aa4e092905dc97.tar.gz
r17949@catbus: nickm | 2008-02-06 13:21:12 -0500
Fix bandwidth bucked calculations again, I think. Bugfix on 0.1.2.x. Backport candidate. svn:r13406
Diffstat (limited to 'src/or/connection.c')
-rw-r--r--src/or/connection.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/or/connection.c b/src/or/connection.c
index 484140f4c..daee14808 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1659,13 +1659,19 @@ connection_bucket_refill_helper(int *bucket, int rate, int burst,
int seconds_elapsed, const char *name)
{
int starting_bucket = *bucket;
- if (starting_bucket < burst) {
- int incr = rate*seconds_elapsed;
- *bucket += incr;
- if (*bucket > burst || *bucket < starting_bucket) {
- /* If we overflow the burst, or underflow our starting bucket,
- * cap the bucket value to burst. */
- *bucket = burst;
+ if (starting_bucket < burst && seconds_elapsed) {
+ if (((burst - starting_bucket)/seconds_elapsed) < rate) {
+ *bucket = burst; /* We would overflow the bucket; just set it to
+ * the maximum. */
+ } else {
+ int incr = rate*seconds_elapsed;
+ *bucket += incr;
+ if (*bucket > burst || *bucket < starting_bucket) {
+ /* If we overflow the burst, or underflow our starting bucket,
+ * cap the bucket value to burst. */
+ /* XXXX020 this might be redundant now. */
+ *bucket = burst;
+ }
}
log(LOG_DEBUG, LD_NET,"%s now %d.", name, *bucket);
}