Commit a65bf32f authored by Matt Traudt's avatar Matt Traudt Committed by Matt Traudt
Browse files

Give ResultError subtypes different freshness reduction factors

A failure to measure a relay is not necessarily that relay's fault. Add
(and use) code that allows different ResultError subtypes to reduce a
result's freshness by different amounts. This way, if a bad result was
not likely to be the relay's fault, it won't be penalized very much.

GH: closes #61
parent ca42026b
......@@ -22,10 +22,6 @@ MIN_TO_RETURN = 50
# Alternatively, we could rewrite best_priority() to not suck so much.
# How much we reduce freshness for results that were non-successful. A larger
# penality reduces freshness more, therefore the relay's priority will be
# better, therefore we'll measure it again sooner.
class RelayPrioritizer:
......@@ -83,9 +79,13 @@ class RelayPrioritizer:
# Reduce the freshness for results containing errors so
# that they are not de-prioritized as much. This way, we
# will come back to them sooner to try again.
log.debug('Cutting freshness for a %s result for %s',
result.type.value, relay.nickname)
freshness *= (1 - ERROR_PENALTY)
assert result.freshness_reduction_factor >= 0.0
assert result.freshness_reduction_factor <= 1.0
log.debug('Cutting freshness for a %s result by %d%% for '
'%s', result.type.value,
result.freshness_reduction_factor * 100,
freshness *= result.freshness_reduction_factor
priority += freshness
relay.priority = priority
# Sort the relays by their priority, with the smallest (best) priority
......@@ -238,6 +238,23 @@ class ResultError(Result):
def type(self):
return _ResultType.Error
def freshness_reduction_factor(self):
When the RelayPrioritizer encounters this Result, how much should it
adjust its freshness? (See RelayPrioritizer.best_priority() for more
information about "freshness")
A higher factor makes the freshness lower (making the Result seem
older). A lower freshness leads to the relay having better priority,
and better priority means it will be measured again sooner.
The value 0.5 was chosen somewhat arbitrarily, but a few weeks of live
network testing verifies that sbws is still able to perform useful
measurements in a reasonable amount of time.
return 0.5
def msg(self):
return self._msg
......@@ -308,6 +325,19 @@ class ResultErrorAuth(ResultError):
def type(self):
return _ResultType.ErrorAuth
def freshness_reduction_factor(self):
Override the default ResultError.freshness_reduction_factor because a
ResultErrorAuth is most likely not the measured relay's fault, so we
shouldn't hurt its priority as much. A higher reduction factor means a
Result's effective freshness is reduced more, which makes the relay's
priority better.
The value 0.9 was chosen somewhat arbitrarily.
return 0.9
def from_dict(d):
assert isinstance(d, dict)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment