From a5289fa79442896b87c2f5dd59eed4289f99c5e4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Fri, 15 Oct 2010 11:16:42 -0400 Subject: [PATCH] Remove the unused old fuzzy-time code --- src/common/util.c | 77 ------------------------------------------ src/common/util.h | 24 ++++++++----- src/or/networkstatus.c | 2 +- src/or/routerlist.c | 59 ++------------------------------ 4 files changed, 20 insertions(+), 142 deletions(-) diff --git a/src/common/util.c b/src/common/util.c index 7af89d917c..16e7370239 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -1502,83 +1502,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 - * -ftime_skew 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 ftime_slop 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 now might be after when. */ -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 now might be before when. */ -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 now is definitely after when. */ -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 now is definitely before when. - */ -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 * ===== */ diff --git a/src/common/util.h b/src/common/util.h index 8c2a9be325..633c613d43 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -248,14 +248,22 @@ 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); + +/** Return true iff a is definitely after b, even if there + * could be up to allow_seconds of skew in one of them. */ +static INLINE int +time_definitely_after(time_t a, time_t b, int allow_skew) +{ + return a-allow_skew > b; +} + +/** Return true iff a is definitely before b, even if there + * could be up to allow_seconds of skew in one of them. */ +static INLINE int +time_definitely_before(time_t a, time_t b, int allow_skew) +{ + return a+allow_skew < b; +} /* Rate-limiter */ diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c index 2a3fb839f2..2361faabf2 100644 --- a/src/or/networkstatus.c +++ b/src/or/networkstatus.c @@ -1800,7 +1800,7 @@ networkstatus_set_current_consensus(const char *consensus, write_str_to_file(consensus_fname, consensus, 0); } - if (ftime_definitely_before(now, c->valid_after)) { + if (time_definitely_before(now, c->valid_after, 60)) { char tbuf[ISO_TIME_LEN+1]; char dbuf[64]; long delta = now - c->valid_after; diff --git a/src/or/routerlist.c b/src/or/routerlist.c index ccd7dc1237..94d59e3aa0 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -315,6 +315,7 @@ trusted_dirs_remove_old_certs(void) time_t now = time(NULL); #define DEAD_CERT_LIFETIME (2*24*60*60) #define OLD_CERT_LIFETIME (7*24*60*60) +#define CERT_EXPIRY_SKEW (60*60) if (!trusted_dir_certs) return; @@ -331,7 +332,7 @@ trusted_dirs_remove_old_certs(void) time_t cert_published; if (newest == cert) continue; - expired = ftime_definitely_after(now, cert->expires); + expired = time_definitely_after(now, cert->expires, CERT_EXPIRY_SKEW); cert_published = cert->cache_info.published_on; /* Store expired certs for 48 hours after a newer arrives; */ @@ -523,7 +524,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 (! time_definitely_after(now, cert->expires, CERT_EXPIRY_SKEW)) { /* 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); @@ -1445,60 +1446,6 @@ nodes_in_same_family(const node_t *node1, const node_t *node2) return 0; } -#if 0 -/** Given a (possibly NULL) comma-and-whitespace separated list of nicknames, - * see which nicknames in list name nodes we know about, and add - * the nodes for those routers to sl. If must_be_running, - * only include routers that we think are running. - * Warn if any non-Named routers are specified by nickname. - */ -static void -add_nickname_list_to_smartlist(smartlist_t *sl, const char *list, - int must_be_running) -{ /*XXXX MOVE or Kill. */ - /*XXXX this is only used in one place. Can we kill it?*/ - const node_t *node; - const routerinfo_t *router; - smartlist_t *nickname_list; - int have_dir_info = router_have_minimum_dir_info(); - - if (!list) - return; /* nothing to do */ - tor_assert(sl); - - nickname_list = smartlist_create(); - if (!warned_nicknames) - warned_nicknames = smartlist_create(); - - smartlist_split_string(nickname_list, list, ",", - SPLIT_SKIP_SPACE|SPLIT_IGNORE_BLANK, 0); - - SMARTLIST_FOREACH_BEGIN(nickname_list, const char *, nick) { - int warned; - if (!is_legal_nickname_or_hexdigest(nick)) { - log_warn(LD_CONFIG, "Nickname '%s' is misformed; skipping", nick); - continue; - } - node = node_get_by_nickname(nick, 1); - router = node->ri; - warned = smartlist_string_isin(warned_nicknames, nick); - if (node) { - if (!must_be_running || node->is_running) { - smartlist_add(sl,(void*)node); - } - } else if (!router_get_consensus_status_by_nickname(nick,1)) { - if (!warned) { - log_fn(have_dir_info ? LOG_WARN : LOG_INFO, LD_CONFIG, - "Nickname list includes '%s' which isn't a known router.",nick); - smartlist_add(warned_nicknames, tor_strdup(nick)); - } - } - } SMARTLIST_FOREACH_END(nick); - SMARTLIST_FOREACH(nickname_list, char *, nick, tor_free(nick)); - smartlist_free(nickname_list); -} -#endif - /** Return 1 iff any member of the (possibly NULL) comma-separated list * list is an acceptable nickname or hexdigest for router. Else * return 0.