summaryrefslogtreecommitdiff
path: root/src/feature/hs/hs_dos.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-06-27 13:32:58 -0400
committerDavid Goulet <dgoulet@torproject.org>2019-08-06 07:58:14 -0400
commite53796854811724fdd1db5127bb67943ba5d423c (patch)
tree9b938ea370fec4a7a642ff06d5452e92d555823c /src/feature/hs/hs_dos.c
parentbe8bd2a46eaba4c992ec912a1bef8d950e481bd4 (diff)
downloadtor-e53796854811724fdd1db5127bb67943ba5d423c.tar.gz
tor-e53796854811724fdd1db5127bb67943ba5d423c.zip
dos: Update HS intro circuits if parameters change
In case the consensus parameters for the rate/burst changes, we need to update all already established introduction circuits to the newest value. This commit introduces a "get all intro circ" function from the HS circuitmap (v2 and v3) so it can be used by the HS DoS module to go over all circuits and adjust the INTRODUCE2 token bucket parameters. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/hs/hs_dos.c')
-rw-r--r--src/feature/hs/hs_dos.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/feature/hs/hs_dos.c b/src/feature/hs/hs_dos.c
index f817b49885..da898dc3a0 100644
--- a/src/feature/hs/hs_dos.c
+++ b/src/feature/hs/hs_dos.c
@@ -23,6 +23,7 @@
#include "core/or/circuitlist.h"
+#include "feature/hs/hs_circuitmap.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/relay/routermode.h"
@@ -77,6 +78,25 @@ get_param_burst_per_sec(const networkstatus_t *ns)
0, INT32_MAX);
}
+/* Go over all introduction circuit relay side and adjust their rate/burst
+ * values using the global parameters. This is called right after the
+ * consensus parameters might have changed. */
+static void
+update_intro_circuits(void)
+{
+ /* Returns all HS version intro circuits. */
+ smartlist_t *intro_circs = hs_circuitmap_get_all_intro_circ_relay_side();
+
+ SMARTLIST_FOREACH_BEGIN(intro_circs, circuit_t *, circ) {
+ /* Adjust the rate/burst value that might have changed. */
+ token_bucket_ctr_adjust(&TO_OR_CIRCUIT(circ)->introduce2_bucket,
+ hs_dos_get_intro2_rate(),
+ hs_dos_get_intro2_burst());
+ } SMARTLIST_FOREACH_END(circ);
+
+ smartlist_free(intro_circs);
+}
+
/* Set consensus parameters. */
static void
set_consensus_parameters(const networkstatus_t *ns)
@@ -84,6 +104,10 @@ set_consensus_parameters(const networkstatus_t *ns)
hs_dos_introduce_rate_per_sec = get_param_rate_per_sec(ns);
hs_dos_introduce_burst_per_sec = get_param_burst_per_sec(ns);
hs_dos_introduce_enabled = get_param_intro_dos_enabled(ns);
+
+ /* The above might have changed which means we need to go through all
+ * introduction circuits (relay side) and update the token buckets. */
+ update_intro_circuits();
}
/*