[tor-commits] [tor/maint-0.2.2] Remove the "fuzzy time" code

nickm at torproject.org nickm at torproject.org
Thu Apr 7 16:04:47 UTC 2011


commit 444e46d96d05c3e12eca02769512c74f2eb16b48
Author: Nick Mathewson <nickm at torproject.org>
Date:   Fri Mar 25 15:27:06 2011 -0400

    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.
---
 changes/kill_ftime     |    7 ++++
 src/common/util.c      |   77 ------------------------------------------------
 src/common/util.h      |   10 ------
 src/or/networkstatus.c |    6 +++-
 src/or/routerlist.c    |    4 +-
 5 files changed, 14 insertions(+), 90 deletions(-)

diff --git a/changes/kill_ftime b/changes/kill_ftime
new file mode 100644
index 0000000..47f4769
--- /dev/null
+++ b/changes/kill_ftime
@@ -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.
diff --git a/src/common/util.c b/src/common/util.c
index abd87ea..38c0ad0 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -1511,83 +1511,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
  * ===== */
 
diff --git a/src/common/util.h b/src/common/util.h
index 3736237..6b54856 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -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
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 687ac03..155dffe 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -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;
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 4421d5c..2dca578 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -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);





More information about the tor-commits mailing list