aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2021-03-09 15:41:11 +0200
committerGeorge Kadianakis <desnacked@riseup.net>2021-03-17 18:22:38 +0200
commite688580277cd0223a32bf08603013b59693c713c (patch)
treef26396b2288b270527c82ec1aad87e0a8ae15d14
parentfaf1fe833eb4a59aae4843b450b85b4d8894ba02 (diff)
downloadtor-e688580277cd0223a32bf08603013b59693c713c.tar.gz
tor-e688580277cd0223a32bf08603013b59693c713c.zip
Implement rate limiting metrics.
-rw-r--r--src/core/mainloop/connection.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/core/mainloop/connection.c b/src/core/mainloop/connection.c
index 9e3a343530..5ed0ba9aa6 100644
--- a/src/core/mainloop/connection.c
+++ b/src/core/mainloop/connection.c
@@ -3439,6 +3439,16 @@ connection_bucket_read_limit(connection_t *conn, time_t now)
int priority = conn->type != CONN_TYPE_DIR;
ssize_t conn_bucket = -1;
size_t global_bucket_val = token_bucket_rw_get_read(&global_bucket);
+ if (global_bucket_val == 0) {
+ /* We reached our global read limit: count this as an overload.
+ *
+ * The token bucket is always initialized (see connection_bucket_init() and
+ * options_validate_relay_bandwidth()) and hence we can assume that if the
+ * token ever hits zero, it's a limit that got popped and not the bucket
+ * being uninitialized.
+ */
+ rep_hist_note_overload(OVERLOAD_READ);
+ }
if (connection_speaks_cells(conn)) {
or_connection_t *or_conn = TO_OR_CONN(conn);
@@ -3469,6 +3479,11 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
int priority = conn->type != CONN_TYPE_DIR;
size_t conn_bucket = buf_datalen(conn->outbuf);
size_t global_bucket_val = token_bucket_rw_get_write(&global_bucket);
+ if (global_bucket_val == 0) {
+ /* We reached our global write limit: We should count this as an overload.
+ * See above function for more information */
+ rep_hist_note_overload(OVERLOAD_WRITE);
+ }
if (!connection_is_rate_limited(conn)) {
/* be willing to write to local conns even if our buckets are empty */