summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Perry <mikeperry-git@fscked.org>2009-08-28 02:05:02 -0700
committerMike Perry <mikeperry-git@fscked.org>2009-09-16 15:51:15 -0700
commit411b60325b9b21bb73d9b3637a726d6394b5c624 (patch)
treef232f21aea49a80fb53d2e5f3b9ae5a9695a8c9a /src
parentb52bce91fc25d29f1d1a7b5a32076eadd7005d2f (diff)
downloadtor-411b60325b9b21bb73d9b3637a726d6394b5c624.tar.gz
tor-411b60325b9b21bb73d9b3637a726d6394b5c624.zip
Factor out the pretimeout handling code.
We need to also call it if we're going to calculate alpha after a normal circuit build.
Diffstat (limited to 'src')
-rw-r--r--src/or/circuitbuild.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index ee9dce2b38..b0bc8404b0 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -301,8 +301,7 @@ circuit_build_times_calculate_timeout(circuit_build_times_t *cbt,
/* Pareto CDF */
double
-circuit_build_times_cdf(circuit_build_times_t *cbt,
- double x)
+circuit_build_times_cdf(circuit_build_times_t *cbt, double x)
{
double ret = 1.0-pow(cbt->Xm/x,cbt->alpha);
tor_assert(0 <= ret && ret <= 1.0);
@@ -360,6 +359,23 @@ circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
cbt->alpha = ln(1.0-quantile)/(ln(cbt->Xm)-ln(timeout));
}
+static void
+circuit_build_times_count_pretimeouts(circuit_build_times_t *cbt)
+{
+ /* Store a timeout as a random position on this curve. */
+ if (cbt->pre_timeouts) {
+ cbt->Xm = circuit_build_times_min(cbt);
+ // Use current timeout to get an estimate on alpha
+ circuit_build_times_initial_alpha(cbt,
+ 1.0-((double)cbt->pre_timeouts)/cbt->total_build_times,
+ get_options()->CircuitBuildTimeout*1000);
+ while (cbt->pre_timeouts-- != 0) {
+ circuit_build_times_add_timeout_worker(cbt);
+ }
+ cbt->pre_timeouts = 0;
+ }
+}
+
/**
* Store a timeout as a synthetic value
*/
@@ -376,19 +392,7 @@ circuit_build_times_add_timeout(circuit_build_times_t *cbt)
return;
}
- /* Store a timeout as a random position on this curve */
- if (cbt->pre_timeouts) {
- cbt->Xm = circuit_build_times_min(cbt);
- // Use current timeout to get an estimate on alpha
- circuit_build_times_initial_alpha(cbt,
- 1.0-((double)cbt->pre_timeouts)/cbt->total_build_times,
- get_options()->CircuitBuildTimeout*1000);
- while (cbt->pre_timeouts-- != 0) {
- circuit_build_times_add_timeout_worker(cbt);
- }
- }
-
- cbt->pre_timeouts = 0;
+ circuit_build_times_count_pretimeouts(cbt);
circuit_build_times_add_timeout_worker(cbt);
}
@@ -405,6 +409,7 @@ circuit_build_times_set_timeout(circuit_build_times_t *cbt)
return;
}
+ circuit_build_times_count_pretimeouts(cbt);
circuit_build_times_update_alpha(cbt);
timeout = circuit_build_times_calculate_timeout(cbt,
BUILDTIMEOUT_QUANTILE_CUTOFF);