diff options
Diffstat (limited to 'src/feature')
-rw-r--r-- | src/feature/client/transports.c | 7 | ||||
-rw-r--r-- | src/feature/control/control_getinfo.c | 3 | ||||
-rw-r--r-- | src/feature/relay/relay_find_addr.c | 14 | ||||
-rw-r--r-- | src/feature/relay/relay_find_addr.h | 7 | ||||
-rw-r--r-- | src/feature/relay/router.c | 6 |
5 files changed, 24 insertions, 13 deletions
diff --git a/src/feature/client/transports.c b/src/feature/client/transports.c index 8a0694449a..2eb05d6a67 100644 --- a/src/feature/client/transports.c +++ b/src/feature/client/transports.c @@ -1652,11 +1652,12 @@ pt_get_extra_info_descriptor_string(void) tor_addr_t addr; /* Attempt to find the IPv4 and then attempt to find the IPv6 if we * can't find it. */ - bool found = relay_find_addr_to_publish(get_options(), AF_INET, false, + bool found = relay_find_addr_to_publish(get_options(), AF_INET, + RELAY_FIND_ADDR_NO_FLAG, &addr); if (!found) { - found = relay_find_addr_to_publish(get_options(), AF_INET6, false, - &addr); + found = relay_find_addr_to_publish(get_options(), AF_INET6, + RELAY_FIND_ADDR_NO_FLAG, &addr); } if (!found) { log_err(LD_PT, "Unable to find address for transport %s", t->name); diff --git a/src/feature/control/control_getinfo.c b/src/feature/control/control_getinfo.c index 4ac4f48a86..3e4feadded 100644 --- a/src/feature/control/control_getinfo.c +++ b/src/feature/control/control_getinfo.c @@ -133,7 +133,8 @@ getinfo_helper_misc(control_connection_t *conn, const char *question, *answer = tor_strdup("VERBOSE_NAMES EXTENDED_EVENTS"); } else if (!strcmp(question, "address")) { tor_addr_t addr; - if (!relay_find_addr_to_publish(get_options(), AF_INET, true, &addr)) { + if (!relay_find_addr_to_publish(get_options(), AF_INET, + RELAY_FIND_ADDR_CACHE_ONLY, &addr)) { *errmsg = "Address unknown"; return -1; } diff --git a/src/feature/relay/relay_find_addr.c b/src/feature/relay/relay_find_addr.c index 9a279d2277..48f28b182a 100644 --- a/src/feature/relay/relay_find_addr.c +++ b/src/feature/relay/relay_find_addr.c @@ -86,18 +86,19 @@ relay_address_new_suggestion(const tor_addr_t *suggested_addr, * 1. Resolved cache. Populated by find_my_address() during the relay * periodic event that attempts to learn if our address has changed. * - * 2. If cache_only is false, attempt to find the address using the - * relay_find_addr.h interface. + * 2. If flags is set with RELAY_FIND_ADDR_CACHE_ONLY, only the resolved + * and suggested cache are looked at. No address discovery will be done. * * 3. Finally, if all fails, use the suggested address cache which is - * populated by the NETINFO cell values. + * populated by the NETINFO cell content or HTTP header from a + * directory. * * Return true on success and addr_out contains the address to use for the * given family. On failure to find the address, false is returned and * addr_out is set to an AF_UNSPEC address. */ MOCK_IMPL(bool, relay_find_addr_to_publish, (const or_options_t *options, int family, - bool cache_only, tor_addr_t *addr_out)) + int flags, tor_addr_t *addr_out)) { tor_assert(options); tor_assert(addr_out); @@ -113,7 +114,7 @@ relay_find_addr_to_publish, (const or_options_t *options, int family, /* Second, attempt to find our address. The following can do a DNS resolve * thus only do it when the no cache only flag is flipped. */ - if (!cache_only) { + if (!(flags & RELAY_FIND_ADDR_CACHE_ONLY)) { if (find_my_address(options, family, LOG_INFO, addr_out, NULL, NULL)) { goto found; } @@ -140,5 +141,6 @@ bool relay_has_address_set(int family) { tor_addr_t addr; - return relay_find_addr_to_publish(get_options(), family, 1, &addr); + return relay_find_addr_to_publish(get_options(), family, + RELAY_FIND_ADDR_CACHE_ONLY, &addr); } diff --git a/src/feature/relay/relay_find_addr.h b/src/feature/relay/relay_find_addr.h index 294ae4db57..3d30946b05 100644 --- a/src/feature/relay/relay_find_addr.h +++ b/src/feature/relay/relay_find_addr.h @@ -9,12 +9,17 @@ #ifndef TOR_RELAY_FIND_ADDR_H #define TOR_RELAY_FIND_ADDR_H +typedef enum { + RELAY_FIND_ADDR_NO_FLAG = (1U << 0), + RELAY_FIND_ADDR_CACHE_ONLY = (1U << 1), +} relay_find_addr_flags_t; + void relay_address_new_suggestion(const tor_addr_t *suggested_addr, const tor_addr_t *peer_addr, const char *identity_digest); MOCK_DECL(bool, relay_find_addr_to_publish, - (const or_options_t *options, int family, bool cache_only, + (const or_options_t *options, int family, int flags, tor_addr_t *addr_out)); bool relay_has_address_set(int family); diff --git a/src/feature/relay/router.c b/src/feature/relay/router.c index 039aeb7343..b75241160f 100644 --- a/src/feature/relay/router.c +++ b/src/feature/relay/router.c @@ -2040,9 +2040,11 @@ router_build_fresh_unsigned_routerinfo,(routerinfo_t **ri_out)) /* Find our resolved address both IPv4 and IPv6. In case the address is not * found, the object is set to an UNSPEC address. */ - bool have_v4 = relay_find_addr_to_publish(options, AF_INET, false, + bool have_v4 = relay_find_addr_to_publish(options, AF_INET, + RELAY_FIND_ADDR_NO_FLAG, &ipv4_addr); - bool have_v6 = relay_find_addr_to_publish(options, AF_INET6, false, + bool have_v6 = relay_find_addr_to_publish(options, AF_INET6, + RELAY_FIND_ADDR_NO_FLAG, &ipv6_addr); /* Tor requires a relay to have an IPv4 so bail if we can't find it. */ |