[tor-commits] [tor/master] Extract the consensus-only part of directory_get_from_dirserver

nickm at torproject.org nickm at torproject.org
Thu May 4 12:58:39 UTC 2017


commit afa39cef6c6f42cca3f2b08462f68bece8db7312
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed May 3 14:19:46 2017 -0400

    Extract the consensus-only part of directory_get_from_dirserver
    
    Right now it just sets an if-modified-since header, but it's about
    to get even bigger.
    
    This patch avoids changing indentation; the next patch will be
    whitespace fixes.
---
 src/or/directory.c | 64 ++++++++++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 26 deletions(-)

diff --git a/src/or/directory.c b/src/or/directory.c
index 8f934bd..f430ddf 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -477,33 +477,16 @@ directory_pick_generic_dirserver(dirinfo_type_t type, int pds_flags,
   return rs;
 }
 
-/** Start a connection to a random running directory server, using
- * connection purpose <b>dir_purpose</b>, intending to fetch descriptors
- * of purpose <b>router_purpose</b>, and requesting <b>resource</b>.
- * Use <b>pds_flags</b> as arguments to router_pick_directory_server()
- * or router_pick_trusteddirserver().
+/**
+ * Set the extra fields in <b>req</b> that are used when requesting a
+ * consensus of type <b>resource</b>.
  */
-MOCK_IMPL(void, directory_get_from_dirserver, (
-                            uint8_t dir_purpose,
-                            uint8_t router_purpose,
-                            const char *resource,
-                            int pds_flags,
-                            download_want_authority_t want_authority))
+static void
+dir_consensus_request_set_additional_headers(directory_request_t *req,
+                                             const char *resource)
 {
-  const routerstatus_t *rs = NULL;
-  const or_options_t *options = get_options();
-  int prefer_authority = (directory_fetches_from_authorities(options)
-                          || want_authority == DL_WANT_AUTHORITY);
-  int require_authority = 0;
-  int get_via_tor = purpose_needs_anonymity(dir_purpose, router_purpose,
-                                            resource);
-  dirinfo_type_t type = dir_fetch_type(dir_purpose, router_purpose, resource);
   time_t if_modified_since = 0;
-
-  if (type == NO_DIRINFO)
-    return;
-
-  if (dir_purpose == DIR_PURPOSE_FETCH_CONSENSUS) {
+  {
     int flav = FLAV_NS;
     networkstatus_t *v;
     if (resource)
@@ -538,6 +521,33 @@ MOCK_IMPL(void, directory_get_from_dirserver, (
         if_modified_since = cd->published + DEFAULT_IF_MODIFIED_SINCE_DELAY;
     }
   }
+  directory_request_set_if_modified_since(req, if_modified_since);
+}
+
+/** Start a connection to a random running directory server, using
+ * connection purpose <b>dir_purpose</b>, intending to fetch descriptors
+ * of purpose <b>router_purpose</b>, and requesting <b>resource</b>.
+ * Use <b>pds_flags</b> as arguments to router_pick_directory_server()
+ * or router_pick_trusteddirserver().
+ */
+MOCK_IMPL(void, directory_get_from_dirserver, (
+                            uint8_t dir_purpose,
+                            uint8_t router_purpose,
+                            const char *resource,
+                            int pds_flags,
+                            download_want_authority_t want_authority))
+{
+  const routerstatus_t *rs = NULL;
+  const or_options_t *options = get_options();
+  int prefer_authority = (directory_fetches_from_authorities(options)
+                          || want_authority == DL_WANT_AUTHORITY);
+  int require_authority = 0;
+  int get_via_tor = purpose_needs_anonymity(dir_purpose, router_purpose,
+                                            resource);
+  dirinfo_type_t type = dir_fetch_type(dir_purpose, router_purpose, resource);
+
+  if (type == NO_DIRINFO)
+    return;
 
   if (!options->FetchServerDescriptors)
     return;
@@ -566,7 +576,8 @@ MOCK_IMPL(void, directory_get_from_dirserver, (
                                             ri->cache_info.identity_digest);
         directory_request_set_router_purpose(req, router_purpose);
         directory_request_set_resource(req, resource);
-        directory_request_set_if_modified_since(req, if_modified_since);
+        if (dir_purpose == DIR_PURPOSE_FETCH_CONSENSUS)
+          dir_consensus_request_set_additional_headers(req, resource);
         directory_request_set_guard_state(req, guard_state);
         directory_initiate_request(req);
         directory_request_free(req);
@@ -634,7 +645,8 @@ MOCK_IMPL(void, directory_get_from_dirserver, (
     directory_request_set_router_purpose(req, router_purpose);
     directory_request_set_indirection(req, indirection);
     directory_request_set_resource(req, resource);
-    directory_request_set_if_modified_since(req, if_modified_since);
+    if (dir_purpose == DIR_PURPOSE_FETCH_CONSENSUS)
+      dir_consensus_request_set_additional_headers(req, resource);
     if (guard_state)
       directory_request_set_guard_state(req, guard_state);
     directory_initiate_request(req);





More information about the tor-commits mailing list