From 6be994fa717cf73e9cfcb63f49f2d335f2d39bb9 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 10 Apr 2018 13:40:34 -0400 Subject: Ensure that global buckets are updated on configuration change --- src/or/connection.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'src/or/connection.c') diff --git a/src/or/connection.c b/src/or/connection.c index b2ef287761..83bab10eb7 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) -- cgit v1.2.3-54-g00ecf