aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2019-05-15 15:13:08 +0300
committerGeorge Kadianakis <desnacked@riseup.net>2019-05-15 15:13:08 +0300
commita7779df84c97acf3f245786566bd72dd9968b99f (patch)
tree348bce69edf983040000cebb12322230b13b4fac /src/test
parentf664c0c31885eac5d36298772d4ecf2e10a10021 (diff)
parent5f47d582d50134d9504ec8e7a912887829904c8a (diff)
downloadtor-a7779df84c97acf3f245786566bd72dd9968b99f.tar.gz
tor-a7779df84c97acf3f245786566bd72dd9968b99f.zip
Merge branch 'bug29085_rebase'
Diffstat (limited to 'src/test')
-rw-r--r--src/test/test_circuitpadding.c295
1 files changed, 238 insertions, 57 deletions
diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c
index db175fecee..b2ae659a60 100644
--- a/src/test/test_circuitpadding.c
+++ b/src/test/test_circuitpadding.c
@@ -55,6 +55,7 @@ void test_circuitpadding_conditions(void *arg);
void test_circuitpadding_serialize(void *arg);
void test_circuitpadding_rtt(void *arg);
void test_circuitpadding_tokens(void *arg);
+void test_circuitpadding_state_length(void *arg);
static void
simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
@@ -329,12 +330,12 @@ test_circuitpadding_rtt(void *arg)
relay_side->padding_info[0] = circpad_circuit_machineinfo_new(client_side,0);
/* Test 1: Test measuring RTT */
- circpad_cell_event_nonpadding_received((circuit_t*)relay_side);
+ circpad_cell_event_nonpadding_received(relay_side);
tt_u64_op(relay_side->padding_info[0]->last_received_time_usec, OP_NE, 0);
timers_advance_and_run(20);
- circpad_cell_event_nonpadding_sent((circuit_t*)relay_side);
+ circpad_cell_event_nonpadding_sent(relay_side);
tt_u64_op(relay_side->padding_info[0]->last_received_time_usec, OP_EQ, 0);
tt_int_op(relay_side->padding_info[0]->rtt_estimate_usec, OP_GE, 19000);
@@ -345,12 +346,12 @@ test_circuitpadding_rtt(void *arg)
circpad_machine_current_state(
relay_side->padding_info[0])->histogram_edges[0]);
- circpad_cell_event_nonpadding_received((circuit_t*)relay_side);
- circpad_cell_event_nonpadding_received((circuit_t*)relay_side);
+ circpad_cell_event_nonpadding_received(relay_side);
+ circpad_cell_event_nonpadding_received(relay_side);
tt_u64_op(relay_side->padding_info[0]->last_received_time_usec, OP_NE, 0);
timers_advance_and_run(20);
- circpad_cell_event_nonpadding_sent((circuit_t*)relay_side);
- circpad_cell_event_nonpadding_sent((circuit_t*)relay_side);
+ circpad_cell_event_nonpadding_sent(relay_side);
+ circpad_cell_event_nonpadding_sent(relay_side);
tt_u64_op(relay_side->padding_info[0]->last_received_time_usec, OP_EQ, 0);
tt_int_op(relay_side->padding_info[0]->rtt_estimate_usec, OP_GE, 20000);
@@ -365,9 +366,9 @@ test_circuitpadding_rtt(void *arg)
tt_int_op(relay_side->padding_info[0]->stop_rtt_update, OP_EQ, 1);
rtt_estimate = relay_side->padding_info[0]->rtt_estimate_usec;
- circpad_cell_event_nonpadding_received((circuit_t*)relay_side);
+ circpad_cell_event_nonpadding_received(relay_side);
timers_advance_and_run(4);
- circpad_cell_event_nonpadding_sent((circuit_t*)relay_side);
+ circpad_cell_event_nonpadding_sent(relay_side);
tt_int_op(relay_side->padding_info[0]->rtt_estimate_usec, OP_EQ,
rtt_estimate);
@@ -380,11 +381,11 @@ test_circuitpadding_rtt(void *arg)
relay_side->padding_info[0])->histogram_edges[0]);
/* Test 3: Make sure client side machine properly ignores RTT */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
tt_u64_op(client_side->padding_info[0]->last_received_time_usec, OP_EQ, 0);
timers_advance_and_run(20);
- circpad_cell_event_nonpadding_sent((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_u64_op(client_side->padding_info[0]->last_received_time_usec, OP_EQ, 0);
tt_int_op(client_side->padding_info[0]->rtt_estimate_usec, OP_EQ, 0);
@@ -415,6 +416,7 @@ helper_create_basic_machine(void)
circ_client_machine.states[CIRCPAD_STATE_START].
next_state[CIRCPAD_EVENT_NONPADDING_RECV] = CIRCPAD_STATE_BURST;
+ circ_client_machine.states[CIRCPAD_STATE_START].use_rtt_estimate = 1;
circ_client_machine.states[CIRCPAD_STATE_BURST].
next_state[CIRCPAD_EVENT_PADDING_RECV] = CIRCPAD_STATE_BURST;
@@ -526,7 +528,7 @@ test_circuitpadding_token_removal_higher(void *arg)
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
/* Setup test environment (time etc.) */
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
monotime_enable_test_mocking();
@@ -537,7 +539,7 @@ test_circuitpadding_token_removal_higher(void *arg)
circpad_circuit_machineinfo_new(client_side, 0);
/* move the machine to the right state */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
tt_int_op(client_side->padding_info[0]->current_state, OP_EQ,
CIRCPAD_STATE_BURST);
@@ -586,12 +588,12 @@ test_circuitpadding_token_removal_higher(void *arg)
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 2);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 1);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
/* Test that we cleaned out this bin. Don't do this in the case of the last
bin since the tokens will get refilled */
@@ -610,7 +612,7 @@ test_circuitpadding_token_removal_higher(void *arg)
CIRCPAD_STATE_BURST);
circ_client_machine.states[CIRCPAD_STATE_BURST].histogram_edges[0] = 100;
mi->padding_scheduled_at_usec = current_time;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[0], OP_EQ, 1);
done:
@@ -631,7 +633,7 @@ test_circuitpadding_token_removal_lower(void *arg)
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
/* Setup test environment (time etc.) */
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
monotime_enable_test_mocking();
@@ -642,7 +644,7 @@ test_circuitpadding_token_removal_lower(void *arg)
circpad_circuit_machineinfo_new(client_side, 0);
/* move the machine to the right state */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
tt_int_op(client_side->padding_info[0]->current_state, OP_EQ,
CIRCPAD_STATE_BURST);
@@ -683,12 +685,12 @@ test_circuitpadding_token_removal_lower(void *arg)
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 2);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 1);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
/* Test that we cleaned out this bin. Don't do this in the case of the last
bin since the tokens will get refilled */
@@ -708,7 +710,7 @@ test_circuitpadding_token_removal_lower(void *arg)
circ_client_machine.states[CIRCPAD_STATE_BURST].
histogram_edges[BIG_HISTOGRAM_LEN-2] = 100;
mi->padding_scheduled_at_usec = current_time - 29202;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[BIG_HISTOGRAM_LEN-2], OP_EQ, 1);
done:
@@ -729,7 +731,7 @@ test_circuitpadding_closest_token_removal(void *arg)
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
/* Setup test environment (time etc.) */
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
monotime_enable_test_mocking();
@@ -740,7 +742,7 @@ test_circuitpadding_closest_token_removal(void *arg)
circpad_circuit_machineinfo_new(client_side, 0);
/* move the machine to the right state */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
tt_int_op(client_side->padding_info[0]->current_state, OP_EQ,
CIRCPAD_STATE_BURST);
@@ -780,12 +782,12 @@ test_circuitpadding_closest_token_removal(void *arg)
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 2);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 1);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
/* Test that we cleaned out this bin. Don't do this in the case of the last
bin since the tokens will get refilled */
@@ -807,14 +809,14 @@ test_circuitpadding_closest_token_removal(void *arg)
circ_client_machine.states[CIRCPAD_STATE_BURST].histogram_edges[2] = 120;
mi->padding_scheduled_at_usec = current_time - 102;
mi->histogram[0] = 0;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[1], OP_EQ, 1);
/* Test above the highest bin, for coverage */
tt_int_op(client_side->padding_info[0]->current_state, OP_EQ,
CIRCPAD_STATE_BURST);
mi->padding_scheduled_at_usec = current_time - 29202;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[BIG_HISTOGRAM_LEN-2], OP_EQ, 1);
done:
@@ -835,7 +837,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
/* Setup test environment (time etc.) */
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
monotime_enable_test_mocking();
@@ -846,7 +848,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
circpad_circuit_machineinfo_new(client_side, 0);
/* move the machine to the right state */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
tt_int_op(client_side->padding_info[0]->current_state, OP_EQ,
CIRCPAD_STATE_BURST);
@@ -889,12 +891,12 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 2);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[bin_to_remove], OP_EQ, 1);
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
/* Test that we cleaned out this bin. Don't do this in the case of the last
bin since the tokens will get refilled */
@@ -916,7 +918,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
circ_client_machine.states[CIRCPAD_STATE_BURST].histogram_edges[2] = 120;
mi->padding_scheduled_at_usec = current_time - 102;
mi->histogram[0] = 0;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[1], OP_EQ, 1);
/* Test above the highest bin, for coverage */
@@ -925,7 +927,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
circ_client_machine.states[CIRCPAD_STATE_BURST].
histogram_edges[BIG_HISTOGRAM_LEN-2] = 100;
mi->padding_scheduled_at_usec = current_time - 29202;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[BIG_HISTOGRAM_LEN-2], OP_EQ, 1);
done:
@@ -946,7 +948,7 @@ test_circuitpadding_token_removal_exact(void *arg)
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
/* Setup test environment (time etc.) */
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
monotime_enable_test_mocking();
@@ -957,7 +959,7 @@ test_circuitpadding_token_removal_exact(void *arg)
circpad_circuit_machineinfo_new(client_side, 0);
/* move the machine to the right state */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
tt_int_op(client_side->padding_info[0]->current_state, OP_EQ,
CIRCPAD_STATE_BURST);
@@ -971,16 +973,16 @@ test_circuitpadding_token_removal_exact(void *arg)
/* Ensure that we will clear out bin #4 with this usec */
mi->padding_scheduled_at_usec = current_time - 57;
tt_int_op(mi->histogram[4], OP_EQ, 2);
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
mi->padding_scheduled_at_usec = current_time - 57;
tt_int_op(mi->histogram[4], OP_EQ, 1);
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
tt_int_op(mi->histogram[4], OP_EQ, 0);
/* Ensure that we will not remove any other tokens even tho we try to, since
* this is what the exact strategy dictates */
mi->padding_scheduled_at_usec = current_time - 57;
- circpad_machine_remove_token(mi);
+ circpad_cell_event_nonpadding_sent(client_side);
for (int i = 0; i < BIG_HISTOGRAM_LEN ; i++) {
if (i != 4) {
tt_int_op(mi->histogram[i], OP_EQ, 2);
@@ -1046,8 +1048,8 @@ test_circuitpadding_tokens(void *arg)
mi = client_side->padding_info[0];
// Pretend a non-padding cell was sent
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
- circpad_cell_event_nonpadding_sent((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
+ circpad_cell_event_nonpadding_sent(client_side);
/* We have to save the infinity bin because one inf delay
* could have been chosen when we transition to burst */
circpad_hist_token_t inf_bin = mi->histogram[4];
@@ -1156,11 +1158,11 @@ test_circuitpadding_tokens(void *arg)
/* Drain the infinity bin and cause a refill */
while (inf_bin != 0) {
tt_int_op(mi->histogram[4], OP_EQ, inf_bin);
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
inf_bin--;
}
- circpad_cell_event_nonpadding_sent((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_sent(client_side);
// We should have refilled here.
tt_int_op(mi->histogram[4], OP_EQ, 2);
@@ -1284,10 +1286,10 @@ test_circuitpadding_wronghop(void *arg)
* padding that gets sent by scheduled timers. */
MOCK(circpad_machine_schedule_padding,circpad_machine_schedule_padding_mock);
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
dummy_channel.cmux = circuitmux_alloc();
- relay_side = (circuit_t *)new_fake_orcirc(&dummy_channel,
- &dummy_channel);
+ relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel,
+ &dummy_channel));
orig_client = TO_ORIGIN_CIRCUIT(client_side);
relay_side->purpose = CIRCUIT_PURPOSE_OR;
@@ -1405,9 +1407,9 @@ test_circuitpadding_wronghop(void *arg)
free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
free_fake_orcirc(relay_side);
- client_side = (circuit_t *)origin_circuit_new();
- relay_side = (circuit_t *)new_fake_orcirc(&dummy_channel,
- &dummy_channel);
+ client_side = TO_CIRCUIT(origin_circuit_new());
+ relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel,
+ &dummy_channel));
relay_side->purpose = CIRCUIT_PURPOSE_OR;
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
@@ -1601,10 +1603,10 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
tor_addr_t addr;
// Pretend a non-padding cell was sent
- circpad_cell_event_nonpadding_sent((circuit_t*)client);
+ circpad_cell_event_nonpadding_sent(client);
// Receive extend cell at middle
- circpad_cell_event_nonpadding_received((circuit_t*)mid_relay);
+ circpad_cell_event_nonpadding_received(mid_relay);
// Advance time a tiny bit so we can calculate an RTT
curr_mocked_time += 10 * TOR_NSEC_PER_MSEC;
@@ -1612,10 +1614,10 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
monotime_set_mock_time_nsec(curr_mocked_time);
// Receive extended cell at middle
- circpad_cell_event_nonpadding_sent((circuit_t*)mid_relay);
+ circpad_cell_event_nonpadding_sent(mid_relay);
// Receive extended cell at first hop
- circpad_cell_event_nonpadding_received((circuit_t*)client);
+ circpad_cell_event_nonpadding_received(client);
// Add a hop to cpath
crypt_path_t *hop = tor_malloc_zero(sizeof(crypt_path_t));
@@ -1643,6 +1645,55 @@ simulate_single_hop_extend(circuit_t *client, circuit_t *mid_relay,
}
static circpad_machine_spec_t *
+helper_create_length_machine(void)
+{
+ circpad_machine_spec_t *ret =
+ tor_malloc_zero(sizeof(circpad_machine_spec_t));
+
+ /* Start, burst */
+ circpad_machine_states_init(ret, 2);
+
+ ret->states[CIRCPAD_STATE_START].
+ next_state[CIRCPAD_EVENT_PADDING_SENT] = CIRCPAD_STATE_BURST;
+
+ ret->states[CIRCPAD_STATE_BURST].
+ next_state[CIRCPAD_EVENT_PADDING_SENT] = CIRCPAD_STATE_BURST;
+
+ ret->states[CIRCPAD_STATE_BURST].
+ next_state[CIRCPAD_EVENT_LENGTH_COUNT] = CIRCPAD_STATE_END;
+
+ ret->states[CIRCPAD_STATE_BURST].
+ next_state[CIRCPAD_EVENT_BINS_EMPTY] = CIRCPAD_STATE_END;
+
+ /* No token removal.. end via state_length only */
+ ret->states[CIRCPAD_STATE_BURST].token_removal =
+ CIRCPAD_TOKEN_REMOVAL_NONE;
+
+ /* Let's have this one end after 12 packets */
+ ret->states[CIRCPAD_STATE_BURST].length_dist.type = CIRCPAD_DIST_UNIFORM;
+ ret->states[CIRCPAD_STATE_BURST].length_dist.param1 = 12;
+ ret->states[CIRCPAD_STATE_BURST].length_dist.param2 = 13;
+ ret->states[CIRCPAD_STATE_BURST].max_length = 12;
+
+ ret->states[CIRCPAD_STATE_BURST].histogram_len = 4;
+
+ ret->states[CIRCPAD_STATE_BURST].histogram_edges[0] = 0;
+ ret->states[CIRCPAD_STATE_BURST].histogram_edges[1] = 1;
+ ret->states[CIRCPAD_STATE_BURST].histogram_edges[2] = 1000000;
+ ret->states[CIRCPAD_STATE_BURST].histogram_edges[3] = 10000000;
+
+ ret->states[CIRCPAD_STATE_BURST].histogram[0] = 0;
+ ret->states[CIRCPAD_STATE_BURST].histogram[1] = 0;
+ ret->states[CIRCPAD_STATE_BURST].histogram[2] = 6;
+
+ ret->states[CIRCPAD_STATE_BURST].histogram_total_tokens = 6;
+ ret->states[CIRCPAD_STATE_BURST].use_rtt_estimate = 0;
+ ret->states[CIRCPAD_STATE_BURST].length_includes_nonpadding = 0;
+
+ return ret;
+}
+
+static circpad_machine_spec_t *
helper_create_conditional_machine(void)
{
circpad_machine_spec_t *ret =
@@ -1738,6 +1789,135 @@ helper_create_conditional_machines(void)
}
void
+test_circuitpadding_state_length(void *arg)
+{
+ /**
+ * Test plan:
+ * * Explicitly test that with no token removal enabled, we hit
+ * the state length limit due to either padding, or non-padding.
+ * * Repeat test with an arbitrary token removal strategy, and
+ * verify that if we run out of tokens due to padding before we
+ * hit the state length, we still go to state end (all our
+ * token removal tests only test nonpadding token removal).
+ */
+ int64_t actual_mocked_monotime_start;
+ (void)arg;
+ MOCK(circuitmux_attach_circuit, circuitmux_attach_circuit_mock);
+ MOCK(circpad_send_command_to_hop, circpad_send_command_to_hop_mock);
+
+ nodes_init();
+ dummy_channel.cmux = circuitmux_alloc();
+ relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel,
+ &dummy_channel));
+ client_side = TO_CIRCUIT(origin_circuit_new());
+ relay_side->purpose = CIRCUIT_PURPOSE_OR;
+ client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
+
+ monotime_init();
+ monotime_enable_test_mocking();
+ actual_mocked_monotime_start = MONOTIME_MOCK_START;
+ monotime_set_mock_time_nsec(actual_mocked_monotime_start);
+ monotime_coarse_set_mock_time_nsec(actual_mocked_monotime_start);
+ curr_mocked_time = actual_mocked_monotime_start;
+
+ /* This is needed so that we are not considered to be dormant */
+ note_user_activity(20);
+
+ timers_initialize();
+ circpad_machine_spec_t *client_machine =
+ helper_create_length_machine();
+
+ MOCK(circuit_package_relay_cell,
+ circuit_package_relay_cell_mock);
+ MOCK(node_get_by_id,
+ node_get_by_id_mock);
+
+ client_side->padding_machine[0] = client_machine;
+ client_side->padding_info[0] =
+ circpad_circuit_machineinfo_new(client_side, 0);
+ circpad_machine_runtime_t *mi = client_side->padding_info[0];
+
+ circpad_cell_event_padding_sent(client_side);
+ tt_int_op(mi->state_length, OP_EQ, 12);
+ tt_ptr_op(mi->histogram, OP_EQ, NULL);
+
+ /* Verify that non-padding does not change our state length */
+ circpad_cell_event_nonpadding_sent(client_side);
+ tt_int_op(mi->state_length, OP_EQ, 12);
+
+ /* verify that sending padding changes our state length */
+ for (uint64_t i = mi->state_length-1; i > 0; i--) {
+ circpad_send_padding_cell_for_callback(mi);
+ tt_int_op(mi->state_length, OP_EQ, i);
+ }
+ circpad_send_padding_cell_for_callback(mi);
+
+ tt_int_op(mi->state_length, OP_EQ, -1);
+ tt_int_op(mi->current_state, OP_EQ, CIRCPAD_STATE_END);
+
+ /* Restart machine */
+ mi->current_state = CIRCPAD_STATE_START;
+
+ /* Now, count nonpadding as part of the state length */
+ client_machine->states[CIRCPAD_STATE_BURST].length_includes_nonpadding = 1;
+
+ circpad_cell_event_padding_sent(client_side);
+ tt_int_op(mi->state_length, OP_EQ, 12);
+
+ /* Verify that non-padding does change our state length now */
+ for (uint64_t i = mi->state_length-1; i > 0; i--) {
+ circpad_cell_event_nonpadding_sent(client_side);
+ tt_int_op(mi->state_length, OP_EQ, i);
+ }
+
+ circpad_cell_event_nonpadding_sent(client_side);
+ tt_int_op(mi->state_length, OP_EQ, -1);
+ tt_int_op(mi->current_state, OP_EQ, CIRCPAD_STATE_END);
+
+ /* Now, just test token removal when we send padding */
+ client_machine->states[CIRCPAD_STATE_BURST].token_removal =
+ CIRCPAD_TOKEN_REMOVAL_EXACT;
+
+ /* Restart machine */
+ mi->current_state = CIRCPAD_STATE_START;
+ circpad_cell_event_padding_sent(client_side);
+ tt_int_op(mi->state_length, OP_EQ, 12);
+ tt_ptr_op(mi->histogram, OP_NE, NULL);
+ tt_int_op(mi->chosen_bin, OP_EQ, 2);
+
+ /* verify that sending padding changes our state length and
+ * our histogram now */
+ for (uint32_t i = mi->histogram[2]-1; i > 0; i--) {
+ circpad_send_padding_cell_for_callback(mi);
+ tt_int_op(mi->chosen_bin, OP_EQ, 2);
+ tt_int_op(mi->histogram[2], OP_EQ, i);
+ }
+
+ tt_int_op(mi->state_length, OP_EQ, 7);
+ tt_int_op(mi->histogram[2], OP_EQ, 1);
+
+ circpad_send_padding_cell_for_callback(mi);
+ tt_int_op(mi->current_state, OP_EQ, CIRCPAD_STATE_END);
+
+ done:
+ tor_free(client_machine->states);
+ tor_free(client_machine);
+
+ free_fake_origin_circuit(TO_ORIGIN_CIRCUIT(client_side));
+ free_fake_orcirc(relay_side);
+
+ circuitmux_detach_all_circuits(dummy_channel.cmux, NULL);
+ circuitmux_free(dummy_channel.cmux);
+ timers_shutdown();
+ monotime_disable_test_mocking();
+ UNMOCK(circuit_package_relay_cell);
+ UNMOCK(circuitmux_attach_circuit);
+ UNMOCK(node_get_by_id);
+
+ return;
+}
+
+void
test_circuitpadding_conditions(void *arg)
{
/**
@@ -1761,9 +1941,9 @@ test_circuitpadding_conditions(void *arg)
nodes_init();
dummy_channel.cmux = circuitmux_alloc();
- relay_side = (circuit_t *)new_fake_orcirc(&dummy_channel,
- &dummy_channel);
- client_side = (circuit_t *)origin_circuit_new();
+ relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel,
+ &dummy_channel));
+ client_side = TO_CIRCUIT(origin_circuit_new());
relay_side->purpose = CIRCUIT_PURPOSE_OR;
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
@@ -2217,7 +2397,7 @@ test_circuitpadding_sample_distribution(void *arg)
}
/* send a non-padding cell to move to the next machine state */
- circpad_cell_event_nonpadding_received((circuit_t*)client_side);
+ circpad_cell_event_nonpadding_received(client_side);
}
done:
@@ -2329,12 +2509,12 @@ test_circuitpadding_global_rate_limiting(void *arg)
curr_mocked_time = actual_mocked_monotime_start;
timers_initialize();
- client_side = (circuit_t *)origin_circuit_new();
+ client_side = TO_CIRCUIT(origin_circuit_new());
client_side->purpose = CIRCUIT_PURPOSE_C_GENERAL;
dummy_channel.cmux = circuitmux_alloc();
/* Setup machine and circuits */
- relay_side = (circuit_t *)new_fake_orcirc(&dummy_channel, &dummy_channel);
+ relay_side = TO_CIRCUIT(new_fake_orcirc(&dummy_channel, &dummy_channel));
relay_side->purpose = CIRCUIT_PURPOSE_OR;
helper_create_basic_machine();
relay_side->padding_machine[0] = &circ_client_machine;
@@ -2555,6 +2735,7 @@ test_circuitpadding_reduce_disable(void *arg)
struct testcase_t circuitpadding_tests[] = {
TEST_CIRCUITPADDING(circuitpadding_tokens, TT_FORK),
+ TEST_CIRCUITPADDING(circuitpadding_state_length, TT_FORK),
TEST_CIRCUITPADDING(circuitpadding_negotiation, TT_FORK),
TEST_CIRCUITPADDING(circuitpadding_wronghop, TT_FORK),
/** Disabled unstable test until #29298 is implemented (see #29122) */