diff options
author | Linus Nordberg <linus@nordberg.se> | 2011-11-28 12:15:58 +0100 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2011-11-30 11:55:46 -0500 |
commit | 2376a6ade4c5258da5512885eba28e3e0461f2a8 (patch) | |
tree | 3d310f9a31e82ee76f69e52639bb4094d1b647fb /src/or/nodelist.c | |
parent | 529820f8baeaccc6efffde1d9b241eb9f11ce82f (diff) | |
download | tor-2376a6ade4c5258da5512885eba28e3e0461f2a8.tar.gz tor-2376a6ade4c5258da5512885eba28e3e0461f2a8.zip |
Merge node_get_{prim,pref,pref_ipv6}_addr with their _orport counterparts.
This keeps the IP address and TCP for a given OR port together,
reducing the risk of using an address for one address family with a
port of another.
Make node_get_addr() a wrapper function for compatibility.
Diffstat (limited to 'src/or/nodelist.c')
-rw-r--r-- | src/or/nodelist.c | 87 |
1 files changed, 29 insertions, 58 deletions
diff --git a/src/or/nodelist.c b/src/or/nodelist.c index 08dcde6f02..493c03f825 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -682,19 +682,30 @@ node_get_all_orports(const node_t *node) return sl; } -/** Copy the primary, IPv4, address for <b>node</b> into - * *<b>addr_out</b>. */ +/** Copy the primary (IPv4) OR port (IP address and TCP port) for + * <b>node</b> into *<b>ap_out</b>. */ void -node_get_prim_addr(const node_t *node, tor_addr_t *addr_out) +node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out) { if (node->ri) { - router_get_prim_addr_port(node->ri, addr_out, NULL); + router_get_prim_addr_port(node->ri, &ap_out->addr, &ap_out->port); } else if (node->rs) { - tor_addr_from_ipv4h(addr_out, node->rs->addr); + tor_addr_from_ipv4h(&ap_out->addr, node->rs->addr); + ap_out->port = node->rs->or_port; } } +/** Wrapper around node_get_prim_orport for backward + compatibility. */ +void +node_get_addr(const node_t *node, tor_addr_t *addr_out) +{ + tor_addr_port_t ap; + node_get_prim_orport(node, &ap); + tor_addr_copy(addr_out, &ap.addr); +} + /** Return the host-order IPv4 address for <b>node</b>, or 0 if it doesn't * seem to have one. */ uint32_t @@ -708,40 +719,34 @@ node_get_prim_addr_ipv4h(const node_t *node) return 0; } -/** Return 1 if we prefer the IPv6 address of <b>node</b>, else 0. */ -static int -node_ipv6_preferred(const node_t *node) -{ - if (node->ri != NULL) - return router_ipv6_preferred(node->ri); - return 0; -} - -/** Copy the preferred address for <b>node</b> into - * <b>addr_out</b>. */ +/** Copy the preferred OR port (IP address and TCP port) for + * <b>node</b> into <b>ap_out</b>. */ void -node_get_pref_addr(const node_t *node, tor_addr_t *addr_out) +node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out) { if (node->ri) { - router_get_pref_addr_port(node->ri, addr_out, NULL); + router_get_pref_addr_port(node->ri, &ap_out->addr, &ap_out->port); } else if (node->rs) { /* No IPv6 in routerstatus_t yet. XXXprop186 ok for private bridges but needs fixing */ - tor_addr_from_ipv4h(addr_out, node->rs->addr); + tor_addr_from_ipv4h(&ap_out->addr, node->rs->addr); + ap_out->port = node->rs->or_port; } } -/** Copy the preferred IPv6 address for <b>node</b> into - * *<b>addr_out</b>. */ +/** Copy the preferred IPv6 OR port (address and TCP port) for + * <b>node</b> into *<b>ap_out</b>. */ void -node_get_pref_ipv6_addr(const node_t *node, tor_addr_t *addr_out) +node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out) { if (node->ri) { - tor_addr_copy(addr_out, &node->ri->ipv6_addr); + tor_addr_copy(&ap_out->addr, &node->ri->ipv6_addr); + ap_out->port = node->ri->ipv6_orport; } else if (node->rs) { /* No IPv6 in routerstatus_t yet. XXXprop186 ok for private bridges but needs fixing */ - tor_addr_make_unspec(addr_out); + tor_addr_make_unspec(&ap_out->addr); + ap_out->port = 0; } } @@ -772,40 +777,6 @@ node_get_declared_uptime(const node_t *node) return -1; } -/** Return <b>node</b>'s declared primary (IPv4) or_port. */ -uint16_t -node_get_prim_orport(const node_t *node) -{ - if (node->ri) - return node->ri->or_port; - else if (node->rs) - return node->rs->or_port; - else - return 0; -} - -/** Return <b>node</b>'s preferred or_port. */ -uint16_t -node_get_pref_orport(const node_t *node) -{ - if (node_ipv6_preferred(node)) - return node_get_pref_ipv6_orport(node); - else - return node_get_prim_orport(node); -} - -/** Return <b>node</b>'s preferred IPv6 or_port. */ -uint16_t -node_get_pref_ipv6_orport(const node_t *node) -{ - if (node->ri) - return node->ri->ipv6_orport; - else if (node->rs) - return 0; /* No IPv6 in routerstatus_t yet. */ - else - return 0; -} - /** Return <b>node</b>'s platform string, or NULL if we don't know it. */ const char * node_get_platform(const node_t *node) |