[tor-commits] [tor/master] Fix dist_min_usec documentation and naming.
nickm at torproject.org
nickm at torproject.org
Wed Mar 13 13:37:52 UTC 2019
commit 331a067ae3ce778037650d5283504350979e50ee
Author: George Kadianakis <desnacked at riseup.net>
Date: Mon Feb 25 13:46:58 2019 +0200
Fix dist_min_usec documentation and naming.
---
src/core/or/circuitpadding.c | 13 +++++++------
src/core/or/circuitpadding.h | 15 +++++++++------
src/test/test_circuitpadding.c | 24 ++++++++++++------------
3 files changed, 28 insertions(+), 24 deletions(-)
diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c
index 09dda6da3..7e76cd7ad 100644
--- a/src/core/or/circuitpadding.c
+++ b/src/core/or/circuitpadding.c
@@ -380,17 +380,17 @@ circpad_choose_state_length(circpad_machine_state_t *mi)
*/
static circpad_delay_t
circpad_distribution_sample_iat_delay(const circpad_state_t *state,
- circpad_delay_t min_delay)
+ circpad_delay_t delay_shift)
{
double val = circpad_distribution_sample(state->iat_dist);
/* These comparisons are safe, because the output is in the range
* [0, 2**32), and double has a precision of 53 bits. */
val = MAX(0, val);
- val = MIN(val, state->dist_max_usec);
+ val = MIN(val, state->dist_max_sample_usec);
/* This addition is exact: val is at most 2**32-1, min_delay
* is at most 2**32-1, and doubles have a precision of 53 bits. */
- val += min_delay;
+ val += delay_shift;
/* Clamp the distribution at infinite delay val */
return (circpad_delay_t)MIN(tor_llround(val), CIRCPAD_DELAY_INFINITE);
@@ -420,9 +420,10 @@ circpad_machine_sample_delay(circpad_machine_state_t *mi)
if (state->iat_dist.type != CIRCPAD_DIST_NONE) {
/* Sample from a fixed IAT distribution and return */
- circpad_delay_t min_iat_delay = state->use_rtt_estimate ?
- mi->rtt_estimate_usec + state->dist_min_usec : state->dist_min_usec;
- return circpad_distribution_sample_iat_delay(state, min_iat_delay);
+ circpad_delay_t iat_delay_shift = state->use_rtt_estimate ?
+ mi->rtt_estimate_usec + state->dist_added_shift_usec :
+ state->dist_added_shift_usec;
+ return circpad_distribution_sample_iat_delay(state, iat_delay_shift);
} else if (state->token_removal != CIRCPAD_TOKEN_REMOVAL_NONE) {
/* We have a mutable histogram. Do basic sanity check and apply: */
if (BUG(!mi->histogram) ||
diff --git a/src/core/or/circuitpadding.h b/src/core/or/circuitpadding.h
index d11358a15..4e6454b4a 100644
--- a/src/core/or/circuitpadding.h
+++ b/src/core/or/circuitpadding.h
@@ -309,13 +309,16 @@ typedef struct circpad_state_t {
* results of sampling from this distribution (range_sec is used as a max).
*/
circpad_distribution_t iat_dist;
- /* If a delay probability distribution is used, this represents the minimum
- * delay we can sample from the distribution. */
- circpad_delay_t dist_min_usec;
/* If a delay probability distribution is used, this is used as the max
- * delay we can sample from the distribution.
- */
- circpad_delay_t dist_max_usec;
+ * value we can sample from the distribution. However, RTT measurements and
+ * dist_added_shift gets applied on top of this value to derive the final
+ * padding delay. */
+ circpad_delay_t dist_max_sample_usec;
+ /* If a delay probability distribution is used and this is set, we will add
+ * this value on top of the value sampled from the IAT distribution to
+ * derive the final padding delay (We also add the RTT measurement if it's
+ * enabled.). */
+ circpad_delay_t dist_added_shift_usec;
/**
* The length dist is a parameterized way of encoding how long this
diff --git a/src/test/test_circuitpadding.c b/src/test/test_circuitpadding.c
index 599b7fb24..3570b179b 100644
--- a/src/test/test_circuitpadding.c
+++ b/src/test/test_circuitpadding.c
@@ -2098,48 +2098,48 @@ helper_circpad_circ_distribution_machine_setup(int min, int max)
zero_st->iat_dist.type = CIRCPAD_DIST_UNIFORM;
zero_st->iat_dist.param1 = min;
zero_st->iat_dist.param2 = max;
- zero_st->dist_min_usec = min;
- zero_st->dist_max_usec = max;
+ zero_st->dist_added_shift_usec = min;
+ zero_st->dist_max_sample_usec = max;
circpad_state_t *first_st = &circ_client_machine.states[1];
first_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 2;
first_st->iat_dist.type = CIRCPAD_DIST_LOGISTIC;
first_st->iat_dist.param1 = min;
first_st->iat_dist.param2 = max;
- first_st->dist_min_usec = min;
- first_st->dist_max_usec = max;
+ first_st->dist_added_shift_usec = min;
+ first_st->dist_max_sample_usec = max;
circpad_state_t *second_st = &circ_client_machine.states[2];
second_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 3;
second_st->iat_dist.type = CIRCPAD_DIST_LOG_LOGISTIC;
second_st->iat_dist.param1 = min;
second_st->iat_dist.param2 = max;
- second_st->dist_min_usec = min;
- second_st->dist_max_usec = max;
+ second_st->dist_added_shift_usec = min;
+ second_st->dist_max_sample_usec = max;
circpad_state_t *third_st = &circ_client_machine.states[3];
third_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 4;
third_st->iat_dist.type = CIRCPAD_DIST_GEOMETRIC;
third_st->iat_dist.param1 = min;
third_st->iat_dist.param2 = max;
- third_st->dist_min_usec = min;
- third_st->dist_max_usec = max;
+ third_st->dist_added_shift_usec = min;
+ third_st->dist_max_sample_usec = max;
circpad_state_t *fourth_st = &circ_client_machine.states[4];
fourth_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 5;
fourth_st->iat_dist.type = CIRCPAD_DIST_WEIBULL;
fourth_st->iat_dist.param1 = min;
fourth_st->iat_dist.param2 = max;
- fourth_st->dist_min_usec = min;
- fourth_st->dist_max_usec = max;
+ fourth_st->dist_added_shift_usec = min;
+ fourth_st->dist_max_sample_usec = max;
circpad_state_t *fifth_st = &circ_client_machine.states[5];
fifth_st->next_state[CIRCPAD_EVENT_NONPADDING_RECV] = 6;
fifth_st->iat_dist.type = CIRCPAD_DIST_PARETO;
fifth_st->iat_dist.param1 = min;
fifth_st->iat_dist.param2 = max;
- fifth_st->dist_min_usec = min;
- fifth_st->dist_max_usec = max;
+ fifth_st->dist_added_shift_usec = min;
+ fifth_st->dist_max_sample_usec = max;
}
/** Simple test that the padding delays sampled from a uniform distribution
More information about the tor-commits
mailing list