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