commit 3b51b326e4fb71b7ec75c5c8ef5a4869f5c4acc1 Author: Linus Nordberg linus@nordberg.se Date: Mon Nov 28 13:47:12 2011 +0100
Make router_get_{prim,alt,pref}_addr_port take tor_addr_port_t *.
Rename to *_orport for consistency with node_*. --- src/or/circuitbuild.c | 16 ++++++-------- src/or/nodelist.c | 6 ++-- src/or/router.c | 54 +++++++++++++++++++++--------------------------- src/or/router.h | 12 +++++----- 4 files changed, 40 insertions(+), 48 deletions(-)
diff --git a/src/or/circuitbuild.c b/src/or/circuitbuild.c index 1283256..faf939e 100644 --- a/src/or/circuitbuild.c +++ b/src/or/circuitbuild.c @@ -3332,16 +3332,15 @@ extend_info_alloc(const char *nickname, const char *digest, extend_info_t * extend_info_from_router(const routerinfo_t *r, int for_direct_connect) { - tor_addr_t addr; - uint16_t port; + tor_addr_port_t ap; tor_assert(r);
if (for_direct_connect) - router_get_pref_addr_port(r, &addr, &port); + router_get_pref_orport(r, &ap); else - router_get_prim_addr_port(r, &addr, &port); + router_get_prim_orport(r, &ap); return extend_info_alloc(r->nickname, r->cache_info.identity_digest, - r->onion_pkey, &addr, port); + r->onion_pkey, &ap.addr, ap.port); }
/** Allocate and return a new extend_info that can be used to build a @@ -4855,11 +4854,10 @@ get_configured_bridge_by_addr_port_digest(const tor_addr_t *addr, static bridge_info_t * get_configured_bridge_by_routerinfo(const routerinfo_t *ri) { - tor_addr_t addr; - uint16_t port; + tor_addr_port_t ap;
- router_get_pref_addr_port(ri, &addr, &port); - return get_configured_bridge_by_addr_port_digest(&addr, port, + router_get_pref_orport(ri, &ap); + return get_configured_bridge_by_addr_port_digest(&ap.addr, ap.port, ri->cache_info.identity_digest); }
diff --git a/src/or/nodelist.c b/src/or/nodelist.c index 493c03f..921ce1a 100644 --- a/src/or/nodelist.c +++ b/src/or/nodelist.c @@ -688,7 +688,7 @@ void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out) { if (node->ri) { - router_get_prim_addr_port(node->ri, &ap_out->addr, &ap_out->port); + router_get_prim_orport(node->ri, ap_out); } else if (node->rs) { tor_addr_from_ipv4h(&ap_out->addr, node->rs->addr); @@ -725,7 +725,7 @@ void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out) { if (node->ri) { - router_get_pref_addr_port(node->ri, &ap_out->addr, &ap_out->port); + router_get_pref_orport(node->ri, ap_out); } else if (node->rs) { /* No IPv6 in routerstatus_t yet. XXXprop186 ok for private bridges but needs fixing */ @@ -737,7 +737,7 @@ node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out) /** Copy the preferred IPv6 OR port (address and TCP port) for * <b>node</b> into *<b>ap_out</b>. */ void -node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out) +node_get_pref_ipv6_addr(const node_t *node, tor_addr_port_t *ap_out) { if (node->ri) { tor_addr_copy(&ap_out->addr, &node->ri->ipv6_addr); diff --git a/src/or/router.c b/src/or/router.c index d021737..a0ae79a 100644 --- a/src/or/router.c +++ b/src/or/router.c @@ -2122,37 +2122,33 @@ router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, }
-/** Copy the primary, IPv4, address and port for <b>router</b> into - *<b>addr_out</b> and *<b>port_out</b>. */ +/** Copy the primary (IPv4) OR port (IP address and TCP port) for + * <b>router</b> into *<b>ap_out</b>. */ void -router_get_prim_addr_port(const routerinfo_t *router, tor_addr_t *addr_out, - uint16_t *port_out) +router_get_prim_orport(const routerinfo_t *router, tor_addr_port_t *ap_out) { - if (addr_out != NULL) - tor_addr_from_ipv4h(addr_out, router->addr); - if (port_out != NULL) - *port_out = router->or_port; + tor_assert(ap_out != NULL); + tor_addr_from_ipv4h(&ap_out->addr, router->addr); + ap_out->port = router->or_port; }
-/** Copy the alternative, presumably IPv6, address and port for - <b>router</b> into *<b>addr_out</b> and *<b>port_out</b>. */ +/** Copy the alternative, presumably IPv6, OR port (IP address and TCP + * port) for <b>router</b> into *<b>ap_out</b>. */ void -router_get_alt_addr_port(const routerinfo_t *router, - tor_addr_t *addr_out, - uint16_t *port_out) +router_get_alt_orport(const routerinfo_t *router, tor_addr_port_t *ap_out) { - if (addr_out != NULL) - tor_addr_copy(addr_out, &router->ipv6_addr); - if (port_out != NULL) - *port_out = router->ipv6_orport; + tor_assert(ap_out != NULL); + tor_addr_copy(&ap_out->addr, &router->ipv6_addr); + ap_out->port = router->ipv6_orport; }
-/** Return 1 if we prefer the IPv6 address of <b>router</b>, else 0. - - We prefer the IPv6 address if the router has one and - i) the routerinfo_t says so - or - ii) the router has no IPv4 address. */ +/** Return 1 if we prefer the IPv6 address and OR TCP port of + * <b>router</b>, else 0. + * + * We prefer the IPv6 address if the router has one and + * i) the routerinfo_t says so + * or + * ii) the router has no IPv4 address. */ int router_ipv6_preferred(const routerinfo_t *router) { @@ -2160,17 +2156,15 @@ router_ipv6_preferred(const routerinfo_t *router) && (router->ipv6_preferred || router->addr == 0)); }
-/** Copy the preferred IP address and port for <b>router</b> into - *<b>addr_out</b> and *<b>port_out</b> . */ +/** Copy the preferred OR port (IP address and TCP port) for + * <b>router</b> into *<b>addr_out</b>. */ void -router_get_pref_addr_port(const routerinfo_t *router, - tor_addr_t *addr_out, - uint16_t *port_out) +router_get_pref_orport(const routerinfo_t *router, tor_addr_port_t *ap_out) { if (router_ipv6_preferred(router)) - router_get_alt_addr_port(router, addr_out, port_out); + router_get_alt_orport(router, ap_out); else - router_get_prim_addr_port(router, addr_out, port_out); + router_get_prim_orport(router, ap_out); }
/** Load the contents of <b>filename</b>, find the last line starting with diff --git a/src/or/router.h b/src/or/router.h index 4094b66..6095d02 100644 --- a/src/or/router.h +++ b/src/or/router.h @@ -85,12 +85,12 @@ int router_pick_published_address(const or_options_t *options, uint32_t *addr); int router_rebuild_descriptor(int force); int router_dump_router_to_string(char *s, size_t maxlen, routerinfo_t *router, crypto_pk_env_t *ident_key); -void router_get_prim_addr_port(const routerinfo_t *router, tor_addr_t *addr_out, - uint16_t *port_out); -void router_get_alt_addr_port(const routerinfo_t *router, tor_addr_t *addr_out, - uint16_t *port_out); -void router_get_pref_addr_port(const routerinfo_t *router, tor_addr_t *addr_out, - uint16_t *port_out); +void router_get_prim_orport(const routerinfo_t *router, + tor_addr_port_t *addr_port_out); +void router_get_alt_orport(const routerinfo_t *router, + tor_addr_port_t *addr_port_out); +void router_get_pref_orport(const routerinfo_t *router, + tor_addr_port_t *addr_port_out); int router_ipv6_preferred(const routerinfo_t *router); int extrainfo_dump_to_string(char **s, extrainfo_t *extrainfo, crypto_pk_env_t *ident_key);