nodelist.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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-2017, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file nodelist.h
  8. * \brief Header file for nodelist.c.
  9. **/
  10. #ifndef TOR_NODELIST_H
  11. #define TOR_NODELIST_H
  12. #define node_assert_ok(n) STMT_BEGIN { \
  13. tor_assert((n)->ri || (n)->rs); \
  14. } STMT_END
  15. node_t *node_get_mutable_by_id(const char *identity_digest);
  16. MOCK_DECL(const node_t *, node_get_by_id, (const char *identity_digest));
  17. node_t *node_get_mutable_by_ed25519_id(const ed25519_public_key_t *ed_id);
  18. MOCK_DECL(const node_t *, node_get_by_ed25519_id,
  19. (const ed25519_public_key_t *ed_id));
  20. #define NNF_NO_WARN_UNNAMED (1u<<0)
  21. const node_t *node_get_by_hex_id(const char *identity_digest,
  22. unsigned flags);
  23. node_t *nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out);
  24. node_t *nodelist_add_microdesc(microdesc_t *md);
  25. void nodelist_set_consensus(networkstatus_t *ns);
  26. void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md);
  27. void nodelist_remove_routerinfo(routerinfo_t *ri);
  28. void nodelist_purge(void);
  29. smartlist_t *nodelist_find_nodes_with_microdesc(const microdesc_t *md);
  30. void nodelist_recompute_all_hsdir_indices(void);
  31. void nodelist_free_all(void);
  32. void nodelist_assert_ok(void);
  33. MOCK_DECL(const node_t *, node_get_by_nickname,
  34. (const char *nickname, unsigned flags));
  35. void node_get_verbose_nickname(const node_t *node,
  36. char *verbose_name_out);
  37. void node_get_verbose_nickname_by_id(const char *id_digest,
  38. char *verbose_name_out);
  39. int node_is_dir(const node_t *node);
  40. int node_has_descriptor(const node_t *node);
  41. int node_get_purpose(const node_t *node);
  42. #define node_is_bridge(node) \
  43. (node_get_purpose((node)) == ROUTER_PURPOSE_BRIDGE)
  44. int node_is_me(const node_t *node);
  45. int node_exit_policy_rejects_all(const node_t *node);
  46. int node_exit_policy_is_exact(const node_t *node, sa_family_t family);
  47. smartlist_t *node_get_all_orports(const node_t *node);
  48. int node_allows_single_hop_exits(const node_t *node);
  49. const char *node_get_nickname(const node_t *node);
  50. const char *node_get_platform(const node_t *node);
  51. uint32_t node_get_prim_addr_ipv4h(const node_t *node);
  52. void node_get_address_string(const node_t *node, char *cp, size_t len);
  53. long node_get_declared_uptime(const node_t *node);
  54. const smartlist_t *node_get_declared_family(const node_t *node);
  55. const ed25519_public_key_t *node_get_ed25519_id(const node_t *node);
  56. int node_ed25519_id_matches(const node_t *node,
  57. const ed25519_public_key_t *id);
  58. int node_supports_ed25519_link_authentication(const node_t *node,
  59. int compatible_with_us);
  60. int node_supports_v3_hsdir(const node_t *node);
  61. int node_supports_ed25519_hs_intro(const node_t *node);
  62. int node_supports_v3_rendezvous_point(const node_t *node);
  63. const uint8_t *node_get_rsa_id_digest(const node_t *node);
  64. int node_has_ipv6_addr(const node_t *node);
  65. int node_has_ipv6_orport(const node_t *node);
  66. int node_has_ipv6_dirport(const node_t *node);
  67. /* Deprecated - use node_ipv6_or_preferred or node_ipv6_dir_preferred */
  68. #define node_ipv6_preferred(node) node_ipv6_or_preferred(node)
  69. int node_ipv6_or_preferred(const node_t *node);
  70. int node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
  71. void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out);
  72. void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out);
  73. int node_ipv6_dir_preferred(const node_t *node);
  74. int node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out);
  75. void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out);
  76. void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out);
  77. int node_has_curve25519_onion_key(const node_t *node);
  78. const curve25519_public_key_t *node_get_curve25519_onion_key(
  79. const node_t *node);
  80. MOCK_DECL(smartlist_t *, nodelist_get_list, (void));
  81. /* Temporary during transition to multiple addresses. */
  82. void node_get_addr(const node_t *node, tor_addr_t *addr_out);
  83. #define node_get_addr_ipv4h(n) node_get_prim_addr_ipv4h((n))
  84. void nodelist_refresh_countries(void);
  85. void node_set_country(node_t *node);
  86. void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node);
  87. int nodes_in_same_family(const node_t *node1, const node_t *node2);
  88. const node_t *router_find_exact_exit_enclave(const char *address,
  89. uint16_t port);
  90. int node_is_unreliable(const node_t *router, int need_uptime,
  91. int need_capacity, int need_guard);
  92. int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
  93. int need_uptime);
  94. void router_set_status(const char *digest, int up);
  95. int addrs_in_same_network_family(const tor_addr_t *a1,
  96. const tor_addr_t *a2);
  97. /** router_have_minimum_dir_info tests to see if we have enough
  98. * descriptor information to create circuits.
  99. * If there are exits in the consensus, we wait until we have enough
  100. * info to create exit paths before creating any circuits. If there are
  101. * no exits in the consensus, we wait for enough info to create internal
  102. * paths, and should avoid creating exit paths, as they will simply fail.
  103. * We make sure we create all available circuit types at the same time. */
  104. MOCK_DECL(int, router_have_minimum_dir_info,(void));
  105. /** Set to CONSENSUS_PATH_EXIT if there is at least one exit node
  106. * in the consensus. We update this flag in compute_frac_paths_available if
  107. * there is at least one relay that has an Exit flag in the consensus.
  108. * Used to avoid building exit circuits when they will almost certainly fail.
  109. * Set to CONSENSUS_PATH_INTERNAL if there are no exits in the consensus.
  110. * (This situation typically occurs during bootstrap of a test network.)
  111. * Set to CONSENSUS_PATH_UNKNOWN if we have never checked, or have
  112. * reason to believe our last known value was invalid or has expired.
  113. */
  114. typedef enum {
  115. /* we haven't checked yet, or we have invalidated our previous check */
  116. CONSENSUS_PATH_UNKNOWN = -1,
  117. /* The consensus only has internal relays, and we should only
  118. * create internal paths, circuits, streams, ... */
  119. CONSENSUS_PATH_INTERNAL = 0,
  120. /* The consensus has at least one exit, and can therefore (potentially)
  121. * create exit and internal paths, circuits, streams, ... */
  122. CONSENSUS_PATH_EXIT = 1
  123. } consensus_path_type_t;
  124. MOCK_DECL(consensus_path_type_t, router_have_consensus_path, (void));
  125. void router_dir_info_changed(void);
  126. const char *get_dir_info_status_string(void);
  127. int count_loading_descriptors_progress(void);
  128. #ifdef NODELIST_PRIVATE
  129. #ifdef TOR_UNIT_TESTS
  130. STATIC void
  131. node_set_hsdir_index(node_t *node, const networkstatus_t *ns);
  132. #endif /* defined(TOR_UNIT_TESTS) */
  133. #endif /* defined(NODELIST_PRIVATE) */
  134. #endif /* !defined(TOR_NODELIST_H) */