mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Make the Xm mode selection a consensus parameter.
This commit is contained in:
+13
-3
@@ -115,6 +115,14 @@ circuit_build_times_max_timeouts(void)
|
||||
return num;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user