[tor-commits] [tor/master] relay: Implement HAVE_MODULE_RELAY for routermode.c

nickm at torproject.org nickm at torproject.org
Mon Oct 21 16:43:35 UTC 2019


commit 57e86a6d749f487d81787439ac84d9bed8a70941
Author: teor <teor at torproject.org>
Date:   Fri Oct 18 13:28:02 2019 +1000

    relay: Implement HAVE_MODULE_RELAY for routermode.c
    
    Part of 32123.
---
 src/app/config/config.c        |  1 +
 src/core/include.am            | 10 +++++++++-
 src/feature/relay/routermode.h | 19 +++++++++++++++++++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 37eab2291..c7ae453d5 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -2757,6 +2757,7 @@ list_deprecated_options(void)
 static void
 list_enabled_modules(void)
 {
+  printf("%s: %s\n", "relay", have_module_relay() ? "yes" : "no");
   printf("%s: %s\n", "dirauth", have_module_dirauth() ? "yes" : "no");
 }
 
diff --git a/src/core/include.am b/src/core/include.am
index 1c97f65f9..17bfb2799 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -146,7 +146,6 @@ LIBTOR_APP_A_SOURCES = 				\
 	src/feature/relay/relay_sys.c		\
 	src/feature/relay/router.c		\
 	src/feature/relay/routerkeys.c		\
-	src/feature/relay/routermode.c		\
 	src/feature/relay/selftest.c		\
 	src/feature/rend/rendcache.c		\
 	src/feature/rend/rendclient.c		\
@@ -170,6 +169,10 @@ endif
 #
 LIBTOR_APP_TESTING_A_SOURCES = $(LIBTOR_APP_A_SOURCES)
 
+# The Relay module.
+MODULE_RELAY_SOURCES = 					    \
+	src/feature/relay/routermode.c
+
 # The Directory Authority module.
 MODULE_DIRAUTH_SOURCES = 					\
 	src/feature/dirauth/authmode.c				\
@@ -189,6 +192,10 @@ MODULE_DIRAUTH_SOURCES = 					\
 	src/feature/dirauth/shared_random_state.c		\
 	src/feature/dirauth/voteflags.c
 
+if BUILD_MODULE_RELAY
+LIBTOR_APP_A_SOURCES += $(MODULE_RELAY_SOURCES)
+endif
+
 if BUILD_MODULE_DIRAUTH
 LIBTOR_APP_A_SOURCES += $(MODULE_DIRAUTH_SOURCES)
 endif
@@ -197,6 +204,7 @@ src_core_libtor_app_a_SOURCES = $(LIBTOR_APP_A_SOURCES)
 if UNITTESTS_ENABLED
 
 # Add the sources of the modules that are needed for tests to work here.
+LIBTOR_APP_TESTING_A_SOURCES += $(MODULE_RELAY_SOURCES)
 LIBTOR_APP_TESTING_A_SOURCES += $(MODULE_DIRAUTH_SOURCES)
 
 src_core_libtor_app_testing_a_SOURCES = $(LIBTOR_APP_TESTING_A_SOURCES)
diff --git a/src/feature/relay/routermode.h b/src/feature/relay/routermode.h
index a391a6485..ddf621e5c 100644
--- a/src/feature/relay/routermode.h
+++ b/src/feature/relay/routermode.h
@@ -12,6 +12,8 @@
 #ifndef TOR_ROUTERMODE_H
 #define TOR_ROUTERMODE_H
 
+#ifdef HAVE_MODULE_RELAY
+
 int dir_server_mode(const or_options_t *options);
 
 MOCK_DECL(int, server_mode, (const or_options_t *options));
@@ -20,4 +22,21 @@ MOCK_DECL(int, advertised_server_mode, (void));
 
 void set_server_advertised(int s);
 
+/* Is the relay module enabled? */
+#define have_module_relay() (1)
+
+#else
+
+#define dir_server_mode(options) (((void)(options)),0)
+#define server_mode(options) (((void)(options)),0)
+#define public_server_mode(options) (((void)(options)),0)
+#define advertised_server_mode() (0)
+
+/* We shouldn't be publishing descriptors when relay mode is disabled. */
+#define set_server_advertised(s) tor_assert_nonfatal(!(s))
+
+#define have_module_relay() (0)
+
+#endif
+
 #endif /* !defined(TOR_ROUTERMODE_H) */





More information about the tor-commits mailing list