Browse Source

Merge remote-tracking branch 'arma/bug1992'

Nick Mathewson 11 years ago
parent
commit
41e0f7146a
6 changed files with 31 additions and 12 deletions
  1. 11 0
      changes/bug1992
  2. 7 0
      src/or/config.c
  3. 1 0
      src/or/config.h
  4. 4 9
      src/or/main.c
  5. 6 2
      src/or/router.c
  6. 2 1
      src/or/routerlist.c

+ 11 - 0
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.
+

+ 7 - 0
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.
  *

+ 1 - 0
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);

+ 4 - 9
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

+ 6 - 2
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 */

+ 2 - 1
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.");