mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-12-06 19:41:15 +01:00
Don't set HSDir index if we don't have a live consensus.
We also had to alter the SRV functions to take a consensus as optional input, since we might be setting our HSDir index using a consensus that is currently being processed and won't be returned by the networkstatus_get_live_consensus() function. This change has two results: a) It makes sure we are using a fresh consensus with the right SRV value when we are calculating the HSDir hash ring. b) It ensures that we will not use the sr_get_current/previous() functions when we don't have a consensus which would have falsely triggered the disaster SRV logic.
This commit is contained in:
committed by
Nick Mathewson
parent
440eaa9b22
commit
b89d2fa1db
+30
-8
@@ -1393,11 +1393,22 @@ sr_get_previous_for_control(void)
|
||||
/* Return current shared random value from the latest consensus. Caller can
|
||||
* NOT keep a reference to the returned pointer. Return NULL if none. */
|
||||
const sr_srv_t *
|
||||
sr_get_current(void)
|
||||
sr_get_current(const networkstatus_t *ns)
|
||||
{
|
||||
const networkstatus_t *c = networkstatus_get_latest_consensus();
|
||||
if (c) {
|
||||
return c->sr_info.current_srv;
|
||||
const networkstatus_t *consensus;
|
||||
|
||||
/* Use provided ns else get a live one */
|
||||
if (ns) {
|
||||
consensus = ns;
|
||||
} else {
|
||||
consensus = networkstatus_get_live_consensus(approx_time());
|
||||
}
|
||||
/* Ideally we would never be asked for an SRV without a live consensus. Make
|
||||
* sure this assumption is correct. */
|
||||
tor_assert_nonfatal(consensus);
|
||||
|
||||
if (consensus) {
|
||||
return consensus->sr_info.current_srv;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@@ -1405,11 +1416,22 @@ sr_get_current(void)
|
||||
/* Return previous shared random value from the latest consensus. Caller can
|
||||
* NOT keep a reference to the returned pointer. Return NULL if none. */
|
||||
const sr_srv_t *
|
||||
sr_get_previous(void)
|
||||
sr_get_previous(const networkstatus_t *ns)
|
||||
{
|
||||
const networkstatus_t *c = networkstatus_get_latest_consensus();
|
||||
if (c) {
|
||||
return c->sr_info.previous_srv;
|
||||
const networkstatus_t *consensus;
|
||||
|
||||
/* Use provided ns else get a live one */
|
||||
if (ns) {
|
||||
consensus = ns;
|
||||
} else {
|
||||
consensus = networkstatus_get_live_consensus(approx_time());
|
||||
}
|
||||
/* Ideally we would never be asked for an SRV without a live consensus. Make
|
||||
* sure this assumption is correct. */
|
||||
tor_assert_nonfatal(consensus);
|
||||
|
||||
if (consensus) {
|
||||
return consensus->sr_info.previous_srv;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user