[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Ensure that global buckets are updated on configuration change



commit 6be994fa717cf73e9cfcb63f49f2d335f2d39bb9
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Tue Apr 10 13:40:34 2018 -0400

    Ensure that global buckets are updated on configuration change
---
 src/or/config.c     |  6 ++++++
 src/or/connection.c | 21 ++++++++++++++++++++-
 src/or/connection.h |  1 +
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/src/or/config.c b/src/or/config.c
index 71f8528b6..c62441948 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -2219,6 +2219,12 @@ options_act(const or_options_t *old_options)
         options->PerConnBWBurst != old_options->PerConnBWBurst)
       connection_or_update_token_buckets(get_connection_array(), options);
 
+    if (options->BandwidthRate != old_options->BandwidthRate ||
+        options->BandwidthBurst != old_options->BandwidthBurst ||
+        options->BandwidthRate != old_options->BandwidthRate ||
+        options->RelayBandwidthBurst != old_options->RelayBandwidthBurst)
+      connection_bucket_adjust(options);
+
     if (options->MainloopStats != old_options->MainloopStats) {
       reset_main_loop_counters();
     }
diff --git a/src/or/connection.c b/src/or/connection.c
index b2ef28776..83bab10eb 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -3104,7 +3104,8 @@ connection_consider_empty_write_buckets(connection_t *conn)
   connection_stop_writing(conn);
 }
 
-/** Initialize the global read bucket to options-\>BandwidthBurst. */
+/** Initialize the global buckets to the values configured in the
+ * options */
 void
 connection_bucket_init(void)
 {
@@ -3127,6 +3128,24 @@ connection_bucket_init(void)
   }
 }
 
+/** Update the global connection bucket settings to a new value. */
+void
+connection_bucket_adjust(const or_options_t *options)
+{
+  token_bucket_adjust(&global_bucket,
+                      (int32_t)options->BandwidthRate,
+                      (int32_t)options->BandwidthBurst);
+  if (options->RelayBandwidthRate) {
+    token_bucket_adjust(&global_relayed_bucket,
+                        (int32_t)options->RelayBandwidthRate,
+                        (int32_t)options->RelayBandwidthBurst);
+  } else {
+    token_bucket_adjust(&global_relayed_bucket,
+                        (int32_t)options->BandwidthRate,
+                        (int32_t)options->BandwidthBurst);
+  }
+}
+
 /** Time has passed; increment buckets appropriately. */
 void
 connection_bucket_refill(time_t now, uint32_t now_ts)
diff --git a/src/or/connection.h b/src/or/connection.h
index 4a57bd311..cfe31c372 100644
--- a/src/or/connection.h
+++ b/src/or/connection.h
@@ -122,6 +122,7 @@ 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);
 void connection_bucket_init(void);
+void connection_bucket_adjust(const or_options_t *options);
 void connection_bucket_refill(time_t now,
                               uint32_t now_ts);
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits