diff options
author | George Kadianakis <desnacked@riseup.net> | 2017-02-13 15:32:13 +0200 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-08 20:29:33 -0400 |
commit | f53b72baf7472423f662b49bebde1a88727901fb (patch) | |
tree | 72e59b442c505ed5dc9d8f3b518906d898037747 /src/or/hs_common.c | |
parent | 0f104ddce578c52d604931c595b28aa61a184b40 (diff) | |
download | tor-f53b72baf7472423f662b49bebde1a88727901fb.tar.gz tor-f53b72baf7472423f662b49bebde1a88727901fb.zip |
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@torproject.org>
Diffstat (limited to 'src/or/hs_common.c')
-rw-r--r-- | src/or/hs_common.c | 28 |
1 files changed, 28 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 |