Tor  0.4.5.0-alpha-dev
nodelist.h
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-2020, 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 
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));
25  const struct ed25519_public_key_t *ed_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);
39 
40 void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md);
42 void nodelist_purge(void);
44 
45 void nodelist_free_all(void);
46 void nodelist_assert_ok(void);
47 
49  (const char *nickname, unsigned flags));
50 void node_get_verbose_nickname(const node_t *node,
51  char *verbose_name_out);
52 void node_get_verbose_nickname_by_id(const char *id_digest,
53  char *verbose_name_out);
54 int node_is_dir(const node_t *node);
55 int node_is_good_exit(const node_t *node);
56 int node_has_any_descriptor(const node_t *node);
58  int for_direct_connect);
59 int node_get_purpose(const node_t *node);
60 #define node_is_bridge(node) \
61  (node_get_purpose((node)) == ROUTER_PURPOSE_BRIDGE)
62 int node_is_me(const node_t *node);
63 int node_exit_policy_rejects_all(const node_t *node);
64 int node_exit_policy_is_exact(const node_t *node, sa_family_t family);
66 int node_allows_single_hop_exits(const node_t *node);
67 const char *node_get_nickname(const node_t *node);
68 const char *node_get_platform(const node_t *node);
69 void node_get_address_string(const node_t *node, char *cp, size_t len);
70 long node_get_declared_uptime(const node_t *node);
72  (const node_t *node));
73 int node_ed25519_id_matches(const node_t *node,
74  const struct ed25519_public_key_t *id);
76  (const node_t *node,
77  bool compatible_with_us));
78 bool node_supports_v3_hsdir(const node_t *node);
79 bool node_supports_ed25519_hs_intro(const node_t *node);
84  bool need_canonical_ipv6_conn);
85 
86 const uint8_t *node_get_rsa_id_digest(const node_t *node);
87 MOCK_DECL(smartlist_t *,node_get_link_specifier_smartlist,(const node_t *node,
88  bool direct_conn));
89 void link_specifier_smartlist_free_(smartlist_t *ls_list);
90 #define link_specifier_smartlist_free(ls_list) \
91  FREE_AND_NULL(smartlist_t, link_specifier_smartlist_free_, (ls_list))
92 
93 int node_has_ipv6_addr(const node_t *node);
94 int node_has_ipv6_orport(const node_t *node);
95 int node_has_ipv6_dirport(const node_t *node);
96 /* Deprecated - use node_ipv6_or_preferred or node_ipv6_dir_preferred */
97 #define node_ipv6_preferred(node) node_ipv6_or_preferred(node)
98 int node_ipv6_or_preferred(const node_t *node);
99 void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
100 void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out);
101 void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out);
102 int node_ipv6_dir_preferred(const node_t *node);
103 void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out);
104 void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out);
105 void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out);
106 int node_has_curve25519_onion_key(const node_t *node);
108  const node_t *node);
109 crypto_pk_t *node_get_rsa_onion_key(const node_t *node);
110 
111 MOCK_DECL(const smartlist_t *, nodelist_get_list, (void));
112 
113 /* Temporary during transition to multiple addresses. */
114 void node_get_addr(const node_t *node, tor_addr_t *addr_out);
115 
116 void nodelist_refresh_countries(void);
117 void node_set_country(node_t *node);
118 void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node);
119 int nodes_in_same_family(const node_t *node1, const node_t *node2);
120 
121 const node_t *router_find_exact_exit_enclave(const char *address,
122  uint16_t port);
123 int node_is_unreliable(const node_t *router, int need_uptime,
124  int need_capacity, int need_guard);
125 int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
126  int need_uptime);
127 void router_set_status(const char *digest, int up);
129  const tor_addr_t *a2);
130 
131 /** router_have_minimum_dir_info tests to see if we have enough
132  * descriptor information to create circuits.
133  * If there are exits in the consensus, we wait until we have enough
134  * info to create exit paths before creating any circuits. If there are
135  * no exits in the consensus, we wait for enough info to create internal
136  * paths, and should avoid creating exit paths, as they will simply fail.
137  * We make sure we create all available circuit types at the same time. */
139 
140 /** Set to CONSENSUS_PATH_EXIT if there is at least one exit node
141  * in the consensus. We update this flag in compute_frac_paths_available if
142  * there is at least one relay that has an Exit flag in the consensus.
143  * Used to avoid building exit circuits when they will almost certainly fail.
144  * Set to CONSENSUS_PATH_INTERNAL if there are no exits in the consensus.
145  * (This situation typically occurs during bootstrap of a test network.)
146  * Set to CONSENSUS_PATH_UNKNOWN if we have never checked, or have
147  * reason to believe our last known value was invalid or has expired.
148  */
149 typedef enum {
150  /* we haven't checked yet, or we have invalidated our previous check */
151  CONSENSUS_PATH_UNKNOWN = -1,
152  /* The consensus only has internal relays, and we should only
153  * create internal paths, circuits, streams, ... */
154  CONSENSUS_PATH_INTERNAL = 0,
155  /* The consensus has at least one exit, and can therefore (potentially)
156  * create exit and internal paths, circuits, streams, ... */
157  CONSENSUS_PATH_EXIT = 1
159 
161 
162 void router_dir_info_changed(void);
163 const char *get_dir_info_status_string(void);
165 
166 #ifdef NODELIST_PRIVATE
167 
168 STATIC int node_nickname_matches(const node_t *node, const char *nickname);
170  const node_t *node);
171 STATIC int node_family_contains(const node_t *n1, const node_t *n2);
172 STATIC bool node_has_declared_family(const node_t *node);
173 STATIC void node_lookup_declared_family(smartlist_t *out, const node_t *node);
174 
175 #ifdef TOR_UNIT_TESTS
176 
177 STATIC void node_set_hsdir_index(node_t *node, const networkstatus_t *ns);
178 
179 #endif /* defined(TOR_UNIT_TESTS) */
180 
181 #endif /* defined(NODELIST_PRIVATE) */
182 
183 MOCK_DECL(int, get_estimated_address_per_node, (void));
184 
185 #endif /* !defined(TOR_NODELIST_H) */
router_exit_policy_all_nodes_reject
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port, int need_uptime)
Definition: nodelist.c:2269
microdesc_t
Definition: microdesc_st.h:27
router_addrs_in_same_network
int router_addrs_in_same_network(const tor_addr_t *a1, const tor_addr_t *a2)
Definition: nodelist.c:2012
routerinfo_t
Definition: routerinfo_st.h:20
nodelist_remove_routerinfo
void nodelist_remove_routerinfo(routerinfo_t *ri)
Definition: nodelist.c:745
nodelist_probably_contains_address
int nodelist_probably_contains_address(const tor_addr_t *addr)
Definition: nodelist.c:489
nodelist_set_consensus
void nodelist_set_consensus(const networkstatus_t *ns)
Definition: nodelist.c:615
tor_addr_t
Definition: address.h:69
node_get_purpose
int node_get_purpose(const node_t *node)
Definition: nodelist.c:1440
node_has_any_descriptor
int node_has_any_descriptor(const node_t *node)
Definition: nodelist.c:1406
router_set_status
void router_set_status(const char *digest, int up)
Definition: nodelist.c:2290
node_get_verbose_nickname
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
Definition: nodelist.c:1452
router_have_minimum_dir_info
int router_have_minimum_dir_info(void)
Definition: nodelist.c:2346
node_supports_accepting_ipv6_extends
bool node_supports_accepting_ipv6_extends(const node_t *node, bool need_canonical_ipv6_conn)
Definition: nodelist.c:1243
node_get_pref_ipv6_dirport
void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1879
node_get_declared_uptime
long node_get_declared_uptime(const node_t *node)
Definition: nodelist.c:1631
node_is_unreliable
int node_is_unreliable(const node_t *router, int need_uptime, int need_capacity, int need_guard)
Definition: nodelist.c:2254
get_dir_info_status_string
const char * get_dir_info_status_string(void)
Definition: nodelist.c:2400
node_get_prim_dirport
void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1841
node_ipv6_or_preferred
int node_ipv6_or_preferred(const node_t *node)
Definition: nodelist.c:1710
node_get_curve25519_onion_key
const struct curve25519_public_key_t * node_get_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:1935
nodes_in_same_family
int nodes_in_same_family(const node_t *node1, const node_t *node2)
Definition: nodelist.c:2114
nodelist_ensure_freshness
void nodelist_ensure_freshness(const networkstatus_t *ns)
Definition: nodelist.c:946
node_get_verbose_nickname_by_id
void node_get_verbose_nickname_by_id(const char *id_digest, char *verbose_name_out)
Definition: nodelist.c:1472
node_get_address_string
void node_get_address_string(const node_t *node, char *cp, size_t len)
Definition: nodelist.c:1617
node_ed25519_id_matches
int node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
Definition: nodelist.c:1114
node_has_preferred_descriptor
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
Definition: nodelist.c:1419
node_get_prim_orport
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1740
node_has_declared_family
STATIC bool node_has_declared_family(const node_t *node)
Definition: nodelist.c:2073
nodelist_assert_ok
void nodelist_assert_ok(void)
Definition: nodelist.c:869
nodelist_add_addr_to_address_set
void nodelist_add_addr_to_address_set(const tor_addr_t *addr)
Definition: nodelist.c:476
tor_addr_port_t
Definition: address.h:81
node_supports_ed25519_hs_intro
bool node_supports_ed25519_hs_intro(const node_t *node)
Definition: nodelist.c:1180
node_get_by_id
const node_t * node_get_by_id(const char *identity_digest)
Definition: nodelist.c:223
node_is_good_exit
int node_is_good_exit(const node_t *node)
Definition: nodelist.c:716
node_ipv6_dir_preferred
int node_ipv6_dir_preferred(const node_t *node)
Definition: nodelist.c:1818
node_t
Definition: node_st.h:34
node_is_me
int node_is_me(const node_t *node)
Definition: nodelist.c:1654
nodelist_add_node_and_family
void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node)
Definition: nodelist.c:2161
ed25519_public_key_t
Definition: crypto_ed25519.h:23
node_supports_ed25519_link_authentication
bool node_supports_ed25519_link_authentication(const node_t *node, bool compatible_with_us)
Definition: nodelist.c:1154
nodelist_free_all
void nodelist_free_all(void)
Definition: nodelist.c:845
node_get_pref_dirport
void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1864
node_nickname_matches
STATIC int node_nickname_matches(const node_t *node, const char *nickname)
Definition: nodelist.c:2034
node_get_mutable_by_id
node_t * node_get_mutable_by_id(const char *identity_digest)
Definition: nodelist.c:194
node_get_ed25519_id
const struct ed25519_public_key_t * node_get_ed25519_id(const node_t *node)
Definition: nodelist.c:1069
node_supports_establish_intro_dos_extension
bool node_supports_establish_intro_dos_extension(const node_t *node)
Definition: nodelist.c:1205
node_exit_policy_rejects_all
int node_exit_policy_rejects_all(const node_t *node)
Definition: nodelist.c:1498
MOCK_DECL
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
router_find_exact_exit_enclave
const node_t * router_find_exact_exit_enclave(const char *address, uint16_t port)
Definition: nodelist.c:2226
node_get_platform
const char * node_get_platform(const node_t *node)
Definition: nodelist.c:1641
nodelist_remove_microdesc
void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md)
Definition: nodelist.c:731
node_get_pref_orport
void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1761
node_get_by_nickname
const node_t * node_get_by_nickname(const char *nickname, unsigned flags)
Definition: nodelist.c:1004
node_get_nickname
const char * node_get_nickname(const node_t *node)
Definition: nodelist.c:1369
nodelist_get_list
const smartlist_t * nodelist_get_list(void)
Definition: nodelist.c:966
router_have_consensus_path
consensus_path_type_t router_have_consensus_path(void)
Definition: nodelist.c:2379
node_exit_policy_is_exact
int node_exit_policy_is_exact(const node_t *node, sa_family_t family)
Definition: nodelist.c:1515
node_is_dir
int node_is_dir(const node_t *node)
Definition: nodelist.c:1383
curve25519_public_key_t
Definition: crypto_curve25519.h:24
nodelist_set_routerinfo
node_t * nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
Definition: nodelist.c:505
node_supports_v3_rendezvous_point
bool node_supports_v3_rendezvous_point(const node_t *node)
Definition: nodelist.c:1190
node_family_contains
STATIC int node_family_contains(const node_t *n1, const node_t *n2)
Definition: nodelist.c:2058
crypto_pk_t
Definition: crypto_rsa_nss.c:37
nodelist_add_microdesc
node_t * nodelist_add_microdesc(microdesc_t *md)
Definition: nodelist.c:561
node_in_nickname_smartlist
STATIC int node_in_nickname_smartlist(const smartlist_t *lst, const node_t *node)
Definition: nodelist.c:2046
node_get_rsa_id_digest
const uint8_t * node_get_rsa_id_digest(const node_t *node)
Definition: nodelist.c:1265
node_set_country
void node_set_country(node_t *node)
Definition: nodelist.c:1981
router_dir_info_changed
void router_dir_info_changed(void)
Definition: nodelist.c:2389
node_supports_v3_hsdir
bool node_supports_v3_hsdir(const node_t *node)
Definition: nodelist.c:1170
node_get_pref_ipv6_orport
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1776
node_get_by_ed25519_id
const node_t * node_get_by_ed25519_id(const ed25519_public_key_t *ed_id)
Definition: nodelist.c:231
node_get_all_orports
smartlist_t * node_get_all_orports(const node_t *node)
Definition: nodelist.c:1554
nodelist_purge
void nodelist_purge(void)
Definition: nodelist.c:816
sa_family_t
uint16_t sa_family_t
Definition: inaddr_st.h:77
node_get_mutable_by_ed25519_id
node_t * node_get_mutable_by_ed25519_id(const ed25519_public_key_t *ed_id)
Definition: nodelist.c:207
nodelist_refresh_countries
void nodelist_refresh_countries(void)
Definition: nodelist.c:2002
STATIC
#define STATIC
Definition: testsupport.h:32
nodelist_find_nodes_with_microdesc
smartlist_t * nodelist_find_nodes_with_microdesc(const microdesc_t *md)
Definition: nodelist.c:785
node_lookup_declared_family
STATIC void node_lookup_declared_family(smartlist_t *out, const node_t *node)
Definition: nodelist.c:2093
networkstatus_t
Definition: networkstatus_st.h:26
node_get_addr
void node_get_addr(const node_t *node, tor_addr_t *addr_out)
Definition: nodelist.c:1591
smartlist_t
Definition: smartlist_core.h:26
node_supports_initiating_ipv6_extends
bool node_supports_initiating_ipv6_extends(const node_t *node)
Definition: nodelist.c:1222
consensus_path_type_t
consensus_path_type_t
Definition: nodelist.h:149
node_has_curve25519_onion_key
int node_has_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:1928
count_loading_descriptors_progress
int count_loading_descriptors_progress(void)
Definition: nodelist.c:2690
node_allows_single_hop_exits
int node_allows_single_hop_exits(const node_t *node)
Definition: nodelist.c:1487
node_get_by_hex_id
const node_t * node_get_by_hex_id(const char *identity_digest, unsigned flags)
Definition: nodelist.c:977