summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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 484140f4cb..daee148080 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);
}