diff options
author | Mike Perry <mikeperry-git@fscked.org> | 2010-06-07 21:17:12 -0700 |
---|---|---|
committer | Mike Perry <mikeperry-git@fscked.org> | 2010-06-09 00:22:39 -0700 |
commit | f897154b26ffddf42f8c9b1988dbcb4355222c37 (patch) | |
tree | ba2379a48523c66971890c90758e67c1dc9f708e | |
parent | e3d5b516c635aaee73bace1bac00dade66cd9c22 (diff) | |
download | tor-f897154b26ffddf42f8c9b1988dbcb4355222c37.tar.gz tor-f897154b26ffddf42f8c9b1988dbcb4355222c37.zip |
Make the Xm mode selection a consensus parameter.
-rw-r--r-- | src/or/circuitbuild.c | 16 | ||||
-rw-r--r-- | src/or/or.h | 2 |
2 files changed, 14 insertions, 4 deletions
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index f16c8b6bd9..7dc544d47d 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -116,6 +116,14 @@ circuit_build_times_max_timeouts(void) } static int32_t +circuit_build_times_default_num_xm_modes(void) +{ + int32_t num = networkstatus_get_param(NULL, "cbtnummodes", + CBT_DEFAULT_NUM_XM_MODES); + return num; +} + +static int32_t circuit_build_times_min_circs_to_observe(void) { int32_t num = networkstatus_get_param(NULL, "cbtmincircs", @@ -410,19 +418,20 @@ static build_time_t circuit_build_times_get_xm(circuit_build_times_t *cbt) { build_time_t i, nbins; - build_time_t nth_max_bin[CBT_NUM_XM_MODES]; + build_time_t *nth_max_bin; int32_t bin_counts=0; build_time_t ret = 0; uint32_t *histogram = circuit_build_times_create_histogram(cbt, &nbins); int n=0; - int num_modes = CBT_NUM_XM_MODES; + int num_modes = circuit_build_times_default_num_xm_modes(); // Only use one mode if < 1000 buildtimes. Not enough data // for multiple. if (cbt->total_build_times < CBT_NCIRCUITS_TO_OBSERVE) num_modes = 1; - memset(nth_max_bin, 0, sizeof(nth_max_bin)); + nth_max_bin = (build_time_t*)tor_malloc_zero(num_modes*sizeof(build_time_t)); + for (i = 0; i < nbins; i++) { if (histogram[i] >= histogram[nth_max_bin[0]]) { nth_max_bin[0] = i; @@ -446,6 +455,7 @@ circuit_build_times_get_xm(circuit_build_times_t *cbt) ret /= bin_counts; tor_free(histogram); + tor_free(nth_max_bin); return ret; } diff --git a/src/or/or.h b/src/or/or.h index 49abf552b6..e99b2e91dd 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -3023,7 +3023,7 @@ void entry_guards_free_all(void); #define CBT_BIN_WIDTH ((build_time_t)50) /** Number of modes to use in the weighted-avg computation of Xm */ -#define CBT_NUM_XM_MODES 3 +#define CBT_DEFAULT_NUM_XM_MODES 3 /** A build_time_t is milliseconds */ typedef uint32_t build_time_t; |