mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
get rid of the new caching notion in resolve_my_address()
and replace it with the good old-fashioned two functions approach
This commit is contained in:
parent
b166e9edb9
commit
178599f026
@ -1893,6 +1893,13 @@ list_torrc_options(void)
|
|||||||
|
|
||||||
/** Last value actually set by resolve_my_address. */
|
/** Last value actually set by resolve_my_address. */
|
||||||
static uint32_t last_resolved_addr = 0;
|
static uint32_t last_resolved_addr = 0;
|
||||||
|
|
||||||
|
/** Accessor for last_resolved_addr from outside this file. */
|
||||||
|
uint32_t get_last_resolved_addr(void)
|
||||||
|
{
|
||||||
|
return last_resolved_addr;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Use <b>options-\>Address</b> to guess our public IP address.
|
* Use <b>options-\>Address</b> to guess our public IP address.
|
||||||
*
|
*
|
||||||
@ -1908,16 +1915,12 @@ static uint32_t last_resolved_addr = 0;
|
|||||||
* holding that hostname. (If we didn't get our address by resolving a
|
* holding that hostname. (If we didn't get our address by resolving a
|
||||||
* hostname, set *<b>hostname_out</b> to NULL.)
|
* hostname, set *<b>hostname_out</b> to NULL.)
|
||||||
*
|
*
|
||||||
* If <b>use_cached_addr</b> is true, and we have a plausible answer,
|
|
||||||
* provide that answer and return.
|
|
||||||
*
|
|
||||||
* XXXX ipv6
|
* XXXX ipv6
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
resolve_my_address(int warn_severity, const or_options_t *options,
|
resolve_my_address(int warn_severity, const or_options_t *options,
|
||||||
uint32_t *addr_out,
|
uint32_t *addr_out,
|
||||||
const char **method_out, char **hostname_out,
|
const char **method_out, char **hostname_out)
|
||||||
int use_cached_addr)
|
|
||||||
{
|
{
|
||||||
struct in_addr in;
|
struct in_addr in;
|
||||||
uint32_t addr; /* host order */
|
uint32_t addr; /* host order */
|
||||||
@ -1934,18 +1937,6 @@ resolve_my_address(int warn_severity, const or_options_t *options,
|
|||||||
|
|
||||||
tor_assert(addr_out);
|
tor_assert(addr_out);
|
||||||
|
|
||||||
/*
|
|
||||||
* Step zero: if used_cached_addr is true, and we have a cached answer,
|
|
||||||
* just return it and be done.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (use_cached_addr && last_resolved_addr) {
|
|
||||||
*addr_out = last_resolved_addr;
|
|
||||||
if (method_out)
|
|
||||||
*method_out = "CACHED";
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Step one: Fill in 'hostname' to be our best guess.
|
* Step one: Fill in 'hostname' to be our best guess.
|
||||||
*/
|
*/
|
||||||
@ -2359,7 +2350,7 @@ options_validate(or_options_t *old_options, or_options_t *options,
|
|||||||
if (authdir_mode(options)) {
|
if (authdir_mode(options)) {
|
||||||
/* confirm that our address isn't broken, so we can complain now */
|
/* confirm that our address isn't broken, so we can complain now */
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL, 0) < 0)
|
if (resolve_my_address(LOG_WARN, options, &tmp, NULL, NULL) < 0)
|
||||||
REJECT("Failed to resolve/guess local address. See logs for details.");
|
REJECT("Failed to resolve/guess local address. See logs for details.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,10 +26,10 @@ const char *get_short_version(void);
|
|||||||
setopt_err_t options_trial_assign(config_line_t *list, int use_defaults,
|
setopt_err_t options_trial_assign(config_line_t *list, int use_defaults,
|
||||||
int clear_first, char **msg);
|
int clear_first, char **msg);
|
||||||
|
|
||||||
|
uint32_t get_last_resolved_addr(void);
|
||||||
int resolve_my_address(int warn_severity, const or_options_t *options,
|
int resolve_my_address(int warn_severity, const or_options_t *options,
|
||||||
uint32_t *addr_out,
|
uint32_t *addr_out,
|
||||||
const char **method_out, char **hostname_out,
|
const char **method_out, char **hostname_out);
|
||||||
int use_cached_addr);
|
|
||||||
int is_local_addr(const tor_addr_t *addr);
|
int is_local_addr(const tor_addr_t *addr);
|
||||||
void options_init(or_options_t *options);
|
void options_init(or_options_t *options);
|
||||||
char *options_dump(const or_options_t *options, int minimal);
|
char *options_dump(const or_options_t *options, int minimal);
|
||||||
|
@ -2750,7 +2750,7 @@ dirserv_generate_networkstatus_vote_obj(crypto_pk_t *private_key,
|
|||||||
tor_assert(private_key);
|
tor_assert(private_key);
|
||||||
tor_assert(cert);
|
tor_assert(cert);
|
||||||
|
|
||||||
if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname, 0)<0) {
|
if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname)<0) {
|
||||||
log_warn(LD_NET, "Couldn't resolve my hostname");
|
log_warn(LD_NET, "Couldn't resolve my hostname");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -2960,7 +2960,7 @@ generate_v2_networkstatus_opinion(void)
|
|||||||
|
|
||||||
private_key = get_server_identity_key();
|
private_key = get_server_identity_key();
|
||||||
|
|
||||||
if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname, 0)<0) {
|
if (resolve_my_address(LOG_WARN, options, &addr, NULL, &hostname)<0) {
|
||||||
log_warn(LD_NET, "Couldn't resolve my hostname");
|
log_warn(LD_NET, "Couldn't resolve my hostname");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
@ -1712,7 +1712,9 @@ static int router_guess_address_from_dir_headers(uint32_t *guess);
|
|||||||
int
|
int
|
||||||
router_pick_published_address(const or_options_t *options, uint32_t *addr)
|
router_pick_published_address(const or_options_t *options, uint32_t *addr)
|
||||||
{
|
{
|
||||||
if (resolve_my_address(LOG_INFO, options, addr, NULL, NULL, 1) < 0) {
|
*addr = get_last_resolved_addr();
|
||||||
|
if (!*addr &&
|
||||||
|
resolve_my_address(LOG_INFO, options, addr, NULL, NULL) < 0) {
|
||||||
log_info(LD_CONFIG, "Could not determine our address locally. "
|
log_info(LD_CONFIG, "Could not determine our address locally. "
|
||||||
"Checking if directory headers provide any hints.");
|
"Checking if directory headers provide any hints.");
|
||||||
if (router_guess_address_from_dir_headers(addr) < 0) {
|
if (router_guess_address_from_dir_headers(addr) < 0) {
|
||||||
@ -2103,7 +2105,7 @@ check_descriptor_ipaddress_changed(time_t now)
|
|||||||
|
|
||||||
/* XXXX ipv6 */
|
/* XXXX ipv6 */
|
||||||
prev = desc_routerinfo->addr;
|
prev = desc_routerinfo->addr;
|
||||||
if (resolve_my_address(LOG_INFO, options, &cur, &method, &hostname, 0) < 0) {
|
if (resolve_my_address(LOG_INFO, options, &cur, &method, &hostname) < 0) {
|
||||||
log_info(LD_CONFIG,"options->Address didn't resolve into an IP.");
|
log_info(LD_CONFIG,"options->Address didn't resolve into an IP.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2159,7 +2161,9 @@ router_new_address_suggestion(const char *suggestion,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* XXXX ipv6 */
|
/* XXXX ipv6 */
|
||||||
if (resolve_my_address(LOG_INFO, options, &cur, NULL, NULL, 1) >= 0) {
|
cur = get_last_resolved_addr();
|
||||||
|
if (cur ||
|
||||||
|
resolve_my_address(LOG_INFO, options, &cur, NULL, NULL) >= 0) {
|
||||||
/* We're all set -- we already know our address. Great. */
|
/* We're all set -- we already know our address. Great. */
|
||||||
tor_addr_from_ipv4h(&last_guessed_ip, cur); /* store it in case we
|
tor_addr_from_ipv4h(&last_guessed_ip, cur); /* store it in case we
|
||||||
need it later */
|
need it later */
|
||||||
|
@ -3952,7 +3952,7 @@ trusted_dir_server_new(const char *nickname, const char *address,
|
|||||||
|
|
||||||
if (!address) { /* The address is us; we should guess. */
|
if (!address) { /* The address is us; we should guess. */
|
||||||
if (resolve_my_address(LOG_WARN, get_options(),
|
if (resolve_my_address(LOG_WARN, get_options(),
|
||||||
&a, NULL, &hostname, 0) < 0) {
|
&a, NULL, &hostname) < 0) {
|
||||||
log_warn(LD_CONFIG,
|
log_warn(LD_CONFIG,
|
||||||
"Couldn't find a suitable address when adding ourself as a "
|
"Couldn't find a suitable address when adding ourself as a "
|
||||||
"trusted directory server.");
|
"trusted directory server.");
|
||||||
|
Loading…
Reference in New Issue
Block a user