]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
prop224: Refactor hs_get_time_period_num() to not use absolute time.
authorGeorge Kadianakis <desnacked@riseup.net>
Mon, 24 Jul 2017 10:31:17 +0000 (13:31 +0300)
committerNick Mathewson <nickm@torproject.org>
Wed, 9 Aug 2017 00:29:34 +0000 (20:29 -0400)
Instead use the SRV protocol duration to calculate the rotation offset
that was previously hardcoded to 12 hours.

src/or/hs_common.c
src/or/hs_common.h

index 0d81063cf77e59ed4d9badb0e9c977ecad798104..0ae196d93e0496be508672a0c171ea6a5e9c8168 100644 (file)
@@ -196,13 +196,18 @@ uint64_t
 hs_get_time_period_num(time_t now)
 {
   uint64_t time_period_num;
+
+  /* Start by calculating minutes since the epoch */
   uint64_t time_period_length = get_time_period_length();
   uint64_t minutes_since_epoch = now / 60;
 
-  /* Now subtract half a day to fit the prop224 time period schedule (see
-   * section [TIME-PERIODS]). */
-  tor_assert(minutes_since_epoch > HS_TIME_PERIOD_ROTATION_OFFSET);
-  minutes_since_epoch -= HS_TIME_PERIOD_ROTATION_OFFSET;
+  /* Apply the rotation offset as specified by prop224 (section
+   * [TIME-PERIODS]), so that new time periods synchronize nicely with SRV
+   * publication */
+  unsigned int time_period_rotation_offset = sr_state_get_phase_duration();
+  time_period_rotation_offset /= 60; /* go from seconds to minutes */
+  tor_assert(minutes_since_epoch > time_period_rotation_offset);
+  minutes_since_epoch -= time_period_rotation_offset;
 
   /* Calculate the time period */
   time_period_num = minutes_since_epoch / time_period_length;
index 519485d576795070a45640b922b1aa8244a94ddf..268a69bb52145414a3da8d7158064c53f530ac07 100644 (file)
@@ -52,8 +52,6 @@
 #define HS_TIME_PERIOD_LENGTH_MIN 30 /* minutes */
 /* The minimum time period length as seen in prop224 section [TIME-PERIODS] */
 #define HS_TIME_PERIOD_LENGTH_MAX (60 * 24 * 10) /* 10 days or 14400 minutes */
-/* The time period rotation offset as seen in prop224 section [TIME-PERIODS] */
-#define HS_TIME_PERIOD_ROTATION_OFFSET (12 * 60) /* minutes */
 
 /* Prefix of the onion address checksum. */
 #define HS_SERVICE_ADDR_CHECKSUM_PREFIX ".onion checksum"