mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Merge branch 'bug4011'
This commit is contained in:
commit
8387d8571f
8
changes/bug4011
Normal file
8
changes/bug4011
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
o Major bugfixes:
|
||||||
|
|
||||||
|
- Do not allow the presence of one consensus flavor to keep us from
|
||||||
|
downloading another. Previously, we had one "time to download a
|
||||||
|
consensus" timer, which didn't understand the idea of having one
|
||||||
|
consensus but wanting to download another. Fixes bug 4011; fix on
|
||||||
|
0.2.3.1-alpha.
|
||||||
|
|
@ -89,7 +89,7 @@ static time_t last_networkstatus_download_attempted = 0;
|
|||||||
/** A time before which we shouldn't try to replace the current consensus:
|
/** A time before which we shouldn't try to replace the current consensus:
|
||||||
* this will be at some point after the next consensus becomes valid, but
|
* this will be at some point after the next consensus becomes valid, but
|
||||||
* before the current consensus becomes invalid. */
|
* before the current consensus becomes invalid. */
|
||||||
static time_t time_to_download_next_consensus = 0;
|
static time_t time_to_download_next_consensus[N_CONSENSUS_FLAVORS];
|
||||||
/** Download status for the current consensus networkstatus. */
|
/** Download status for the current consensus networkstatus. */
|
||||||
static download_status_t consensus_dl_status[N_CONSENSUS_FLAVORS];
|
static download_status_t consensus_dl_status[N_CONSENSUS_FLAVORS];
|
||||||
|
|
||||||
@ -1220,19 +1220,24 @@ update_consensus_networkstatus_downloads(time_t now)
|
|||||||
int i;
|
int i;
|
||||||
const or_options_t *options = get_options();
|
const or_options_t *options = get_options();
|
||||||
|
|
||||||
if (!networkstatus_get_live_consensus(now))
|
|
||||||
time_to_download_next_consensus = now; /* No live consensus? Get one now!*/
|
|
||||||
if (time_to_download_next_consensus > now)
|
|
||||||
return; /* Wait until the current consensus is older. */
|
|
||||||
|
|
||||||
for (i=0; i < N_CONSENSUS_FLAVORS; ++i) {
|
for (i=0; i < N_CONSENSUS_FLAVORS; ++i) {
|
||||||
/* XXXX need some way to download unknown flavors if we are caching. */
|
/* XXXX need some way to download unknown flavors if we are caching. */
|
||||||
const char *resource;
|
const char *resource;
|
||||||
consensus_waiting_for_certs_t *waiting;
|
consensus_waiting_for_certs_t *waiting;
|
||||||
|
networkstatus_t *c;
|
||||||
|
|
||||||
if (! we_want_to_fetch_flavor(options, i))
|
if (! we_want_to_fetch_flavor(options, i))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
c = networkstatus_get_latest_consensus_by_flavor(i);
|
||||||
|
if (! (c && c->valid_after <= now && now <= c->valid_until)) {
|
||||||
|
/* No live consensus? Get one now!*/
|
||||||
|
time_to_download_next_consensus[i] = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (time_to_download_next_consensus[i] > now)
|
||||||
|
return; /* Wait until the current consensus is older. */
|
||||||
|
|
||||||
resource = networkstatus_get_flavor_name(i);
|
resource = networkstatus_get_flavor_name(i);
|
||||||
|
|
||||||
if (!download_status_is_ready(&consensus_dl_status[i], now,
|
if (!download_status_is_ready(&consensus_dl_status[i], now,
|
||||||
@ -1284,13 +1289,17 @@ networkstatus_consensus_download_failed(int status_code, const char *flavname)
|
|||||||
#define CONSENSUS_MIN_SECONDS_BEFORE_CACHING 120
|
#define CONSENSUS_MIN_SECONDS_BEFORE_CACHING 120
|
||||||
|
|
||||||
/** Update the time at which we'll consider replacing the current
|
/** Update the time at which we'll consider replacing the current
|
||||||
* consensus. */
|
* consensus of flavor <b>flav</b> */
|
||||||
void
|
static void
|
||||||
update_consensus_networkstatus_fetch_time(time_t now)
|
update_consensus_networkstatus_fetch_time_impl(time_t now, int flav)
|
||||||
{
|
{
|
||||||
const or_options_t *options = get_options();
|
const or_options_t *options = get_options();
|
||||||
networkstatus_t *c = networkstatus_get_live_consensus(now);
|
networkstatus_t *c = networkstatus_get_latest_consensus_by_flavor(flav);
|
||||||
if (c) {
|
const char *flavor = networkstatus_get_flavor_name(flav);
|
||||||
|
if (! we_want_to_fetch_flavor(get_options(), flav))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (c && c->valid_after <= now && now <= c->valid_until) {
|
||||||
long dl_interval;
|
long dl_interval;
|
||||||
long interval = c->fresh_until - c->valid_after;
|
long interval = c->fresh_until - c->valid_after;
|
||||||
long min_sec_before_caching = CONSENSUS_MIN_SECONDS_BEFORE_CACHING;
|
long min_sec_before_caching = CONSENSUS_MIN_SECONDS_BEFORE_CACHING;
|
||||||
@ -1339,22 +1348,36 @@ update_consensus_networkstatus_fetch_time(time_t now)
|
|||||||
tor_assert(c->fresh_until < start);
|
tor_assert(c->fresh_until < start);
|
||||||
/* We must download the next one before c is invalid: */
|
/* We must download the next one before c is invalid: */
|
||||||
tor_assert(start+dl_interval < c->valid_until);
|
tor_assert(start+dl_interval < c->valid_until);
|
||||||
time_to_download_next_consensus = start +crypto_rand_int((int)dl_interval);
|
time_to_download_next_consensus[flav] =
|
||||||
|
start + crypto_rand_int((int)dl_interval);
|
||||||
{
|
{
|
||||||
char tbuf1[ISO_TIME_LEN+1];
|
char tbuf1[ISO_TIME_LEN+1];
|
||||||
char tbuf2[ISO_TIME_LEN+1];
|
char tbuf2[ISO_TIME_LEN+1];
|
||||||
char tbuf3[ISO_TIME_LEN+1];
|
char tbuf3[ISO_TIME_LEN+1];
|
||||||
format_local_iso_time(tbuf1, c->fresh_until);
|
format_local_iso_time(tbuf1, c->fresh_until);
|
||||||
format_local_iso_time(tbuf2, c->valid_until);
|
format_local_iso_time(tbuf2, c->valid_until);
|
||||||
format_local_iso_time(tbuf3, time_to_download_next_consensus);
|
format_local_iso_time(tbuf3, time_to_download_next_consensus[flav]);
|
||||||
log_info(LD_DIR, "Live consensus %s the most recent until %s and will "
|
log_info(LD_DIR, "Live %s consensus %s the most recent until %s and will "
|
||||||
"expire at %s; fetching the next one at %s.",
|
"expire at %s; fetching the next one at %s.",
|
||||||
(c->fresh_until > now) ? "will be" : "was",
|
flavor, (c->fresh_until > now) ? "will be" : "was",
|
||||||
tbuf1, tbuf2, tbuf3);
|
tbuf1, tbuf2, tbuf3);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
time_to_download_next_consensus = now;
|
time_to_download_next_consensus[flav] = now;
|
||||||
log_info(LD_DIR, "No live consensus; we should fetch one immediately.");
|
log_info(LD_DIR, "No live %s consensus; we should fetch one immediately.",
|
||||||
|
flavor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Update the time at which we'll consider replacing the current
|
||||||
|
* consensus of flavor 'flavor' */
|
||||||
|
void
|
||||||
|
update_consensus_networkstatus_fetch_time(time_t now)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < N_CONSENSUS_FLAVORS; ++i) {
|
||||||
|
if (we_want_to_fetch_flavor(get_options(), i))
|
||||||
|
update_consensus_networkstatus_fetch_time_impl(now, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user