[tor-commits] [tor/master] config: Move server transport actions into the relay module

teor at torproject.org teor at torproject.org
Tue Nov 5 04:28:52 UTC 2019


commit 6d03c0566568f4a56efb4aea2f32bcd86c090a22
Author: teor <teor at torproject.org>
Date:   Wed Oct 30 13:55:49 2019 +1000

    config: Move server transport actions into the relay module
    
    This commit:
    * moves server transport config checks into transport_config.c,
    * adds thin wrappers to make the moved code compile.
    
    No functional changes: the moved code is still enabled,
    even if the relay module is disabled. (Some of the checks
    are re-ordered, so the order of some warnings may change.)
    
    Part of 32213.
---
 src/app/config/config.c              | 38 ++++--------------------
 src/feature/relay/transport_config.c | 57 ++++++++++++++++++++++++++++++++++++
 src/feature/relay/transport_config.h |  2 ++
 3 files changed, 64 insertions(+), 33 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 7c31a4443..b257603b0 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -1865,19 +1865,6 @@ options_act,(const or_options_t *old_options))
              "in a non-anonymous mode. It will provide NO ANONYMITY.");
   }
 
-  /* If we are a bridge with a pluggable transport proxy but no
-     Extended ORPort, inform the user that they are missing out. */
-  if (server_mode(options) && options->ServerTransportPlugin &&
-      !options->ExtORPort_lines) {
-    log_notice(LD_CONFIG, "We use pluggable transports but the Extended "
-               "ORPort is disabled. Tor and your pluggable transports proxy "
-               "communicate with each other via the Extended ORPort so it "
-               "is suggested you enable it: it will also allow your Bridge "
-               "to collect statistics about its clients that use pluggable "
-               "transports. Please enable it using the ExtORPort torrc option "
-               "(e.g. set 'ExtORPort auto').");
-  }
-
   if (options->Bridges) {
     mark_bridge_list();
     for (cl = options->Bridges; cl; cl = cl->next) {
@@ -1930,13 +1917,7 @@ options_act,(const or_options_t *old_options))
     rep_hist_load_mtbf_data(time(NULL));
   }
 
-  /* If we have an ExtORPort, initialize its auth cookie. */
-  if (running_tor &&
-      init_ext_or_cookie_authentication(!!options->ExtORPort_lines) < 0) {
-    log_warn(LD_CONFIG,"Error creating Extended ORPort cookie file.");
-    return -1;
-  }
-
+  /* 31851: some of the code in these functions is relay-only */
   mark_transport_list();
   pt_prepare_proxy_list_for_config_read();
   if (!options->DisableNetwork) {
@@ -1952,20 +1933,11 @@ options_act,(const or_options_t *old_options))
         }
       }
     }
-
-    if (options->ServerTransportPlugin && server_mode(options)) {
-      for (cl = options->ServerTransportPlugin; cl; cl = cl->next) {
-        if (parse_transport_line(options, cl->value, 0, 1) < 0) {
-          // LCOV_EXCL_START
-          log_warn(LD_BUG,
-                   "Previously validated ServerTransportPlugin line "
-                   "could not be added!");
-          return -1;
-          // LCOV_EXCL_STOP
-        }
-      }
-    }
   }
+
+  if (options_act_server_transport(old_options) < 0)
+    return -1;
+
   sweep_transport_list();
   sweep_proxy_list();
 
diff --git a/src/feature/relay/transport_config.c b/src/feature/relay/transport_config.c
index b323f4299..4ce00ec6c 100644
--- a/src/feature/relay/transport_config.c
+++ b/src/feature/relay/transport_config.c
@@ -245,3 +245,60 @@ options_validate_server_transport(const or_options_t *old_options,
 
   return 0;
 }
+
+/** Fetch the active option list, and take server pluggable transport actions
+ * based on it. All of the things we do should survive being done repeatedly.
+ * If present, <b>old_options</b> contains the previous value of the options.
+ *
+ * Return 0 if all goes well, return -1 if it's time to die.
+ *
+ * Note: We haven't moved all the "act on new configuration" logic
+ * into the options_act* functions yet.  Some is still in do_hup() and other
+ * places.
+ */
+int
+options_act_server_transport(const or_options_t *old_options)
+{
+  (void)old_options;
+
+  config_line_t *cl;
+  const or_options_t *options = get_options();
+  int running_tor = options->command == CMD_RUN_TOR;
+
+  /* If we are a bridge with a pluggable transport proxy but no
+     Extended ORPort, inform the user that they are missing out. */
+  if (server_mode(options) && options->ServerTransportPlugin &&
+      !options->ExtORPort_lines) {
+    log_notice(LD_CONFIG, "We use pluggable transports but the Extended "
+               "ORPort is disabled. Tor and your pluggable transports proxy "
+               "communicate with each other via the Extended ORPort so it "
+               "is suggested you enable it: it will also allow your Bridge "
+               "to collect statistics about its clients that use pluggable "
+               "transports. Please enable it using the ExtORPort torrc option "
+               "(e.g. set 'ExtORPort auto').");
+  }
+
+  /* If we have an ExtORPort, initialize its auth cookie. */
+  if (running_tor &&
+      init_ext_or_cookie_authentication(!!options->ExtORPort_lines) < 0) {
+    log_warn(LD_CONFIG,"Error creating Extended ORPort cookie file.");
+    return -1;
+  }
+
+  if (!options->DisableNetwork) {
+    if (options->ServerTransportPlugin && server_mode(options)) {
+      for (cl = options->ServerTransportPlugin; cl; cl = cl->next) {
+        if (parse_transport_line(options, cl->value, 0, 1) < 0) {
+          // LCOV_EXCL_START
+          log_warn(LD_BUG,
+                   "Previously validated ServerTransportPlugin line "
+                   "could not be added!");
+          return -1;
+          // LCOV_EXCL_STOP
+        }
+      }
+    }
+  }
+
+  return 0;
+}
diff --git a/src/feature/relay/transport_config.h b/src/feature/relay/transport_config.h
index 6ef1bc402..d3ecc9338 100644
--- a/src/feature/relay/transport_config.h
+++ b/src/feature/relay/transport_config.h
@@ -24,4 +24,6 @@ int options_validate_server_transport(const or_options_t *old_options,
                                       or_options_t *options,
                                       char **msg);
 
+int options_act_server_transport(const or_options_t *old_options);
+
 #endif /* !defined(TOR_FEATURE_RELAY_TRANSPORT_CONFIG_H) */





More information about the tor-commits mailing list