aboutsummaryrefslogtreecommitdiff
path: root/src/feature/hs_common
diff options
context:
space:
mode:
authorGeorge Kadianakis <desnacked@riseup.net>2020-11-02 12:42:08 +0200
committerGeorge Kadianakis <desnacked@riseup.net>2020-11-03 11:12:17 +0200
commitd0be2ae7f99fe1fe4d97f30b0ea565930f63c698 (patch)
treec24b8368dcb8ad097d5a159286a60a4a297d0af0 /src/feature/hs_common
parentf2eff171264595de9a534c01628909d0ba6cb9fb (diff)
downloadtor-d0be2ae7f99fe1fe4d97f30b0ea565930f63c698.tar.gz
tor-d0be2ae7f99fe1fe4d97f30b0ea565930f63c698.zip
Extend get_voting_interval() so that it's callable by relays.
In the past, only authorities and clients had to use that function because of the SRV subsystem. However, because of its use in rep_hist_hs_stats_init() it will now also be used by relays when bootstrapping without a consensus. Make it do something sensible. Another approach (instead of using magic values) would be to wait initialization of HSv3 stats until we get a consensus but that seems messy to schedule. Another approach would be to make dirauth_sched_get_configured_interval() also work for relays (particularly when TestingNetwork is enabled), but that also seems a good amount of work.
Diffstat (limited to 'src/feature/hs_common')
-rw-r--r--src/feature/hs_common/shared_random_client.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/feature/hs_common/shared_random_client.c b/src/feature/hs_common/shared_random_client.c
index c2ea5afe32..2c7d6c8d90 100644
--- a/src/feature/hs_common/shared_random_client.c
+++ b/src/feature/hs_common/shared_random_client.c
@@ -33,12 +33,11 @@ srv_to_control_string(const sr_srv_t *srv)
}
/**
- * If we have no consensus and we are not an authority, assume that this is
- * the voting interval. We should never actually use this: only authorities
- * should be trying to figure out the schedule when they don't have a
- * consensus.
- **/
+ * If we have no consensus and we are not an authority, assume that this is the
+ * voting interval. This can be used while bootstrapping as a relay and we are
+ * asked to initialize HS stats (see rep_hist_hs_stats_init()) */
#define DEFAULT_NETWORK_VOTING_INTERVAL (3600)
+#define TESTING_DEFAULT_NETWORK_VOTING_INTERVAL (20)
/* This is an unpleasing workaround for tests. Our unit tests assume that we
* are scheduling all of our shared random stuff as if we were a directory
@@ -69,11 +68,13 @@ get_voting_interval(void)
* It's better than falling back to the non-consensus case. */
interval = (int)(consensus->fresh_until - consensus->valid_after);
} else {
- /* We should never be reaching this point, since a client should never
- * call this code unless they have some kind of a consensus. All we can
- * do is hope that this network is using the default voting interval. */
- tor_assert_nonfatal_unreached_once();
- interval = DEFAULT_NETWORK_VOTING_INTERVAL;
+ /* We can reach this as a relay when bootstrapping and we are asked to
+ * initialize HS stats (see rep_hist_hs_stats_init()). */
+ if (get_options()->TestingTorNetwork) {
+ interval = TESTING_DEFAULT_NETWORK_VOTING_INTERVAL;
+ } else {
+ interval = DEFAULT_NETWORK_VOTING_INTERVAL;
+ }
}
tor_assert(interval > 0);
return interval;