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

[tor-commits] [tor/maint-0.4.0] Implement an DormantCanceledByStartup option



commit d194f6bedf48410132b03fdab06b679512c14db1
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Sun Mar 17 13:48:00 2019 -0400

    Implement an DormantCanceledByStartup option
    
    Closes ticket 29357, and comes with appropriate notions of caution.
---
 changes/ticket29357            |  7 +++++++
 doc/tor.1.txt                  | 15 +++++++++++++++
 src/app/config/config.c        |  1 +
 src/app/config/or_options_st.h |  5 +++++
 src/core/mainloop/netstatus.c  |  4 ++++
 src/test/test_mainloop.c       |  8 ++++++++
 6 files changed, 40 insertions(+)

diff --git a/changes/ticket29357 b/changes/ticket29357
new file mode 100644
index 000000000..3aab930cd
--- /dev/null
+++ b/changes/ticket29357
@@ -0,0 +1,7 @@
+  o Minor features (dormant mode):
+    - Add a DormantCanceledByStartup option to tell Tor that it should
+      treat a startup event as cancelling any previous dormant state.
+      Integrators should use this option with caution: it should
+      only be used if Tor is being started because of something that the
+      user did, and not if Tor is being automatically started in the
+      background. Closes ticket 29357.
diff --git a/doc/tor.1.txt b/doc/tor.1.txt
index 52f5bfa0c..ea9942a28 100644
--- a/doc/tor.1.txt
+++ b/doc/tor.1.txt
@@ -1850,6 +1850,21 @@ The following options are useful only for clients (that is, if
     After the first time Tor starts, it begins in dormant mode if it was
     dormant before, and not otherwise. (Default: 0)
 
+[[DormantCanceledByStartup]] **DormantCanceledByStartup** **0**|**1**::
+    By default, Tor starts in active mode if it was active the last time
+    it was shut down, and in dormant mode if it was dormant.  But if
+    this option is true, Tor treats every startup event as user
+    activity, and Tor will never start in Dormant mode, even if it has
+    been unused for a long time on previous runs. (Default: 0)
+ +
+    Note: Packagers and application developers should change the value of
+    this option only with great caution: it has the potential to
+    create spurious traffic on the network.  This option should only
+    be used if Tor is started by an affirmative user activity (like
+    clicking on an applcation or running a command), and not if Tor
+    is launched for some other reason (for example, by a startup
+    process, or by an application that launches itself on every login.)
+
 SERVER OPTIONS
 --------------
 
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 8e0bfbe79..dc213ce2f 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -396,6 +396,7 @@ static config_var_t option_vars_[] = {
   V(DormantClientTimeout,         INTERVAL, "24 hours"),
   V(DormantTimeoutDisabledByIdleStreams, BOOL,     "1"),
   V(DormantOnFirstStartup,       BOOL,      "0"),
+  V(DormantCanceledByStartup,    BOOL,      "0"),
   /* DoS circuit creation options. */
   V(DoSCircuitCreationEnabled,   AUTOBOOL, "auto"),
   V(DoSCircuitCreationMinConnections,      UINT, "0"),
diff --git a/src/app/config/or_options_st.h b/src/app/config/or_options_st.h
index 06e11d3c7..bd707fd19 100644
--- a/src/app/config/or_options_st.h
+++ b/src/app/config/or_options_st.h
@@ -1092,6 +1092,11 @@ struct or_options_t {
   /** Boolean: true if Tor should be dormant the first time it starts with
    * a datadirectory; false otherwise. */
   int DormantOnFirstStartup;
+  /**
+   * Boolean: true if Tor should treat every startup event as cancelling
+   * a possible previous dormant state.
+   **/
+  int DormantCanceledByStartup;
 };
 
 #endif
diff --git a/src/core/mainloop/netstatus.c b/src/core/mainloop/netstatus.c
index fc5a465ff..492488859 100644
--- a/src/core/mainloop/netstatus.c
+++ b/src/core/mainloop/netstatus.c
@@ -144,6 +144,10 @@ netstatus_load_from_state(const or_state_t *state, time_t now)
     last_activity = now - 60 * state->MinutesSinceUserActivity;
     participating_on_network = true;
   }
+  if (get_options()->DormantCanceledByStartup) {
+    last_activity = now;
+    participating_on_network = true;
+  }
   reset_user_activity(last_activity);
 }
 
diff --git a/src/test/test_mainloop.c b/src/test/test_mainloop.c
index 2c3449305..ed6b8a9b6 100644
--- a/src/test/test_mainloop.c
+++ b/src/test/test_mainloop.c
@@ -317,6 +317,14 @@ test_mainloop_dormant_load_state(void *arg)
   tt_assert(is_participating_on_network());
   tt_i64_op(get_last_user_activity_time(), OP_EQ, start - 123*60);
 
+  // If we would start dormant, but DormantCanceledByStartup is set, then
+  // we start up non-dormant.
+  state->Dormant = 1;
+  get_options_mutable()->DormantCanceledByStartup = 1;
+  netstatus_load_from_state(state, start);
+  tt_assert(is_participating_on_network());
+  tt_i64_op(get_last_user_activity_time(), OP_EQ, start);
+
  done:
   or_state_free(state);
 }



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