From f7a3cdc8f27c2306cf06d742af63846c82ebdc56 Mon Sep 17 00:00:00 2001 From: Sebastian Hahn Date: Wed, 9 Mar 2011 11:34:04 +0100 Subject: Use observed instead of declared uptime for HSDir It is important to verify the uptime claim of a relay instead of just trusting it, otherwise it becomes too easy to blackhole a specific hidden service. rephist already has data available that we can use here. Bugfix on 0.2.0.10-alpha. --- src/or/rephist.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/or/rephist.c') diff --git a/src/or/rephist.c b/src/or/rephist.c index 53214d61ef..69001de839 100644 --- a/src/or/rephist.c +++ b/src/or/rephist.c @@ -528,6 +528,20 @@ get_weighted_fractional_uptime(or_history_t *hist, time_t when) return ((double) up) / total; } +/** Return how long the router whose identity digest is id has + * been reachable. Return 0 if the router is unknown or currently deemed + * unreachable. */ +long +rep_hist_get_uptime(const char *id, time_t when) +{ + or_history_t *hist = get_or_history(id); + if (!hist) + return 0; + if (!hist->start_of_run) + return 0; + return when - hist->start_of_run; +} + /** Return an estimated MTBF for the router whose identity digest is * id. Return 0 if the router is unknown. */ double -- cgit v1.2.3-54-g00ecf