[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [tor/master] Handle negative run lengths in wfu/mtbf calculations
commit 5a9903b9e09697ac131c841310dd82eebcca02e0
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date: Mon Nov 22 12:39:22 2010 -0500
Handle negative run lengths in wfu/mtbf calculations
---
changes/bug1035 | 5 +++++
src/or/rephist.c | 22 +++++++++++++++-------
2 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/changes/bug1035 b/changes/bug1035
index 4b62b46..041e3b3 100644
--- a/changes/bug1035
+++ b/changes/bug1035
@@ -4,4 +4,9 @@
treat it as having any downtime for the purposes of stability
calculation, whereas clients would experience downtime since the
IP could take a while to propagate to them. Resolves issue 1035.
+ o Minor bugfixes (authorities)
+ - Try to be more robust to hops back in time when calculating
+ router stability. Previously, if a run of uptime or downtime
+ appeared to be negative, the calculation could give incorrect
+ results. Bugfix on 0.2.0.6-alpha.
diff --git a/src/or/rephist.c b/src/or/rephist.c
index a0c9c9f..e59fcb5 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -380,12 +380,20 @@ rep_hist_note_router_unreachable(const char *id, time_t when)
long run_length = when - hist->start_of_run;
format_local_iso_time(tbuf, hist->start_of_run);
- hist->weighted_run_length += run_length;
hist->total_run_weights += 1.0;
hist->start_of_run = 0;
- hist->weighted_uptime += run_length;
- hist->total_weighted_time += run_length;
+ if (run_length < 0) {
+ unsigned long penalty = -run_length;
+#define SUBTRACT_CLAMPED(var, penalty) \
+ do { (var) = (var) < (penalty) ? 0 : (var) - (penalty); } while (0)
+ SUBTRACT_CLAMPED(hist->weighted_run_length, penalty);
+ SUBTRACT_CLAMPED(hist->weighted_uptime, penalty);
+ } else {
+ hist->weighted_run_length += run_length;
+ hist->weighted_uptime += run_length;
+ hist->total_weighted_time += run_length;
+ }
was_running = 1;
log_info(LD_HIST, "Router %s is now non-Running: it had previously been "
"Running since %s. Its total weighted uptime is %lu/%lu.",
@@ -458,7 +466,7 @@ rep_hist_downrate_old_runs(time_t now)
static double
get_stability(or_history_t *hist, time_t when)
{
- unsigned long total = hist->weighted_run_length;
+ long total = hist->weighted_run_length;
double total_weights = hist->total_run_weights;
if (hist->start_of_run) {
@@ -494,8 +502,8 @@ get_total_weighted_time(or_history_t *hist, time_t when)
static double
get_weighted_fractional_uptime(or_history_t *hist, time_t when)
{
- unsigned long total = hist->total_weighted_time;
- unsigned long up = hist->weighted_uptime;
+ long total = hist->total_weighted_time;
+ long up = hist->weighted_uptime;
if (hist->start_of_run) {
long run_length = (when - hist->start_of_run);
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits