Ticket #9969: 0001-Increase-objs-requested-tunneled-dir-connection.patch

File 0001-Increase-objs-requested-tunneled-dir-connection.patch, 9.6 KB (added by arlolra, 6 years ago)
  • new file changes/bug9969

    From 95a055f48f0055b3985589f0ccd428213ae897fd Mon Sep 17 00:00:00 2001
    From: Arlo Breault <arlolra@gmail.com>
    Date: Fri, 28 Feb 2014 18:47:41 -0800
    Subject: [PATCH] Increase objs requested / tunneled dir connection
    
     * Fixes #9969.
     * With some cleanup.
    ---
     changes/bug9969     |  3 ++
     src/or/directory.c  | 83 ++++++++++++++++++++++++-----------------------------
     src/or/entrynodes.c |  2 +-
     src/or/entrynodes.h |  1 +
     src/or/routerlist.c | 33 +++++++++++----------
     5 files changed, 60 insertions(+), 62 deletions(-)
     create mode 100644 changes/bug9969
    
    diff --git a/changes/bug9969 b/changes/bug9969
    new file mode 100644
    index 0000000..d39389f
    - +  
     1  o Minor bugfixes:
     2    - Increase the number of microdescs we're willing to request per
     3      tunneled directory connection.
     4 No newline at end of file
  • src/or/directory.c

    diff --git a/src/or/directory.c b/src/or/directory.c
    index 739885c..17d33ad 100644
    a b dir_conn_purpose_to_string(int purpose) 
    200200  return "(unknown)";
    201201}
    202202
     203/** Return the requisite directory information types. */
     204dirinfo_type_t
     205dir_fetch_type(int dir_purpose, int router_purpose, const char *resource)
     206{
     207  switch (dir_purpose) {
     208    case DIR_PURPOSE_FETCH_EXTRAINFO:
     209      return EXTRAINFO_DIRINFO |
     210             (router_purpose == ROUTER_PURPOSE_BRIDGE ? BRIDGE_DIRINFO :
     211                                                        V3_DIRINFO);
     212    case DIR_PURPOSE_FETCH_SERVERDESC:
     213      return (router_purpose == ROUTER_PURPOSE_BRIDGE ? BRIDGE_DIRINFO :
     214                                                        V3_DIRINFO);
     215    case DIR_PURPOSE_FETCH_STATUS_VOTE:
     216    case DIR_PURPOSE_FETCH_DETACHED_SIGNATURES:
     217    case DIR_PURPOSE_FETCH_CERTIFICATE:
     218      return V3_DIRINFO;
     219    case DIR_PURPOSE_FETCH_CONSENSUS:
     220      return V3_DIRINFO |
     221             (resource && !strcmp(resource,"microdesc") ? MICRODESC_DIRINFO :
     222                                                          NO_DIRINFO);
     223    case DIR_PURPOSE_FETCH_MICRODESC:
     224      return MICRODESC_DIRINFO;
     225    default:
     226      log_warn(LD_BUG, "Unexpected purpose %d", (int)dir_purpose);
     227      return NO_DIRINFO;
     228  }
     229}
     230
    203231/** Return true iff <b>identity_digest</b> is the digest of a router we
    204232 * believe to support extrainfo downloads.  (If <b>is_authority</b> we do
    205233 * additional checking that's only valid for authorities.) */
    should_use_directory_guards(const or_options_t *options) 
    346374  return 1;
    347375}
    348376
    349 /** Pick an unconsetrained directory server from among our guards, the latest
     377/** Pick an unconstrained directory server from among our guards, the latest
    350378 * networkstatus, or the fallback dirservers, for use in downloading
    351379 * information of type <b>type</b>, and return its routerstatus. */
    352380static const routerstatus_t *
    directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose, 
    391419  int prefer_authority = directory_fetches_from_authorities(options);
    392420  int require_authority = 0;
    393421  int get_via_tor = purpose_needs_anonymity(dir_purpose, router_purpose);
    394   dirinfo_type_t type;
     422  dirinfo_type_t type = dir_fetch_type(dir_purpose, router_purpose, resource);
    395423  time_t if_modified_since = 0;
    396424
    397   /* FFFF we could break this switch into its own function, and call
    398    * it elsewhere in directory.c. -RD */
    399   switch (dir_purpose) {
    400     case DIR_PURPOSE_FETCH_EXTRAINFO:
    401       type = EXTRAINFO_DIRINFO |
    402              (router_purpose == ROUTER_PURPOSE_BRIDGE ? BRIDGE_DIRINFO :
    403                                                         V3_DIRINFO);
    404       break;
    405     case DIR_PURPOSE_FETCH_SERVERDESC:
    406       type = (router_purpose == ROUTER_PURPOSE_BRIDGE ? BRIDGE_DIRINFO :
    407                                                         V3_DIRINFO);
    408       break;
    409     case DIR_PURPOSE_FETCH_STATUS_VOTE:
    410     case DIR_PURPOSE_FETCH_DETACHED_SIGNATURES:
    411     case DIR_PURPOSE_FETCH_CERTIFICATE:
    412       type = V3_DIRINFO;
    413       break;
    414     case DIR_PURPOSE_FETCH_CONSENSUS:
    415       type = V3_DIRINFO;
    416       if (resource && !strcmp(resource,"microdesc"))
    417         type |= MICRODESC_DIRINFO;
    418       break;
    419     case DIR_PURPOSE_FETCH_MICRODESC:
    420       type = MICRODESC_DIRINFO;
    421       break;
    422     default:
    423       log_warn(LD_BUG, "Unexpected purpose %d", (int)dir_purpose);
    424       return;
    425   }
     425  if (type == NO_DIRINFO)
     426    return;
    426427
    427428  if (dir_purpose == DIR_PURPOSE_FETCH_CONSENSUS) {
    428429    int flav = FLAV_NS;
    directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose, 
    516517    }
    517518  } else { /* get_via_tor */
    518519    /* Never use fascistfirewall; we're going via Tor. */
    519     if (1) {
    520       /* anybody with a non-zero dirport will do. Disregard firewalls. */
    521       pds_flags |= PDS_IGNORE_FASCISTFIREWALL;
    522       rs = router_pick_directory_server(type, pds_flags);
    523       /* If we have any hope of building an indirect conn, we know some router
    524        * descriptors.  If (rs==NULL), we can't build circuits anyway, so
    525        * there's no point in falling back to the authorities in this case. */
    526     }
     520    pds_flags |= PDS_IGNORE_FASCISTFIREWALL;
     521    rs = router_pick_directory_server(type, pds_flags);
     522    /* If we have any hope of building an indirect conn, we know some router
     523     * descriptors.  If (rs==NULL), we can't build circuits anyway, so
     524     * there's no point in falling back to the authorities in this case. */
    527525  }
    528526
    529527  if (rs) {
    directory_send_command(dir_connection_t *conn, 
    12651263      return;
    12661264  }
    12671265
    1268   if (strlen(proxystring) + strlen(url) >= 4096) {
    1269     log_warn(LD_BUG,
    1270              "Squid does not like URLs longer than 4095 bytes, and this "
    1271              "one is %d bytes long: %s%s",
    1272              (int)(strlen(proxystring) + strlen(url)), proxystring, url);
    1273   }
    1274 
    12751266  tor_snprintf(request, sizeof(request), "%s %s", httpcommand, proxystring);
    12761267  connection_write_to_buf(request, strlen(request), TO_CONN(conn));
    12771268  connection_write_to_buf(url, strlen(url), TO_CONN(conn));
  • src/or/entrynodes.c

    diff --git a/src/or/entrynodes.c b/src/or/entrynodes.c
    index d463303..324ffb8 100644
    a b add_an_entry_guard(const node_t *chosen, int reset_status, int prepend, 
    435435/** Choose how many entry guards or directory guards we'll use. If
    436436 * <b>for_directory</b> is true, we return how many directory guards to
    437437 * use; else we return how many entry guards to use. */
    438 static int
     438int
    439439decide_num_guards(const or_options_t *options, int for_directory)
    440440{
    441441  if (for_directory && options->NumDirectoryGuards != 0)
  • src/or/entrynodes.h

    diff --git a/src/or/entrynodes.h b/src/or/entrynodes.h
    index 772c666..983bae6 100644
    a b int num_live_entry_guards(int for_directory); 
    7777
    7878#endif
    7979
     80int decide_num_guards(const or_options_t *options, int for_directory);
    8081void remove_all_entry_guards(void);
    8182
    8283void entry_guards_compute_status(const or_options_t *options, time_t now);
  • src/or/routerlist.c

    diff --git a/src/or/routerlist.c b/src/or/routerlist.c
    index d636a1e..49f2b8d 100644
    a b initiate_descriptor_downloads(const routerstatus_t *source, 
    42634263                              smartlist_t *digests,
    42644264                              int lo, int hi, int pds_flags)
    42654265{
    4266   int i, n = hi-lo;
     4266  int i, n;
    42674267  char *resource, *cp;
    42684268  size_t r_len;
    42694269
    initiate_descriptor_downloads(const routerstatus_t *source, 
    42804280    b64_256 = 1;
    42814281  }
    42824282
    4283   if (n <= 0)
    4284     return;
    42854283  if (lo < 0)
    42864284    lo = 0;
    42874285  if (hi > smartlist_len(digests))
    42884286    hi = smartlist_len(digests);
    42894287
    4290   r_len = 8 + (enc_digest_len+1)*n;
     4288  n = hi-lo;
     4289  if (n <= 0)
     4290    return;
     4291
     4292  r_len = 4 + (enc_digest_len+1)*n;
    42914293  cp = resource = tor_malloc(r_len);
    42924294  memcpy(cp, "d/", 2);
    42934295  cp += 2;
    initiate_descriptor_downloads(const routerstatus_t *source, 
    43164318  tor_free(resource);
    43174319}
    43184320
    4319 /** Max amount of hashes to download per request.
    4320  * Since squid does not like URLs >= 4096 bytes we limit it to 96.
    4321  *   4096 - strlen(http://255.255.255.255/tor/server/d/.z) == 4058
    4322  *   4058/41 (40 for the hash and 1 for the + that separates them) => 98
    4323  *   So use 96 because it's a nice number.
    4324  */
     4321/* Max amount of hashes to download per request. */
    43254322#define MAX_DL_PER_REQUEST 96
    4326 #define MAX_MICRODESC_DL_PER_REQUEST 92
     4323#define MAX_MICRODESC_DL_PER_REQUEST 300
    43274324/** Don't split our requests so finely that we are requesting fewer than
    43284325 * this number per server. */
    43294326#define MIN_DL_PER_REQUEST 4
    4330 /** To prevent a single screwy cache from confusing us by selective reply,
    4331  * try to split our requests into at least this many requests. */
    4332 #define MIN_REQUESTS 3
    43334327/** If we want fewer than this many descriptors, wait until we
    43344328 * want more, or until TestingClientMaxIntervalWithoutRequest has passed. */
    43354329#define MAX_DL_TO_DELAY 16
    43364330
     4331/** To prevent a single screwy cache from confusing us by selective reply,
     4332 * try to split our requests into at least this many requests. */
     4333int
     4334get_min_requests(const or_options_t *options)
     4335{
     4336  int num_guards = decide_num_guards(options, 1);
     4337  return num_guards ? num_guards * 2 : 6;
     4338}
     4339
    43374340/** Given a <b>purpose</b> (FETCH_MICRODESC or FETCH_SERVERDESC) and a list of
    43384341 * router descriptor digests or microdescriptor digest256s in
    43394342 * <b>downloadable</b>, decide whether to delay fetching until we have more.
    launch_descriptor_downloads(int purpose, 
    44034406        PDS_NO_EXISTING_SERVERDESC_FETCH;
    44044407    }
    44054408
    4406     n_per_request = CEIL_DIV(n_downloadable, MIN_REQUESTS);
     4409    n_per_request = CEIL_DIV(n_downloadable, get_min_requests(options));
    44074410    if (purpose == DIR_PURPOSE_FETCH_MICRODESC) {
    44084411      if (n_per_request > MAX_MICRODESC_DL_PER_REQUEST)
    44094412        n_per_request = MAX_MICRODESC_DL_PER_REQUEST;