Sfoglia il codice sorgente

Functionify the descriptor age check so that we can NOP it in tests.

George Kadianakis 10 anni fa
parent
commit
4245662b28
2 ha cambiato i file con 11 aggiunte e 2 eliminazioni
  1. 9 2
      src/or/routerlist.c
  2. 2 0
      src/or/routerlist.h

+ 9 - 2
src/or/routerlist.c

@@ -3292,6 +3292,14 @@ 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. */
+MOCK_IMPL(int,
+router_descriptor_is_too_old,(const routerinfo_t *router))
+{
+  return router->cache_info.published_on < time(NULL)-OLD_ROUTER_DESC_MAX_AGE;
+}
+
 /** Add <b>router</b> to the routerlist, if we don't already have it.  Replace
  * older entries (if any) with the same key.  Note: Callers should not hold
  * their pointers to <b>router</b> if this function fails; <b>router</b>
@@ -3460,8 +3468,7 @@ router_add_to_routerlist(routerinfo_t *router, const char **msg,
     }
   }
 
-  if (!in_consensus && from_cache &&
-      router->cache_info.published_on < time(NULL) - OLD_ROUTER_DESC_MAX_AGE) {
+  if (!in_consensus && from_cache && router_descriptor_is_too_old(router)) {
     *msg = "Router descriptor was really old.";
     routerinfo_free(router);
     return ROUTER_WAS_NOT_NEW;

+ 2 - 0
src/or/routerlist.h

@@ -212,6 +212,8 @@ STATIC int choose_array_element_by_weight(const u64_dbl_t *entries,
                                           int n_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));
 #endif
 
 #endif