]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
mainloop: Rename global_write_bucket_low()
authorDavid Goulet <dgoulet@torproject.org>
Wed, 22 Jan 2020 16:06:11 +0000 (11:06 -0500)
committerDavid Goulet <dgoulet@torproject.org>
Tue, 11 Feb 2020 14:34:55 +0000 (09:34 -0500)
That function is only used to test the global bucket write limit for a
directory connection.

It should _not_ be used for anything else since that function looks to see if
we are a directory authority.

Rename it to something more meaningful. No change in behavior at this commit,
only renaming.

Part of #33029

Signed-off-by: David Goulet <dgoulet@torproject.org>
src/core/mainloop/connection.c
src/core/mainloop/connection.h
src/feature/dircache/dircache.c

index 6094f33e4dbdeddb810a6af10dc5f1afc9220e2d..2c075ba6be80f9b49776fd33ba810079e0e6a660 100644 (file)
@@ -3186,9 +3186,9 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
                                      global_bucket_val, conn_bucket);
 }
 
-/** Return 1 if the global write buckets are low enough that we
+/** Return true iff the global write buckets are low enough that we
  * shouldn't send <b>attempt</b> bytes of low-priority directory stuff
- * out to <b>conn</b>. Else return 0.
+ * out to <b>conn</b>.
 
  * Priority was 1 for v1 requests (directories and running-routers),
  * and 2 for v2 requests and later (statuses and descriptors).
@@ -3206,7 +3206,8 @@ connection_bucket_write_limit(connection_t *conn, time_t now)
  *   that's harder to quantify and harder to keep track of.
  */
 int
-global_write_bucket_low(connection_t *conn, size_t attempt, int priority)
+connection_dir_is_global_write_low(connection_t *conn, size_t attempt,
+                                   int priority)
 {
   size_t smaller_bucket =
     MIN(token_bucket_rw_get_write(&global_bucket),
index c93f1ef8e8a140855fb1031c1da52dddf305ae46..4f15c1dd6fcd9517fcbfe19cacb65271fdc5f2e1 100644 (file)
@@ -195,8 +195,9 @@ int retry_all_listeners(smartlist_t *new_conns,
 void connection_mark_all_noncontrol_listeners(void);
 void connection_mark_all_noncontrol_connections(void);
 
-ssize_t connection_bucket_write_limit(connection_t *conn, time_t now);
-int global_write_bucket_low(connection_t *conn, size_t attempt, int priority);
+ssize_t connection_bucket_write_limit(struct connection_t *conn, time_t now);
+int connection_dir_is_global_write_low(struct connection_t *conn,
+                                       size_t attempt, int priority);
 void connection_bucket_init(void);
 void connection_bucket_adjust(const or_options_t *options);
 void connection_bucket_refill_all(time_t now,
index d4d0ad99398cea3d0700915ead0925e149809540..266729cdd39bfd88d5301ade57593036ad9f8cec 100644 (file)
@@ -951,7 +951,7 @@ handle_get_current_consensus(dir_connection_t *conn,
     goto done;
   }
 
-  if (global_write_bucket_low(TO_CONN(conn), size_guess, 2)) {
+  if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess, 2)) {
     log_debug(LD_DIRSERV,
               "Client asked for network status lists, but we've been "
               "writing too many bytes lately. Sending 503 Dir busy.");
@@ -1060,7 +1060,7 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
         }
       });
 
-    if (global_write_bucket_low(TO_CONN(conn), estimated_len, 2)) {
+    if (connection_dir_is_global_write_low(TO_CONN(conn), estimated_len, 2)) {
       write_short_http_response(conn, 503, "Directory busy, try again later");
       goto vote_done;
     }
@@ -1119,7 +1119,7 @@ handle_get_microdesc(dir_connection_t *conn, const get_handler_args_t *args)
       write_short_http_response(conn, 404, "Not found");
       goto done;
     }
-    if (global_write_bucket_low(TO_CONN(conn), size_guess, 2)) {
+    if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess, 2)) {
       log_info(LD_DIRSERV,
                "Client asked for server descriptors, but we've been "
                "writing too many bytes lately. Sending 503 Dir busy.");
@@ -1217,7 +1217,7 @@ handle_get_descriptor(dir_connection_t *conn, const get_handler_args_t *args)
         msg = "Not found";
       write_short_http_response(conn, 404, msg);
     } else {
-      if (global_write_bucket_low(TO_CONN(conn), size_guess, 2)) {
+      if (connection_dir_is_global_write_low(TO_CONN(conn), size_guess, 2)) {
         log_info(LD_DIRSERV,
                  "Client asked for server descriptors, but we've been "
                  "writing too many bytes lately. Sending 503 Dir busy.");
@@ -1313,7 +1313,7 @@ handle_get_keys(dir_connection_t *conn, const get_handler_args_t *args)
     SMARTLIST_FOREACH(certs, authority_cert_t *, c,
                       len += c->cache_info.signed_descriptor_len);
 
-    if (global_write_bucket_low(TO_CONN(conn),
+    if (connection_dir_is_global_write_low(TO_CONN(conn),
                                 compress_method != NO_METHOD ? len/2 : len,
                                 2)) {
       write_short_http_response(conn, 503, "Directory busy, try again later");