|
@@ -176,7 +176,7 @@ test_dos_bucket_refill(void *arg)
|
|
|
|
|
|
dos_init();
|
|
|
uint32_t max_circuit_count = get_param_cc_circuit_burst(NULL);
|
|
|
- int circ_rate = tor_lround(get_circuit_rate_per_second());
|
|
|
+ uint64_t circ_rate = get_circuit_rate_per_second();
|
|
|
|
|
|
* circuit count */
|
|
|
tt_int_op(circ_rate, OP_GT, 1);
|
|
@@ -234,6 +234,152 @@ test_dos_bucket_refill(void *arg)
|
|
|
current_circ_count += max_circuit_count;
|
|
|
tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * more than max_circs allowance, even tho we let it simmer for so long. */
|
|
|
+ now = INT32_MAX;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+ current_circ_count += max_circuit_count;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * the max_circs allowance, because backward clock jumps are rare. */
|
|
|
+ now = INT32_MIN;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+ current_circ_count += max_circuit_count;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * refill happened correctly. */
|
|
|
+ now += 1;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+
|
|
|
+ current_circ_count += circ_rate;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * not have more than max_circs allowance, even tho we let it simmer for so
|
|
|
+ * long. */
|
|
|
+ now = INT32_MAX;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+ current_circ_count += max_circuit_count;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * code that initialises the bucket. */
|
|
|
+#if SIZEOF_TIME_T == 8
|
|
|
+
|
|
|
+ * exactly the max_circs allowance, because backward clock jumps are rare.
|
|
|
+ */
|
|
|
+ now = (time_t)INT64_MIN;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+ current_circ_count += max_circuit_count;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * refill happened correctly. */
|
|
|
+ now += 1;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+
|
|
|
+ current_circ_count += circ_rate;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * exactly the max_circs allowance, because backward clock jumps are rare.
|
|
|
+ */
|
|
|
+ now = (time_t)INT64_MIN;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+ current_circ_count += max_circuit_count;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * have more than max_circs allowance, even tho we let it simmer for so
|
|
|
+ * long. */
|
|
|
+ now = (time_t)INT64_MAX;
|
|
|
+ update_approx_time(now);
|
|
|
+ cc_stats_refill_bucket(&dos_stats->cc_stats, addr);
|
|
|
+ current_circ_count += max_circuit_count;
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+
|
|
|
+
|
|
|
+ * completely */
|
|
|
+ for (; current_circ_count != 0; current_circ_count--) {
|
|
|
+ dos_cc_new_create_cell(chan);
|
|
|
+ }
|
|
|
+ tt_uint_op(current_circ_count, OP_EQ, 0);
|
|
|
+ tt_uint_op(dos_stats->cc_stats.circuit_bucket, OP_EQ, current_circ_count);
|
|
|
+#endif
|
|
|
+
|
|
|
done:
|
|
|
tor_free(chan);
|
|
|
dos_free_all();
|