Update copyrights to 2021, using "make update-copyright"
[tor.git] / src / feature / dirauth / authmode.c
blobde3261096edacc606277334a9e6ca796e354920d
1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file authmode.c
9 * \brief What kind of directory authority are we?
11 * If we're not an authority, these functions are all replaced with 0 in
12 * authmode.h.
13 **/
15 #include "core/or/or.h"
16 #include "app/config/config.h"
17 #include "feature/dirauth/authmode.h"
19 #include "feature/nodelist/routerinfo_st.h"
21 /** Return true iff we believe ourselves to be an authoritative
22 * directory server.
24 int
25 authdir_mode(const or_options_t *options)
27 return options->AuthoritativeDir != 0;
30 /* Return true iff we believe ourselves to be a v3 authoritative directory
31 * server. */
32 int
33 authdir_mode_v3(const or_options_t *options)
35 return authdir_mode(options) && options->V3AuthoritativeDir != 0;
38 /** Return true iff we are an authoritative directory server that is
39 * authoritative about receiving and serving descriptors of type
40 * <b>purpose</b> on its dirport.
42 int
43 authdir_mode_handles_descs(const or_options_t *options, int purpose)
45 if (BUG(purpose < 0)) /* Deprecated. */
46 return authdir_mode(options);
47 else if (purpose == ROUTER_PURPOSE_GENERAL)
48 return authdir_mode_v3(options);
49 else if (purpose == ROUTER_PURPOSE_BRIDGE)
50 return authdir_mode_bridge(options);
51 else
52 return 0;
54 /** Return true iff we are an authoritative directory server that
55 * publishes its own network statuses.
57 int
58 authdir_mode_publishes_statuses(const or_options_t *options)
60 if (authdir_mode_bridge(options))
61 return 0;
62 return authdir_mode(options);
64 /** Return true iff we are an authoritative directory server that
65 * tests reachability of the descriptors it learns about.
67 int
68 authdir_mode_tests_reachability(const or_options_t *options)
70 return authdir_mode(options);
72 /** Return true iff we believe ourselves to be a bridge authoritative
73 * directory server.
75 int
76 authdir_mode_bridge(const or_options_t *options)
78 return authdir_mode(options) && options->BridgeAuthoritativeDir != 0;