nodelist.h 8.2 KB

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