tor  0.4.0.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-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
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);
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);
38 
39 void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md);
41 void nodelist_purge(void);
43 
44 void nodelist_free_all(void);
45 void nodelist_assert_ok(void);
46 
47 MOCK_DECL(const node_t *, node_get_by_nickname,
48  (const char *nickname, unsigned flags));
49 void node_get_verbose_nickname(const node_t *node,
50  char *verbose_name_out);
51 void node_get_verbose_nickname_by_id(const char *id_digest,
52  char *verbose_name_out);
53 int node_is_dir(const node_t *node);
54 int node_is_good_exit(const node_t *node);
55 int node_has_any_descriptor(const node_t *node);
57  int for_direct_connect);
58 int node_get_purpose(const node_t *node);
59 #define node_is_bridge(node) \
60  (node_get_purpose((node)) == ROUTER_PURPOSE_BRIDGE)
61 int node_is_me(const node_t *node);
62 int node_exit_policy_rejects_all(const node_t *node);
63 int node_exit_policy_is_exact(const node_t *node, sa_family_t family);
65 int node_allows_single_hop_exits(const node_t *node);
66 const char *node_get_nickname(const node_t *node);
67 const char *node_get_platform(const node_t *node);
68 uint32_t node_get_prim_addr_ipv4h(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);
71 const struct ed25519_public_key_t *node_get_ed25519_id(const node_t *node);
72 int node_ed25519_id_matches(const node_t *node,
73  const struct ed25519_public_key_t *id);
75  int compatible_with_us);
76 int node_supports_v3_hsdir(const node_t *node);
77 int node_supports_ed25519_hs_intro(const node_t *node);
79 const uint8_t *node_get_rsa_id_digest(const node_t *node);
80 
81 int node_has_ipv6_addr(const node_t *node);
82 int node_has_ipv6_orport(const node_t *node);
83 int node_has_ipv6_dirport(const node_t *node);
84 /* Deprecated - use node_ipv6_or_preferred or node_ipv6_dir_preferred */
85 #define node_ipv6_preferred(node) node_ipv6_or_preferred(node)
86 int node_ipv6_or_preferred(const node_t *node);
87 void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out);
88 void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out);
89 void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out);
90 int node_ipv6_dir_preferred(const node_t *node);
91 void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out);
92 void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out);
93 void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out);
94 int node_has_curve25519_onion_key(const node_t *node);
96  const node_t *node);
97 crypto_pk_t *node_get_rsa_onion_key(const node_t *node);
98 
99 MOCK_DECL(smartlist_t *, nodelist_get_list, (void));
100 
101 /* Temporary during transition to multiple addresses. */
102 void node_get_addr(const node_t *node, tor_addr_t *addr_out);
103 #define node_get_addr_ipv4h(n) node_get_prim_addr_ipv4h((n))
104 
105 void nodelist_refresh_countries(void);
106 void node_set_country(node_t *node);
107 void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node);
108 int nodes_in_same_family(const node_t *node1, const node_t *node2);
109 
110 const node_t *router_find_exact_exit_enclave(const char *address,
111  uint16_t port);
112 int node_is_unreliable(const node_t *router, int need_uptime,
113  int need_capacity, int need_guard);
114 int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
115  int need_uptime);
116 void router_set_status(const char *digest, int up);
118  const tor_addr_t *a2);
119 
127 MOCK_DECL(int, router_have_minimum_dir_info,(void));
128 
138 typedef enum {
139  /* we haven't checked yet, or we have invalidated our previous check */
140  CONSENSUS_PATH_UNKNOWN = -1,
141  /* The consensus only has internal relays, and we should only
142  * create internal paths, circuits, streams, ... */
143  CONSENSUS_PATH_INTERNAL = 0,
144  /* The consensus has at least one exit, and can therefore (potentially)
145  * create exit and internal paths, circuits, streams, ... */
146  CONSENSUS_PATH_EXIT = 1
148 
149 MOCK_DECL(consensus_path_type_t, router_have_consensus_path, (void));
150 
151 void router_dir_info_changed(void);
152 const char *get_dir_info_status_string(void);
154 
155 #ifdef NODELIST_PRIVATE
156 
157 STATIC int node_nickname_matches(const node_t *node, const char *nickname);
158 STATIC int node_in_nickname_smartlist(const smartlist_t *lst,
159  const node_t *node);
160 STATIC int node_family_contains(const node_t *n1, const node_t *n2);
161 STATIC bool node_has_declared_family(const node_t *node);
162 STATIC void node_lookup_declared_family(smartlist_t *out, const node_t *node);
163 
164 #ifdef TOR_UNIT_TESTS
165 
166 STATIC void node_set_hsdir_index(node_t *node, const networkstatus_t *ns);
167 
168 #endif /* defined(TOR_UNIT_TESTS) */
169 
170 #endif /* defined(NODELIST_PRIVATE) */
171 
172 MOCK_DECL(int, get_estimated_address_per_node, (void));
173 
174 #endif /* !defined(TOR_NODELIST_H) */
const node_t * router_find_exact_exit_enclave(const char *address, uint16_t port)
Definition: nodelist.c:2068
int node_is_dir(const node_t *node)
Definition: nodelist.c:1208
const char * node_get_nickname(const node_t *node)
Definition: nodelist.c:1194
int node_exit_policy_is_exact(const node_t *node, sa_family_t family)
Definition: nodelist.c:1341
Definition: node_st.h:28
node_t * nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
Definition: nodelist.c:493
uint16_t sa_family_t
Definition: inaddr_st.h:77
int node_is_me(const node_t *node)
Definition: nodelist.c:1502
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
Definition: nodelist.c:1277
int node_has_any_descriptor(const node_t *node)
Definition: nodelist.c:1231
const struct ed25519_public_key_t * node_get_ed25519_id(const node_t *node)
Definition: nodelist.c:1051
smartlist_t * node_get_all_orports(const node_t *node)
Definition: nodelist.c:1398
void node_get_addr(const node_t *node, tor_addr_t *addr_out)
Definition: nodelist.c:1436
int node_ipv6_dir_preferred(const node_t *node)
Definition: nodelist.c:1666
long node_get_declared_uptime(const node_t *node)
Definition: nodelist.c:1479
void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1712
int node_is_unreliable(const node_t *router, int need_uptime, int need_capacity, int need_guard)
Definition: nodelist.c:2099
MOCK_DECL(int, router_have_minimum_dir_info,(void))
int addrs_in_same_network_family(const tor_addr_t *a1, const tor_addr_t *a2)
Definition: nodelist.c:1854
uint32_t node_get_prim_addr_ipv4h(const node_t *node)
Definition: nodelist.c:1446
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1624
const uint8_t * node_get_rsa_id_digest(const node_t *node)
Definition: nodelist.c:1186
int node_supports_ed25519_link_authentication(const node_t *node, int compatible_with_us)
Definition: nodelist.c:1135
STATIC void node_lookup_declared_family(smartlist_t *out, const node_t *node)
Definition: nodelist.c:1935
consensus_path_type_t
Definition: nodelist.h:138
void nodelist_free_all(void)
Definition: nodelist.c:827
void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md)
Definition: nodelist.c:713
void node_set_country(node_t *node)
Definition: nodelist.c:1829
STATIC int node_family_contains(const node_t *n1, const node_t *n2)
Definition: nodelist.c:1900
int node_exit_policy_rejects_all(const node_t *node)
Definition: nodelist.c:1323
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port, int need_uptime)
Definition: nodelist.c:2114
void nodelist_set_consensus(networkstatus_t *ns)
Definition: nodelist.c:603
const char * get_dir_info_status_string(void)
Definition: nodelist.c:2245
int node_allows_single_hop_exits(const node_t *node)
Definition: nodelist.c:1312
int node_supports_v3_rendezvous_point(const node_t *node)
Definition: nodelist.c:1172
void nodelist_refresh_countries(void)
Definition: nodelist.c:1844
int node_supports_ed25519_hs_intro(const node_t *node)
Definition: nodelist.c:1162
void nodelist_ensure_freshness(networkstatus_t *ns)
Definition: nodelist.c:928
void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1727
void nodelist_remove_routerinfo(routerinfo_t *ri)
Definition: nodelist.c:727
smartlist_t * nodelist_find_nodes_with_microdesc(const microdesc_t *md)
Definition: nodelist.c:767
void router_set_status(const char *digest, int up)
Definition: nodelist.c:2135
STATIC bool node_has_declared_family(const node_t *node)
Definition: nodelist.c:1915
int node_supports_v3_hsdir(const node_t *node)
Definition: nodelist.c:1152
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
Definition: nodelist.c:1244
int nodes_in_same_family(const node_t *node1, const node_t *node2)
Definition: nodelist.c:1956
void router_dir_info_changed(void)
Definition: nodelist.c:2234
int nodelist_probably_contains_address(const tor_addr_t *addr)
Definition: nodelist.c:477
void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1609
void node_get_verbose_nickname_by_id(const char *id_digest, char *verbose_name_out)
Definition: nodelist.c:1297
const char * node_get_platform(const node_t *node)
Definition: nodelist.c:1489
const struct curve25519_public_key_t * node_get_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:1783
int node_has_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:1776
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1588
const node_t * node_get_by_hex_id(const char *identity_digest, unsigned flags)
Definition: nodelist.c:959
int node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
Definition: nodelist.c:1096
node_t * nodelist_add_microdesc(microdesc_t *md)
Definition: nodelist.c:549
void nodelist_purge(void)
Definition: nodelist.c:798
int node_get_purpose(const node_t *node)
Definition: nodelist.c:1265
STATIC int node_in_nickname_smartlist(const smartlist_t *lst, const node_t *node)
Definition: nodelist.c:1888
void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1689
void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node)
Definition: nodelist.c:2003
void node_get_address_string(const node_t *node, char *cp, size_t len)
Definition: nodelist.c:1463
void nodelist_assert_ok(void)
Definition: nodelist.c:851
int node_is_good_exit(const node_t *node)
Definition: nodelist.c:698
STATIC int node_nickname_matches(const node_t *node, const char *nickname)
Definition: nodelist.c:1876
int node_ipv6_or_preferred(const node_t *node)
Definition: nodelist.c:1558
node_t * node_get_mutable_by_ed25519_id(const ed25519_public_key_t *ed_id)
Definition: nodelist.c:207
int count_loading_descriptors_progress(void)
Definition: nodelist.c:2529