Browse Source

Add an option to start tor in dormant mode for the first time.

Nick Mathewson 5 years ago
parent
commit
4f55884315
4 changed files with 23 additions and 3 deletions
  1. 10 1
      doc/tor.1.txt
  2. 1 0
      src/app/config/config.c
  3. 4 0
      src/app/config/or_options_st.h
  4. 8 2
      src/core/mainloop/netstatus.c

+ 10 - 1
doc/tor.1.txt

@@ -1803,11 +1803,20 @@ The following options are useful only for clients (that is, if
     Does not affect servers or onion services. Must be at least 10 minutes.
     Does not affect servers or onion services. Must be at least 10 minutes.
     (Default: 24 hours)
     (Default: 24 hours)
 
 
-[[DormantTimeoutDisabledByIdleStreams]] **DormantTimeoutDisabledByIdleStreams  **0**|**1**::
+[[DormantTimeoutDisabledByIdleStreams]] **DormantTimeoutDisabledByIdleStreams**  **0**|**1**::
     If true, then any open client stream (even one not reading or writing)
     If true, then any open client stream (even one not reading or writing)
     counts as client activity for the purpose of DormantClientTimeout.
     counts as client activity for the purpose of DormantClientTimeout.
     If false, then only network activity counts. (Default: 1)
     If false, then only network activity counts. (Default: 1)
 
 
+[[DormantOnFirstStartup]] **DormantOnFirstStartup** **0**|**1**::
+    If true, then the first time Tor starts up with a fresh DataDirectory,
+    it starts in dormant mode, and takes no actions until the user has made
+    a request.  (This mode is recommended if installing a Tor client for a
+    user who might not actually use it.)  If false, Tor bootstraps the first
+    time it is started, whether it sees a user request or not.
+ +
+    After the first time Tor starts, it begins in dormant mode if it was
+    dormant before, and not otherwise. (Default: 0)
 
 
 SERVER OPTIONS
 SERVER OPTIONS
 --------------
 --------------

+ 1 - 0
src/app/config/config.c

@@ -392,6 +392,7 @@ static config_var_t option_vars_[] = {
   OBSOLETE("DNSListenAddress"),
   OBSOLETE("DNSListenAddress"),
   V(DormantClientTimeout,         INTERVAL, "24 hours"),
   V(DormantClientTimeout,         INTERVAL, "24 hours"),
   V(DormantTimeoutDisabledByIdleStreams, BOOL,     "1"),
   V(DormantTimeoutDisabledByIdleStreams, BOOL,     "1"),
+  V(DormantOnFirstStartup,       BOOL,      "0"),
   /* DoS circuit creation options. */
   /* DoS circuit creation options. */
   V(DoSCircuitCreationEnabled,   AUTOBOOL, "auto"),
   V(DoSCircuitCreationEnabled,   AUTOBOOL, "auto"),
   V(DoSCircuitCreationMinConnections,      UINT, "0"),
   V(DoSCircuitCreationMinConnections,      UINT, "0"),

+ 4 - 0
src/app/config/or_options_st.h

@@ -1085,6 +1085,10 @@ struct or_options_t {
    * from becoming dormant.
    * from becoming dormant.
    **/
    **/
   int DormantTimeoutDisabledByIdleStreams;
   int DormantTimeoutDisabledByIdleStreams;
+
+  /** Boolean: true if Tor should be dormant the first time it starts with
+   * a datadirectory; false otherwise. */
+  int DormantOnFirstStartup;
 };
 };
 
 
 #endif
 #endif

+ 8 - 2
src/core/mainloop/netstatus.c

@@ -129,8 +129,14 @@ netstatus_load_from_state(const or_state_t *state, time_t now)
 {
 {
   time_t last_activity;
   time_t last_activity;
   if (state->Dormant == -1) { // Initial setup.
   if (state->Dormant == -1) { // Initial setup.
-    last_activity = now;
-    participating_on_network = true;
+    if (get_options()->DormantOnFirstStartup) {
+      last_activity = 0;
+      participating_on_network = false;
+    } else {
+      // Start up as active, treat activity as happening now.
+      last_activity = now;
+      participating_on_network = true;
+    }
   } else if (state->Dormant) {
   } else if (state->Dormant) {
     last_activity = 0;
     last_activity = 0;
     participating_on_network = false;
     participating_on_network = false;