mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 22:03:31 +01:00
Fix test prob distr parameters that caused warnings.
They were causing the following warnings in circuitpadding/circuitpadding_sample_distribution: src/lib/math/prob_distr.c:1311:17: runtime error: division by zero SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/lib/math/prob_distr.c:1311:17 in src/lib/math/prob_distr.c:1219:49: runtime error: division by zero SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior src/lib/math/prob_distr.c:1219:49 in because the distributions were called with erroneous parameters (e.g. geometric distribution with p=0). We now defined these test probability distributions with more realistic parameters. As far as the circuitpadding_sample_distribution() test is concerned, it doesn't matter if the distributions return values outside of [0,10] since we already restrict the values into that interval using min=0 and max=10 (and RTT estimate is disabled).
This commit is contained in:
parent
18de065cbb
commit
a71999462b
@ -389,11 +389,14 @@ circpad_distribution_sample_iat_delay(const circpad_state_t *state,
|
|||||||
double val = circpad_distribution_sample(state->iat_dist);
|
double val = circpad_distribution_sample(state->iat_dist);
|
||||||
/* These comparisons are safe, because the output is in the range
|
/* These comparisons are safe, because the output is in the range
|
||||||
* [0, 2**32), and double has a precision of 53 bits. */
|
* [0, 2**32), and double has a precision of 53 bits. */
|
||||||
|
/* We want a positive sample value */
|
||||||
val = MAX(0, val);
|
val = MAX(0, val);
|
||||||
|
/* Respect the maximum sample setting */
|
||||||
val = MIN(val, state->dist_max_sample_usec);
|
val = MIN(val, state->dist_max_sample_usec);
|
||||||
|
|
||||||
/* This addition is exact: val is at most 2**32-1, min_delay
|
/* Now apply the shift:
|
||||||
* is at most 2**32-1, and doubles have a precision of 53 bits. */
|
* This addition is exact: val is at most 2**32-1, delay_shift is at most
|
||||||
|
* 2**32-1, and doubles have a precision of 53 bits. */
|
||||||
val += delay_shift;
|
val += delay_shift;
|
||||||
|
|
||||||
/* Clamp the distribution at infinite delay val */
|
/* Clamp the distribution at infinite delay val */
|
||||||
|
@ -198,14 +198,23 @@ typedef enum {
|
|||||||
* These can be used instead of histograms for the inter-packet
|
* These can be used instead of histograms for the inter-packet
|
||||||
* timing distribution, or to specify a distribution on the number
|
* timing distribution, or to specify a distribution on the number
|
||||||
* of cells that can be sent while in a specific state of the state
|
* of cells that can be sent while in a specific state of the state
|
||||||
* machine. */
|
* machine.
|
||||||
|
*
|
||||||
|
* Each distribution takes up to two parameters which are described below. */
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
/* No probability distribution is used */
|
||||||
CIRCPAD_DIST_NONE = 0,
|
CIRCPAD_DIST_NONE = 0,
|
||||||
|
/* Uniform distribution: param1 is lower bound and param2 is upper bound */
|
||||||
CIRCPAD_DIST_UNIFORM = 1,
|
CIRCPAD_DIST_UNIFORM = 1,
|
||||||
|
/* Logistic distribution: param1 is Mu, param2 is sigma. */
|
||||||
CIRCPAD_DIST_LOGISTIC = 2,
|
CIRCPAD_DIST_LOGISTIC = 2,
|
||||||
|
/* Log-logistic distribution: param1 is Alpha, param2 is 1.0/Beta */
|
||||||
CIRCPAD_DIST_LOG_LOGISTIC = 3,
|
CIRCPAD_DIST_LOG_LOGISTIC = 3,
|
||||||
|
/* Geometric distribution: param1 is 'p' (success probability) */
|
||||||
CIRCPAD_DIST_GEOMETRIC = 4,
|
CIRCPAD_DIST_GEOMETRIC = 4,
|
||||||
|
/* Weibull distribution: param1 is k, param2 is Lambda */
|
||||||
CIRCPAD_DIST_WEIBULL = 5,
|
CIRCPAD_DIST_WEIBULL = 5,
|
||||||
|
/* Generalized Pareto distribution: param1 is sigma, param2 is xi */
|
||||||
CIRCPAD_DIST_PARETO = 6
|
CIRCPAD_DIST_PARETO = 6
|
||||||
} circpad_distribution_type_t;
|
} circpad_distribution_type_t;
|
||||||
|
|
||||||
|
@ -2096,6 +2096,7 @@ helper_circpad_circ_distribution_machine_setup(int min, int max)
|
|||||||
circpad_state_t *zero_st = &circ_client_machine.states[0];
|
circpad_state_t *zero_st = &circ_client_machine.states[0];
|
||||||
zero_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 1;
|
zero_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 1;
|
||||||
zero_st->iat_dist.type = CIRCPAD_DIST_UNIFORM;
|
zero_st->iat_dist.type = CIRCPAD_DIST_UNIFORM;
|
||||||
|
/* param2 is upper bound, param1 is lower */
|
||||||
zero_st->iat_dist.param1 = min;
|
zero_st->iat_dist.param1 = min;
|
||||||
zero_st->iat_dist.param2 = max;
|
zero_st->iat_dist.param2 = max;
|
||||||
zero_st->dist_added_shift_usec = min;
|
zero_st->dist_added_shift_usec = min;
|
||||||
@ -2104,48 +2105,50 @@ helper_circpad_circ_distribution_machine_setup(int min, int max)
|
|||||||
circpad_state_t *first_st = &circ_client_machine.states[1];
|
circpad_state_t *first_st = &circ_client_machine.states[1];
|
||||||
first_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 2;
|
first_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 2;
|
||||||
first_st->iat_dist.type = CIRCPAD_DIST_LOGISTIC;
|
first_st->iat_dist.type = CIRCPAD_DIST_LOGISTIC;
|
||||||
first_st->iat_dist.param1 = min;
|
/* param1 is Mu, param2 is sigma. */
|
||||||
first_st->iat_dist.param2 = max;
|
first_st->iat_dist.param1 = 9;
|
||||||
|
first_st->iat_dist.param2 = 3;
|
||||||
first_st->dist_added_shift_usec = min;
|
first_st->dist_added_shift_usec = min;
|
||||||
first_st->dist_max_sample_usec = max;
|
first_st->dist_max_sample_usec = max;
|
||||||
|
|
||||||
circpad_state_t *second_st = &circ_client_machine.states[2];
|
circpad_state_t *second_st = &circ_client_machine.states[2];
|
||||||
second_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 3;
|
second_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 3;
|
||||||
second_st->iat_dist.type = CIRCPAD_DIST_LOG_LOGISTIC;
|
second_st->iat_dist.type = CIRCPAD_DIST_LOG_LOGISTIC;
|
||||||
second_st->iat_dist.param1 = min;
|
/* param1 is Alpha, param2 is 1.0/Beta */
|
||||||
second_st->iat_dist.param2 = max;
|
second_st->iat_dist.param1 = 1;
|
||||||
|
second_st->iat_dist.param2 = 0.5;
|
||||||
second_st->dist_added_shift_usec = min;
|
second_st->dist_added_shift_usec = min;
|
||||||
second_st->dist_max_sample_usec = max;
|
second_st->dist_max_sample_usec = max;
|
||||||
|
|
||||||
circpad_state_t *third_st = &circ_client_machine.states[3];
|
circpad_state_t *third_st = &circ_client_machine.states[3];
|
||||||
third_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 4;
|
third_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 4;
|
||||||
third_st->iat_dist.type = CIRCPAD_DIST_GEOMETRIC;
|
third_st->iat_dist.type = CIRCPAD_DIST_GEOMETRIC;
|
||||||
third_st->iat_dist.param1 = min;
|
/* param1 is 'p' (success probability) */
|
||||||
third_st->iat_dist.param2 = max;
|
third_st->iat_dist.param1 = 0.2;
|
||||||
third_st->dist_added_shift_usec = min;
|
third_st->dist_added_shift_usec = min;
|
||||||
third_st->dist_max_sample_usec = max;
|
third_st->dist_max_sample_usec = max;
|
||||||
|
|
||||||
circpad_state_t *fourth_st = &circ_client_machine.states[4];
|
circpad_state_t *fourth_st = &circ_client_machine.states[4];
|
||||||
fourth_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 5;
|
fourth_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 5;
|
||||||
fourth_st->iat_dist.type = CIRCPAD_DIST_WEIBULL;
|
fourth_st->iat_dist.type = CIRCPAD_DIST_WEIBULL;
|
||||||
fourth_st->iat_dist.param1 = min;
|
/* param1 is k, param2 is Lambda */
|
||||||
fourth_st->iat_dist.param2 = max;
|
fourth_st->iat_dist.param1 = 1.5;
|
||||||
|
fourth_st->iat_dist.param2 = 1;
|
||||||
fourth_st->dist_added_shift_usec = min;
|
fourth_st->dist_added_shift_usec = min;
|
||||||
fourth_st->dist_max_sample_usec = max;
|
fourth_st->dist_max_sample_usec = max;
|
||||||
|
|
||||||
circpad_state_t *fifth_st = &circ_client_machine.states[5];
|
circpad_state_t *fifth_st = &circ_client_machine.states[5];
|
||||||
fifth_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 6;
|
fifth_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 6;
|
||||||
fifth_st->iat_dist.type = CIRCPAD_DIST_PARETO;
|
fifth_st->iat_dist.type = CIRCPAD_DIST_PARETO;
|
||||||
fifth_st->iat_dist.param1 = min;
|
/* param1 is sigma, param2 is xi */
|
||||||
fifth_st->iat_dist.param2 = max;
|
fifth_st->iat_dist.param1 = 1;
|
||||||
|
fifth_st->iat_dist.param2 = 5;
|
||||||
fifth_st->dist_added_shift_usec = min;
|
fifth_st->dist_added_shift_usec = min;
|
||||||
fifth_st->dist_max_sample_usec = max;
|
fifth_st->dist_max_sample_usec = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Simple test that the padding delays sampled from a uniform distribution
|
/** Simple test that the padding delays sampled from a uniform distribution
|
||||||
* actually faill within the uniform distribution range. */
|
* actually faill within the uniform distribution range. */
|
||||||
/* TODO: Upgrade this test so that each state tests a different prob
|
|
||||||
* distribution */
|
|
||||||
static void
|
static void
|
||||||
test_circuitpadding_sample_distribution(void *arg)
|
test_circuitpadding_sample_distribution(void *arg)
|
||||||
{
|
{
|
||||||
@ -2159,8 +2162,7 @@ test_circuitpadding_sample_distribution(void *arg)
|
|||||||
MOCK(circpad_machine_schedule_padding,
|
MOCK(circpad_machine_schedule_padding,
|
||||||
circpad_machine_schedule_padding_mock);
|
circpad_machine_schedule_padding_mock);
|
||||||
|
|
||||||
/* Initialize a machine with multiple probability distributions that should
|
/* Initialize a machine with multiple probability distributions */
|
||||||
* return values between 0 and 5 */
|
|
||||||
circpad_machines_init();
|
circpad_machines_init();
|
||||||
helper_circpad_circ_distribution_machine_setup(0, 10);
|
helper_circpad_circ_distribution_machine_setup(0, 10);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user