[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Audit all of the "is the network turned off" checks.



commit 0c6eabf08898e0c9f2faa397f2c2bb5fb80b78b9
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Thu Sep 21 14:34:36 2017 -0400

    Audit all of the "is the network turned off" checks.
    
    DisableNetwork is a subset of net_is_disabled(), which is (now) a
    subset of should_delay_dir_fetches().
    
    Some of these changes are redundant with others higher or lower in
    the call stack.  The ones that I think are behavior-relevant are
    listed in the changes file.  I've also added comments in a few
    places where the behavior is subtle.
    
    Fixes bug 12062; bugfix on various versions.
---
 changes/bug12062       | 16 ++++++++++++++++
 src/or/connection.c    |  6 +++++-
 src/or/dns.c           |  4 ++--
 src/or/main.c          | 14 +++++++++-----
 src/or/networkstatus.c |  9 +++++++++
 src/or/routerlist.c    |  2 +-
 6 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/changes/bug12062 b/changes/bug12062
new file mode 100644
index 000000000..c02fd7503
--- /dev/null
+++ b/changes/bug12062
@@ -0,0 +1,16 @@
+  o Minor bugfixes:
+
+    - When hibernating, do not attempt to launch DNS checks. Fixes a
+      case of bug 12062; bugfix on 0.1.2.2-alpha.
+
+    - Resolve several bugs related to descriptor fetching on bridge
+      clients with bandwidth accounting enabled. (This combination is
+      not recommended!) Fixes a case of bug 12062; bugfix on
+      0.2.0.3-alpha.
+
+    - When hibernating, do not try to upload or download
+      descriptors. Fixes a case of bug 12062; bugfix on 0.0.9pre5.
+
+    - Do not attempt to launch self-reachability tests when entering
+      hibernation. Fixes a base of bug 12062; bugfix on 0.0.9pre5.
+
diff --git a/src/or/connection.c b/src/or/connection.c
index 632a83365..66eccf7ce 100644
--- a/src/or/connection.c
+++ b/src/or/connection.c
@@ -1746,7 +1746,11 @@ connection_connect_sockaddr,(connection_t *conn,
 
   if (get_options()->DisableNetwork) {
     /* We should never even try to connect anyplace if DisableNetwork is set.
-     * Warn if we do, and refuse to make the connection. */
+     * Warn if we do, and refuse to make the connection.
+     *
+     * We only check DisableNetwork here, not we_are_hibernating(), since
+     * we'll still try to fulfill client requests sometimes in the latter case
+     * (if it is soft hibernation) */
     static ratelim_t disablenet_violated = RATELIM_INIT(30*60);
     *socket_error = SOCK_ERRNO(ENETUNREACH);
     log_fn_ratelim(&disablenet_violated, LOG_WARN, LD_BUG,
diff --git a/src/or/dns.c b/src/or/dns.c
index 078bde3ef..1de606f8d 100644
--- a/src/or/dns.c
+++ b/src/or/dns.c
@@ -1648,7 +1648,7 @@ launch_resolve,(cached_resolve_t *resolve))
   tor_addr_t a;
   int r;
 
-  if (get_options()->DisableNetwork)
+  if (net_is_disabled())
     return -1;
 
   /* What? Nameservers not configured?  Sounds like a bug. */
@@ -1883,7 +1883,7 @@ launch_test_addresses(evutil_socket_t fd, short event, void *args)
   (void)event;
   (void)args;
 
-  if (options->DisableNetwork)
+  if (net_is_disabled())
     return;
 
   log_info(LD_EXIT, "Launching checks to see whether our nameservers like to "
diff --git a/src/or/main.c b/src/or/main.c
index 65b0b8f4d..7eeaf4004 100644
--- a/src/or/main.c
+++ b/src/or/main.c
@@ -1405,7 +1405,9 @@ run_scheduled_events(time_t now)
   /* Maybe enough time elapsed for us to reconsider a circuit. */
   circuit_upgrade_circuits_from_guard_wait();
 
-  if (options->UseBridges && !options->DisableNetwork) {
+  if (options->UseBridges && !net_is_disabled()) {
+    /* Note: this check uses net_is_disabled(), not should_delay_dir_fetches()
+     * -- the latter is only for fetching consensus-derived directory info. */
     fetch_bridge_descriptors(options, now);
   }
 
@@ -1511,7 +1513,7 @@ rotate_onion_key_callback(time_t now, const or_options_t *options)
     if (router_rebuild_descriptor(1)<0) {
       log_info(LD_CONFIG, "Couldn't rebuild router descriptor");
     }
-    if (advertised_server_mode() && !options->DisableNetwork)
+    if (advertised_server_mode() && !net_is_disabled())
       router_upload_dir_desc_to_dirservers(0);
     return ONION_KEY_CONSENSUS_CHECK_INTERVAL;
   }
@@ -1877,9 +1879,11 @@ check_descriptor_callback(time_t now, const or_options_t *options)
  * address has changed. */
 #define CHECK_DESCRIPTOR_INTERVAL (60)
 
+  (void)options;
+
   /* 2b. Once per minute, regenerate and upload the descriptor if the old
    * one is inaccurate. */
-  if (!options->DisableNetwork) {
+  if (!net_is_disabled()) {
     check_descriptor_bandwidth_changed(now);
     check_descriptor_ipaddress_changed(now);
     mark_my_descriptor_dirty_if_too_old(now);
@@ -1911,7 +1915,7 @@ check_for_reachability_bw_callback(time_t now, const or_options_t *options)
    * 20 minutes of our uptime. */
   if (server_mode(options) &&
       (have_completed_a_circuit() || !any_predicted_circuits(now)) &&
-      !we_are_hibernating()) {
+      !net_is_disabled()) {
     if (stats_n_seconds_working < TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT) {
       consider_testing_reachability(1, dirport_reachability_count==0);
       if (++dirport_reachability_count > 5)
@@ -2405,7 +2409,7 @@ do_hup(void)
   /* retry appropriate downloads */
   router_reset_status_download_failures();
   router_reset_descriptor_download_failures();
-  if (!options->DisableNetwork)
+  if (!net_is_disabled())
     update_networkstatus_downloads(time(NULL));
 
   /* We'll retry routerstatus downloads in about 10 seconds; no need to
diff --git a/src/or/networkstatus.c b/src/or/networkstatus.c
index 93bb8643d..9590fe080 100644
--- a/src/or/networkstatus.c
+++ b/src/or/networkstatus.c
@@ -52,6 +52,7 @@
 #include "dirserv.h"
 #include "dirvote.h"
 #include "entrynodes.h"
+#include "hibernate.h"
 #include "main.h"
 #include "microdesc.h"
 #include "networkstatus.h"
@@ -1208,6 +1209,14 @@ should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
     return 1;
   }
 
+  if (we_are_hibernating()) {
+    if (msg_out) {
+      *msg_out = "We are hibernating or shutting down.";
+    }
+    log_info(LD_DIR, "Delaying dir fetches (Hibernating or shutting down)");
+    return 1;
+  }
+
   if (options->UseBridges) {
     if (!any_bridge_descriptors_known()) {
       if (msg_out) {
diff --git a/src/or/routerlist.c b/src/or/routerlist.c
index c7c109253..d005df945 100644
--- a/src/or/routerlist.c
+++ b/src/or/routerlist.c
@@ -4531,7 +4531,7 @@ signed_desc_digest_is_recognized(signed_descriptor_t *desc)
 void
 update_all_descriptor_downloads(time_t now)
 {
-  if (get_options()->DisableNetwork)
+  if (should_delay_dir_fetches(get_options(), NULL))
     return;
   update_router_descriptor_downloads(now);
   update_microdesc_downloads(now);



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits