diff options
author | George Kadianakis <desnacked@riseup.net> | 2019-03-13 15:24:04 +0200 |
---|---|---|
committer | teor <teor@torproject.org> | 2019-03-22 09:23:05 +1000 |
commit | 57291602532bfe55060668293130b0aac1fd702e (patch) | |
tree | 14d78126b270adf23a0e5ead007b7cf84bfcb048 /src | |
parent | 846d379b50b4f4790a9fe2ec88746748e0fab2b7 (diff) | |
download | tor-57291602532bfe55060668293130b0aac1fd702e.tar.gz tor-57291602532bfe55060668293130b0aac1fd702e.zip |
circpad: Rename circpad_machine_state_t to circpad_machine_runtime_t.
The name of circpad_machine_state_t was very confusing since it was conflicting
with circpad_state_t and circpad_circuit_state_t.
Right now here is the current meaning of these structs:
circpad_state_t -> A state of the state machine.
circpad_machine_runtime_t -> The current mutable runtime info of the state machine.
circpad_circuit_state_t -> Circuit conditions based on which we should apply a machine to the circuit
Diffstat (limited to 'src')
-rw-r--r-- | src/core/or/circuit_st.h | 8 | ||||
-rw-r--r-- | src/core/or/circuitpadding.c | 64 | ||||
-rw-r--r-- | src/core/or/circuitpadding.h | 44 | ||||
-rw-r--r-- | src/test/test_circuitpadding.c | 22 |
4 files changed, 69 insertions, 69 deletions
diff --git a/src/core/or/circuit_st.h b/src/core/or/circuit_st.h index af343f082e..c972b99318 100644 --- a/src/core/or/circuit_st.h +++ b/src/core/or/circuit_st.h @@ -13,7 +13,7 @@ struct hs_token_t; struct circpad_machine_spec_t; -struct circpad_machine_state_t; +struct circpad_machine_runtime_t; /** Number of padding state machines on a circuit. */ #define CIRCPAD_MAX_MACHINES (2) @@ -193,8 +193,8 @@ struct circuit_t { * and we can have up to CIRCPAD_MAX_MACHINES such machines. */ const struct circpad_machine_spec_t *padding_machine[CIRCPAD_MAX_MACHINES]; - /** Adaptive Padding machine info for above machines. This is the - * per-circuit mutable information, such as the current state and + /** Adaptive Padding machine runtime info for above machines. This is + * the per-circuit mutable information, such as the current state and * histogram token counts. Some of it is optional (aka NULL). * If a machine is being shut down, these indexes can be NULL * without the corresponding padding_machine being NULL, while we @@ -202,7 +202,7 @@ struct circuit_t { * * Each element of this array corresponds to a different padding machine, * and we can have up to CIRCPAD_MAX_MACHINES such machines. */ - struct circpad_machine_state_t *padding_info[CIRCPAD_MAX_MACHINES]; + struct circpad_machine_runtime_t *padding_info[CIRCPAD_MAX_MACHINES]; }; #endif diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c index 4514111a96..b921f1993f 100644 --- a/src/core/or/circuitpadding.c +++ b/src/core/or/circuitpadding.c @@ -23,7 +23,7 @@ * As specified by prop#254, clients can negotiate padding with relays by using * PADDING_NEGOTIATE cells. After successful padding negotiation, padding * machines are assigned to the circuit in their mutable form as a - * circpad_machine_state_t. + * circpad_machine_runtime_t. * * Each state of a padding state machine can be either: * - A histogram that specifies inter-arrival padding delays. @@ -188,11 +188,11 @@ circpad_circuit_free_all_machineinfos(circuit_t *circ) /** * Allocate a new mutable machineinfo structure. */ -STATIC circpad_machine_state_t * +STATIC circpad_machine_runtime_t * circpad_circuit_machineinfo_new(circuit_t *on_circ, int machine_index) { - circpad_machine_state_t *mi = - tor_malloc_zero(sizeof(circpad_machine_state_t)); + circpad_machine_runtime_t *mi = + tor_malloc_zero(sizeof(circpad_machine_runtime_t)); mi->machine_index = machine_index; mi->on_circ = on_circ; @@ -207,7 +207,7 @@ circpad_circuit_machineinfo_new(circuit_t *on_circ, int machine_index) * invalid state. */ STATIC const circpad_state_t * -circpad_machine_current_state(const circpad_machine_state_t *mi) +circpad_machine_current_state(const circpad_machine_runtime_t *mi) { const circpad_machine_spec_t *machine = CIRCPAD_GET_MACHINE(mi); @@ -234,7 +234,7 @@ circpad_machine_current_state(const circpad_machine_state_t *mi) * CIRCPAD_DELAY_INFINITE is returned. */ STATIC circpad_delay_t -circpad_histogram_bin_to_usec(const circpad_machine_state_t *mi, +circpad_histogram_bin_to_usec(const circpad_machine_runtime_t *mi, circpad_hist_index_t bin) { const circpad_state_t *state = circpad_machine_current_state(mi); @@ -265,7 +265,7 @@ circpad_histogram_bin_to_usec(const circpad_machine_state_t *mi, * (The upper bound is included in the bin.) */ STATIC circpad_delay_t -histogram_get_bin_upper_bound(const circpad_machine_state_t *mi, +histogram_get_bin_upper_bound(const circpad_machine_runtime_t *mi, circpad_hist_index_t bin) { return circpad_histogram_bin_to_usec(mi, bin+1) - 1; @@ -273,7 +273,7 @@ histogram_get_bin_upper_bound(const circpad_machine_state_t *mi, /** Return the midpoint of the histogram bin <b>bin_index</b>. */ static circpad_delay_t -circpad_get_histogram_bin_midpoint(const circpad_machine_state_t *mi, +circpad_get_histogram_bin_midpoint(const circpad_machine_runtime_t *mi, int bin_index) { circpad_delay_t left_bound = circpad_histogram_bin_to_usec(mi, bin_index); @@ -291,7 +291,7 @@ circpad_get_histogram_bin_midpoint(const circpad_machine_state_t *mi, * the highest non-infinity bin, that bin index will be returned. */ STATIC circpad_hist_index_t -circpad_histogram_usec_to_bin(const circpad_machine_state_t *mi, +circpad_histogram_usec_to_bin(const circpad_machine_runtime_t *mi, circpad_delay_t usec) { const circpad_state_t *state = circpad_machine_current_state(mi); @@ -331,7 +331,7 @@ circpad_histogram_usec_to_bin(const circpad_machine_state_t *mi, * Called after a state transition, or if the bins are empty. */ STATIC void -circpad_machine_setup_tokens(circpad_machine_state_t *mi) +circpad_machine_setup_tokens(circpad_machine_runtime_t *mi) { const circpad_state_t *state = circpad_machine_current_state(mi); @@ -363,7 +363,7 @@ circpad_machine_setup_tokens(circpad_machine_state_t *mi) * Choose a length for this state (in cells), if specified. */ static void -circpad_choose_state_length(circpad_machine_state_t *mi) +circpad_choose_state_length(circpad_machine_runtime_t *mi) { const circpad_state_t *state = circpad_machine_current_state(mi); double length; @@ -413,7 +413,7 @@ circpad_distribution_sample_iat_delay(const circpad_state_t *state, * that bin's [start,end) time range. */ STATIC circpad_delay_t -circpad_machine_sample_delay(circpad_machine_state_t *mi) +circpad_machine_sample_delay(circpad_machine_runtime_t *mi) { const circpad_state_t *state = circpad_machine_current_state(mi); const circpad_hist_token_t *histogram = NULL; @@ -601,7 +601,7 @@ circpad_distribution_sample(circpad_distribution_t dist) * greater than the target, and that has tokens remaining. */ static circpad_hist_index_t -circpad_machine_first_higher_index(const circpad_machine_state_t *mi, +circpad_machine_first_higher_index(const circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec) { circpad_hist_index_t bin = circpad_histogram_usec_to_bin(mi, @@ -623,7 +623,7 @@ circpad_machine_first_higher_index(const circpad_machine_state_t *mi, * <b>target_bin_usec</b>, and that still has tokens remaining. */ static circpad_hist_index_t -circpad_machine_first_lower_index(const circpad_machine_state_t *mi, +circpad_machine_first_lower_index(const circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec) { circpad_hist_index_t bin = circpad_histogram_usec_to_bin(mi, @@ -644,7 +644,7 @@ circpad_machine_first_lower_index(const circpad_machine_state_t *mi, * greater than the target. */ STATIC void -circpad_machine_remove_higher_token(circpad_machine_state_t *mi, +circpad_machine_remove_higher_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec) { /* We need to remove the token from the first bin @@ -665,7 +665,7 @@ circpad_machine_remove_higher_token(circpad_machine_state_t *mi, * lower than the target. */ STATIC void -circpad_machine_remove_lower_token(circpad_machine_state_t *mi, +circpad_machine_remove_lower_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec) { circpad_hist_index_t bin = circpad_machine_first_lower_index(mi, @@ -694,7 +694,7 @@ circpad_machine_remove_lower_token(circpad_machine_state_t *mi, * If it is false, use bin index distance only. */ STATIC void -circpad_machine_remove_closest_token(circpad_machine_state_t *mi, +circpad_machine_remove_closest_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec, bool use_usec) { @@ -776,7 +776,7 @@ circpad_machine_remove_closest_token(circpad_machine_state_t *mi, * If it is empty, do nothing. */ static void -circpad_machine_remove_exact(circpad_machine_state_t *mi, +circpad_machine_remove_exact(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_usec) { circpad_hist_index_t bin = circpad_histogram_usec_to_bin(mi, @@ -793,7 +793,7 @@ circpad_machine_remove_exact(circpad_machine_state_t *mi, * otherwise returns 0. */ static circpad_decision_t -check_machine_token_supply(circpad_machine_state_t *mi) +check_machine_token_supply(circpad_machine_runtime_t *mi) { uint32_t histogram_total_tokens = 0; @@ -833,7 +833,7 @@ check_machine_token_supply(circpad_machine_state_t *mi) * Returns 1 if we transition states, 0 otherwise. */ STATIC circpad_decision_t -circpad_machine_remove_token(circpad_machine_state_t *mi) +circpad_machine_remove_token(circpad_machine_runtime_t *mi) { const circpad_state_t *state = NULL; circpad_time_t current_time; @@ -960,7 +960,7 @@ circpad_send_command_to_hop,(origin_circuit_t *circ, uint8_t hopnum, * CIRCPAD_STATE_CHANGED. Otherwise return CIRCPAD_STATE_UNCHANGED. */ circpad_decision_t -circpad_send_padding_cell_for_callback(circpad_machine_state_t *mi) +circpad_send_padding_cell_for_callback(circpad_machine_runtime_t *mi) { circuit_t *circ = mi->on_circ; int machine_idx = mi->machine_index; @@ -1046,7 +1046,7 @@ circpad_send_padding_cell_for_callback(circpad_machine_state_t *mi) /** * Tor-timer compatible callback that tells us to send a padding cell. * - * Timers are associated with circpad_machine_state_t's. When the machineinfo + * Timers are associated with circpad_machine_runtime_t's. When the machineinfo * is freed on a circuit, the timers are cancelled. Since the lifetime * of machineinfo is always longer than the timers, handles are not * needed. @@ -1055,7 +1055,7 @@ static void circpad_send_padding_callback(tor_timer_t *timer, void *args, const struct monotime_t *time) { - circpad_machine_state_t *mi = ((circpad_machine_state_t*)args); + circpad_machine_runtime_t *mi = ((circpad_machine_runtime_t*)args); (void)timer; (void)time; if (mi && mi->on_circ) { @@ -1105,7 +1105,7 @@ circpad_new_consensus_params(const networkstatus_t *ns) * Returns 1 if limits are set and we've hit them. Otherwise returns 0. */ STATIC bool -circpad_machine_reached_padding_limit(circpad_machine_state_t *mi) +circpad_machine_reached_padding_limit(circpad_machine_runtime_t *mi) { const circpad_machine_spec_t *machine = CIRCPAD_GET_MACHINE(mi); @@ -1153,7 +1153,7 @@ circpad_machine_reached_padding_limit(circpad_machine_state_t *mi) * 0 otherwise. */ MOCK_IMPL(circpad_decision_t, -circpad_machine_schedule_padding,(circpad_machine_state_t *mi)) +circpad_machine_schedule_padding,(circpad_machine_runtime_t *mi)) { circpad_delay_t in_usec = 0; struct timeval timeout; @@ -1249,7 +1249,7 @@ circpad_machine_schedule_padding,(circpad_machine_state_t *mi)) * not access it. */ static void -circpad_machine_spec_transitioned_to_end(circpad_machine_state_t *mi) +circpad_machine_spec_transitioned_to_end(circpad_machine_runtime_t *mi) { const circpad_machine_spec_t *machine = CIRCPAD_GET_MACHINE(mi); @@ -1299,7 +1299,7 @@ circpad_machine_spec_transitioned_to_end(circpad_machine_state_t *mi) * Returns 1 if we transition states, 0 otherwise. */ MOCK_IMPL(circpad_decision_t, -circpad_machine_spec_transition,(circpad_machine_state_t *mi, +circpad_machine_spec_transition,(circpad_machine_runtime_t *mi, circpad_event_t event)) { const circpad_state_t *state = @@ -1380,7 +1380,7 @@ circpad_machine_spec_transition,(circpad_machine_state_t *mi, */ static void circpad_estimate_circ_rtt_on_received(circuit_t *circ, - circpad_machine_state_t *mi) + circpad_machine_runtime_t *mi) { /* Origin circuits don't estimate RTT. They could do it easily enough, * but they have no reason to use it in any delay calculations. */ @@ -1427,7 +1427,7 @@ circpad_estimate_circ_rtt_on_received(circuit_t *circ, */ static void circpad_estimate_circ_rtt_on_send(circuit_t *circ, - circpad_machine_state_t *mi) + circpad_machine_runtime_t *mi) { /* Origin circuits don't estimate RTT. They could do it easily enough, * but they have no reason to use it in any delay calculations. */ @@ -1572,7 +1572,7 @@ circpad_cell_event_padding_received(circuit_t *on_circ) * Return 1 if we decide to transition, 0 otherwise. */ circpad_decision_t -circpad_internal_event_infinity(circpad_machine_state_t *mi) +circpad_internal_event_infinity(circpad_machine_runtime_t *mi) { return circpad_machine_spec_transition(mi, CIRCPAD_EVENT_INFINITY); } @@ -1586,7 +1586,7 @@ circpad_internal_event_infinity(circpad_machine_state_t *mi) * Return 1 if we decide to transition, 0 otherwise. */ circpad_decision_t -circpad_internal_event_bins_empty(circpad_machine_state_t *mi) +circpad_internal_event_bins_empty(circpad_machine_runtime_t *mi) { if (circpad_machine_spec_transition(mi, CIRCPAD_EVENT_BINS_EMPTY) == CIRCPAD_STATE_CHANGED) { @@ -1605,7 +1605,7 @@ circpad_internal_event_bins_empty(circpad_machine_state_t *mi) * Return 1 if we decide to transition, 0 otherwise. */ circpad_decision_t -circpad_internal_event_state_length_up(circpad_machine_state_t *mi) +circpad_internal_event_state_length_up(circpad_machine_runtime_t *mi) { return circpad_machine_spec_transition(mi, CIRCPAD_EVENT_LENGTH_COUNT); } diff --git a/src/core/or/circuitpadding.h b/src/core/or/circuitpadding.h index 54039fa59a..7f6696380e 100644 --- a/src/core/or/circuitpadding.h +++ b/src/core/or/circuitpadding.h @@ -88,7 +88,7 @@ typedef uint32_t circpad_delay_t; /** * Macro to clarify when we're checking the infinity bin. * - * Works with either circpad_state_t or circpad_machine_state_t + * Works with either circpad_state_t or circpad_machine_runtime_t */ #define CIRCPAD_INFINITY_BIN(mi) ((mi)->histogram_len-1) @@ -245,7 +245,7 @@ typedef uint16_t circpad_statenum_t; * A state of a padding state machine. The information here are immutable and * represent the initial form of the state; it does not get updated as things * happen. The mutable information that gets updated in runtime are carried in - * a circpad_machine_state_t. + * a circpad_machine_runtime_t. * * This struct describes the histograms and parameters of a single * state in the adaptive padding machine. Instances of this struct @@ -467,7 +467,7 @@ typedef struct circpad_state_t { * * XXX: Play with layout to minimize space on x64 Linux (most common relay). */ -typedef struct circpad_machine_state_t { +typedef struct circpad_machine_runtime_t { /** The callback pointer for the padding callbacks. * * These timers stick around the machineinfo until the machineinfo's circuit @@ -551,7 +551,7 @@ typedef struct circpad_machine_state_t { * CIRCPAD_MAX_MACHINES define). */ unsigned machine_index : 1; -} circpad_machine_state_t; +} circpad_machine_runtime_t; /** Helper macro to get an actual state machine from a machineinfo */ #define CIRCPAD_GET_MACHINE(machineinfo) \ @@ -629,11 +629,11 @@ void circpad_cell_event_padding_received(struct circuit_t *on_circ); /** Internal events are events the machines send to themselves */ circpad_decision_t -circpad_internal_event_infinity(circpad_machine_state_t *mi); +circpad_internal_event_infinity(circpad_machine_runtime_t *mi); circpad_decision_t -circpad_internal_event_bins_empty(circpad_machine_state_t *); +circpad_internal_event_bins_empty(circpad_machine_runtime_t *); circpad_decision_t circpad_internal_event_state_length_up( - circpad_machine_state_t *); + circpad_machine_runtime_t *); /** Machine creation events are events that cause us to set up or * tear down padding state machines. */ @@ -676,47 +676,47 @@ bool circpad_padding_negotiated(struct circuit_t *circ, uint8_t response); MOCK_DECL(circpad_decision_t, -circpad_machine_schedule_padding,(circpad_machine_state_t *)); +circpad_machine_schedule_padding,(circpad_machine_runtime_t *)); MOCK_DECL(circpad_decision_t, -circpad_machine_spec_transition, (circpad_machine_state_t *mi, +circpad_machine_spec_transition, (circpad_machine_runtime_t *mi, circpad_event_t event)); circpad_decision_t circpad_send_padding_cell_for_callback( - circpad_machine_state_t *mi); + circpad_machine_runtime_t *mi); #ifdef CIRCUITPADDING_PRIVATE STATIC circpad_delay_t -circpad_machine_sample_delay(circpad_machine_state_t *mi); +circpad_machine_sample_delay(circpad_machine_runtime_t *mi); STATIC bool -circpad_machine_reached_padding_limit(circpad_machine_state_t *mi); +circpad_machine_reached_padding_limit(circpad_machine_runtime_t *mi); STATIC -circpad_decision_t circpad_machine_remove_token(circpad_machine_state_t *mi); +circpad_decision_t circpad_machine_remove_token(circpad_machine_runtime_t *mi); STATIC circpad_delay_t -circpad_histogram_bin_to_usec(const circpad_machine_state_t *mi, +circpad_histogram_bin_to_usec(const circpad_machine_runtime_t *mi, circpad_hist_index_t bin); STATIC const circpad_state_t * -circpad_machine_current_state(const circpad_machine_state_t *mi); +circpad_machine_current_state(const circpad_machine_runtime_t *mi); STATIC circpad_hist_index_t circpad_histogram_usec_to_bin( - const circpad_machine_state_t *mi, + const circpad_machine_runtime_t *mi, circpad_delay_t us); -STATIC circpad_machine_state_t *circpad_circuit_machineinfo_new( +STATIC circpad_machine_runtime_t *circpad_circuit_machineinfo_new( struct circuit_t *on_circ, int machine_index); -STATIC void circpad_machine_remove_higher_token(circpad_machine_state_t *mi, +STATIC void circpad_machine_remove_higher_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_us); -STATIC void circpad_machine_remove_lower_token(circpad_machine_state_t *mi, +STATIC void circpad_machine_remove_lower_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_us); -STATIC void circpad_machine_remove_closest_token(circpad_machine_state_t *mi, +STATIC void circpad_machine_remove_closest_token(circpad_machine_runtime_t *mi, circpad_delay_t target_bin_us, bool use_usec); -STATIC void circpad_machine_setup_tokens(circpad_machine_state_t *mi); +STATIC void circpad_machine_setup_tokens(circpad_machine_runtime_t *mi); MOCK_DECL(STATIC signed_error_t, circpad_send_command_to_hop,(struct origin_circuit_t *circ, uint8_t hopnum, @@ -724,7 +724,7 @@ circpad_send_command_to_hop,(struct origin_circuit_t *circ, uint8_t hopnum, ssize_t payload_len)); STATIC circpad_delay_t -histogram_get_bin_upper_bound(const circpad_machine_state_t *mi, +histogram_get_bin_upper_bound(const circpad_machine_runtime_t *mi, circpad_hist_index_t bin); #ifdef TOR_UNIT_TESTS diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c index ba58cd0d97..d02f40f21c 100644 --- a/src/test/test_circuitpadding.c +++ b/src/test/test_circuitpadding.c @@ -493,7 +493,7 @@ helper_create_machine_with_big_histogram(circpad_removal_t removal_strategy) } static circpad_decision_t -circpad_machine_schedule_padding_mock(circpad_machine_state_t *mi) +circpad_machine_schedule_padding_mock(circpad_machine_runtime_t *mi) { (void)mi; return 0; @@ -509,7 +509,7 @@ mock_monotime_absolute_usec(void) static void test_circuitpadding_token_removal_higher(void *arg) { - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; (void)arg; /* Mock it up */ @@ -614,7 +614,7 @@ test_circuitpadding_token_removal_higher(void *arg) static void test_circuitpadding_token_removal_lower(void *arg) { - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; (void)arg; /* Mock it up */ @@ -712,7 +712,7 @@ test_circuitpadding_token_removal_lower(void *arg) static void test_circuitpadding_closest_token_removal(void *arg) { - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; (void)arg; /* Mock it up */ @@ -818,7 +818,7 @@ test_circuitpadding_closest_token_removal(void *arg) static void test_circuitpadding_closest_token_removal_usec(void *arg) { - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; (void)arg; /* Mock it up */ @@ -929,7 +929,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg) static void test_circuitpadding_token_removal_exact(void *arg) { - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; (void)arg; /* Mock it up */ @@ -990,7 +990,7 @@ void test_circuitpadding_tokens(void *arg) { const circpad_state_t *state; - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; (void)arg; /** Test plan: @@ -2157,7 +2157,7 @@ helper_circpad_circ_distribution_machine_setup(int min, int max) static void test_circuitpadding_sample_distribution(void *arg) { - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; int n_samples; int n_states; @@ -2202,7 +2202,7 @@ test_circuitpadding_sample_distribution(void *arg) } static circpad_decision_t -circpad_machine_spec_transition_mock(circpad_machine_state_t *mi, +circpad_machine_spec_transition_mock(circpad_machine_runtime_t *mi, circpad_event_t event) { (void) mi; @@ -2217,7 +2217,7 @@ test_circuitpadding_machine_rate_limiting(void *arg) { (void) arg; bool retval; - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; int i; /* Ignore machine transitions for the purposes of this function, we only @@ -2285,7 +2285,7 @@ test_circuitpadding_global_rate_limiting(void *arg) { (void) arg; bool retval; - circpad_machine_state_t *mi; + circpad_machine_runtime_t *mi; int i; /* Ignore machine transitions for the purposes of this function, we only |