summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2008-09-28 15:48:36 +0000
committerNick Mathewson <nickm@torproject.org>2008-09-28 15:48:36 +0000
commit99755f374d6fa3a7797677f25ff913ea55c89cdd (patch)
treebad6de123f5f5c87fe952bde092a58c5dee98222
parentec56889013444d6a309e701cd98406a8a3ecba80 (diff)
downloadtor-99755f374d6fa3a7797677f25ff913ea55c89cdd.tar.gz
tor-99755f374d6fa3a7797677f25ff913ea55c89cdd.zip
Fix 0/0 calculation in get_weighted_fractional_uptime().
svn:r16994
-rw-r--r--ChangeLog2
-rw-r--r--src/or/rephist.c8
2 files changed, 10 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index aa1abac5fd..b3eb32ed88 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -66,6 +66,8 @@ Changes in version 0.2.1.6-alpha - 2008-09-xx
directory writes. Previously, we had only counted this when we
had met our limits precisely. Fixes bug 824. Patch from by rovv.
Bugfix on 0.2.0.x (??).
+ - Avoid a 0/0 calculation when calculating router uptime at directory
+ authorities. Bugfix on 0.2.0.8-alpha.
o Minor bugfixes (controller):
- Make DNS resolved events into "CLOSED", not "FAILED". Bugfix on
diff --git a/src/or/rephist.c b/src/or/rephist.c
index 76f3165235..8019be7257 100644
--- a/src/or/rephist.c
+++ b/src/or/rephist.c
@@ -462,6 +462,14 @@ get_weighted_fractional_uptime(or_history_t *hist, time_t when)
} else if (hist->start_of_downtime) {
total += (when - hist->start_of_downtime);
}
+
+ if (!total) {
+ /* Avoid calling anybody's uptime infinity (which should be impossible if
+ * the code is working), or NaN (which can happen for any router we haven't
+ * observed up or down yet). */
+ return 0.0;
+ }
+
return ((double) up) / total;
}