[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r16994: {tor} Fix 0/0 calculation in get_weighted_fractional_uptime(). (in tor/trunk: . src/or)
Author: nickm
Date: 2008-09-28 11:48:36 -0400 (Sun, 28 Sep 2008)
New Revision: 16994
Modified:
tor/trunk/ChangeLog
tor/trunk/src/or/rephist.c
Log:
Fix 0/0 calculation in get_weighted_fractional_uptime().
Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog 2008-09-28 15:42:56 UTC (rev 16993)
+++ tor/trunk/ChangeLog 2008-09-28 15:48:36 UTC (rev 16994)
@@ -66,6 +66,8 @@
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
Modified: tor/trunk/src/or/rephist.c
===================================================================
--- tor/trunk/src/or/rephist.c 2008-09-28 15:42:56 UTC (rev 16993)
+++ tor/trunk/src/or/rephist.c 2008-09-28 15:48:36 UTC (rev 16994)
@@ -462,6 +462,14 @@
} 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;
}