summaryrefslogtreecommitdiff
path: root/src/feature/dirauth
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2018-09-25 15:39:24 -0400
committerNick Mathewson <nickm@torproject.org>2018-09-25 15:39:24 -0400
commit70539e3d5e357521616a083a69712605b7b98c23 (patch)
tree86de66335cd30e0e29111c65286eccd74a7cac76 /src/feature/dirauth
parent9385b7ec5f6effce97ae26aa6cda08df5b90309b (diff)
downloadtor-70539e3d5e357521616a083a69712605b7b98c23.tar.gz
tor-70539e3d5e357521616a083a69712605b7b98c23.zip
Move all authdir_mode_*() functions into authmode.h
Diffstat (limited to 'src/feature/dirauth')
-rw-r--r--src/feature/dirauth/authmode.c70
-rw-r--r--src/feature/dirauth/authmode.h28
-rw-r--r--src/feature/dirauth/reachability.c1
3 files changed, 87 insertions, 12 deletions
diff --git a/src/feature/dirauth/authmode.c b/src/feature/dirauth/authmode.c
new file mode 100644
index 0000000000..7c900ea7bf
--- /dev/null
+++ b/src/feature/dirauth/authmode.c
@@ -0,0 +1,70 @@
+/* Copyright (c) 2001 Matej Pfajfar.
+ * Copyright (c) 2001-2004, Roger Dingledine.
+ * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
+ * Copyright (c) 2007-2018, The Tor Project, Inc. */
+/* See LICENSE for licensing information */
+
+/**
+ * \file authmode.c
+ * \brief What kind of directory authority are we?
+ *
+ * If we're not an authority, these functions are all replaced with 0 in
+ * authmode.h.
+ **/
+
+#include "core/or/or.h"
+#include "app/config/config.h"
+#include "feature/dirauth/authmode.h"
+
+#include "feature/nodelist/routerinfo_st.h"
+
+/** Return true iff we believe ourselves to be an authoritative
+ * directory server.
+ */
+int
+authdir_mode(const or_options_t *options)
+{
+ return options->AuthoritativeDir != 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.
+ */
+int
+authdir_mode_handles_descs(const or_options_t *options, int purpose)
+{
+ if (BUG(purpose < 0)) /* Deprecated. */
+ return authdir_mode(options);
+ else if (purpose == ROUTER_PURPOSE_GENERAL)
+ return authdir_mode_v3(options);
+ else if (purpose == ROUTER_PURPOSE_BRIDGE)
+ return authdir_mode_bridge(options);
+ else
+ return 0;
+}
+/** Return true iff we are an authoritative directory server that
+ * publishes its own network statuses.
+ */
+int
+authdir_mode_publishes_statuses(const or_options_t *options)
+{
+ if (authdir_mode_bridge(options))
+ return 0;
+ return authdir_mode(options);
+}
+/** Return true iff we are an authoritative directory server that
+ * tests reachability of the descriptors it learns about.
+ */
+int
+authdir_mode_tests_reachability(const or_options_t *options)
+{
+ return authdir_mode(options);
+}
+/** Return true iff we believe ourselves to be a bridge authoritative
+ * directory server.
+ */
+int
+authdir_mode_bridge(const or_options_t *options)
+{
+ return authdir_mode(options) && options->BridgeAuthoritativeDir != 0;
+}
diff --git a/src/feature/dirauth/authmode.h b/src/feature/dirauth/authmode.h
index 8bb961dffb..3ca127b829 100644
--- a/src/feature/dirauth/authmode.h
+++ b/src/feature/dirauth/authmode.h
@@ -2,16 +2,22 @@
/* See LICENSE for licensing information */
/**
- * \file mode.h
- * \brief Standalone header file for directory authority mode.
+ * \file authmode.h
+ * \brief Header file for directory authority mode.
**/
#ifndef TOR_DIRAUTH_MODE_H
#define TOR_DIRAUTH_MODE_H
+#include "feature/relay/router.h"
+
#ifdef HAVE_MODULE_DIRAUTH
-#include "feature/relay/router.h"
+int authdir_mode(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);
+int authdir_mode_bridge(const or_options_t *options);
/* Return true iff we believe ourselves to be a v3 authoritative directory
* server. */
@@ -23,16 +29,14 @@ authdir_mode_v3(const or_options_t *options)
#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;
-}
+#define authdir_mode(options) (((void)(options)),0)
+#define authdir_mode_handles_descs(options,purpose) \
+ (((void)(options)),((void)(purpose)),0)
+#define authdir_mode_publishes_statuses(options) (((void)(options)),0)
+#define authdir_mode_tests_reachability(options) (((void)(options)),0)
+#define authdir_mode_bridge(options) (((void)(options)),0)
+#define authdir_mode_v3(options) (((void)(options)),0)
#endif /* HAVE_MODULE_DIRAUTH */
#endif /* TOR_MODE_H */
-
diff --git a/src/feature/dirauth/reachability.c b/src/feature/dirauth/reachability.c
index abc7249b65..79c98d3ee9 100644
--- a/src/feature/dirauth/reachability.c
+++ b/src/feature/dirauth/reachability.c
@@ -16,6 +16,7 @@
#include "core/or/channel.h"
#include "core/or/channeltls.h"
#include "core/or/command.h"
+#include "feature/dirauth/authmode.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/nodelist/torcert.h"