summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Perry <mikeperry-git@fscked.org>2013-01-30 18:40:46 -0400
committerNick Mathewson <nickm@torproject.org>2013-02-01 17:01:12 -0500
commitdfcfb5d17dcb89d51cdfe11ee89cb82791624ee3 (patch)
tree74905d5a4689ddd6d1976a49313a420ae9b9a9f6
parent2b2c7f23f5b36ee01540d40acae1230b38aa66a0 (diff)
downloadtor-dfcfb5d17dcb89d51cdfe11ee89cb82791624ee3.tar.gz
tor-dfcfb5d17dcb89d51cdfe11ee89cb82791624ee3.zip
Refactor the scaling parameter fetching into a single function.
Also, deprecate the torrc options for the scaling values. It's unlikely anyone but developers will ever tweak them, even if we provided a single ratio value.
-rw-r--r--doc/tor.1.txt13
-rw-r--r--src/or/circuitbuild.c83
-rw-r--r--src/or/config.c4
-rw-r--r--src/or/or.h2
4 files changed, 38 insertions, 64 deletions
diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index 5d4b51c185..bdc78eac64 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1238,11 +1238,7 @@ The following options are useful only for clients (that is, if
**PathBiasDropGuards** __NUM__ +
-**PathBiasScaleThreshold** __NUM__ +
-
-**PathBiasMultFactor** __NUM__ +
-
-**PathBiasScaleFactor** __NUM__::
+**PathBiasScaleThreshold** __NUM__::
These options override the default behavior of Tor's (**currently
experimental**) path bias detection algorithm. To try to find broken or
misbehaving guard nodes, Tor looks for nodes where more than a certain
@@ -1256,14 +1252,13 @@ The following options are useful only for clients (that is, if
is set to 1, we disable use of that guard. +
+
When we have seen more than PathBiasScaleThreshold
- circuits through a guard, we scale our observations by
- PathBiasMultFactor/PathBiasScaleFactor, so that new observations don't get
- swamped by old ones. +
+ circuits through a guard, we scale our observations by 0.5 (governed by
+ the consensus) so that new observations don't get swamped by old ones. +
+
By default, or if a negative value is provided for one of these options,
Tor uses reasonable defaults from the networkstatus consensus document.
If no defaults are available there, these options default to 150, .70,
- .50, .30, 0, 300, 1, and 2 respectively.
+ .50, .30, 0, and 300 respectively.
**PathBiasUseThreshold** __NUM__ +
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
index 958e4102ab..4f4f3911d6 100644
--- a/src/or/circuitbuild.c
+++ b/src/or/circuitbuild.c
@@ -1175,38 +1175,31 @@ pathbias_get_scale_threshold(const or_options_t *options)
}
/**
- * The scale factor is the denominator for our scaling
- * of circuit counts for our path bias window.
+ * Compute the path bias scaling ratio from the consensus
+ * parameters pb_multfactor/pb_scalefactor.
*
- * Note that our use of doubles for the path bias state
- * file means that powers of 2 work best here.
+ * Returns a value in (0, 1.0] which we multiply our pathbias
+ * counts with to scale them down.
*/
-static int
-pathbias_get_scale_factor(const or_options_t *options)
-{
-#define DFLT_PATH_BIAS_SCALE_FACTOR 2
- if (options->PathBiasScaleFactor >= 1)
- return options->PathBiasScaleFactor;
- else
- return networkstatus_get_param(NULL, "pb_scalefactor",
- DFLT_PATH_BIAS_SCALE_FACTOR, 1, INT32_MAX);
-}
-
-/**
- * The mult factor is the numerator for our scaling
- * of circuit counts for our path bias window. It
- * allows us to scale by fractions.
- */
-static int
-pathbias_get_mult_factor(const or_options_t *options)
+static double
+pathbias_get_scale_ratio(const or_options_t *options)
{
-#define DFLT_PATH_BIAS_MULT_FACTOR 1
- if (options->PathBiasMultFactor >= 1)
- return options->PathBiasMultFactor;
- else
- return networkstatus_get_param(NULL, "pb_multfactor",
- DFLT_PATH_BIAS_MULT_FACTOR, 1,
- pathbias_get_scale_factor(options));
+ /*
+ * The scale factor is the denominator for our scaling
+ * of circuit counts for our path bias window.
+ *
+ * Note that our use of doubles for the path bias state
+ * file means that powers of 2 work best here.
+ */
+ int denominator = networkstatus_get_param(NULL, "pb_scalefactor",
+ 2, 2, INT32_MAX);
+ /**
+ * The mult factor is the numerator for our scaling
+ * of circuit counts for our path bias window. It
+ * allows us to scale by fractions.
+ */
+ return networkstatus_get_param(NULL, "pb_multfactor",
+ 1, 1, denominator)/((double)denominator);
}
/** The minimum number of circuit usage attempts before we start
@@ -2301,17 +2294,13 @@ pathbias_check_use_rate(entry_guard_t *guard)
/* If we get a ton of circuits, just scale everything down */
if (guard->use_attempts > pathbias_get_scale_use_threshold(options)) {
- const int scale_factor = pathbias_get_scale_factor(options);
- const int mult_factor = pathbias_get_mult_factor(options);
+ double scale_ratio = pathbias_get_scale_ratio(options);
int opened_attempts = pathbias_count_circs_in_states(guard,
PATH_STATE_USE_ATTEMPTED, PATH_STATE_USE_SUCCEEDED);
guard->use_attempts -= opened_attempts;
- guard->use_attempts *= mult_factor;
- guard->use_successes *= mult_factor;
-
- guard->use_attempts /= scale_factor;
- guard->use_successes /= scale_factor;
+ guard->use_attempts *= scale_ratio;
+ guard->use_successes *= scale_ratio;
guard->use_attempts += opened_attempts;
@@ -2449,8 +2438,7 @@ pathbias_check_close_rate(entry_guard_t *guard)
/* If we get a ton of circuits, just scale everything down */
if (guard->circ_attempts > pathbias_get_scale_threshold(options)) {
- const int scale_factor = pathbias_get_scale_factor(options);
- const int mult_factor = pathbias_get_mult_factor(options);
+ double scale_ratio = pathbias_get_scale_ratio(options);
int opened_attempts = pathbias_count_circs_in_states(guard,
PATH_STATE_BUILD_ATTEMPTED, PATH_STATE_BUILD_ATTEMPTED);
int opened_built = pathbias_count_circs_in_states(guard,
@@ -2459,19 +2447,12 @@ pathbias_check_close_rate(entry_guard_t *guard)
guard->circ_attempts -= opened_attempts;
guard->circ_successes -= opened_built;
- guard->circ_attempts *= mult_factor;
- guard->circ_successes *= mult_factor;
- guard->timeouts *= mult_factor;
- guard->successful_circuits_closed *= mult_factor;
- guard->collapsed_circuits *= mult_factor;
- guard->unusable_circuits *= mult_factor;
-
- guard->circ_attempts /= scale_factor;
- guard->circ_successes /= scale_factor;
- guard->timeouts /= scale_factor;
- guard->successful_circuits_closed /= scale_factor;
- guard->collapsed_circuits /= scale_factor;
- guard->unusable_circuits /= scale_factor;
+ guard->circ_attempts *= scale_ratio;
+ guard->circ_successes *= scale_ratio;
+ guard->timeouts *= scale_ratio;
+ guard->successful_circuits_closed *= scale_ratio;
+ guard->collapsed_circuits *= scale_ratio;
+ guard->unusable_circuits *= scale_ratio;
guard->circ_attempts += opened_attempts;
guard->circ_successes += opened_built;
diff --git a/src/or/config.c b/src/or/config.c
index 74b635e850..70d87034a8 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -321,8 +321,8 @@ static config_var_t option_vars_[] = {
V(PathBiasWarnRate, DOUBLE, "-1"),
V(PathBiasExtremeRate, DOUBLE, "-1"),
V(PathBiasScaleThreshold, INT, "-1"),
- V(PathBiasScaleFactor, INT, "-1"),
- V(PathBiasMultFactor, INT, "-1"),
+ OBSOLETE("PathBiasScaleFactor"),
+ OBSOLETE("PathBiasMultFactor"),
V(PathBiasDropGuards, AUTOBOOL, "0"),
OBSOLETE("PathBiasUseCloseCounts"),
diff --git a/src/or/or.h b/src/or/or.h
index 3c962e360b..e5fc06ac39 100644
--- a/src/or/or.h
+++ b/src/or/or.h
@@ -3949,8 +3949,6 @@ typedef struct {
double PathBiasExtremeRate;
int PathBiasDropGuards;
int PathBiasScaleThreshold;
- int PathBiasScaleFactor;
- int PathBiasMultFactor;
/** @} */
/**