Browse Source

dirauth: Move authdir_mode_v3() to module

This function must return false if the module is not compiled in. In order to
do that, we move the authdir_mode_v3() function out of router.c and into the
dirauth module new header file named mode.h.

It is always returning false if we don't have the module.

Closes #25990

Signed-off-by: David Goulet <dgoulet@torproject.org>
David Goulet 6 years ago
parent
commit
1f739e9b06

+ 1 - 0
src/or/config.c

@@ -112,6 +112,7 @@
 #include "procmon.h"
 
 #include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
 
 #ifdef HAVE_SYSTEMD
 #   if defined(__COVERITY__) && !defined(__INCLUDE_LEVEL__)

+ 4 - 2
src/or/dirauth/dirvote.c

@@ -9,7 +9,6 @@
 #include "dircollate.h"
 #include "directory.h"
 #include "dirserv.h"
-#include "dirvote.h"
 #include "microdesc.h"
 #include "networkstatus.h"
 #include "nodelist.h"
@@ -23,9 +22,12 @@
 #include "routerparse.h"
 #include "entrynodes.h" /* needed for guardfraction methods */
 #include "torcert.h"
-#include "shared_random_state.h"
 #include "voting_schedule.h"
 
+#include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
+#include "dirauth/shared_random_state.h"
+
 /**
  * \file dirvote.c
  * \brief Functions to compute directory consensus, and schedule voting.

+ 38 - 0
src/or/dirauth/mode.h

@@ -0,0 +1,38 @@
+/* Copyright (c) 2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file mode.h
+ * \brief Standalone header file for directory authority mode.
+ **/
+
+#ifndef TOR_DIRAUTH_MODE_H
+#define TOR_DIRAUTH_MODE_H
+
+#ifdef HAVE_MODULE_DIRAUTH
+
+#include "router.h"
+
+/* Return true iff we believe ourselves to be a v3 authoritative directory
+ * server. */
+static inline int
+authdir_mode_v3(const or_options_t *options)
+{
+  return authdir_mode(options) && options->V3AuthoritativeDir != 0;
+}
+
+#else /* HAVE_MODULE_DIRAUTH */
+
+/* Without the dirauth module, we can't be a v3 directory authority, ever. */
+
+static inline int
+authdir_mode_v3(const or_options_t *options)
+{
+  (void) options;
+  return 0;
+}
+
+#endif /* HAVE_MODULE_DIRAUTH */
+
+#endif /* TOR_MODE_H */
+

+ 1 - 0
src/or/dirauth/shared_random.c

@@ -101,6 +101,7 @@
 #include "voting_schedule.h"
 
 #include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
 
 /* String prefix of shared random values in votes/consensuses. */
 static const char previous_srv_str[] = "shared-rand-previous-value";

+ 2 - 1
src/or/directory.c

@@ -40,7 +40,6 @@
 #include "routerlist.h"
 #include "routerparse.h"
 #include "routerset.h"
-#include "dirauth/shared_random.h"
 
 #if defined(EXPORTMALLINFO) && defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 #if !defined(OpenBSD)
@@ -49,6 +48,8 @@
 #endif
 
 #include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
+#include "dirauth/shared_random.h"
 
 /**
  * \file directory.c

+ 1 - 0
src/or/include.am

@@ -279,6 +279,7 @@ ORHEADERS = \
 ORHEADERS += \
 	src/or/dirauth/dircollate.h				\
 	src/or/dirauth/dirvote.h				\
+	src/or/dirauth/mode.h					\
 	src/or/dirauth/shared_random.h				\
 	src/or/dirauth/shared_random_state.h
 

+ 2 - 1
src/or/main.c

@@ -103,7 +103,6 @@
 #include "routerlist.h"
 #include "routerparse.h"
 #include "scheduler.h"
-#include "dirauth/shared_random.h"
 #include "statefile.h"
 #include "status.h"
 #include "tor_api.h"
@@ -119,6 +118,8 @@
 #include <event2/event.h>
 
 #include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
+#include "dirauth/shared_random.h"
 
 #ifdef HAVE_SYSTEMD
 #   if defined(__COVERITY__) && !defined(__INCLUDE_LEVEL__)

+ 2 - 1
src/or/networkstatus.c

@@ -63,13 +63,14 @@
 #include "routerlist.h"
 #include "routerparse.h"
 #include "scheduler.h"
-#include "dirauth/shared_random.h"
 #include "transports.h"
 #include "torcert.h"
 #include "channelpadding.h"
 #include "voting_schedule.h"
 
 #include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
+#include "dirauth/shared_random.h"
 
 /** Most recently received and validated v3 "ns"-flavored consensus network
  * status. */

+ 2 - 0
src/or/nodelist.c

@@ -66,6 +66,8 @@
 
 #include <string.h>
 
+#include "dirauth/mode.h"
+
 static void nodelist_drop_node(node_t *node, int remove_from_ht);
 #define node_free(val) \
   FREE_AND_NULL(node_t, node_free_, (val))

+ 2 - 8
src/or/router.c

@@ -35,6 +35,8 @@
 #include "transports.h"
 #include "routerset.h"
 
+#include "dirauth/mode.h"
+
 /**
  * \file router.c
  * \brief Miscellaneous relay functionality, including RSA key maintenance,
@@ -1612,14 +1614,6 @@ authdir_mode(const or_options_t *options)
 {
   return options->AuthoritativeDir != 0;
 }
-/** Return true iff we believe ourselves to be a v3 authoritative
- * directory server.
- */
-int
-authdir_mode_v3(const or_options_t *options)
-{
-  return authdir_mode(options) && options->V3AuthoritativeDir != 0;
-}
 /** Return true iff we are an authoritative directory server that is
  * authoritative about receiving and serving descriptors of type
  * <b>purpose</b> on its dirport.

+ 0 - 1
src/or/router.h

@@ -55,7 +55,6 @@ void router_perform_bandwidth_test(int num_circs, time_t now);
 int net_is_disabled(void);
 
 int authdir_mode(const or_options_t *options);
-int authdir_mode_v3(const or_options_t *options);
 int authdir_mode_handles_descs(const or_options_t *options, int purpose);
 int authdir_mode_publishes_statuses(const or_options_t *options);
 int authdir_mode_tests_reachability(const or_options_t *options);

+ 1 - 0
src/or/routerlist.c

@@ -122,6 +122,7 @@
 #include "torcert.h"
 
 #include "dirauth/dirvote.h"
+#include "dirauth/mode.h"
 
 // #define DEBUG_ROUTERLIST