mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
Remove the unused old fuzzy-time code
This commit is contained in:
parent
adc4f678f1
commit
a5289fa794
@ -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
|
||||
* -<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
|
||||
* ===== */
|
||||
|
@ -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>a</b> is definitely after <b>b</b>, even if there
|
||||
* could be up to <b>allow_seconds</b> 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>a</b> is definitely before <b>b</b>, even if there
|
||||
* could be up to <b>allow_seconds</b> 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 */
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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 <b>list</b> name nodes we know about, and add
|
||||
* the nodes for those routers to <b>sl</b>. If <b>must_be_running</b>,
|
||||
* 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
|
||||
* <b>list</b> is an acceptable nickname or hexdigest for <b>router</b>. Else
|
||||
* return 0.
|
||||
|
Loading…
Reference in New Issue
Block a user