[tor-commits] [tor/master] prop224: Add descriptor overlap mode function

nickm at torproject.org nickm at torproject.org
Wed Aug 9 00:36:37 UTC 2017


commit f53b72baf7472423f662b49bebde1a88727901fb
Author: George Kadianakis <desnacked at riseup.net>
Date:   Mon Feb 13 15:32:13 2017 +0200

    prop224: Add descriptor overlap mode function
    
    The function has been added but not used except for the unit tests.
    
    Signed-off-by: David Goulet <dgoulet at torproject.org>
---
 src/or/hs_common.c         | 28 ++++++++++++++++++++++++++
 src/or/hs_common.h         |  2 ++
 src/or/hs_service.c        |  2 ++
 src/test/test_hs_service.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 81 insertions(+)

diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 9d42c8f10..631e4b711 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -663,6 +663,34 @@ hs_build_blinded_keypair(const ed25519_keypair_t *kp,
   ed25519_keypair_blind(blinded_kp_out, kp, param);
 }
 
+/* Return true if overlap mode is active given the date in consensus. If
+ * consensus is NULL, then we use the latest live consensus we can find. */
+int
+hs_overlap_mode_is_active(const networkstatus_t *consensus, time_t now)
+{
+  struct tm valid_after_tm;
+
+  if (!consensus) {
+    consensus = networkstatus_get_live_consensus(now);
+    if (!consensus) {
+      return 0;
+    }
+  }
+
+  /* XXX: Futur commits will change this to a slot system so it can be
+   * fine tuned better for testing networks in terms of timings. */
+
+  /* From the spec: "Specifically, when a hidden service fetches a consensus
+   * with "valid-after" between 00:00UTC and 12:00UTC, it goes into
+   * "descriptor overlap" mode." */
+  tor_gmtime_r(&consensus->valid_after, &valid_after_tm);
+  if (valid_after_tm.tm_hour > 0 && valid_after_tm.tm_hour < 12) {
+    return 1;
+  }
+
+  return 0;
+}
+
 /* Initialize the entire HS subsytem. This is called in tor_init() before any
  * torrc options are loaded. Only for >= v3. */
 void
diff --git a/src/or/hs_common.h b/src/or/hs_common.h
index ae9c4e36a..bda91515b 100644
--- a/src/or/hs_common.h
+++ b/src/or/hs_common.h
@@ -144,6 +144,8 @@ uint64_t hs_get_next_time_period_num(time_t now);
 
 link_specifier_t *hs_link_specifier_dup(const link_specifier_t *lspec);
 
+int hs_overlap_mode_is_active(const networkstatus_t *consensus, time_t now);
+
 #ifdef HS_COMMON_PRIVATE
 
 #ifdef TOR_UNIT_TESTS
diff --git a/src/or/hs_service.c b/src/or/hs_service.c
index a890389ca..9114655ed 100644
--- a/src/or/hs_service.c
+++ b/src/or/hs_service.c
@@ -9,8 +9,10 @@
 #define HS_SERVICE_PRIVATE
 
 #include "or.h"
+#include "circpathbias.h"
 #include "circuitlist.h"
 #include "config.h"
+#include "networkstatus.h"
 #include "nodelist.h"
 #include "relay.h"
 #include "rendservice.h"
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 174d07f48..fe4ce4233 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -553,6 +553,53 @@ test_access_service(void *arg)
   hs_free_all();
 }
 
+/** Test that our HS overlap period functions work properly. */
+static void
+test_desc_overlap_period(void *arg)
+{
+  (void) arg;
+  int retval;
+  time_t now = time(NULL);
+  networkstatus_t *dummy_consensus = NULL;
+
+  /* First try with a consensus inside the overlap period */
+  dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t));
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 10:00:00 UTC",
+                              &dummy_consensus->valid_after);
+  tt_int_op(retval, ==, 0);
+
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 1);
+
+  /* Now increase the valid_after so that it goes to 11:00:00 UTC. Overlap
+     period is still active. */
+  dummy_consensus->valid_after += 3600;
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 1);
+
+  /* Now increase the valid_after so that it goes to 11:59:59 UTC. Overlap
+     period is still active. */
+  dummy_consensus->valid_after += 3599;
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 1);
+
+  /* Now increase the valid_after so that it drifts to noon, and check that
+     overlap mode is not active anymore. */
+  dummy_consensus->valid_after += 1;
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 0);
+
+  /* Check that overlap mode is also inactive at 23:59:59 UTC */
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 23:59:59 UTC",
+                              &dummy_consensus->valid_after);
+  tt_int_op(retval, ==, 0);
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 0);
+
+ done:
+  tor_free(dummy_consensus);
+}
+
 struct testcase_t hs_service_tests[] = {
   { "gen_establish_intro_cell", test_gen_establish_intro_cell, TT_FORK,
     NULL, NULL },
@@ -572,6 +619,8 @@ struct testcase_t hs_service_tests[] = {
     NULL, NULL },
   { "access_service", test_access_service, TT_FORK,
     NULL, NULL },
+  { "desc_overlap_period", test_desc_overlap_period, TT_FORK,
+    NULL, NULL },
 
   END_OF_TESTCASES
 };





More information about the tor-commits mailing list