Remove the "fuzzy time" code

It was the start of a neat idea, but it only got used in 3 places,
none of which really needed it.
This commit is contained in:
Nick Mathewson 2011-03-25 15:27:06 -04:00
parent fe86be61b6
commit 444e46d96d
5 changed files with 14 additions and 90 deletions

7
changes/kill_ftime Normal file
View File

@ -0,0 +1,7 @@
o Code simplification and refactoring
- Remove the old 'fuzzy time' logic. It was supposed to be used
for handling calculations where we have a known amount of clock
skew and an allowed amount of unknown skew. But we only used it
in three places, and we never adjusted the known/unknown skew
values. This is still something we might want to do someday,
but if we do, we'll want to do it differently.

View File

@ -1510,83 +1510,6 @@ update_approx_time(time_t now)
}
#endif
/* =====
* Fuzzy time
* XXXX022 Use this consistently or rip most of it out.
* ===== */
/* In a perfect world, everybody would run NTP, and NTP would be perfect, so
* if we wanted to know "Is the current time before time X?" we could just say
* "time(NULL) < X".
*
* But unfortunately, many users are running Tor in an imperfect world, on
* even more imperfect computers. Hence, we need to track time oddly. We
* model the user's computer as being "skewed" from accurate time by
* -<b>ftime_skew</b> seconds, such that our best guess of the current time is
* time(NULL)+ftime_skew. We also assume that our measurements of time may
* have up to <b>ftime_slop</b> seconds of inaccuracy; IOW, our window of
* estimate for the current time is now + ftime_skew +/- ftime_slop.
*/
/** Our current estimate of our skew, such that we think the current time is
* closest to time(NULL)+ftime_skew. */
static int ftime_skew = 0;
/** Tolerance during time comparisons, in seconds. */
static int ftime_slop = 60;
/** Set the largest amount of sloppiness we'll allow in fuzzy time
* comparisons. */
void
ftime_set_maximum_sloppiness(int seconds)
{
tor_assert(seconds >= 0);
ftime_slop = seconds;
}
/** Set the amount by which we believe our system clock to differ from
* real time. */
void
ftime_set_estimated_skew(int seconds)
{
ftime_skew = seconds;
}
#if 0
void
ftime_get_window(time_t now, ftime_t *ft_out)
{
ft_out->earliest = now + ftime_skew - ftime_slop;
ft_out->latest = now + ftime_skew + ftime_slop;
}
#endif
/** Return true iff we think that <b>now</b> might be after <b>when</b>. */
int
ftime_maybe_after(time_t now, time_t when)
{
/* It may be after when iff the latest possible current time is after when */
return (now + ftime_skew + ftime_slop) >= when;
}
/** Return true iff we think that <b>now</b> might be before <b>when</b>. */
int
ftime_maybe_before(time_t now, time_t when)
{
/* It may be before when iff the earliest possible current time is before */
return (now + ftime_skew - ftime_slop) < when;
}
/** Return true if we think that <b>now</b> is definitely after <b>when</b>. */
int
ftime_definitely_after(time_t now, time_t when)
{
/* It is definitely after when if the earliest time it could be is still
* after when. */
return (now + ftime_skew - ftime_slop) >= when;
}
/** Return true if we think that <b>now</b> is definitely before <b>when</b>.
*/
int
ftime_definitely_before(time_t now, time_t when)
{
/* It is definitely before when if the latest time it could be is still
* before when. */
return (now + ftime_skew + ftime_slop) < when;
}
/* =====
* Rate limiting
* ===== */

View File

@ -247,16 +247,6 @@ time_t approx_time(void);
void update_approx_time(time_t now);
#endif
/* Fuzzy time. */
void ftime_set_maximum_sloppiness(int seconds);
void ftime_set_estimated_skew(int seconds);
/* typedef struct ftime_t { time_t earliest; time_t latest; } ftime_t; */
/* void ftime_get_window(time_t now, ftime_t *ft_out); */
int ftime_maybe_after(time_t now, time_t when);
int ftime_maybe_before(time_t now, time_t when);
int ftime_definitely_after(time_t now, time_t when);
int ftime_definitely_before(time_t now, time_t when);
/* Rate-limiter */
/** A ratelim_t remembers how often an event is occurring, and how often

View File

@ -1764,7 +1764,11 @@ networkstatus_set_current_consensus(const char *consensus,
write_str_to_file(consensus_fname, consensus, 0);
}
if (ftime_definitely_before(now, current_consensus->valid_after)) {
/** If a consensus appears more than this many seconds before its declared
* valid-after time, declare that our clock is skewed. */
#define EARLY_CONSENSUS_NOTICE_SKEW 60
if (now < current_consensus->valid_after - EARLY_CONSENSUS_NOTICE_SKEW) {
char tbuf[ISO_TIME_LEN+1];
char dbuf[64];
long delta = now - current_consensus->valid_after;

View File

@ -328,7 +328,7 @@ trusted_dirs_remove_old_certs(void)
time_t cert_published;
if (newest == cert)
continue;
expired = ftime_definitely_after(now, cert->expires);
expired = now > cert->expires;
cert_published = cert->cache_info.published_on;
/* Store expired certs for 48 hours after a newer arrives;
*/
@ -520,7 +520,7 @@ authority_certs_fetch_missing(networkstatus_t *status, time_t now)
continue;
cl = get_cert_list(ds->v3_identity_digest);
SMARTLIST_FOREACH(cl->certs, authority_cert_t *, cert, {
if (!ftime_definitely_after(now, cert->expires)) {
if (now < cert->expires) {
/* It's not expired, and we weren't looking for something to
* verify a consensus with. Call it done. */
download_status_reset(&cl->dl_status);