[tor-commits] [tor/master] config: Move dirauth stats actions into the module

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


commit 1d4d2deea1987171dea64bf3e563b24194b6ac84
Author: teor <teor at torproject.org>
Date:   Wed Oct 30 15:38:23 2019 +1000

    config: Move dirauth stats actions into the module
    
    This commit:
    * moves dirauth stats and mtbf config actions into dirauth_config,
    * adds thin wrappers to make the moved code compile.
    
    The moved code is disabled when the dirauth module is disabled.
    
    Part of 32213.
---
 src/app/config/config.c              | 19 ++--------
 src/feature/dirauth/dirauth_config.c | 73 ++++++++++++++++++++++++++++++++++++
 src/feature/dirauth/dirauth_config.h | 11 ++++++
 3 files changed, 88 insertions(+), 15 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 4dc023c1a..901ed92e5 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -106,7 +106,6 @@
 #include "feature/rend/rendservice.h"
 #include "lib/geoip/geoip.h"
 #include "feature/stats/geoip_stats.h"
-#include "feature/stats/rephist.h"
 #include "lib/compress/compress.h"
 #include "lib/confmgt/structvar.h"
 #include "lib/crypt_ops/crypto_init.h"
@@ -1897,7 +1896,8 @@ options_act,(const or_options_t *old_options))
   if (! or_state_loaded() && running_tor) {
     if (or_state_load())
       return -1;
-    rep_hist_load_mtbf_data(time(NULL));
+    if (options_act_dirauth_mtbf(options) < 0)
+      return -1;
   }
 
   /* 31851: some of the code in these functions is relay-only */
@@ -2131,21 +2131,10 @@ options_act,(const or_options_t *old_options))
   }
 
   bool print_notice = 0;
-  if (options->BridgeAuthoritativeDir) {
-    time_t now = time(NULL);
-
-    if ((!old_options || !old_options->BridgeAuthoritativeDir) &&
-        options->BridgeAuthoritativeDir) {
-      rep_hist_desc_stats_init(now);
-      print_notice = 1;
-    }
-
-  if (old_options && old_options->BridgeAuthoritativeDir &&
-      !options->BridgeAuthoritativeDir)
-    rep_hist_desc_stats_term();
-
   if (options_act_relay_stats(old_options, &print_notice) < 0)
     return -1;
+  if (options_act_dirauth_stats(old_options, &print_notice) < 0)
+    return -1;
   if (print_notice)
     options_act_relay_stats_msg();
 
diff --git a/src/feature/dirauth/dirauth_config.c b/src/feature/dirauth/dirauth_config.c
index 6574edb54..99e3a45fc 100644
--- a/src/feature/dirauth/dirauth_config.c
+++ b/src/feature/dirauth/dirauth_config.c
@@ -21,6 +21,7 @@
 #include "app/config/config.h"
 
 #include "feature/dircommon/voting_schedule.h"
+#include "feature/stats/rephist.h"
 
 #include "feature/dirauth/authmode.h"
 #include "feature/dirauth/bwauth.h"
@@ -352,3 +353,75 @@ options_act_dirauth(const or_options_t *old_options)
 
   return 0;
 }
+
+/** Fetch the active option list, and take dirauth mtbf 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.
+ *
+ * Must be called immediately after a successful or_state_load().
+ *
+ * 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_dirauth_mtbf(const or_options_t *old_options)
+{
+  (void)old_options;
+
+  const or_options_t *options = get_options();
+  int running_tor = options->command == CMD_RUN_TOR;
+
+  /* Load dirauth state */
+  if (running_tor) {
+    rep_hist_load_mtbf_data(time(NULL));
+  }
+
+  return 0;
+}
+
+/** Fetch the active option list, and take dirauth statistics 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.
+ *
+ * Sets <b>*print_notice_out</b> if we enabled stats, and need to print
+ * a stats log using options_act_relay_stats_msg().
+ *
+ * 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_dirauth_stats(const or_options_t *old_options,
+                          bool *print_notice_out)
+{
+  if (BUG(!print_notice_out))
+    return -1;
+
+  const or_options_t *options = get_options();
+
+  if (options->BridgeAuthoritativeDir) {
+    time_t now = time(NULL);
+    int print_notice = 0;
+
+    if ((!old_options || !old_options->BridgeAuthoritativeDir) &&
+        options->BridgeAuthoritativeDir) {
+      rep_hist_desc_stats_init(now);
+      print_notice = 1;
+    }
+    if (print_notice)
+      *print_notice_out = 1;
+  }
+
+  /* If we used to have statistics enabled but we just disabled them,
+     stop gathering them.  */
+  if (old_options && old_options->BridgeAuthoritativeDir &&
+      !options->BridgeAuthoritativeDir)
+    rep_hist_desc_stats_term();
+
+  return 0;
+}
diff --git a/src/feature/dirauth/dirauth_config.h b/src/feature/dirauth/dirauth_config.h
index 2c67c62ec..965472aa2 100644
--- a/src/feature/dirauth/dirauth_config.h
+++ b/src/feature/dirauth/dirauth_config.h
@@ -16,6 +16,8 @@ typedef struct or_options_t or_options_t;
 
 #ifdef HAVE_MODULE_DIRAUTH
 
+#include "lib/cc/torint.h"
+
 int options_validate_dirauth_mode(const or_options_t *old_options,
                                   or_options_t *options,
                                   char **msg);
@@ -33,6 +35,9 @@ int options_validate_dirauth_testing(const or_options_t *old_options,
                                      char **msg);
 
 int options_act_dirauth(const or_options_t *old_options);
+int options_act_dirauth_mtbf(const or_options_t *old_options);
+int options_act_dirauth_stats(const or_options_t *old_options,
+                              bool *print_notice_out);
 
 #else
 
@@ -75,6 +80,12 @@ options_validate_dirauth_mode(const or_options_t *old_options,
 #define options_act_dirauth(old_options) \
   (((void)(old_options)),0)
 
+#define options_act_dirauth_mtbf(old_options) \
+  (((void)(old_options)),0)
+
+#define options_act_dirauth_stats(old_options, print_notice_out) \
+  (((void)(old_options)),((void)(print_notice_out)),0)
+
 #endif /* defined(HAVE_MODULE_DIRAUTH) */
 
 #endif /* !defined(TOR_FEATURE_DIRAUTH_DIRAUTH_CONFIG_H) */





More information about the tor-commits mailing list