tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

authmode.c (2174B)


      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 */
      6 
      7 /**
      8 * \file authmode.c
      9 * \brief What kind of directory authority are we?
     10 *
     11 * If we're not an authority, these functions are all replaced with 0 in
     12 * authmode.h.
     13 **/
     14 
     15 #include "core/or/or.h"
     16 #include "app/config/config.h"
     17 #include "feature/dirauth/authmode.h"
     18 
     19 #include "feature/nodelist/routerinfo_st.h"
     20 
     21 /** Return true iff we believe ourselves to be an authoritative
     22 * directory server.
     23 */
     24 int
     25 authdir_mode(const or_options_t *options)
     26 {
     27  return options->AuthoritativeDir != 0;
     28 }
     29 
     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)
     34 {
     35  return authdir_mode(options) && options->V3AuthoritativeDir != 0;
     36 }
     37 
     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.
     41 */
     42 int
     43 authdir_mode_handles_descs(const or_options_t *options, int purpose)
     44 {
     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;
     53 }
     54 /** Return true iff we are an authoritative directory server that
     55 * publishes its own network statuses.
     56 */
     57 int
     58 authdir_mode_publishes_statuses(const or_options_t *options)
     59 {
     60  if (authdir_mode_bridge(options))
     61    return 0;
     62  return authdir_mode(options);
     63 }
     64 /** Return true iff we are an authoritative directory server that
     65 * tests reachability of the descriptors it learns about.
     66 */
     67 int
     68 authdir_mode_tests_reachability(const or_options_t *options)
     69 {
     70  return authdir_mode(options);
     71 }
     72 /** Return true iff we believe ourselves to be a bridge authoritative
     73 * directory server.
     74 */
     75 int
     76 authdir_mode_bridge(const or_options_t *options)
     77 {
     78  return authdir_mode(options) && options->BridgeAuthoritativeDir != 0;
     79 }