aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_hs_dos.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2019-08-20 08:52:34 -0400
committerGeorge Kadianakis <desnacked@riseup.net>2019-08-26 15:53:46 +0300
commit94a22217082f99bb7d5409e22af69d45def52889 (patch)
tree7602be4f6818a56e20b5a1f70b9c2288d0f04710 /src/test/test_hs_dos.c
parent184c76e339fdf25ea5f61ed052810cd5f356852e (diff)
downloadtor-94a22217082f99bb7d5409e22af69d45def52889.tar.gz
tor-94a22217082f99bb7d5409e22af69d45def52889.zip
hs-v3: Privatize access to HS DoS consensus param
Remove the public functions returning the HS DoS consensus param or default values as it is exclusively used internally now. Rename the param_* variables to consensus_param_* for better code semantic. Finally, make some private functions available to unit tests. Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_hs_dos.c')
-rw-r--r--src/test/test_hs_dos.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/test/test_hs_dos.c b/src/test/test_hs_dos.c
index f92d953fa6..370e12bf72 100644
--- a/src/test/test_hs_dos.c
+++ b/src/test/test_hs_dos.c
@@ -8,6 +8,7 @@
#define CIRCUITLIST_PRIVATE
#define NETWORKSTATUS_PRIVATE
+#define HS_DOS_PRIVATE
#include "test/test.h"
#include "test/test_helpers.h"
@@ -57,11 +58,8 @@ test_can_send_intro2(void *arg)
/* Make that circuit a service intro point. */
circuit_change_purpose(TO_CIRCUIT(or_circ), CIRCUIT_PURPOSE_INTRO_POINT);
+ hs_dos_setup_default_intro2_defenses(or_circ);
or_circ->introduce2_dos_defense_enabled = 1;
- /* Initialize the INTRODUCE2 token bucket for the rate limiting. */
- token_bucket_ctr_init(&or_circ->introduce2_bucket,
- hs_dos_get_intro2_rate_param(),
- hs_dos_get_intro2_burst_param(), now);
/* Brand new circuit, we should be able to send INTRODUCE2 cells. */
tt_int_op(true, OP_EQ, hs_dos_can_send_intro2(or_circ));
@@ -73,13 +71,13 @@ test_can_send_intro2(void *arg)
tt_int_op(true, OP_EQ, hs_dos_can_send_intro2(or_circ));
}
tt_uint_op(token_bucket_ctr_get(&or_circ->introduce2_bucket), OP_EQ,
- hs_dos_get_intro2_burst_param() - 10);
+ get_intro2_burst_consensus_param(NULL) - 10);
/* Fully refill the bucket minus 1 cell. */
update_approx_time(++now);
tt_int_op(true, OP_EQ, hs_dos_can_send_intro2(or_circ));
tt_uint_op(token_bucket_ctr_get(&or_circ->introduce2_bucket), OP_EQ,
- hs_dos_get_intro2_burst_param() - 1);
+ get_intro2_burst_consensus_param(NULL) - 1);
/* Receive an INTRODUCE2 at each second. We should have the bucket full
* since at every second it gets refilled. */
@@ -89,18 +87,18 @@ test_can_send_intro2(void *arg)
}
/* Last check if we can send the cell decrements the bucket so minus 1. */
tt_uint_op(token_bucket_ctr_get(&or_circ->introduce2_bucket), OP_EQ,
- hs_dos_get_intro2_burst_param() - 1);
+ get_intro2_burst_consensus_param(NULL) - 1);
/* Manually reset bucket for next test. */
token_bucket_ctr_reset(&or_circ->introduce2_bucket, now);
tt_uint_op(token_bucket_ctr_get(&or_circ->introduce2_bucket), OP_EQ,
- hs_dos_get_intro2_burst_param());
+ get_intro2_burst_consensus_param(NULL));
/* Do a full burst in the current second which should empty the bucket and
* we shouldn't be allowed to send one more cell after that. We go minus 1
* cell else the very last check if we can send the INTRO2 cell returns
* false because the bucket goes down to 0. */
- for (uint32_t i = 0; i < hs_dos_get_intro2_burst_param() - 1; i++) {
+ for (uint32_t i = 0; i < get_intro2_burst_consensus_param(NULL) - 1; i++) {
tt_int_op(true, OP_EQ, hs_dos_can_send_intro2(or_circ));
}
tt_uint_op(token_bucket_ctr_get(&or_circ->introduce2_bucket), OP_EQ, 1);
@@ -118,7 +116,7 @@ test_can_send_intro2(void *arg)
update_approx_time(++now);
tt_int_op(true, OP_EQ, hs_dos_can_send_intro2(or_circ));
tt_uint_op(token_bucket_ctr_get(&or_circ->introduce2_bucket), OP_EQ,
- hs_dos_get_intro2_rate_param() - 1);
+ get_intro2_rate_consensus_param(NULL) - 1);
done:
circuit_free_(TO_CIRCUIT(or_circ));