[tor-commits] [tor/master] Change interface of router_descriptor_is_too_old().

nickm at torproject.org nickm at torproject.org
Wed Jul 16 13:34:44 UTC 2014


commit b74442db944be074785ce9590c34358959d7650a
Author: George Kadianakis <desnacked at riseup.net>
Date:   Wed Jul 9 19:20:41 2014 +0300

    Change interface of router_descriptor_is_too_old().
---
 src/or/routerlist.c        |   11 ++++++-----
 src/or/routerlist.h        |    3 ++-
 src/test/test_entrynodes.c |   12 +++++++-----
 3 files changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index bf4aff3..04d43e4 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -3292,12 +3292,12 @@ routerlist_reset_warnings(void)
   networkstatus_reset_warnings();
 }
 
-/** Return 1 if the signed descriptor of this router is too old to be used.
- *  Otherwise return 0. */
+/** Return 1 if the signed descriptor of this router is older than
+ *  <b>seconds</b> seconds.  Otherwise return 0. */
 MOCK_IMPL(int,
-router_descriptor_is_too_old,(const routerinfo_t *router))
+router_descriptor_is_older_than,(const routerinfo_t *router, int seconds))
 {
-  return router->cache_info.published_on < time(NULL)-OLD_ROUTER_DESC_MAX_AGE;
+  return router->cache_info.published_on < time(NULL) - seconds;
 }
 
 /** Add <b>router</b> to the routerlist, if we don't already have it.  Replace
@@ -3468,7 +3468,8 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
     }
   }
 
-  if (!in_consensus && from_cache && router_descriptor_is_too_old(router)) {
+  if (!in_consensus && from_cache &&
+      router_descriptor_is_older_than(router, OLD_ROUTER_DESC_MAX_AGE)) {
     *msg = "Router descriptor was really old.";
     routerinfo_free(router);
     return ROUTER_WAS_NOT_NEW;
diff --git a/src/or/routerlist.h b/src/or/routerlist.h
index adf5d32..52f2303 100644
--- a/src/or/routerlist.h
+++ b/src/or/routerlist.h
@@ -213,7 +213,8 @@ STATIC int choose_array_element_by_weight(const u64_dbl_t *entries,
 STATIC void scale_array_elements_to_u64(u64_dbl_t *entries, int n_entries,
                                         uint64_t *total_out);
 
-MOCK_DECL(int, router_descriptor_is_too_old, (const routerinfo_t *router));
+MOCK_DECL(int, router_descriptor_is_older_than, (const routerinfo_t *router,
+                                                 int seconds));
 #endif
 
 #endif
diff --git a/src/test/test_entrynodes.c b/src/test/test_entrynodes.c
index 09a847f..c9b8321 100644
--- a/src/test/test_entrynodes.c
+++ b/src/test/test_entrynodes.c
@@ -35,11 +35,13 @@ get_or_state_replacement(void)
   return dummy_state;
 }
 
-/* NOP replacement for router_descriptor_is_too_old() */
+/* NOP replacement for router_descriptor_is_older_than() */
 static int
-router_descriptor_is_too_old_replacement(const routerinfo_t *router)
+router_descriptor_is_older_than_replacement(const routerinfo_t *router,
+                                            int seconds)
 {
   (void) router;
+  (void) seconds;
   return 0;
 }
 
@@ -65,8 +67,8 @@ setup_fake_routerlist(const char *fname)
 
   /* We need to mock this function otherwise the descriptors will not
      accepted as they are too old. */
-  MOCK(router_descriptor_is_too_old,
-       router_descriptor_is_too_old_replacement);
+  MOCK(router_descriptor_is_older_than,
+       router_descriptor_is_older_than_replacement);
 
   /* Load all the test descriptors to the routerlist. */
   retval = router_load_routers_from_string(contents, NULL, SAVED_IN_JOURNAL,
@@ -89,7 +91,7 @@ setup_fake_routerlist(const char *fname)
   } SMARTLIST_FOREACH_END(node);
 
  done:
-  UNMOCK(router_descriptor_is_too_old);
+  UNMOCK(router_descriptor_is_older_than);
   tor_free(contents);
 }
 





More information about the tor-commits mailing list