Go to the documentation of this file.
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 */
8 * \file nodelist.h
9 * \brief Header file for nodelist.c.
10 **/
12#ifndef TOR_NODELIST_H
13#define TOR_NODELIST_H
18#define node_assert_ok(n) STMT_BEGIN { \
19 tor_assert((n)->ri || (n)->rs); \
22MOCK_DECL(node_t *, node_get_mutable_by_id,(const char *identity_digest));
23MOCK_DECL(const node_t *, node_get_by_id, (const char *identity_digest));
25 const struct ed25519_public_key_t *ed_id);
27 (const struct ed25519_public_key_t *ed_id));
29#define NNF_NO_WARN_UNNAMED (1u<<0)
31const node_t *node_get_by_hex_id(const char *identity_digest,
32 unsigned flags);
38bool nodelist_reentry_contains(const tor_addr_t *addr, uint16_t port);
40 uint16_t or_port, uint16_t dir_port);
42void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md);
44void nodelist_purge(void);
47void nodelist_free_all(void);
48void nodelist_assert_ok(void);
51 (const char *nickname, unsigned flags));
52void node_get_verbose_nickname(const node_t *node,
53 char *verbose_name_out);
54void node_get_verbose_nickname_by_id(const char *id_digest,
55 char *verbose_name_out);
56int node_is_dir(const node_t *node);
57int node_is_good_exit(const node_t *node);
58int node_has_any_descriptor(const node_t *node);
60 int for_direct_connect);
61int node_get_purpose(const node_t *node);
62#define node_is_bridge(node) \
63 (node_get_purpose((node)) == ROUTER_PURPOSE_BRIDGE)
64int node_is_me(const node_t *node);
66int node_exit_policy_is_exact(const node_t *node, sa_family_t family);
69const char *node_get_nickname(const node_t *node);
70const char *node_get_platform(const node_t *node);
71void node_get_address_string(const node_t *node, char *cp, size_t len);
72long node_get_declared_uptime(const node_t *node);
74 (const node_t *node));
75int node_ed25519_id_matches(const node_t *node,
76 const struct ed25519_public_key_t *id);
78 (const node_t *node,
79 bool compatible_with_us));
80bool node_supports_v3_hsdir(const node_t *node);
86 bool need_canonical_ipv6_conn);
87bool node_supports_conflux(const node_t *node);
89const uint8_t *node_get_rsa_id_digest(const node_t *node);
90MOCK_DECL(smartlist_t *,node_get_link_specifier_smartlist,(const node_t *node,
91 bool direct_conn));
92void link_specifier_smartlist_free_(smartlist_t *ls_list);
93#define link_specifier_smartlist_free(ls_list) \
94 FREE_AND_NULL(smartlist_t, link_specifier_smartlist_free_, (ls_list))
96int node_has_ipv6_addr(const node_t *node);
97int node_has_ipv6_orport(const node_t *node);
98int node_has_ipv6_dirport(const node_t *node);
99/* Deprecated - use node_ipv6_or_preferred or node_ipv6_dir_preferred */
100#define node_ipv6_preferred(node) node_ipv6_or_preferred(node)
101int node_ipv6_or_preferred(const node_t *node);
102void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
103void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out);
104void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out);
105int node_ipv6_dir_preferred(const node_t *node);
106void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out);
107void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out);
108void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out);
111 const node_t *node);
112crypto_pk_t *node_get_rsa_onion_key(const node_t *node);
114MOCK_DECL(const smartlist_t *, nodelist_get_list, (void));
116/* Temporary during transition to multiple addresses. */
117void node_get_addr(const node_t *node, tor_addr_t *addr_out);
120void node_set_country(node_t *node);
121void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node);
122int nodes_in_same_family(const node_t *node1, const node_t *node2);
124const node_t *router_find_exact_exit_enclave(const char *address,
125 uint16_t port);
126int node_is_unreliable(const node_t *router, int need_uptime,
127 int need_capacity, int need_guard);
128int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
129 int need_uptime);
130void router_set_status(const char *digest, int up);
132 const tor_addr_t *a2);
134/** router_have_minimum_dir_info tests to see if we have enough
135 * descriptor information to create circuits.
136 * If there are exits in the consensus, we wait until we have enough
137 * info to create exit paths before creating any circuits. If there are
138 * no exits in the consensus, we wait for enough info to create internal
139 * paths, and should avoid creating exit paths, as they will simply fail.
140 * We make sure we create all available circuit types at the same time. */
143/** Set to CONSENSUS_PATH_EXIT if there is at least one exit node
144 * in the consensus. We update this flag in compute_frac_paths_available if
145 * there is at least one relay that has an Exit flag in the consensus.
146 * Used to avoid building exit circuits when they will almost certainly fail.
147 * Set to CONSENSUS_PATH_INTERNAL if there are no exits in the consensus.
148 * (This situation typically occurs during bootstrap of a test network.)
149 * Set to CONSENSUS_PATH_UNKNOWN if we have never checked, or have
150 * reason to believe our last known value was invalid or has expired.
151 */
152typedef enum {
153 /* we haven't checked yet, or we have invalidated our previous check */
155 /* The consensus only has internal relays, and we should only
156 * create internal paths, circuits, streams, ... */
158 /* The consensus has at least one exit, and can therefore (potentially)
159 * create exit and internal paths, circuits, streams, ... */
165void router_dir_info_changed(void);
166const char *get_dir_info_status_string(void);
171STATIC int node_nickname_matches(const node_t *node, const char *nickname);
173 const node_t *node);
174STATIC int node_family_contains(const node_t *n1, const node_t *n2);
175STATIC bool node_has_declared_family(const node_t *node);
178#ifdef TOR_UNIT_TESTS
180STATIC void node_set_hsdir_index(node_t *node, const networkstatus_t *ns);
182#endif /* defined(TOR_UNIT_TESTS) */
184#endif /* defined(NODELIST_PRIVATE) */
186MOCK_DECL(int, get_estimated_address_per_node, (void));
188#endif /* !defined(TOR_NODELIST_H) */
uint16_t sa_family_t
Definition: inaddr_st.h:77
STATIC void node_lookup_declared_family(smartlist_t *out, const node_t *node)
Definition: nodelist.c:2183
STATIC int node_in_nickname_smartlist(const smartlist_t *lst, const node_t *node)
Definition: nodelist.c:2136
node_t * node_get_mutable_by_ed25519_id(const ed25519_public_key_t *ed_id)
Definition: nodelist.c:210
const node_t * node_get_by_ed25519_id(const ed25519_public_key_t *ed_id)
Definition: nodelist.c:234
int node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
Definition: nodelist.c:1195
STATIC bool node_has_declared_family(const node_t *node)
Definition: nodelist.c:2163
STATIC int node_nickname_matches(const node_t *node, const char *nickname)
Definition: nodelist.c:2124
STATIC int node_family_contains(const node_t *n1, const node_t *n2)
Definition: nodelist.c:2148
const node_t * router_find_exact_exit_enclave(const char *address, uint16_t port)
Definition: nodelist.c:2316
void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1851
bool node_supports_establish_intro_dos_extension(const node_t *node)
Definition: nodelist.c:1286
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1830
int nodelist_probably_contains_address(const tor_addr_t *addr)
Definition: nodelist.c:548
void node_get_verbose_nickname_by_id(const char *id_digest, char *verbose_name_out)
Definition: nodelist.c:1562
const uint8_t * node_get_rsa_id_digest(const node_t *node)
Definition: nodelist.c:1355
const node_t * node_get_by_id(const char *identity_digest)
Definition: nodelist.c:226
void nodelist_free_all(void)
Definition: nodelist.c:923
void node_get_address_string(const node_t *node, char *cp, size_t len)
Definition: nodelist.c:1707
void nodelist_refresh_countries(void)
Definition: nodelist.c:2092
void router_dir_info_changed(void)
Definition: nodelist.c:2479
const smartlist_t * nodelist_get_list(void)
Definition: nodelist.c:1047
int node_is_good_exit(const node_t *node)
Definition: nodelist.c:794
const node_t * node_get_by_nickname(const char *nickname, unsigned flags)
Definition: nodelist.c:1085
const char * node_get_platform(const node_t *node)
Definition: nodelist.c:1731
int node_exit_policy_is_exact(const node_t *node, sa_family_t family)
Definition: nodelist.c:1605
int router_addrs_in_same_network(const tor_addr_t *a1, const tor_addr_t *a2)
Definition: nodelist.c:2102
bool node_supports_accepting_ipv6_extends(const node_t *node, bool need_canonical_ipv6_conn)
Definition: nodelist.c:1324
void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1954
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
Definition: nodelist.c:1509
node_t * nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
Definition: nodelist.c:579
smartlist_t * node_get_all_orports(const node_t *node)
Definition: nodelist.c:1644
int node_is_me(const node_t *node)
Definition: nodelist.c:1744
const char * node_get_nickname(const node_t *node)
Definition: nodelist.c:1459
bool node_supports_conflux(const node_t *node)
Definition: nodelist.c:1346
int node_has_any_descriptor(const node_t *node)
Definition: nodelist.c:1496
void nodelist_purge(void)
Definition: nodelist.c:894
node_t * nodelist_add_microdesc(microdesc_t *md)
Definition: nodelist.c:635
int node_is_dir(const node_t *node)
Definition: nodelist.c:1473
smartlist_t * nodelist_find_nodes_with_microdesc(const microdesc_t *md)
Definition: nodelist.c:863
bool node_supports_v3_rendezvous_point(const node_t *node)
Definition: nodelist.c:1271
void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1931
bool node_supports_ed25519_link_authentication(const node_t *node, bool compatible_with_us)
Definition: nodelist.c:1235
bool node_supports_v3_hsdir(const node_t *node)
Definition: nodelist.c:1251
int node_ipv6_dir_preferred(const node_t *node)
Definition: nodelist.c:1908
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port, int need_uptime)
Definition: nodelist.c:2359
long node_get_declared_uptime(const node_t *node)
Definition: nodelist.c:1721
const char * get_dir_info_status_string(void)
Definition: nodelist.c:2489
int node_is_unreliable(const node_t *router, int need_uptime, int need_capacity, int need_guard)
Definition: nodelist.c:2344
consensus_path_type_t router_have_consensus_path(void)
Definition: nodelist.c:2469
void nodelist_add_addr_to_address_set(const tor_addr_t *addr, uint16_t or_port, uint16_t dir_port)
Definition: nodelist.c:525
int node_allows_single_hop_exits(const node_t *node)
Definition: nodelist.c:1577
int node_get_purpose(const node_t *node)
Definition: nodelist.c:1530
void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1969
void nodelist_set_consensus(const networkstatus_t *ns)
Definition: nodelist.c:689
bool nodelist_reentry_contains(const tor_addr_t *addr, uint16_t port)
Definition: nodelist.c:562
node_t * node_get_mutable_by_id(const char *identity_digest)
Definition: nodelist.c:197
Definition: nodelist.h:152
void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node)
Definition: nodelist.c:2251
void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md)
Definition: nodelist.c:809
void node_set_country(node_t *node)
Definition: nodelist.c:2071
int node_ipv6_or_preferred(const node_t *node)
Definition: nodelist.c:1800
void nodelist_remove_routerinfo(routerinfo_t *ri)
Definition: nodelist.c:823
void nodelist_ensure_freshness(const networkstatus_t *ns)
Definition: nodelist.c:1026
const struct ed25519_public_key_t * node_get_ed25519_id(const node_t *node)
Definition: nodelist.c:1150
void node_get_addr(const node_t *node, tor_addr_t *addr_out)
Definition: nodelist.c:1681
const node_t * node_get_by_hex_id(const char *identity_digest, unsigned flags)
Definition: nodelist.c:1058
int count_loading_descriptors_progress(void)
Definition: nodelist.c:2779
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
Definition: nodelist.c:1542
bool node_supports_initiating_ipv6_extends(const node_t *node)
Definition: nodelist.c:1303
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1866
int nodes_in_same_family(const node_t *node1, const node_t *node2)
Definition: nodelist.c:2204
int node_has_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:2018
int router_have_minimum_dir_info(void)
Definition: nodelist.c:2436
const struct curve25519_public_key_t * node_get_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:2025
void nodelist_assert_ok(void)
Definition: nodelist.c:949
int node_exit_policy_rejects_all(const node_t *node)
Definition: nodelist.c:1588
bool node_supports_ed25519_hs_intro(const node_t *node)
Definition: nodelist.c:1261
void router_set_status(const char *digest, int up)
Definition: nodelist.c:2380
Definition: node_st.h:34
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127