authmode.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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-2018, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file authmode.c
  8. * \brief What kind of directory authority are we?
  9. *
  10. * If we're not an authority, these functions are all replaced with 0 in
  11. * authmode.h.
  12. **/
  13. #include "core/or/or.h"
  14. #include "app/config/config.h"
  15. #include "feature/dirauth/authmode.h"
  16. #include "feature/nodelist/routerinfo_st.h"
  17. /** Return true iff we believe ourselves to be an authoritative
  18. * directory server.
  19. */
  20. int
  21. authdir_mode(const or_options_t *options)
  22. {
  23. return options->AuthoritativeDir != 0;
  24. }
  25. /** Return true iff we are an authoritative directory server that is
  26. * authoritative about receiving and serving descriptors of type
  27. * <b>purpose</b> on its dirport.
  28. */
  29. int
  30. authdir_mode_handles_descs(const or_options_t *options, int purpose)
  31. {
  32. if (BUG(purpose < 0)) /* Deprecated. */
  33. return authdir_mode(options);
  34. else if (purpose == ROUTER_PURPOSE_GENERAL)
  35. return authdir_mode_v3(options);
  36. else if (purpose == ROUTER_PURPOSE_BRIDGE)
  37. return authdir_mode_bridge(options);
  38. else
  39. return 0;
  40. }
  41. /** Return true iff we are an authoritative directory server that
  42. * publishes its own network statuses.
  43. */
  44. int
  45. authdir_mode_publishes_statuses(const or_options_t *options)
  46. {
  47. if (authdir_mode_bridge(options))
  48. return 0;
  49. return authdir_mode(options);
  50. }
  51. /** Return true iff we are an authoritative directory server that
  52. * tests reachability of the descriptors it learns about.
  53. */
  54. int
  55. authdir_mode_tests_reachability(const or_options_t *options)
  56. {
  57. return authdir_mode(options);
  58. }
  59. /** Return true iff we believe ourselves to be a bridge authoritative
  60. * directory server.
  61. */
  62. int
  63. authdir_mode_bridge(const or_options_t *options)
  64. {
  65. return authdir_mode(options) && options->BridgeAuthoritativeDir != 0;
  66. }