Browse Source

Change interface of router_descriptor_is_too_old().

George Kadianakis 9 years ago
parent
commit
b74442db94
3 changed files with 15 additions and 11 deletions
  1. 6 5
      src/or/routerlist.c
  2. 2 1
      src/or/routerlist.h
  3. 7 5
      src/test/test_entrynodes.c

+ 6 - 5
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;

+ 2 - 1
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

+ 7 - 5
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);
 }