diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-10-18 14:19:56 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-10-18 14:19:56 +0000 |
commit | 8f21a0a0b7e695d824201f19b758bf140f4001f3 (patch) | |
tree | 6534389c5b641054335da25ec3206335be33a684 /src/or | |
parent | c96167a6bdd59aac767c37631443d6cdd016bb1c (diff) | |
download | tor-8f21a0a0b7e695d824201f19b758bf140f4001f3.tar tor-8f21a0a0b7e695d824201f19b758bf140f4001f3.tar.gz |
r15907@catbus: nickm | 2007-10-18 10:18:53 -0400
Fix up logic for choosing the time at which to download a consensus: Never attempt it when the current consensus is still the most recent.
svn:r12020
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/networkstatus.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index a93001146..eac77f2f0 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -761,21 +761,24 @@ update_consensus_networkstatus_fetch_time(time_t now) /* XXXX020 call this when DirPort switches on or off. NMNM */ networkstatus_vote_t *c = networkstatus_get_live_consensus(now); if (c) { + long dl_interval; + long interval = c->fresh_until - c->valid_after; time_t start; - long interval; if (dirserver_mode(options)) { - start = c->valid_after + 120; /*XXXX020 make this a macro. */ - /* XXXX020 too much magic. */ - interval = (c->fresh_until - c->valid_after) / 2; + start = c->fresh_until + 120; /*XXXX020 make this a macro. */ + dl_interval = interval/2; } else { - start = c->fresh_until; + start = c->fresh_until + (interval*3)/4; /* XXXX020 too much magic. */ - interval = (c->valid_until - c->fresh_until) * 7 / 8; + dl_interval = (c->valid_until - start) * 7 / 8; } - if (interval < 1) - interval = 1; - tor_assert(start+interval < c->valid_until); - time_to_download_next_consensus = start + crypto_rand_int(interval); + if (dl_interval < 1) + dl_interval = 1; + /* We must not try to replace c while it's still the most valid: */ + tor_assert(c->fresh_until < start); + /* We must download the next one before c is invalid: */ + tor_assert(start+dl_interval < c->valid_until); + time_to_download_next_consensus = start + crypto_rand_int(dl_interval); { char tbuf[ISO_TIME_LEN+1]; format_local_iso_time(tbuf, time_to_download_next_consensus); |