summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-02-14 14:55:49 -0500
committerNick Mathewson <nickm@torproject.org>2013-02-14 14:55:49 -0500
commit41e0f7146a0377fb67858433deb4d9f4d7e95327 (patch)
tree7c6c1a6c7c56b4e12e76b921c2eb8feacea2827d
parent47cfee781d104a23ed44318c0c763c9834c0b7b6 (diff)
parent178599f026d9c7575a2b790c7cb5ccfba7ba1635 (diff)
downloadtor-41e0f7146a0377fb67858433deb4d9f4d7e95327.tar.gz
tor-41e0f7146a0377fb67858433deb4d9f4d7e95327.zip
Merge remote-tracking branch 'arma/bug1992'
-rw-r--r--changes/bug199211
-rw-r--r--src/or/config.c7
-rw-r--r--src/or/config.h1
-rw-r--r--src/or/main.c13
-rw-r--r--src/or/router.c8
-rw-r--r--src/or/routerlist.c3
6 files changed, 31 insertions, 12 deletions
diff --git a/changes/bug1992 b/changes/bug1992
new file mode 100644
index 0000000000..6a751dc7e6
--- /dev/null
+++ b/changes/bug1992
@@ -0,0 +1,11 @@
+ o Minor bugfixes:
+ - Stop trying to resolve our hostname so often (e.g. every time we
+ think about doing a directory fetch). Now we reuse the cached
+ answer in some cases. Fixes bugs 1992 (bugfix on 0.2.0.20-rc)
+ and 2410 (bugfix on 0.1.2.2-alpha).
+
+ o Minor features:
+ - Make bridge relays check once a minute for whether their IP
+ address has changed, rather than only every 15 minutes. Resolves
+ bugs 1913 and 1992.
+
diff --git a/src/or/config.c b/src/or/config.c
index 7ca20e46b4..a11c44bdfa 100644
--- a/src/or/config.c
+++ b/src/or/config.c
@@ -1893,6 +1893,13 @@ list_torrc_options(void)
/** Last value actually set by resolve_my_address. */
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.
*
diff --git a/src/or/config.h b/src/or/config.h
index e0748a07bf..ef4acac514 100644
--- a/src/or/config.h
+++ b/src/or/config.h
@@ -26,6 +26,7 @@ const char *get_short_version(void);
setopt_err_t options_trial_assign(config_line_t *list, int use_defaults,
int clear_first, char **msg);
+uint32_t get_last_resolved_addr(void);
int resolve_my_address(int warn_severity, const or_options_t *options,
uint32_t *addr_out,
const char **method_out, char **hostname_out);
diff --git a/src/or/main.c b/src/or/main.c
index aa601e5a4f..b5d1e2da34 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1157,7 +1157,6 @@ run_scheduled_events(time_t now)
static time_t time_to_check_v3_certificate = 0;
static time_t time_to_check_listeners = 0;
static time_t time_to_check_descriptor = 0;
- static time_t time_to_check_ipaddress = 0;
static time_t time_to_shrink_memory = 0;
static time_t time_to_try_getting_descriptors = 0;
static time_t time_to_reset_descriptor_failures = 0;
@@ -1403,11 +1402,10 @@ run_scheduled_events(time_t now)
/** 2. Periodically, we consider force-uploading our descriptor
* (if we've passed our internal checks). */
-/** How often do we check whether part of our router info has changed in a way
- * that would require an upload? */
+/** How often do we check whether part of our router info has changed in a
+ * way that would require an upload? That includes checking whether our IP
+ * address has changed. */
#define CHECK_DESCRIPTOR_INTERVAL (60)
-/** How often do we (as a router) check whether our IP address has changed? */
-#define CHECK_IPADDRESS_INTERVAL (15*60)
/* 2b. Once per minute, regenerate and upload the descriptor if the old
* one is inaccurate. */
@@ -1415,10 +1413,7 @@ run_scheduled_events(time_t now)
static int dirport_reachability_count = 0;
time_to_check_descriptor = now + CHECK_DESCRIPTOR_INTERVAL;
check_descriptor_bandwidth_changed(now);
- if (time_to_check_ipaddress < now) {
- time_to_check_ipaddress = now + CHECK_IPADDRESS_INTERVAL;
- check_descriptor_ipaddress_changed(now);
- }
+ check_descriptor_ipaddress_changed(now);
mark_my_descriptor_dirty_if_too_old(now);
consider_publishable_server(0);
/* also, check religiously for reachability, if it's within the first
diff --git a/src/or/router.c b/src/or/router.c
index 4492ed271f..7b1fdc0dfe 100644
--- a/src/or/router.c
+++ b/src/or/router.c
@@ -1712,7 +1712,9 @@ static int router_guess_address_from_dir_headers(uint32_t *guess);
int
router_pick_published_address(const or_options_t *options, uint32_t *addr)
{
- if (resolve_my_address(LOG_INFO, options, addr, NULL, NULL) < 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. "
"Checking if directory headers provide any hints.");
if (router_guess_address_from_dir_headers(addr) < 0) {
@@ -2159,7 +2161,9 @@ router_new_address_suggestion(const char *suggestion,
}
/* XXXX ipv6 */
- if (resolve_my_address(LOG_INFO, options, &cur, NULL, NULL) >= 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. */
tor_addr_from_ipv4h(&last_guessed_ip, cur); /* store it in case we
need it later */
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index 90b707bcdb..2f08167f18 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -3951,7 +3951,8 @@ trusted_dir_server_new(const char *nickname, const char *address,
dir_server_t *result;
if (!address) { /* The address is us; we should guess. */
- if (resolve_my_address(LOG_WARN, get_options(), &a, NULL, &hostname) < 0) {
+ if (resolve_my_address(LOG_WARN, get_options(),
+ &a, NULL, &hostname) < 0) {
log_warn(LD_CONFIG,
"Couldn't find a suitable address when adding ourself as a "
"trusted directory server.");