aboutsummaryrefslogtreecommitdiff
path: root/src/or/dirserv.c
diff options
context:
space:
mode:
authorSebastian Hahn <sebastian@torproject.org>2011-03-09 11:34:04 +0100
committerSebastian Hahn <sebastian@torproject.org>2011-03-11 18:44:35 +0100
commitf7a3cdc8f27c2306cf06d742af63846c82ebdc56 (patch)
tree7b276a43f4ea8ce0baf8e111523125333fd71e6f /src/or/dirserv.c
parent48c4d532814ae4fdbf07635e57911bdf0e962b75 (diff)
downloadtor-f7a3cdc8f27c2306cf06d742af63846c82ebdc56.tar.gz
tor-f7a3cdc8f27c2306cf06d742af63846c82ebdc56.zip
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.
Diffstat (limited to 'src/or/dirserv.c')
-rw-r--r--src/or/dirserv.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c
index aeeab45383..40136a18e3 100644
--- a/src/or/dirserv.c
+++ b/src/or/dirserv.c
@@ -43,6 +43,8 @@
extern time_t time_of_process_start; /* from main.c */
+extern long stats_n_seconds_working; /* from main.c */
+
/** Do we need to regenerate the v1 directory when someone asks for it? */
static time_t the_directory_is_dirty = 1;
/** Do we need to regenerate the v1 runningrouters document when somebody
@@ -1775,7 +1777,22 @@ dirserv_thinks_router_is_unreliable(time_t now,
static int
dirserv_thinks_router_is_hs_dir(routerinfo_t *router, time_t now)
{
- long uptime = real_uptime(router, now);
+
+ long uptime;
+
+ /* If we haven't been running for at least
+ * get_options()->MinUptimeHidServDirectoryV2 seconds, we can't
+ * have accurate data telling us a relay has been up for at least
+ * that long. We also want to allow a bit of slack: Reachability
+ * tests aren't instant. If we haven't been running long enough,
+ * trust the relay. */
+
+ if (stats_n_seconds_working >
+ get_options()->MinUptimeHidServDirectoryV2 * 1.1)
+ uptime = MIN(rep_hist_get_uptime(router->cache_info.identity_digest, now),
+ real_uptime(router, now));
+ else
+ uptime = real_uptime(router, now);
/* XXX We shouldn't need to check dir_port, but we do because of
* bug 1693. In the future, once relays set wants_to_be_hs_dir