aboutsummaryrefslogtreecommitdiff
path: root/src/or/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/or/main.c')
-rw-r--r--src/or/main.c46
1 files changed, 25 insertions, 21 deletions
diff --git a/src/or/main.c b/src/or/main.c
index 4cc51de07b..0e67ea6f68 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -152,19 +152,19 @@ static void shutdown_did_not_work_callback(evutil_socket_t fd, short event,
void *arg) ATTR_NORETURN;
/********* START VARIABLES **********/
-int global_read_bucket; /**< Max number of bytes I can read this second. */
-int global_write_bucket; /**< Max number of bytes I can write this second. */
-
-/** Max number of relayed (bandwidth class 1) bytes I can read this second. */
-int global_relayed_read_bucket;
-/** Max number of relayed (bandwidth class 1) bytes I can write this second. */
-int global_relayed_write_bucket;
-/** What was the read bucket before the last second_elapsed_callback() call?
- * (used to determine how many bytes we've read). */
-static int stats_prev_global_read_bucket;
+
+/* Token bucket for all traffic. */
+token_bucket_t global_bucket;
+
+/* Token bucket for relayed traffic. */
+token_bucket_t global_relayed_bucket;
+
+/** What was the read/write bucket before the last second_elapsed_callback()
+ * call? (used to determine how many bytes we've read). */
+static size_t stats_prev_global_read_bucket;
/** What was the write bucket before the last second_elapsed_callback() call?
* (used to determine how many bytes we've written). */
-static int stats_prev_global_write_bucket;
+static size_t stats_prev_global_write_bucket;
/* DOCDOC stats_prev_n_read */
static uint64_t stats_prev_n_read = 0;
@@ -2389,19 +2389,23 @@ refill_callback(periodic_timer_t *timer, void *arg)
refill_timer_current_millisecond.tv_sec);
}
- bytes_written = stats_prev_global_write_bucket - global_write_bucket;
- bytes_read = stats_prev_global_read_bucket - global_read_bucket;
+ bytes_written = stats_prev_global_write_bucket -
+ token_bucket_get_write(&global_bucket);
+ bytes_read = stats_prev_global_read_bucket -
+ token_bucket_get_read(&global_bucket);
stats_n_bytes_read += bytes_read;
stats_n_bytes_written += bytes_written;
if (accounting_is_enabled(options) && milliseconds_elapsed >= 0)
accounting_add_bytes(bytes_read, bytes_written, seconds_rolled_over);
- if (milliseconds_elapsed > 0)
- connection_bucket_refill(milliseconds_elapsed, (time_t)now.tv_sec);
+ if (milliseconds_elapsed > 0) {
+ connection_bucket_refill((time_t)now.tv_sec,
+ monotime_coarse_get_stamp());
+ }
- stats_prev_global_read_bucket = global_read_bucket;
- stats_prev_global_write_bucket = global_write_bucket;
+ stats_prev_global_read_bucket = token_bucket_get_read(&global_bucket);
+ stats_prev_global_write_bucket = token_bucket_get_write(&global_bucket);
/* remember what time it is, for next time */
refill_timer_current_millisecond = now;
@@ -2605,8 +2609,8 @@ do_main_loop(void)
/* Set up our buckets */
connection_bucket_init();
- stats_prev_global_read_bucket = global_read_bucket;
- stats_prev_global_write_bucket = global_write_bucket;
+ stats_prev_global_read_bucket = token_bucket_get_read(&global_bucket);
+ stats_prev_global_write_bucket = token_bucket_get_write(&global_bucket);
/* initialize the bootstrap status events to know we're starting up */
control_event_bootstrap(BOOTSTRAP_STATUS_STARTING, 0);
@@ -3501,8 +3505,8 @@ tor_free_all(int postfork)
periodic_timer_free(systemd_watchdog_timer);
#endif
- global_read_bucket = global_write_bucket = 0;
- global_relayed_read_bucket = global_relayed_write_bucket = 0;
+ memset(&global_bucket, 0, sizeof(global_bucket));
+ memset(&global_relayed_bucket, 0, sizeof(global_relayed_bucket));
stats_prev_global_read_bucket = stats_prev_global_write_bucket = 0;
stats_prev_n_read = stats_prev_n_written = 0;
stats_n_bytes_read = stats_n_bytes_written = 0;