Ticket #2355: tor-01-tristate_usebridges.patch

File tor-01-tristate_usebridges.patch, 10.4 KB (added by anonym, 8 years ago)

Parsing for new AUTOBOOL behaviour of UseBridges.

  • src/or/circuitbuild.c

    diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
    index d02ea16..2c16334 100644
    a b entry_guard_set_status(entry_guard_t *e, const node_t *node, 
    33913391    *reason = "unlisted";
    33923392  else if (!node->is_running)
    33933393    *reason = "down";
    3394   else if (options->UseBridges && (!node->ri ||
    3395                                   node->ri->purpose != ROUTER_PURPOSE_BRIDGE))
     3394  else if (options->EffectiveUseBridges &&
     3395           (!node->ri || node->ri->purpose != ROUTER_PURPOSE_BRIDGE))
    33963396    *reason = "not a bridge";
    3397   else if (!options->UseBridges && !node->is_possible_guard &&
     3397  else if (!options->EffectiveUseBridges && !node->is_possible_guard &&
    33983398           !routerset_contains_node(options->EntryNodes,node))
    33993399    *reason = "not recommended as a guard";
    34003400  else if (routerset_contains_node(options->ExcludeNodes, node))
    entry_is_live(entry_guard_t *e, int need_uptime, int need_capacity, 
    34783478    *msg = "no descriptor";
    34793479    return NULL;
    34803480  }
    3481   if (get_options()->UseBridges) {
     3481  if (get_options()->EffectiveUseBridges) {
    34823482    if (node_get_purpose(node) != ROUTER_PURPOSE_BRIDGE) {
    34833483      *msg = "not a bridge";
    34843484      return NULL;
    34853485    }
    3486   } else { /* !get_options()->UseBridges */
     3486  } else { /* !get_options()->EffectiveUseBridges */
    34873487    if (node_get_purpose(node) != ROUTER_PURPOSE_GENERAL) {
    34883488      *msg = "not general-purpose";
    34893489      return NULL;
    entry_list_is_constrained(or_options_t *options) 
    40544054{
    40554055  if (options->EntryNodes)
    40564056    return 1;
    4057   if (options->UseBridges)
     4057  if (options->EffectiveUseBridges)
    40584058    return 1;
    40594059  return 0;
    40604060}
    learned_bridge_descriptor(routerinfo_t *ri, int from_cache) 
    47824782{
    47834783  tor_assert(ri);
    47844784  tor_assert(ri->purpose == ROUTER_PURPOSE_BRIDGE);
    4785   if (get_options()->UseBridges) {
     4785  if (get_options()->EffectiveUseBridges) {
    47864786    int first = !any_bridge_descriptors_known();
    47874787    bridge_info_t *bridge = get_configured_bridge_by_routerinfo(ri);
    47884788    time_t now = time(NULL);
    learned_bridge_descriptor(routerinfo_t *ri, int from_cache) 
    48204820int
    48214821any_bridge_descriptors_known(void)
    48224822{
    4823   tor_assert(get_options()->UseBridges);
     4823  tor_assert(get_options()->EffectiveUseBridges);
    48244824  return choose_random_entry(NULL)!=NULL ? 1 : 0;
    48254825}
    48264826
    entries_retry_helper(or_options_t *options, int act) 
    48564856  const node_t *node;
    48574857  int any_known = 0;
    48584858  int any_running = 0;
    4859   int need_bridges = options->UseBridges != 0;
     4859  int need_bridges = options->EffectiveUseBridges != 0;
    48604860  if (!entry_guards)
    48614861    entry_guards = smartlist_create();
    48624862  SMARTLIST_FOREACH_BEGIN(entry_guards, entry_guard_t *, e) {
  • src/or/circuituse.c

    diff --git a/src/or/circuituse.c b/src/or/circuituse.c
    index 135aa80..5813178 100644
    a b circuit_get_open_circ_or_launch(edge_connection_t *conn, 
    12521252        log_fn(severity, LD_APP|LD_DIR,
    12531253               "Application request when we haven't used client functionality "
    12541254               "lately. Optimistically trying known %s again.",
    1255                options->UseBridges ? "bridges" : "entrynodes");
     1255               options->EffectiveUseBridges ? "bridges" : "entrynodes");
    12561256        entries_retry_all(options);
    1257       } else if (!options->UseBridges || any_bridge_descriptors_known()) {
     1257      } else if (!options->EffectiveUseBridges ||
     1258                 any_bridge_descriptors_known()) {
    12581259        log_fn(severity, LD_APP|LD_DIR,
    12591260               "Application request when we haven't used client functionality "
    12601261               "lately. Optimistically trying directory fetches again.");
  • src/or/config.c

    diff --git a/src/or/config.c b/src/or/config.c
    index 5b251d3..c377c09 100644
    a b static config_var_t _option_vars[] = { 
    380380  V(TransPort,                   UINT,     "0"),
    381381  V(TunnelDirConns,              BOOL,     "1"),
    382382  V(UpdateBridgesFromAuthority,  BOOL,     "0"),
    383   V(UseBridges,                  BOOL,     "0"),
     383  V(UseBridges,                  AUTOBOOL, "auto"),
    384384  V(UseEntryGuards,              BOOL,     "1"),
    385385  V(UseMicrodescriptors,         AUTOBOOL, "0"),
    386386  V(User,                        STRING,   NULL),
    options_act(or_options_t *old_options) 
    12791279  /* Change the cell EWMA settings */
    12801280  cell_ewma_set_scale_factor(options, networkstatus_get_latest_consensus());
    12811281
     1282  /* parse UseBridges tristate */
     1283  if (options->UseBridges == 0)
     1284    options->EffectiveUseBridges = 0;
     1285  else if (options->UseBridges == 1)
     1286    options->EffectiveUseBridges = 1;
     1287  else if (options->UseBridges == -1 ) {
     1288    if (!options->Bridges || server_mode(options) || options->EntryNodes)
     1289      options->EffectiveUseBridges = 0;
     1290    else
     1291      options->EffectiveUseBridges = 1;
     1292  }
     1293
    12821294  /* Check for transitions that need action. */
    12831295  if (old_options) {
    12841296    if ((options->UseEntryGuards && !old_options->UseEntryGuards) ||
    options_validate(or_options_t *old_options, or_options_t *options, 
    32623274           "of the Internet, so they must not set Reachable*Addresses "
    32633275           "or FascistFirewall.");
    32643276
    3265   if (options->UseBridges &&
     3277  if (options->UseBridges == 1 &&
    32663278      server_mode(options))
    32673279    REJECT("Servers must be able to freely connect to the rest "
    32683280           "of the Internet, so they must not set UseBridges.");
    options_validate(or_options_t *old_options, or_options_t *options, 
    32703282  /* If both of these are set, we'll end up with funny behavior where we
    32713283   * demand enough entrynodes be up and running else we won't build
    32723284   * circuits, yet we never actually use them. */
    3273   if (options->UseBridges && options->EntryNodes)
     3285  if (options->UseBridges == 1 && options->EntryNodes)
    32743286    REJECT("You cannot set both UseBridges and EntryNodes.");
    32753287
    32763288  options->_AllowInvalid = 0;
    options_validate(or_options_t *old_options, or_options_t *options, 
    35973609  if (validate_dir_authorities(options, old_options) < 0)
    35983610    REJECT("Directory authority line did not parse. See logs for details.");
    35993611
    3600   if (options->UseBridges && !options->Bridges)
    3601     REJECT("If you set UseBridges, you must specify at least one bridge.");
    36023612  if (options->UseBridges && !options->TunnelDirConns)
    3603     REJECT("If you set UseBridges, you must set TunnelDirConns.");
     3613    REJECT("TunnelDirConns set to 0 only works with UseBridges set to 0.");
    36043614  if (options->Bridges) {
    36053615    for (cl = options->Bridges; cl; cl = cl->next) {
    36063616      if (parse_bridge_line(cl->value, 1)<0)
  • src/or/control.c

    diff --git a/src/or/control.c b/src/or/control.c
    index 0aada57..404965d 100644
    a b control_event_bootstrap_problem(const char *warn, int reason) 
    40674067  if (reason == END_OR_CONN_REASON_NO_ROUTE)
    40684068    recommendation = "warn";
    40694069
    4070   if (get_options()->UseBridges &&
     4070  if (get_options()->EffectiveUseBridges &&
    40714071      !any_bridge_descriptors_known() &&
    40724072      !any_pending_bridge_descriptor_fetches())
    40734073    recommendation = "warn";
  • src/or/directory.c

    diff --git a/src/or/directory.c b/src/or/directory.c
    index 313c6c5..5f7a8b7 100644
    a b directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose, 
    413413    return;
    414414
    415415  if (!get_via_tor) {
    416     if (options->UseBridges && type != BRIDGE_DIRINFO) {
     416    if (options->EffectiveUseBridges && type != BRIDGE_DIRINFO) {
    417417      /* want to ask a running bridge for which we have a descriptor. */
    418418      /* XXX023 we assume that all of our bridges can answer any
    419419       * possible directory question. This won't be true forever. -RD */
    connection_dir_client_reached_eof(dir_connection_t *conn) 
    19191919    if (which || (conn->requested_resource &&
    19201920                  (!strcmpstart(conn->requested_resource, "all") ||
    19211921                   (!strcmpstart(conn->requested_resource, "authority") &&
    1922                     get_options()->UseBridges)))) {
     1922                    get_options()->EffectiveUseBridges)))) {
    19231923      /* as we learn from them, we remove them from 'which' */
    19241924      if (was_ei) {
    19251925        router_load_extrainfo_from_string(body, NULL, SAVED_NOWHERE, which,
  • src/or/dirserv.c

    diff --git a/src/or/dirserv.c b/src/or/dirserv.c
    index 0ac2d80..dad02c8 100644
    a b directory_fetches_dir_info_early(or_options_t *options) 
    12341234int
    12351235directory_fetches_dir_info_later(or_options_t *options)
    12361236{
    1237   return options->UseBridges != 0;
     1237  return options->EffectiveUseBridges != 0;
    12381238}
    12391239
    12401240/** Return 1 if we want to cache v2 dir info (each status file).
  • src/or/main.c

    diff --git a/src/or/main.c b/src/or/main.c
    index 0e866b7..295cec0 100644
    a b run_scheduled_events(time_t now) 
    11101110  if (time_to_try_getting_descriptors < now) {
    11111111    update_all_descriptor_downloads(now);
    11121112    update_extrainfo_downloads(now);
    1113     if (options->UseBridges)
     1113    if (options->EffectiveUseBridges)
    11141114      fetch_bridge_descriptors(options, now);
    11151115    if (router_have_minimum_dir_info())
    11161116      time_to_try_getting_descriptors = now + LAZY_DESCRIPTOR_RETRY_INTERVAL;
  • src/or/networkstatus.c

    diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
    index 7fd3d36..81bafbe 100644
    a b update_consensus_networkstatus_fetch_time(time_t now) 
    13501350int
    13511351should_delay_dir_fetches(or_options_t *options)
    13521352{
    1353   if (options->UseBridges && !any_bridge_descriptors_known()) {
     1353  if (options->EffectiveUseBridges && !any_bridge_descriptors_known()) {
    13541354    log_info(LD_DIR, "delaying dir fetches (no running bridges known)");
    13551355    return 1;
    13561356  }
  • src/or/or.h

    diff --git a/src/or/or.h b/src/or/or.h
    index f58876e..b2dc11a 100644
    a b typedef struct { 
    26332633   * when doing so. */
    26342634  char *BridgePassword;
    26352635
    2636   int UseBridges; /**< Boolean: should we start all circuits with a bridge? */
     2636 /** Whether we should start all circuits with a bridge. 1 means strictly
     2637  * yes, 0 means stricly no, and -1 means that we do iff any bridges are
     2638  * configured, we are not running a server and have not specified a list of
     2639  * entry nodes. */
     2640  int UseBridges;
     2641  /** Effective value of UseBridges. Will be set equally for UseBriges set to
     2642   * 1 or 0, but for -1 it will be set to 1 iff any bridges are configured, we
     2643   * are not running a server and have not specified a list of entry nodes. */
     2644  int EffectiveUseBridges;
    26372645  config_line_t *Bridges; /**< List of bootstrap bridge addresses. */
    26382646
    26392647  int BridgeRelay; /**< Boolean: are we acting as a bridge relay? We make