Rename circpad_machineinfo_t -> circpad_machine_state_t

This commit is contained in:
George Kadianakis 2019-01-10 12:38:00 +02:00
parent 5738a0ab6c
commit f4938179c5
4 changed files with 68 additions and 65 deletions

View File

@ -13,7 +13,7 @@
struct hs_token_t;
typedef struct circpad_machine_spec_t circpad_machine_spec_t;
typedef struct circpad_machineinfo_t circpad_machineinfo_t;
typedef struct circpad_machine_state_t circpad_machine_state_t;
/** Number of padding state machines on a circuit. */
#define CIRCPAD_MAX_MACHINES (2)
@ -200,7 +200,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. */
circpad_machineinfo_t *padding_info[CIRCPAD_MAX_MACHINES];
circpad_machine_state_t *padding_info[CIRCPAD_MAX_MACHINES];
};
#endif

View File

@ -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_machineinfo_t.
* circpad_machine_state_t.
*
* Each state of a padding state machine can be either:
* - A histogram that specifies inter-arrival padding delays.
@ -177,10 +177,11 @@ circpad_circuit_free_all_machineinfos(circuit_t *circ)
/**
* Allocate a new mutable machineinfo structure.
*/
STATIC circpad_machineinfo_t *
STATIC circpad_machine_state_t *
circpad_circuit_machineinfo_new(circuit_t *on_circ, int machine_index)
{
circpad_machineinfo_t *mi = tor_malloc_zero(sizeof(circpad_machineinfo_t));
circpad_machine_state_t *mi =
tor_malloc_zero(sizeof(circpad_machine_state_t));
mi->machine_index = machine_index;
mi->on_circ = on_circ;
@ -195,7 +196,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_machineinfo_t *mi)
circpad_machine_current_state(const circpad_machine_state_t *mi)
{
const circpad_machine_spec_t *machine = CIRCPAD_GET_MACHINE(mi);
@ -227,7 +228,7 @@ circpad_machine_current_state(const circpad_machineinfo_t *mi)
* It has a usec value of CIRCPAD_DELAY_INFINITE (UINT32_MAX).
*/
STATIC circpad_delay_t
circpad_histogram_bin_to_usec(const circpad_machineinfo_t *mi,
circpad_histogram_bin_to_usec(const circpad_machine_state_t *mi,
circpad_hist_index_t bin)
{
const circpad_state_t *state = circpad_machine_current_state(mi);
@ -264,7 +265,7 @@ circpad_histogram_bin_to_usec(const circpad_machineinfo_t *mi,
/** Return the midpoint of the histogram bin <b>bin_index</b>. */
static circpad_delay_t
circpad_get_histogram_bin_midpoint(const circpad_machineinfo_t *mi,
circpad_get_histogram_bin_midpoint(const circpad_machine_state_t *mi,
int bin_index)
{
circpad_delay_t left_bound = circpad_histogram_bin_to_usec(mi, bin_index);
@ -285,7 +286,7 @@ circpad_get_histogram_bin_midpoint(const circpad_machineinfo_t *mi,
* has range [start_usec+range_usec, CIRCPAD_DELAY_INFINITE].
*/
STATIC circpad_hist_index_t
circpad_histogram_usec_to_bin(const circpad_machineinfo_t *mi,
circpad_histogram_usec_to_bin(const circpad_machine_state_t *mi,
circpad_delay_t usec)
{
const circpad_state_t *state = circpad_machine_current_state(mi);
@ -333,7 +334,7 @@ circpad_histogram_usec_to_bin(const circpad_machineinfo_t *mi,
* Called after a state transition, or if the bins are empty.
*/
STATIC void
circpad_machine_setup_tokens(circpad_machineinfo_t *mi)
circpad_machine_setup_tokens(circpad_machine_state_t *mi)
{
const circpad_state_t *state = circpad_machine_current_state(mi);
@ -365,7 +366,7 @@ circpad_machine_setup_tokens(circpad_machineinfo_t *mi)
* Choose a length for this state (in cells), if specified.
*/
static void
circpad_choose_state_length(circpad_machineinfo_t *mi)
circpad_choose_state_length(circpad_machine_state_t *mi)
{
const circpad_state_t *state = circpad_machine_current_state(mi);
double length;
@ -413,7 +414,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_machineinfo_t *mi)
circpad_machine_sample_delay(circpad_machine_state_t *mi)
{
const circpad_state_t *state = circpad_machine_current_state(mi);
const circpad_hist_token_t *histogram = NULL;
@ -602,7 +603,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_machineinfo_t *mi,
circpad_machine_first_higher_index(const circpad_machine_state_t *mi,
circpad_delay_t target_bin_usec)
{
circpad_hist_index_t bin = circpad_histogram_usec_to_bin(mi,
@ -624,7 +625,7 @@ circpad_machine_first_higher_index(const circpad_machineinfo_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_machineinfo_t *mi,
circpad_machine_first_lower_index(const circpad_machine_state_t *mi,
circpad_delay_t target_bin_usec)
{
circpad_hist_index_t bin = circpad_histogram_usec_to_bin(mi,
@ -645,7 +646,7 @@ circpad_machine_first_lower_index(const circpad_machineinfo_t *mi,
* greater than the target.
*/
STATIC void
circpad_machine_remove_higher_token(circpad_machineinfo_t *mi,
circpad_machine_remove_higher_token(circpad_machine_state_t *mi,
circpad_delay_t target_bin_usec)
{
/* We need to remove the token from the first bin
@ -666,7 +667,7 @@ circpad_machine_remove_higher_token(circpad_machineinfo_t *mi,
* lower than the target.
*/
STATIC void
circpad_machine_remove_lower_token(circpad_machineinfo_t *mi,
circpad_machine_remove_lower_token(circpad_machine_state_t *mi,
circpad_delay_t target_bin_usec)
{
circpad_hist_index_t bin = circpad_machine_first_lower_index(mi,
@ -695,7 +696,7 @@ circpad_machine_remove_lower_token(circpad_machineinfo_t *mi,
* If it is false, use bin index distance only.
*/
STATIC void
circpad_machine_remove_closest_token(circpad_machineinfo_t *mi,
circpad_machine_remove_closest_token(circpad_machine_state_t *mi,
circpad_delay_t target_bin_usec,
bool use_usec)
{
@ -777,7 +778,7 @@ circpad_machine_remove_closest_token(circpad_machineinfo_t *mi,
* If it is empty, do nothing.
*/
static void
circpad_machine_remove_exact(circpad_machineinfo_t *mi,
circpad_machine_remove_exact(circpad_machine_state_t *mi,
circpad_delay_t target_bin_usec)
{
circpad_hist_index_t bin = circpad_histogram_usec_to_bin(mi,
@ -794,7 +795,7 @@ circpad_machine_remove_exact(circpad_machineinfo_t *mi,
* otherwise returns 0.
*/
static circpad_decision_t
check_machine_token_supply(circpad_machineinfo_t *mi)
check_machine_token_supply(circpad_machine_state_t *mi)
{
uint32_t histogram_total_tokens = 0;
@ -834,7 +835,7 @@ check_machine_token_supply(circpad_machineinfo_t *mi)
* Returns 1 if we transition states, 0 otherwise.
*/
STATIC circpad_decision_t
circpad_machine_remove_token(circpad_machineinfo_t *mi)
circpad_machine_remove_token(circpad_machine_state_t *mi)
{
const circpad_state_t *state = NULL;
circpad_time_t current_time;
@ -961,7 +962,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_machineinfo_t *mi)
circpad_send_padding_cell_for_callback(circpad_machine_state_t *mi)
{
circuit_t *circ = mi->on_circ;
int machine_idx = mi->machine_index;
@ -1040,7 +1041,7 @@ circpad_send_padding_cell_for_callback(circpad_machineinfo_t *mi)
/**
* Tor-timer compatible callback that tells us to send a padding cell.
*
* Timers are associated with circpad_machineinfo_t's. When the machineinfo
* Timers are associated with circpad_machine_state_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.
@ -1049,7 +1050,7 @@ static void
circpad_send_padding_callback(tor_timer_t *timer, void *args,
const struct monotime_t *time)
{
circpad_machineinfo_t *mi = ((circpad_machineinfo_t*)args);
circpad_machine_state_t *mi = ((circpad_machine_state_t*)args);
(void)timer; (void)time;
if (mi && mi->on_circ) {
@ -1095,7 +1096,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_machineinfo_t *mi)
circpad_machine_reached_padding_limit(circpad_machine_state_t *mi)
{
const circpad_machine_spec_t *machine = CIRCPAD_GET_MACHINE(mi);
@ -1143,7 +1144,7 @@ circpad_machine_reached_padding_limit(circpad_machineinfo_t *mi)
* 0 otherwise.
*/
MOCK_IMPL(circpad_decision_t,
circpad_machine_schedule_padding,(circpad_machineinfo_t *mi))
circpad_machine_schedule_padding,(circpad_machine_state_t *mi))
{
circpad_delay_t in_usec = 0;
struct timeval timeout;
@ -1233,7 +1234,7 @@ circpad_machine_schedule_padding,(circpad_machineinfo_t *mi))
* not access it.
*/
static void
circpad_machine_spec_transitioned_to_end(circpad_machineinfo_t *mi)
circpad_machine_spec_transitioned_to_end(circpad_machine_state_t *mi)
{
const circpad_machine_spec_t *machine = CIRCPAD_GET_MACHINE(mi);
@ -1283,7 +1284,7 @@ circpad_machine_spec_transitioned_to_end(circpad_machineinfo_t *mi)
* Returns 1 if we transition states, 0 otherwise.
*/
MOCK_IMPL(circpad_decision_t,
circpad_machine_spec_transition,(circpad_machineinfo_t *mi,
circpad_machine_spec_transition,(circpad_machine_state_t *mi,
circpad_event_t event))
{
const circpad_state_t *state =
@ -1364,7 +1365,7 @@ circpad_machine_spec_transition,(circpad_machineinfo_t *mi,
*/
static void
circpad_estimate_circ_rtt_on_received(circuit_t *circ,
circpad_machineinfo_t *mi)
circpad_machine_state_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. */
@ -1411,7 +1412,7 @@ circpad_estimate_circ_rtt_on_received(circuit_t *circ,
*/
static void
circpad_estimate_circ_rtt_on_send(circuit_t *circ,
circpad_machineinfo_t *mi)
circpad_machine_state_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. */
@ -1556,7 +1557,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_machineinfo_t *mi)
circpad_internal_event_infinity(circpad_machine_state_t *mi)
{
return circpad_machine_spec_transition(mi, CIRCPAD_EVENT_INFINITY);
}
@ -1570,7 +1571,7 @@ circpad_internal_event_infinity(circpad_machineinfo_t *mi)
* Return 1 if we decide to transition, 0 otherwise.
*/
circpad_decision_t
circpad_internal_event_bins_empty(circpad_machineinfo_t *mi)
circpad_internal_event_bins_empty(circpad_machine_state_t *mi)
{
if (circpad_machine_spec_transition(mi, CIRCPAD_EVENT_BINS_EMPTY)
== CIRCPAD_STATE_CHANGED) {
@ -1589,7 +1590,7 @@ circpad_internal_event_bins_empty(circpad_machineinfo_t *mi)
* Return 1 if we decide to transition, 0 otherwise.
*/
circpad_decision_t
circpad_internal_event_state_length_up(circpad_machineinfo_t *mi)
circpad_internal_event_state_length_up(circpad_machine_state_t *mi)
{
return circpad_machine_spec_transition(mi, CIRCPAD_EVENT_LENGTH_COUNT);
}

View File

@ -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_machineinfo_t
* Works with either circpad_state_t or circpad_machine_state_t
*/
#define CIRCPAD_INFINITY_BIN(mi) ((mi)->histogram_len-1)
@ -237,10 +237,10 @@ typedef uint16_t circpad_statenum_t;
#define CIRCPAD_MAX_HISTOGRAM_LEN (sizeof(circpad_delay_t)*8 + 1)
/**
* A state of a padding machine. The information here are immutable and
* 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_machineinfo_t.
* a circpad_machine_state_t.
*
* This struct describes the histograms and parameters of a single
* state in the adaptive padding machine. Instances of this struct
@ -430,7 +430,7 @@ typedef struct circpad_state_t {
*
* XXX: Play with layout to minimize space on x64 Linux (most common relay).
*/
typedef struct circpad_machineinfo_t {
typedef struct circpad_machine_state_t {
/** The callback pointer for the padding callbacks.
*
* These timers stick around the machineinfo until the machineinfo's circuit
@ -514,7 +514,7 @@ typedef struct circpad_machineinfo_t {
* CIRCPAD_MAX_MACHINES define). */
unsigned machine_index : 1;
} circpad_machineinfo_t;
} circpad_machine_state_t;
/** Helper macro to get an actual state machine from a machineinfo */
#define CIRCPAD_GET_MACHINE(machineinfo) \
@ -591,10 +591,12 @@ void circpad_cell_event_padding_sent(circuit_t *on_circ);
void circpad_cell_event_padding_received(circuit_t *on_circ);
/** Internal events are events the machines send to themselves */
circpad_decision_t circpad_internal_event_infinity(circpad_machineinfo_t *mi);
circpad_decision_t circpad_internal_event_bins_empty(circpad_machineinfo_t *);
circpad_decision_t
circpad_internal_event_infinity(circpad_machine_state_t *mi);
circpad_decision_t
circpad_internal_event_bins_empty(circpad_machine_state_t *);
circpad_decision_t circpad_internal_event_state_length_up(
circpad_machineinfo_t *);
circpad_machine_state_t *);
/** Machine creation events are events that cause us to set up or
* tear down padding state machines. */
@ -634,47 +636,47 @@ bool circpad_padding_negotiated(circuit_t *circ,
uint8_t response);
MOCK_DECL(circpad_decision_t,
circpad_machine_schedule_padding,(circpad_machineinfo_t *));
circpad_machine_schedule_padding,(circpad_machine_state_t *));
MOCK_DECL(circpad_decision_t,
circpad_machine_spec_transition, (circpad_machineinfo_t *mi,
circpad_machine_spec_transition, (circpad_machine_state_t *mi,
circpad_event_t event));
circpad_decision_t circpad_send_padding_cell_for_callback(
circpad_machineinfo_t *mi);
circpad_machine_state_t *mi);
#ifdef CIRCUITPADDING_PRIVATE
STATIC circpad_delay_t
circpad_machine_sample_delay(circpad_machineinfo_t *mi);
circpad_machine_sample_delay(circpad_machine_state_t *mi);
STATIC bool
circpad_machine_reached_padding_limit(circpad_machineinfo_t *mi);
circpad_machine_reached_padding_limit(circpad_machine_state_t *mi);
STATIC
circpad_decision_t circpad_machine_remove_token(circpad_machineinfo_t *mi);
circpad_decision_t circpad_machine_remove_token(circpad_machine_state_t *mi);
STATIC circpad_delay_t
circpad_histogram_bin_to_usec(const circpad_machineinfo_t *mi,
circpad_histogram_bin_to_usec(const circpad_machine_state_t *mi,
circpad_hist_index_t bin);
STATIC const circpad_state_t *
circpad_machine_current_state(const circpad_machineinfo_t *mi);
circpad_machine_current_state(const circpad_machine_state_t *mi);
STATIC circpad_hist_index_t circpad_histogram_usec_to_bin(
const circpad_machineinfo_t *mi,
const circpad_machine_state_t *mi,
circpad_delay_t us);
STATIC circpad_machineinfo_t *circpad_circuit_machineinfo_new(
STATIC circpad_machine_state_t *circpad_circuit_machineinfo_new(
circuit_t *on_circ,
int machine_index);
STATIC void circpad_machine_remove_higher_token(circpad_machineinfo_t *mi,
STATIC void circpad_machine_remove_higher_token(circpad_machine_state_t *mi,
circpad_delay_t target_bin_us);
STATIC void circpad_machine_remove_lower_token(circpad_machineinfo_t *mi,
STATIC void circpad_machine_remove_lower_token(circpad_machine_state_t *mi,
circpad_delay_t target_bin_us);
STATIC void circpad_machine_remove_closest_token(circpad_machineinfo_t *mi,
STATIC void circpad_machine_remove_closest_token(circpad_machine_state_t *mi,
circpad_delay_t target_bin_us,
bool use_usec);
STATIC void circpad_machine_setup_tokens(circpad_machineinfo_t *mi);
STATIC void circpad_machine_setup_tokens(circpad_machine_state_t *mi);
MOCK_DECL(STATIC signed_error_t,
circpad_send_command_to_hop,(origin_circuit_t *circ, uint8_t hopnum,

View File

@ -479,7 +479,7 @@ helper_create_machine_with_big_histogram(circpad_removal_t removal_strategy)
}
static circpad_decision_t
circpad_machine_schedule_padding_mock(circpad_machineinfo_t *mi)
circpad_machine_schedule_padding_mock(circpad_machine_state_t *mi)
{
(void)mi;
return 0;
@ -495,7 +495,7 @@ mock_monotime_absolute_usec(void)
static void
test_circuitpadding_token_removal_higher(void *arg)
{
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
(void)arg;
/* Mock it up */
@ -592,7 +592,7 @@ test_circuitpadding_token_removal_higher(void *arg)
static void
test_circuitpadding_token_removal_lower(void *arg)
{
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
(void)arg;
/* Mock it up */
@ -689,7 +689,7 @@ test_circuitpadding_token_removal_lower(void *arg)
static void
test_circuitpadding_closest_token_removal(void *arg)
{
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
(void)arg;
/* Mock it up */
@ -794,7 +794,7 @@ test_circuitpadding_closest_token_removal(void *arg)
static void
test_circuitpadding_closest_token_removal_usec(void *arg)
{
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
(void)arg;
/* Mock it up */
@ -902,7 +902,7 @@ test_circuitpadding_closest_token_removal_usec(void *arg)
static void
test_circuitpadding_token_removal_exact(void *arg)
{
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
(void)arg;
/* Mock it up */
@ -963,7 +963,7 @@ void
test_circuitpadding_tokens(void *arg)
{
const circpad_state_t *state;
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
(void)arg;
/** Test plan:
@ -2114,7 +2114,7 @@ helper_circpad_circ_distribution_machine_setup(int min, int max)
static void
test_circuitpadding_sample_distribution(void *arg)
{
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
int n_samples;
int n_states;
@ -2159,7 +2159,7 @@ test_circuitpadding_sample_distribution(void *arg)
}
static circpad_decision_t
circpad_machine_spec_transition_mock(circpad_machineinfo_t *mi,
circpad_machine_spec_transition_mock(circpad_machine_state_t *mi,
circpad_event_t event)
{
(void) mi;
@ -2174,7 +2174,7 @@ test_circuitpadding_machine_rate_limiting(void *arg)
{
(void) arg;
bool retval;
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
int i;
/* Ignore machine transitions for the purposes of this function, we only
@ -2242,7 +2242,7 @@ test_circuitpadding_global_rate_limiting(void *arg)
{
(void) arg;
bool retval;
circpad_machineinfo_t *mi;
circpad_machine_state_t *mi;
int i;
/* Ignore machine transitions for the purposes of this function, we only