aboutsummaryrefslogtreecommitdiff
path: root/src/core/or/circuitpadding_machines.c
diff options
context:
space:
mode:
authorMike Perry <mikeperry-git@torproject.org>2019-05-16 19:30:42 +0000
committerMike Perry <mikeperry-git@torproject.org>2019-05-16 20:17:11 +0000
commit0cba53c6edcc8c9c67a83a836e562552adf95e2d (patch)
tree8a68e5705539b670871c32e444502d40b5247ace /src/core/or/circuitpadding_machines.c
parentbbb974234c67d8d7dc95a760101ca61a9e88d647 (diff)
downloadtor-0cba53c6edcc8c9c67a83a836e562552adf95e2d.tar.gz
tor-0cba53c6edcc8c9c67a83a836e562552adf95e2d.zip
Refactor rend machines, stage 1/2: Move state transition code.
Diffstat (limited to 'src/core/or/circuitpadding_machines.c')
-rw-r--r--src/core/or/circuitpadding_machines.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/src/core/or/circuitpadding_machines.c b/src/core/or/circuitpadding_machines.c
index be02a597dc..5350e6e86a 100644
--- a/src/core/or/circuitpadding_machines.c
+++ b/src/core/or/circuitpadding_machines.c
@@ -284,26 +284,6 @@ setup_obf_state_for_hiding_rend_circuits(circpad_state_t *obf_state)
obf_state->histogram_total_tokens = 1;
}
-/* Setup the simple state machine we use for all HS padding machines */
-static void
-setup_state_machine_for_hiding_rend_circuits(circpad_machine_spec_t *machine)
-{
- /* Two states: START, OBFUSCATE_CIRC_SETUP (and END) */
- circpad_machine_states_init(machine, 2);
-
- /* START -> OBFUSCATE_CIRC_SETUP transition upon sending the first
- * non-padding cell (which is PADDING_NEGOTIATE) */
- machine->states[CIRCPAD_STATE_START].
- next_state[CIRCPAD_EVENT_NONPADDING_SENT] =
- CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP;
-
- /* OBFUSCATE_CIRC_SETUP -> END transition when we finish all the tokens */
- machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP].
- next_state[CIRCPAD_EVENT_PADDING_RECV] = CIRCPAD_STATE_END;
- machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP].
- next_state[CIRCPAD_EVENT_LENGTH_COUNT] = CIRCPAD_STATE_END;
-}
-
/** Create a client-side padding machine that aims to hide rendezvous
* circuits.*/
void
@@ -360,8 +340,22 @@ circpad_machine_client_hide_rend_circuits(smartlist_t *machines_sl)
client_machine->allowed_padding_count = 1;
client_machine->max_padding_percent = 1;
- /* Setup states and histograms */
- setup_state_machine_for_hiding_rend_circuits(client_machine);
+ /* Two states: START, OBFUSCATE_CIRC_SETUP (and END) */
+ circpad_machine_states_init(client_machine, 2);
+
+ /* START -> OBFUSCATE_CIRC_SETUP transition upon sending the first
+ * non-padding cell (which is PADDING_NEGOTIATE) */
+ client_machine->states[CIRCPAD_STATE_START].
+ next_state[CIRCPAD_EVENT_NONPADDING_SENT] =
+ CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP;
+
+ /* OBFUSCATE_CIRC_SETUP -> END transition when we send our first
+ * padding packet and/or hit the state length (the state length is 1). */
+ client_machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP].
+ next_state[CIRCPAD_EVENT_PADDING_RECV] = CIRCPAD_STATE_END;
+ client_machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP].
+ next_state[CIRCPAD_EVENT_LENGTH_COUNT] = CIRCPAD_STATE_END;
+
setup_obf_state_for_hiding_rend_circuits(
&client_machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP]);
@@ -398,8 +392,22 @@ circpad_machine_relay_hide_rend_circuits(smartlist_t *machines_sl)
relay_machine->allowed_padding_count = 1;
relay_machine->max_padding_percent = 1;
- /* Setup states and histograms */
- setup_state_machine_for_hiding_rend_circuits(relay_machine);
+ /* Two states: START, OBFUSCATE_CIRC_SETUP (and END) */
+ circpad_machine_states_init(relay_machine, 2);
+
+ /* START -> OBFUSCATE_CIRC_SETUP transition upon sending the first
+ * non-padding cell (which is PADDING_NEGOTIATED) */
+ relay_machine->states[CIRCPAD_STATE_START].
+ next_state[CIRCPAD_EVENT_NONPADDING_SENT] =
+ CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP;
+
+ /* OBFUSCATE_CIRC_SETUP -> END transition when we send our first
+ * padding packet and/or hit the state length (the state length is 1). */
+ relay_machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP].
+ next_state[CIRCPAD_EVENT_PADDING_RECV] = CIRCPAD_STATE_END;
+ relay_machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP].
+ next_state[CIRCPAD_EVENT_LENGTH_COUNT] = CIRCPAD_STATE_END;
+
setup_obf_state_for_hiding_rend_circuits(
&relay_machine->states[CIRCPAD_STATE_OBFUSCATE_CIRC_SETUP]);