Ticket #23873: b23873-p002.diff

File b23873-p002.diff, 5.5 KB (added by neel, 8 months ago)

Patch to remove the return value of node_get_prim_orport() and node_get_prim_dirport() (Revision 2)

  • new file changes/ticket23873

    From c858ed08ad632ec95708651cc621bcb60196460c Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Mon, 5 Feb 2018 21:38:02 -0500
    Subject: [PATCH] Remove the return value of node_get_prim_orport() and
     node_get_prim_dirport()
    
    ---
     changes/ticket23873   |  6 ++++++
     src/or/circuitbuild.c |  6 ++++--
     src/or/nodelist.c     | 27 +++++++++++----------------
     src/or/nodelist.h     |  4 ++--
     4 files changed, 23 insertions(+), 20 deletions(-)
     create mode 100644 changes/ticket23873
    
    diff --git a/changes/ticket23873 b/changes/ticket23873
    new file mode 100644
    index 000000000..ffe65e5ed
    - +  
     1  o Code simplification and refactoring:
     2    - We remove the return value of node_get_prim_orport() and
     3      node_get_prim_dirport(), and introduce node_get_prim_orport()
     4      in node_ipv6_or_preferred() and node_ipv6_dir_preferred() in
     5      order to check for a null address. Closes ticket 23873. Patch
     6      by Neel Chauhan.
  • src/or/circuitbuild.c

    diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c
    index 9c049a24b..ad1b60f70 100644
    a b extend_info_from_node(const node_t *node, int for_direct_connect) 
    29062906    valid_addr = fascist_firewall_choose_address_node(node,
    29072907                                                      FIREWALL_OR_CONNECTION,
    29082908                                                      0, &ap);
    2909   else
    2910     valid_addr = !node_get_prim_orport(node, &ap);
     2909  else {
     2910    node_get_prim_orport(node, &ap);
     2911    valid_addr = tor_addr_port_is_valid_ap(&ap, 0);
     2912  }
    29112913
    29122914  if (valid_addr)
    29132915    log_debug(LD_CIRC, "using %s for %s",
  • src/or/nodelist.c

    diff --git a/src/or/nodelist.c b/src/or/nodelist.c
    index 17a50ca86..040d9f950 100644
    a b node_ipv6_or_preferred(const node_t *node) 
    13781378  /* XX/teor - node->ipv6_preferred is set from
    13791379   * fascist_firewall_prefer_ipv6_orport() each time the consensus is loaded.
    13801380   */
     1381  node_get_prim_orport(node, &ipv4_addr);
    13811382  if (!fascist_firewall_use_ipv6(options)) {
    13821383    return 0;
    1383   } else if (node->ipv6_preferred || node_get_prim_orport(node, &ipv4_addr)) {
     1384  } else if (node->ipv6_preferred ||
     1385             tor_addr_port_is_valid_ap(&ipv4_addr, 0)) {
    13841386    return node_has_ipv6_orport(node);
    13851387  }
    13861388  return 0;
    node_ipv6_or_preferred(const node_t *node) 
    13911393    if (r && tor_addr_port_is_valid_ipv4h((r)->addr, (r)->port_field, 0)) { \
    13921394      tor_addr_from_ipv4h(&(ap_out)->addr, (r)->addr); \
    13931395      (ap_out)->port = (r)->port_field; \
    1394       return 0; \
    13951396    } \
    13961397  STMT_END
    13971398
    1398 /** Copy the primary (IPv4) OR port (IP address and TCP port) for
    1399  * <b>node</b> into *<b>ap_out</b>. Return 0 if a valid address and
    1400  * port was copied, else return non-zero.*/
    1401 int
     1399/** Copy the primary (IPv4) OR port (IP address and TCP port) for <b>node</b>
     1400 * into *<b>ap_out</b>. */
     1401void
    14021402node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
    14031403{
    14041404  node_assert_ok(node);
    node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out) 
    14141414
    14151415  RETURN_IPV4_AP(node->ri, or_port, ap_out);
    14161416  RETURN_IPV4_AP(node->rs, or_port, ap_out);
    1417   /* Microdescriptors only have an IPv6 address */
    1418 
    1419   return -1;
    14201417}
    14211418
    14221419/** Copy the preferred OR port (IP address and TCP port) for
    node_ipv6_dir_preferred(const node_t *node) 
    14881485   * so we can't use it to determine DirPort IPv6 preference.
    14891486   * This means that bridge clients will use IPv4 DirPorts by default.
    14901487   */
     1488  node_get_prim_dirport(node, &ipv4_addr);
    14911489  if (!fascist_firewall_use_ipv6(options)) {
    14921490    return 0;
    1493   } else if (node_get_prim_dirport(node, &ipv4_addr)
     1491  } else if (tor_addr_port_is_valid_ap(&ipv4_addr, 0)
    14941492      || fascist_firewall_prefer_ipv6_dirport(get_options())) {
    14951493    return node_has_ipv6_dirport(node);
    14961494  }
    14971495  return 0;
    14981496}
    14991497
    1500 /** Copy the primary (IPv4) Dir port (IP address and TCP port) for
    1501  * <b>node</b> into *<b>ap_out</b>. Return 0 if a valid address and
    1502  * port was copied, else return non-zero.*/
    1503 int
     1498/** Copy the primary (IPv4) Dir port (IP address and TCP port) for <b>node</b>
     1499 * into *<b>ap_out</b>. */
     1500void
    15041501node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out)
    15051502{
    15061503  node_assert_ok(node);
    node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out) 
    15121509  RETURN_IPV4_AP(node->ri, dir_port, ap_out);
    15131510  RETURN_IPV4_AP(node->rs, dir_port, ap_out);
    15141511  /* Microdescriptors only have an IPv6 address */
    1515 
    1516   return -1;
    15171512}
    15181513
    15191514#undef RETURN_IPV4_AP
  • src/or/nodelist.h

    diff --git a/src/or/nodelist.h b/src/or/nodelist.h
    index 0abdcd604..e18a4eef5 100644
    a b int node_has_ipv6_dirport(const node_t *node); 
    7676/* Deprecated - use node_ipv6_or_preferred or node_ipv6_dir_preferred */
    7777#define node_ipv6_preferred(node) node_ipv6_or_preferred(node)
    7878int node_ipv6_or_preferred(const node_t *node);
    79 int node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
     79void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
    8080void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out);
    8181void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out);
    8282int node_ipv6_dir_preferred(const node_t *node);
    83 int node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out);
     83void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out);
    8484void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out);
    8585void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out);
    8686int node_has_curve25519_onion_key(const node_t *node);