Rename router_get_advertised_*() functions.

These now (or_port and dir_port) now have "find" names, since they
look at the portcfg first, then at the actual ports from the
listeners.

This is an automated commit, generated by this command:

./scripts/maint/rename_c_identifier.py \
        router_get_advertised_or_port routerconf_find_or_port \
        router_get_advertised_ipv6_or_ap routerconf_find_ipv6_or_ap \
        router_has_advertised_ipv6_orport routerconf_has_ipv6_orport \
        router_get_advertised_dir_port routerconf_find_dir_port
This commit is contained in:
Nick Mathewson 2020-07-21 12:59:03 -04:00
parent f478080bd0
commit 088100d698
5 changed files with 46 additions and 46 deletions

View File

@ -3168,10 +3168,10 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
smartlist_t *replacements = smartlist_new(); smartlist_t *replacements = smartlist_new();
const or_options_t *options = get_options(); const or_options_t *options = get_options();
int retval = 0; int retval = 0;
const uint16_t old_or_port = router_get_advertised_or_port(options, AF_INET); const uint16_t old_or_port = routerconf_find_or_port(options, AF_INET);
const uint16_t old_or_port_ipv6 = const uint16_t old_or_port_ipv6 =
router_get_advertised_or_port(options,AF_INET6); routerconf_find_or_port(options,AF_INET6);
const uint16_t old_dir_port = router_get_advertised_dir_port(options, 0); const uint16_t old_dir_port = routerconf_find_dir_port(options, 0);
SMARTLIST_FOREACH_BEGIN(get_connection_array(), connection_t *, conn) { SMARTLIST_FOREACH_BEGIN(get_connection_array(), connection_t *, conn) {
if (connection_is_listener(conn) && !conn->marked_for_close) if (connection_is_listener(conn) && !conn->marked_for_close)
@ -3241,9 +3241,9 @@ retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
SMARTLIST_FOREACH(replacements, listener_replacement_t *, r, tor_free(r)); SMARTLIST_FOREACH(replacements, listener_replacement_t *, r, tor_free(r));
smartlist_free(replacements); smartlist_free(replacements);
if (old_or_port != router_get_advertised_or_port(options, AF_INET) || if (old_or_port != routerconf_find_or_port(options, AF_INET) ||
old_or_port_ipv6 != router_get_advertised_or_port(options, AF_INET6) || old_or_port_ipv6 != routerconf_find_or_port(options, AF_INET6) ||
old_dir_port != router_get_advertised_dir_port(options, 0)) { old_dir_port != routerconf_find_dir_port(options, 0)) {
/* Our chosen ORPort or DirPort is not what it used to be: the /* Our chosen ORPort or DirPort is not what it used to be: the
* descriptor we had (if any) should be regenerated. (We won't * descriptor we had (if any) should be regenerated. (We won't
* automatically notice this because of changes in the option, * automatically notice this because of changes in the option,

View File

@ -4724,8 +4724,8 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
voter->sigs = smartlist_new(); voter->sigs = smartlist_new();
voter->address = hostname; voter->address = hostname;
tor_addr_copy(&voter->ipv4_addr, &addr); tor_addr_copy(&voter->ipv4_addr, &addr);
voter->ipv4_dirport = router_get_advertised_dir_port(options, 0); voter->ipv4_dirport = routerconf_find_dir_port(options, 0);
voter->ipv4_orport = router_get_advertised_or_port(options, AF_INET); voter->ipv4_orport = routerconf_find_or_port(options, AF_INET);
voter->contact = tor_strdup(contact); voter->contact = tor_strdup(contact);
if (options->V3AuthUseLegacyKey) { if (options->V3AuthUseLegacyKey) {
authority_cert_t *c = get_my_v3_legacy_cert(); authority_cert_t *c = get_my_v3_legacy_cert();

View File

@ -1151,10 +1151,10 @@ init_keys(void)
ds = router_get_trusteddirserver_by_digest(digest); ds = router_get_trusteddirserver_by_digest(digest);
if (!ds) { if (!ds) {
tor_addr_port_t ipv6_orport; tor_addr_port_t ipv6_orport;
router_get_advertised_ipv6_or_ap(options, &ipv6_orport); routerconf_find_ipv6_or_ap(options, &ipv6_orport);
ds = trusted_dir_server_new(options->Nickname, NULL, ds = trusted_dir_server_new(options->Nickname, NULL,
router_get_advertised_dir_port(options, 0), routerconf_find_dir_port(options, 0),
router_get_advertised_or_port(options,AF_INET), routerconf_find_or_port(options,AF_INET),
&ipv6_orport, &ipv6_orport,
digest, digest,
v3_digest, v3_digest,
@ -1306,10 +1306,10 @@ decide_to_advertise_dir_impl(const or_options_t *options,
return 1; return 1;
if (net_is_disabled()) if (net_is_disabled())
return 0; return 0;
if (dir_port && !router_get_advertised_dir_port(options, dir_port)) if (dir_port && !routerconf_find_dir_port(options, dir_port))
return 0; return 0;
if (supports_tunnelled_dir_requests && if (supports_tunnelled_dir_requests &&
!router_get_advertised_or_port(options, AF_INET)) !routerconf_find_or_port(options, AF_INET))
return 0; return 0;
/* Part two: consider config options that could make us choose to /* Part two: consider config options that could make us choose to
@ -1390,7 +1390,7 @@ decide_if_publishable_server(void)
return 0; return 0;
if (authdir_mode(options)) if (authdir_mode(options))
return 1; return 1;
if (!router_get_advertised_or_port(options, AF_INET)) if (!routerconf_find_or_port(options, AF_INET))
return 0; return 0;
if (!router_orport_seems_reachable(options, AF_INET)) { if (!router_orport_seems_reachable(options, AF_INET)) {
// We have an ipv4 orport, and it doesn't seem reachable. // We have an ipv4 orport, and it doesn't seem reachable.
@ -1463,7 +1463,7 @@ router_get_active_listener_port_by_type_af(int listener_type,
* family; this is either the one configured in the ORPort option, or the one * family; this is either the one configured in the ORPort option, or the one
* we actually bound to if ORPort is "auto". Returns 0 if no port is found. */ * we actually bound to if ORPort is "auto". Returns 0 if no port is found. */
uint16_t uint16_t
router_get_advertised_or_port(const or_options_t *options, routerconf_find_or_port(const or_options_t *options,
sa_family_t family) sa_family_t family)
{ {
int port = portconf_get_first_advertised_port(CONN_TYPE_OR_LISTENER, int port = portconf_get_first_advertised_port(CONN_TYPE_OR_LISTENER,
@ -1479,11 +1479,11 @@ router_get_advertised_or_port(const or_options_t *options,
return port; return port;
} }
/** As router_get_advertised_or_port(), but returns the IPv6 address and /** As routerconf_find_or_port(), but returns the IPv6 address and
* port in ipv6_ap_out, which must not be NULL. Returns a null address and * port in ipv6_ap_out, which must not be NULL. Returns a null address and
* zero port, if no ORPort is found. */ * zero port, if no ORPort is found. */
void void
router_get_advertised_ipv6_or_ap(const or_options_t *options, routerconf_find_ipv6_or_ap(const or_options_t *options,
tor_addr_port_t *ipv6_ap_out) tor_addr_port_t *ipv6_ap_out)
{ {
/* Bug in calling function, we can't return a sensible result, and it /* Bug in calling function, we can't return a sensible result, and it
@ -1497,7 +1497,7 @@ router_get_advertised_ipv6_or_ap(const or_options_t *options,
const tor_addr_t *addr = portconf_get_first_advertised_addr( const tor_addr_t *addr = portconf_get_first_advertised_addr(
CONN_TYPE_OR_LISTENER, CONN_TYPE_OR_LISTENER,
AF_INET6); AF_INET6);
const uint16_t port = router_get_advertised_or_port(options, const uint16_t port = routerconf_find_or_port(options,
AF_INET6); AF_INET6);
if (!addr || port == 0) { if (!addr || port == 0) {
@ -1524,10 +1524,10 @@ router_get_advertised_ipv6_or_ap(const or_options_t *options,
/** Returns true if this router has an advertised IPv6 ORPort. */ /** Returns true if this router has an advertised IPv6 ORPort. */
bool bool
router_has_advertised_ipv6_orport(const or_options_t *options) routerconf_has_ipv6_orport(const or_options_t *options)
{ {
tor_addr_port_t ipv6_ap; tor_addr_port_t ipv6_ap;
router_get_advertised_ipv6_or_ap(options, &ipv6_ap); routerconf_find_ipv6_or_ap(options, &ipv6_ap);
return tor_addr_port_is_valid_ap(&ipv6_ap, 0); return tor_addr_port_is_valid_ap(&ipv6_ap, 0);
} }
@ -1552,7 +1552,7 @@ router_can_extend_over_ipv6,(const or_options_t *options))
{ {
/* We might add some extra checks here, such as ExtendAllowIPv6Addresses /* We might add some extra checks here, such as ExtendAllowIPv6Addresses
* from ticket 33818. */ * from ticket 33818. */
return router_has_advertised_ipv6_orport(options); return routerconf_has_ipv6_orport(options);
} }
/** Return the port that we should advertise as our DirPort; /** Return the port that we should advertise as our DirPort;
@ -1561,7 +1561,7 @@ router_can_extend_over_ipv6,(const or_options_t *options))
* the one configured in the DirPort option, * the one configured in the DirPort option,
* or the one we actually bound to if DirPort is "auto". */ * or the one we actually bound to if DirPort is "auto". */
uint16_t uint16_t
router_get_advertised_dir_port(const or_options_t *options, uint16_t dirport) routerconf_find_dir_port(const or_options_t *options, uint16_t dirport)
{ {
int dirport_configured = portconf_get_primary_dir_port(); int dirport_configured = portconf_get_primary_dir_port();
(void)options; (void)options;
@ -2056,13 +2056,13 @@ router_build_fresh_unsigned_routerinfo,(routerinfo_t **ri_out))
/* IPv4. */ /* IPv4. */
tor_addr_copy(&ri->ipv4_addr, &ipv4_addr); tor_addr_copy(&ri->ipv4_addr, &ipv4_addr);
ri->ipv4_orport = router_get_advertised_or_port(options, AF_INET); ri->ipv4_orport = routerconf_find_or_port(options, AF_INET);
ri->ipv4_dirport = router_get_advertised_dir_port(options, 0); ri->ipv4_dirport = routerconf_find_dir_port(options, 0);
/* IPv6. Do not publish an IPv6 if we don't have an ORPort that can be used /* IPv6. Do not publish an IPv6 if we don't have an ORPort that can be used
* with the address. This is possible for instance if the ORPort is * with the address. This is possible for instance if the ORPort is
* IPv4Only. */ * IPv4Only. */
ipv6_orport = router_get_advertised_or_port(options, AF_INET6); ipv6_orport = routerconf_find_or_port(options, AF_INET6);
if (have_v6 && ipv6_orport != 0) { if (have_v6 && ipv6_orport != 0) {
tor_addr_copy(&ri->ipv6_addr, &ipv6_addr); tor_addr_copy(&ri->ipv6_addr, &ipv6_addr);
ri->ipv6_orport = ipv6_orport; ri->ipv6_orport = ipv6_orport;

View File

@ -65,13 +65,13 @@ int init_keys_client(void);
uint16_t router_get_active_listener_port_by_type_af(int listener_type, uint16_t router_get_active_listener_port_by_type_af(int listener_type,
sa_family_t family); sa_family_t family);
void router_get_advertised_ipv6_or_ap(const or_options_t *options, void routerconf_find_ipv6_or_ap(const or_options_t *options,
tor_addr_port_t *ipv6_ap_out); tor_addr_port_t *ipv6_ap_out);
bool router_has_advertised_ipv6_orport(const or_options_t *options); bool routerconf_has_ipv6_orport(const or_options_t *options);
MOCK_DECL(bool, router_can_extend_over_ipv6,(const or_options_t *options)); MOCK_DECL(bool, router_can_extend_over_ipv6,(const or_options_t *options));
uint16_t router_get_advertised_or_port(const or_options_t *options, uint16_t routerconf_find_or_port(const or_options_t *options,
sa_family_t family); sa_family_t family);
uint16_t router_get_advertised_dir_port(const or_options_t *options, uint16_t routerconf_find_dir_port(const or_options_t *options,
uint16_t dirport); uint16_t dirport);
int router_should_advertise_dirport(const or_options_t *options, int router_should_advertise_dirport(const or_options_t *options,

View File

@ -507,12 +507,12 @@ test_router_get_advertised_or_port(void *arg)
listener_connection_t *listener = NULL; listener_connection_t *listener = NULL;
tor_addr_port_t ipv6; tor_addr_port_t ipv6;
// Test one failing case of router_get_advertised_ipv6_or_ap(). // Test one failing case of routerconf_find_ipv6_or_ap().
router_get_advertised_ipv6_or_ap(opts, &ipv6); routerconf_find_ipv6_or_ap(opts, &ipv6);
tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0"); tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
// And one failing case of router_get_advertised_or_port(). // And one failing case of routerconf_find_or_port().
tt_int_op(0, OP_EQ, router_get_advertised_or_port(opts, AF_INET)); tt_int_op(0, OP_EQ, routerconf_find_or_port(opts, AF_INET));
// Set up a couple of configured ports. // Set up a couple of configured ports.
config_line_append(&opts->ORPort_lines, "ORPort", "[1234::5678]:auto"); config_line_append(&opts->ORPort_lines, "ORPort", "[1234::5678]:auto");
@ -521,12 +521,12 @@ test_router_get_advertised_or_port(void *arg)
tt_assert(r == 0); tt_assert(r == 0);
// There are no listeners, so the "auto" case will turn up no results. // There are no listeners, so the "auto" case will turn up no results.
tt_int_op(0, OP_EQ, router_get_advertised_or_port(opts, AF_INET6)); tt_int_op(0, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
router_get_advertised_ipv6_or_ap(opts, &ipv6); routerconf_find_ipv6_or_ap(opts, &ipv6);
tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0"); tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
// This will return the matching value from the configured port. // This will return the matching value from the configured port.
tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET)); tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET));
// Now set up a dummy listener. // Now set up a dummy listener.
MOCK(get_connection_array, mock_get_connection_array); MOCK(get_connection_array, mock_get_connection_array);
@ -536,15 +536,15 @@ test_router_get_advertised_or_port(void *arg)
smartlist_add(fake_connection_array, TO_CONN(listener)); smartlist_add(fake_connection_array, TO_CONN(listener));
// We should get a port this time. // We should get a port this time.
tt_int_op(54321, OP_EQ, router_get_advertised_or_port(opts, AF_INET6)); tt_int_op(54321, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
// Test one succeeding case of router_get_advertised_ipv6_or_ap(). // Test one succeeding case of routerconf_find_ipv6_or_ap().
router_get_advertised_ipv6_or_ap(opts, &ipv6); routerconf_find_ipv6_or_ap(opts, &ipv6);
tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ,
"[1234::5678]:54321"); "[1234::5678]:54321");
// This will return the matching value from the configured port. // This will return the matching value from the configured port.
tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET)); tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET));
done: done:
or_options_free(opts); or_options_free(opts);
@ -570,26 +570,26 @@ test_router_get_advertised_or_port_localhost(void *arg)
tt_assert(r == 0); tt_assert(r == 0);
// We should refuse to advertise them, since we have default dirauths. // We should refuse to advertise them, since we have default dirauths.
router_get_advertised_ipv6_or_ap(opts, &ipv6); routerconf_find_ipv6_or_ap(opts, &ipv6);
tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0"); tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::]:0");
// But the lower-level function should still report the correct value // But the lower-level function should still report the correct value
tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET6)); tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
// The IPv4 checks are done in resolve_my_address(), which doesn't use // The IPv4 checks are done in resolve_my_address(), which doesn't use
// ORPorts so we can't test them here. (See #33681.) Both these lower-level // ORPorts so we can't test them here. (See #33681.) Both these lower-level
// functions should still report the correct value. // functions should still report the correct value.
tt_int_op(8888, OP_EQ, router_get_advertised_or_port(opts, AF_INET)); tt_int_op(8888, OP_EQ, routerconf_find_or_port(opts, AF_INET));
// Now try with a fake authority set up. // Now try with a fake authority set up.
config_line_append(&opts->DirAuthorities, "DirAuthority", config_line_append(&opts->DirAuthorities, "DirAuthority",
"127.0.0.1:1066 " "127.0.0.1:1066 "
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
tt_int_op(9999, OP_EQ, router_get_advertised_or_port(opts, AF_INET6)); tt_int_op(9999, OP_EQ, routerconf_find_or_port(opts, AF_INET6));
router_get_advertised_ipv6_or_ap(opts, &ipv6); routerconf_find_ipv6_or_ap(opts, &ipv6);
tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::1]:9999"); tt_str_op(fmt_addrport(&ipv6.addr, ipv6.port), OP_EQ, "[::1]:9999");
tt_int_op(8888, OP_EQ, router_get_advertised_or_port(opts, AF_INET)); tt_int_op(8888, OP_EQ, routerconf_find_or_port(opts, AF_INET));
done: done:
or_options_free(opts); or_options_free(opts);