[tor-commits] [tor/master] Remove start_usec/range_usec and make equivalent fields for distributions.
nickm at torproject.org
nickm at torproject.org
Wed Mar 13 13:37:52 UTC 2019
commit 98af25e0137f283569aee3537a0ef19cda403426
Author: George Kadianakis <desnacked at riseup.net>
Date: Wed Feb 13 16:17:01 2019 +0200
Remove start_usec/range_usec and make equivalent fields for distributions.
---
src/core/or/circuitpadding.c | 18 +++++++-----------
src/core/or/circuitpadding.h | 25 +++++++------------------
src/test/test_circuitpadding.c | 24 ++++++++++++------------
3 files changed, 26 insertions(+), 41 deletions(-)
diff --git a/src/core/or/circuitpadding.c b/src/core/or/circuitpadding.c
index 0dadc5213..a9c5796ca 100644
--- a/src/core/or/circuitpadding.c
+++ b/src/core/or/circuitpadding.c
@@ -399,17 +399,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 start_usec)
+ circpad_delay_t min_delay)
{
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->range_usec);
+ val = MIN(val, state->dist_max_usec);
- /* This addition is exact: val is at most 2**32-1, start_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 += start_usec;
+ val += min_delay;
/* Clamp the distribution at infinite delay val */
return (circpad_delay_t)MIN(tor_llround(val), CIRCPAD_DELAY_INFINITE);
@@ -429,7 +429,6 @@ circpad_machine_sample_delay(circpad_machine_state_t *mi)
const circpad_hist_token_t *histogram = NULL;
circpad_hist_index_t curr_bin = 0;
circpad_delay_t bin_start, bin_end;
- circpad_delay_t start_usec;
/* These three must all be larger than circpad_hist_token_t, because
* we sum several circpad_hist_token_t values across the histogram */
uint64_t curr_weight = 0;
@@ -438,14 +437,11 @@ circpad_machine_sample_delay(circpad_machine_state_t *mi)
tor_assert(state);
- if (state->use_rtt_estimate)
- start_usec = mi->rtt_estimate_usec+state->start_usec;
- else
- start_usec = state->start_usec;
-
if (state->iat_dist.type != CIRCPAD_DIST_NONE) {
/* Sample from a fixed IAT distribution and return */
- return circpad_distribution_sample_iat_delay(state, start_usec);
+ 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);
} 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 57bd37981..918a7d0dd 100644
--- a/src/core/or/circuitpadding.h
+++ b/src/core/or/circuitpadding.h
@@ -297,24 +297,6 @@ typedef struct circpad_state_t {
* refilling the histogram. */
uint32_t histogram_total_tokens;
- /** Minimum padding delay of this state in microseconds.
- *
- * If histograms are used, this is the left (and right) bound of the first
- * bin (since it has zero width).
- *
- * If a delay probability distribution is used, this represents the minimum
- * delay we can sample from the distribution.
- */
- circpad_delay_t start_usec;
-
- /** If histograms are used, this is the width of the whole histogram in
- * microseconds, and it's used to calculate individual bin width.
- *
- * If a delay probability distribution is used, this is used as the max
- * delay we can sample from the distribution.
- */
- circpad_delay_t range_usec;
-
/**
* Represents a delay probability distribution (aka IAT distribution). It's a
* parametrized way of encoding inter-packet delay information in
@@ -327,6 +309,13 @@ 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;
/**
* 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 12a07fa95..63d8f8e09 100644
--- a/src/test/test_circuitpadding.c
+++ b/src/test/test_circuitpadding.c
@@ -2067,48 +2067,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->start_usec = min;
- zero_st->range_usec = max;
+ zero_st->dist_min_usec = min;
+ zero_st->dist_max_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->start_usec = min;
- first_st->range_usec = max;
+ first_st->dist_min_usec = min;
+ first_st->dist_max_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->start_usec = min;
- second_st->range_usec = max;
+ second_st->dist_min_usec = min;
+ second_st->dist_max_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->start_usec = min;
- third_st->range_usec = max;
+ third_st->dist_min_usec = min;
+ third_st->dist_max_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->start_usec = min;
- fourth_st->range_usec = max;
+ fourth_st->dist_min_usec = min;
+ fourth_st->dist_max_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->start_usec = min;
- fifth_st->range_usec = max;
+ fifth_st->dist_min_usec = min;
+ fifth_st->dist_max_usec = max;
}
/** Simple test that the padding delays sampled from a uniform distribution
More information about the tor-commits
mailing list