tor  master
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-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_NODELIST_H
13 #define TOR_NODELIST_H
14 
15 #define node_assert_ok(n) STMT_BEGIN { \
16  tor_assert((n)->ri || (n)->rs); \
17  } STMT_END
18 
19 MOCK_DECL(node_t *, node_get_mutable_by_id,(const char *identity_digest));
20 MOCK_DECL(const node_t *, node_get_by_id, (const char *identity_digest));
22 MOCK_DECL(const node_t *, node_get_by_ed25519_id,
23  (const ed25519_public_key_t *ed_id));
24 
25 #define NNF_NO_WARN_UNNAMED (1u<<0)
26 
27 const node_t *node_get_by_hex_id(const char *identity_digest,
28  unsigned flags);
33 
34 void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md);
36 void nodelist_purge(void);
38 
39 void nodelist_free_all(void);
40 void nodelist_assert_ok(void);
41 
42 MOCK_DECL(const node_t *, node_get_by_nickname,
43  (const char *nickname, unsigned flags));
44 void node_get_verbose_nickname(const node_t *node,
45  char *verbose_name_out);
46 void node_get_verbose_nickname_by_id(const char *id_digest,
47  char *verbose_name_out);
48 int node_is_dir(const node_t *node);
49 int node_has_any_descriptor(const node_t *node);
51  int for_direct_connect);
52 int node_get_purpose(const node_t *node);
53 #define node_is_bridge(node) \
54  (node_get_purpose((node)) == ROUTER_PURPOSE_BRIDGE)
55 int node_is_me(const node_t *node);
56 int node_exit_policy_rejects_all(const node_t *node);
57 int node_exit_policy_is_exact(const node_t *node, sa_family_t family);
59 int node_allows_single_hop_exits(const node_t *node);
60 const char *node_get_nickname(const node_t *node);
61 const char *node_get_platform(const node_t *node);
62 uint32_t node_get_prim_addr_ipv4h(const node_t *node);
63 void node_get_address_string(const node_t *node, char *cp, size_t len);
64 long node_get_declared_uptime(const node_t *node);
65 const smartlist_t *node_get_declared_family(const node_t *node);
67 int node_ed25519_id_matches(const node_t *node,
68  const ed25519_public_key_t *id);
70  int compatible_with_us);
71 int node_supports_v3_hsdir(const node_t *node);
72 int node_supports_ed25519_hs_intro(const node_t *node);
74 const uint8_t *node_get_rsa_id_digest(const node_t *node);
75 
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);
91  const node_t *node);
92 
93 MOCK_DECL(smartlist_t *, nodelist_get_list, (void));
94 
95 /* Temporary during transition to multiple addresses. */
96 void node_get_addr(const node_t *node, tor_addr_t *addr_out);
97 #define node_get_addr_ipv4h(n) node_get_prim_addr_ipv4h((n))
98 
100 void node_set_country(node_t *node);
101 void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node);
102 int nodes_in_same_family(const node_t *node1, const node_t *node2);
103 
104 const node_t *router_find_exact_exit_enclave(const char *address,
105  uint16_t port);
106 int node_is_unreliable(const node_t *router, int need_uptime,
107  int need_capacity, int need_guard);
108 int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port,
109  int need_uptime);
110 void router_set_status(const char *digest, int up);
112  const tor_addr_t *a2);
113 
121 MOCK_DECL(int, router_have_minimum_dir_info,(void));
122 
132 typedef enum {
133  /* we haven't checked yet, or we have invalidated our previous check */
134  CONSENSUS_PATH_UNKNOWN = -1,
135  /* The consensus only has internal relays, and we should only
136  * create internal paths, circuits, streams, ... */
137  CONSENSUS_PATH_INTERNAL = 0,
138  /* The consensus has at least one exit, and can therefore (potentially)
139  * create exit and internal paths, circuits, streams, ... */
140  CONSENSUS_PATH_EXIT = 1
142 
143 MOCK_DECL(consensus_path_type_t, router_have_consensus_path, (void));
144 
145 void router_dir_info_changed(void);
146 const char *get_dir_info_status_string(void);
148 
149 #ifdef NODELIST_PRIVATE
150 
151 #ifdef TOR_UNIT_TESTS
152 
153 STATIC void
154 node_set_hsdir_index(node_t *node, const networkstatus_t *ns);
155 
156 #endif /* defined(TOR_UNIT_TESTS) */
157 
158 #endif /* defined(NODELIST_PRIVATE) */
159 
160 MOCK_DECL(int, get_estimated_address_per_node, (void));
161 
162 #endif /* !defined(TOR_NODELIST_H) */
163 
const node_t * router_find_exact_exit_enclave(const char *address, uint16_t port)
Definition: nodelist.c:1895
const curve25519_public_key_t * node_get_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:1705
int node_is_dir(const node_t *node)
Definition: nodelist.c:1117
const char * node_get_nickname(const node_t *node)
Definition: nodelist.c:1103
int node_exit_policy_is_exact(const node_t *node, sa_family_t family)
Definition: nodelist.c:1250
Definition: or.h:2504
node_t * nodelist_set_routerinfo(routerinfo_t *ri, routerinfo_t **ri_old_out)
Definition: nodelist.c:440
int node_is_me(const node_t *node)
Definition: nodelist.c:1411
void node_get_verbose_nickname(const node_t *node, char *verbose_name_out)
Definition: nodelist.c:1186
Definition: crypto_ed25519.h:23
Definition: address.h:56
int node_has_any_descriptor(const node_t *node)
Definition: nodelist.c:1140
const smartlist_t * node_get_declared_family(const node_t *node)
Definition: nodelist.c:1419
smartlist_t * node_get_all_orports(const node_t *node)
Definition: nodelist.c:1307
void node_get_addr(const node_t *node, tor_addr_t *addr_out)
Definition: nodelist.c:1345
node_t * node_get_mutable_by_ed25519_id(const ed25519_public_key_t *ed_id)
Definition: nodelist.c:181
int node_ipv6_dir_preferred(const node_t *node)
Definition: nodelist.c:1588
long node_get_declared_uptime(const node_t *node)
Definition: nodelist.c:1388
void node_get_pref_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1634
int node_is_unreliable(const node_t *router, int need_uptime, int need_capacity, int need_guard)
Definition: nodelist.c:1926
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:1745
uint32_t node_get_prim_addr_ipv4h(const node_t *node)
Definition: nodelist.c:1355
void node_get_pref_ipv6_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1546
const uint8_t * node_get_rsa_id_digest(const node_t *node)
Definition: nodelist.c:1095
Definition: container.h:18
int node_supports_ed25519_link_authentication(const node_t *node, int compatible_with_us)
Definition: nodelist.c:1049
consensus_path_type_t
Definition: nodelist.h:132
void nodelist_free_all(void)
Definition: nodelist.c:759
Definition: or.h:2687
Definition: address.h:68
void nodelist_remove_microdesc(const char *identity_digest, microdesc_t *md)
Definition: nodelist.c:645
void node_set_country(node_t *node)
Definition: nodelist.c:1720
int node_exit_policy_rejects_all(const node_t *node)
Definition: nodelist.c:1232
int router_exit_policy_all_nodes_reject(const tor_addr_t *addr, uint16_t port, int need_uptime)
Definition: nodelist.c:1941
void nodelist_set_consensus(networkstatus_t *ns)
Definition: nodelist.c:550
const ed25519_public_key_t * node_get_ed25519_id(const node_t *node)
Definition: nodelist.c:965
const char * get_dir_info_status_string(void)
Definition: nodelist.c:2072
int node_allows_single_hop_exits(const node_t *node)
Definition: nodelist.c:1221
int node_supports_v3_rendezvous_point(const node_t *node)
Definition: nodelist.c:1086
void nodelist_refresh_countries(void)
Definition: nodelist.c:1735
int node_supports_ed25519_hs_intro(const node_t *node)
Definition: nodelist.c:1076
void node_get_pref_ipv6_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1649
void nodelist_remove_routerinfo(routerinfo_t *ri)
Definition: nodelist.c:659
int node_ed25519_id_matches(const node_t *node, const ed25519_public_key_t *id)
Definition: nodelist.c:1010
smartlist_t * nodelist_find_nodes_with_microdesc(const microdesc_t *md)
Definition: nodelist.c:699
void router_set_status(const char *digest, int up)
Definition: nodelist.c:1962
int node_supports_v3_hsdir(const node_t *node)
Definition: nodelist.c:1066
int node_has_preferred_descriptor(const node_t *node, int for_direct_connect)
Definition: nodelist.c:1153
Definition: crypto_curve25519.h:24
int nodes_in_same_family(const node_t *node1, const node_t *node2)
Definition: nodelist.c:1781
void router_dir_info_changed(void)
Definition: nodelist.c:2061
int nodelist_probably_contains_address(const tor_addr_t *addr)
Definition: nodelist.c:424
void node_get_pref_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1531
void node_get_verbose_nickname_by_id(const char *id_digest, char *verbose_name_out)
Definition: nodelist.c:1206
const char * node_get_platform(const node_t *node)
Definition: nodelist.c:1398
int node_has_curve25519_onion_key(const node_t *node)
Definition: nodelist.c:1698
void node_get_prim_orport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1510
const node_t * node_get_by_hex_id(const char *identity_digest, unsigned flags)
Definition: nodelist.c:872
node_t * nodelist_add_microdesc(microdesc_t *md)
Definition: nodelist.c:496
void nodelist_purge(void)
Definition: nodelist.c:730
int node_get_purpose(const node_t *node)
Definition: nodelist.c:1174
void node_get_prim_dirport(const node_t *node, tor_addr_port_t *ap_out)
Definition: nodelist.c:1611
Definition: or.h:2433
void nodelist_add_node_and_family(smartlist_t *nodes, const node_t *node)
Definition: nodelist.c:1827
void node_get_address_string(const node_t *node, char *cp, size_t len)
Definition: nodelist.c:1372
void nodelist_assert_ok(void)
Definition: nodelist.c:783
int node_ipv6_or_preferred(const node_t *node)
Definition: nodelist.c:1480
Definition: or.h:2232
int count_loading_descriptors_progress(void)
Definition: nodelist.c:2329