summaryrefslogtreecommitdiff
path: root/src/or
diff options
context:
space:
mode:
Diffstat (limited to 'src/or')
-rw-r--r--src/or/hs_common.c28
-rw-r--r--src/or/hs_common.h2
-rw-r--r--src/or/hs_service.c2
3 files changed, 32 insertions, 0 deletions
diff --git a/src/or/hs_common.c b/src/or/hs_common.c
index 9d42c8f105..631e4b7115 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 ae9c4e36a5..bda91515b1 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 a890389cad..9114655edf 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"