[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] prop224: Refactor the overlap function to not use absolute time.



commit 2e5a2d64bd4d26323a226d1069b960b28bd25440
Author: George Kadianakis <desnacked@xxxxxxxxxx>
Date:   Tue Jul 18 16:06:12 2017 +0300

    prop224: Refactor the overlap function to not use absolute time.
    
    We consider to be in overlap mode when we are in the period of time between a
    fresh SRV and the beginning of the new time period (in the normal network this
    is between 00:00 and 12:00 UTC). This commit edits that function to use the
    above semantic logic instead of absolute times.
    
    Signed-off-by: David Goulet <dgoulet@xxxxxxxxxxxxxx>
---
 src/or/hs_common.c         | 19 ++++++------
 src/test/test_hs_common.c  | 72 ++++++++++++++++++++++++++++++++++++++++++++--
 src/test/test_hs_service.c |  6 ++++
 3 files changed, 86 insertions(+), 11 deletions(-)

diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 9c3d2c171..20b470ff6 100644
--- a/src/or/hs_common.c
+++ b/src/or/hs_common.c
@@ -908,7 +908,8 @@ hs_build_blinded_keypair(const ed25519_keypair_t *kp,
 MOCK_IMPL(int,
 hs_overlap_mode_is_active, (const networkstatus_t *consensus, time_t now))
 {
-  struct tm valid_after_tm;
+  time_t valid_after;
+  time_t srv_start_time, tp_start_time;
 
   if (!consensus) {
     consensus = networkstatus_get_live_consensus(now);
@@ -917,16 +918,18 @@ hs_overlap_mode_is_active, (const networkstatus_t *consensus, time_t now))
     }
   }
 
-  /* XXX: Futur commits will change this to a slot system so it can be
-   * fine tuned better for testing networks in terms of timings. */
+  /* We consider to be in overlap mode when we are in the period of time
+   * between a fresh SRV and the beginning of the new time period (in the
+   * normal network this is between 00:00 (inclusive) and 12:00 UTC
+   * (exclusive)) */
+  valid_after = consensus->valid_after;
+  srv_start_time =sr_state_get_start_time_of_current_protocol_run(valid_after);
+  tp_start_time = hs_get_start_time_of_next_time_period(srv_start_time);
 
-  /* 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) {
+  if (valid_after >= srv_start_time && valid_after < tp_start_time) {
     return 1;
   }
+
   return 0;
 }
 
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index e41d68d42..a5c499112 100644
--- a/src/test/test_hs_common.c
+++ b/src/test/test_hs_common.c
@@ -200,9 +200,9 @@ test_desc_overlap_period(void *arg)
   time_t now = time(NULL);
   networkstatus_t *dummy_consensus = NULL;
 
-  /* First try with a consensus inside the overlap period */
+  /* First try with a consensus just inside the overlap period */
   dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t));
-  retval = parse_rfc1123_time("Wed, 13 Apr 2016 10:00:00 UTC",
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:00:00 UTC",
                               &dummy_consensus->valid_after);
   tt_int_op(retval, ==, 0);
 
@@ -211,7 +211,7 @@ test_desc_overlap_period(void *arg)
 
   /* Now increase the valid_after so that it goes to 11:00:00 UTC. Overlap
      period is still active. */
-  dummy_consensus->valid_after += 3600;
+  dummy_consensus->valid_after += 3600*11;
   retval = hs_overlap_mode_is_active(dummy_consensus, now);
   tt_int_op(retval, ==, 1);
 
@@ -238,6 +238,70 @@ test_desc_overlap_period(void *arg)
   tor_free(dummy_consensus);
 }
 
+/* Test the overlap period functions on a testnet with altered voting
+ * schedule */
+static void
+test_desc_overlap_period_testnet(void *arg)
+{
+  int retval;
+  time_t now = approx_time();
+  networkstatus_t *dummy_consensus = NULL;
+  or_options_t *options = get_options_mutable();
+
+  (void) arg;
+
+  /* Set the testnet option and a 10-second voting interval */
+  options->TestingTorNetwork = 1;
+  options->V3AuthVotingInterval = 10;
+  options->TestingV3AuthInitialVotingInterval = 10;
+
+  dummy_consensus = tor_malloc_zero(sizeof(networkstatus_t));
+
+  /* A 10-second voting interval means that the lengths of an SRV run and of a
+   * time period are both 10*24 seconds (4 minutes). The SRV gets published at
+   * 00:00:00 and the TP starts at 00:02:00 (rotation offset: 2 mins). Those
+   * two minutes between SRV publish and TP start is the overlap period
+   * window. Let's test it: */
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00: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);
+
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:01:59 UTC",
+                              &dummy_consensus->valid_after);
+  tt_int_op(retval, ==, 0);
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 1);
+
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:02:00 UTC",
+                              &dummy_consensus->valid_after);
+  tt_int_op(retval, ==, 0);
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 0);
+
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:04: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);
+
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:05:59 UTC",
+                              &dummy_consensus->valid_after);
+  tt_int_op(retval, ==, 0);
+  retval = hs_overlap_mode_is_active(dummy_consensus, now);
+  tt_int_op(retval, ==, 1);
+
+  retval = parse_rfc1123_time("Wed, 13 Apr 2016 00:06:00 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_common_tests[] = {
   { "build_address", test_build_address, TT_FORK,
     NULL, NULL },
@@ -249,6 +313,8 @@ struct testcase_t hs_common_tests[] = {
     TT_FORK, NULL, NULL },
   { "desc_overlap_period", test_desc_overlap_period, TT_FORK,
     NULL, NULL },
+  { "desc_overlap_period_testnet", test_desc_overlap_period_testnet, TT_FORK,
+    NULL, NULL },
 
   END_OF_TESTCASES
 };
diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c
index 1b8d8252e..30f1682d8 100644
--- a/src/test/test_hs_service.c
+++ b/src/test/test_hs_service.c
@@ -936,6 +936,8 @@ test_rotate_descriptors(void *arg)
    * overlap check doesn't care about the year. */
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
                            &mock_ns.valid_after);
+  ret = parse_rfc1123_time("Sat, 26 Oct 1985 14:00:00 UTC",
+                           &mock_ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
 
   /* Create a service with a default descriptor and state. It's added to the
@@ -954,6 +956,8 @@ test_rotate_descriptors(void *arg)
   /* Entering an overlap period. */
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 01:00:00 UTC",
                            &mock_ns.valid_after);
+  ret = parse_rfc1123_time("Sat, 26 Oct 1985 02:00:00 UTC",
+                           &mock_ns.fresh_until);
   tt_int_op(ret, OP_EQ, 0);
   desc_next = service_descriptor_new();
   desc_next->next_upload_time = 42; /* Our marker to recognize it. */
@@ -977,6 +981,8 @@ test_rotate_descriptors(void *arg)
   /* Going out of the overlap period. */
   ret = parse_rfc1123_time("Sat, 26 Oct 1985 12:00:00 UTC",
                            &mock_ns.valid_after);
+  ret = parse_rfc1123_time("Sat, 26 Oct 1985 13:00:00 UTC",
+                           &mock_ns.fresh_until);
   /* This should reset the state and not touch the current descriptor. */
   tt_int_op(ret, OP_EQ, 0);
   rotate_all_descriptors(now);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits