aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_hs_common.c
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2017-07-18 16:06:12 +0300
committerNick Mathewson <nickm@torproject.org>2017-08-08 20:29:34 -0400
commit2e5a2d64bd4d26323a226d1069b960b28bd25440 (patch)
tree4482242eed9d5448e32ea69091fcc82083156edb /src/test/test_hs_common.c
parent6c00bd1f10f4683824deeaa7dd8a23aaf6b9a40e (diff)
downloadtor-2e5a2d64bd4d26323a226d1069b960b28bd25440.tar.gz
tor-2e5a2d64bd4d26323a226d1069b960b28bd25440.zip
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@torproject.org>
Diffstat (limited to 'src/test/test_hs_common.c')
-rw-r--r--src/test/test_hs_common.c72
1 files changed, 69 insertions, 3 deletions
diff --git a/src/test/test_hs_common.c b/src/test/test_hs_common.c
index e41d68d42e..a5c499112e 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
};