Tor 0.4.9.0-alpha-dev
routerlist.h
Go to the documentation of this file.
1/* Copyright (c) 2001-2004, Roger Dingledine.
2 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
3 * Copyright (c) 2007-2021, The Tor Project, Inc. */
4/* See LICENSE for licensing information */
5
6/**
7 * \file routerlist.h
8 * \brief Header file for routerlist.c.
9 **/
10
11#ifndef TOR_ROUTERLIST_H
12#define TOR_ROUTERLIST_H
13
15
16/** Return value for router_add_to_routerlist() and dirserv_add_descriptor() */
17typedef enum was_router_added_t {
18 /* Router was added successfully. */
19 ROUTER_ADDED_SUCCESSFULLY = 1,
20 /* Extrainfo document was rejected because no corresponding router
21 * descriptor was found OR router descriptor was rejected because
22 * it was incompatible with its extrainfo document. */
23 ROUTER_BAD_EI = -1,
24 /* Router descriptor was rejected because it is already known. */
25 ROUTER_IS_ALREADY_KNOWN = -2,
26 /* General purpose router was rejected, because it was not listed
27 * in consensus. */
28 ROUTER_NOT_IN_CONSENSUS = -3,
29 /* Router was neither in directory consensus nor in any of
30 * networkstatus documents. Caching it to access later.
31 * (Applies to fetched descriptors only.) */
32 ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS = -4,
33 /* Router was rejected by directory authority. */
34 ROUTER_AUTHDIR_REJECTS = -5,
35 /* Bridge descriptor was rejected because such bridge was not one
36 * of the bridges we have listed in our configuration. */
37 ROUTER_WAS_NOT_WANTED = -6,
38 /* Router descriptor was rejected because it was older than
39 * OLD_ROUTER_DESC_MAX_AGE. */
40 ROUTER_WAS_TOO_OLD = -7, /* note contrast with 'ROUTER_IS_ALREADY_KNOWN' */
41 /* Some certs on this router are expired. */
42 ROUTER_CERTS_EXPIRED = -8,
43 /* We couldn't format the annotations for this router. This is a directory
44 * authority bug. */
45 ROUTER_AUTHDIR_BUG_ANNOTATIONS = -10
47
48/** How long do we avoid using a directory server after it's given us a 503? */
49#define DIR_503_TIMEOUT (60*60)
50
52
53int router_or_conn_should_skip_reachable_address_check(
54 const or_options_t *options,
55 int try_ip_pref);
56int router_dir_conn_should_skip_reachable_address_check(
57 const or_options_t *options,
58 int try_ip_pref);
61bool router_can_choose_node(const node_t *node, int flags);
63
65uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);
67
68int hexdigest_to_digest(const char *hexdigest, char *digest);
69const routerinfo_t *router_get_by_id_digest(const char *digest);
73 (const char *digest));
75 (const char *digest));
76const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
79void routerinfo_free_(routerinfo_t *router);
80#define routerinfo_free(router) \
81 FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router))
82void extrainfo_free_(extrainfo_t *extrainfo);
83#define extrainfo_free(ei) FREE_AND_NULL(extrainfo_t, extrainfo_free_, (ei))
85#define routerlist_free(rl) FREE_AND_NULL(routerlist_t, routerlist_free_, (rl))
86void dump_routerlist_mem_usage(int severity);
87void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
88 time_t now);
89void routerlist_free_all(void);
91
92/* XXXX move this */
93void list_pending_downloads(digestmap_t *result,
94 digest256map_t *result256,
95 int purpose, const char *prefix);
96
101/** Return true iff the outcome code in <b>s</b> indicates that the descriptor
102 * was added. It might still be necessary to check whether the descriptor
103 * generator should be notified.
104 */
105static inline int
107 return s == ROUTER_ADDED_SUCCESSFULLY;
108}
109/** Return true iff the outcome code in <b>s</b> indicates that the descriptor
110 * was not added because it was either:
111 * - not in the consensus
112 * - neither in the consensus nor in any networkstatus document
113 * - it was outdated.
114 * - its certificates were expired.
115 */
117{
118 return (s == ROUTER_WAS_TOO_OLD ||
119 s == ROUTER_IS_ALREADY_KNOWN ||
120 s == ROUTER_NOT_IN_CONSENSUS ||
121 s == ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS ||
122 s == ROUTER_CERTS_EXPIRED);
123}
124/** Return true iff the outcome code in <b>s</b> indicates that the descriptor
125 * was flat-out rejected. */
127{
128 return (s == ROUTER_AUTHDIR_REJECTS);
129}
130/** Return true iff the outcome code in <b>s</b> indicates that the descriptor
131 * was flat-out rejected. */
133{
134 return (s == ROUTER_AUTHDIR_REJECTS ||
135 s == ROUTER_BAD_EI ||
136 s == ROUTER_WAS_TOO_OLD ||
137 s == ROUTER_CERTS_EXPIRED);
138}
140 const char **msg,
141 int from_cache,
142 int from_fetch);
144 extrainfo_t *ei, const char **msg,
145 int from_cache, int from_fetch);
146void routerlist_descriptors_added(smartlist_t *sl, int from_cache);
148void routerlist_drop_bridge_descriptors(void);
149int router_load_single_router(const char *s, uint8_t purpose, int cache,
150 const char **msg);
151int router_load_routers_from_string(const char *s, const char *eos,
152 saved_location_t saved_location,
153 smartlist_t *requested_fingerprints,
154 int descriptor_digests,
155 const char *prepend_annotations);
156void router_load_extrainfo_from_string(const char *s, const char *eos,
157 saved_location_t saved_location,
158 smartlist_t *requested_fingerprints,
159 int descriptor_digests);
160
162
164
165void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
166 networkstatus_t *consensus);
168void update_all_descriptor_downloads(time_t now);
169void update_extrainfo_downloads(time_t now);
172 const routerinfo_t *r2);
174 extrainfo_t *ei,
176 const char **msg);
177int routerinfo_has_curve25519_onion_key(const routerinfo_t *ri);
178int routerstatus_version_supports_extend2_cells(const routerstatus_t *rs,
179 int allow_unknown_versions);
180
181void routerlist_assert_ok(const routerlist_t *rl);
182const char *esc_router_info(const routerinfo_t *router);
184
185void refresh_all_country_info(void);
186
187void list_pending_microdesc_downloads(digest256map_t *result);
188void launch_descriptor_downloads(int purpose,
189 smartlist_t *downloadable,
190 const routerstatus_t *source,
191 time_t now);
192
193int hex_digest_nickname_decode(const char *hexdigest,
194 char *digest_out,
195 char *nickname_qualifier_out,
196 char *nickname_out);
197int hex_digest_nickname_matches(const char *hexdigest,
198 const char *identity_digest,
199 const char *nickname);
200
201#ifdef ROUTERLIST_PRIVATE
203 int seconds));
205 (routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible));
206
208 (const routerstatus_t *source, int purpose, smartlist_t *digests,
209 int lo, int hi, int pds_flags));
210
211#endif /* defined(ROUTERLIST_PRIVATE) */
212
213#endif /* !defined(TOR_ROUTERLIST_H) */
saved_location_t
Definition: or.h:623
STATIC void initiate_descriptor_downloads(const routerstatus_t *source, int purpose, smartlist_t *digests, int lo, int hi, int pds_flags)
Definition: routerlist.c:2441
int router_descriptor_is_older_than(const routerinfo_t *router, int seconds)
Definition: routerlist.c:1549
STATIC was_router_added_t extrainfo_insert(routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible)
Definition: routerlist.c:1153
void routerinfo_free_(routerinfo_t *router)
Definition: routerlist.c:923
void routerlist_free_all(void)
Definition: routerlist.c:1518
const char * esc_router_info(const routerinfo_t *router)
Definition: routerlist.c:3285
const char * signed_descriptor_get_body(const signed_descriptor_t *desc)
Definition: routerlist.c:883
void list_pending_microdesc_downloads(digest256map_t *result)
Definition: routerlist.c:2428
void update_consensus_router_descriptor_downloads(time_t now, int is_vote, networkstatus_t *consensus)
Definition: routerlist.c:2650
int router_exit_policy_rejects_all(const routerinfo_t *router)
Definition: routerlist.c:2362
void routerlist_free_(routerlist_t *rl)
Definition: routerlist.c:1031
int hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest, const char *nickname)
Definition: routerlist.c:723
void launch_descriptor_downloads(int purpose, smartlist_t *downloadable, const routerstatus_t *source, time_t now)
Definition: routerlist.c:2552
void router_load_extrainfo_from_string(const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests)
Definition: routerlist.c:2245
static int WRA_WAS_ADDED(was_router_added_t s)
Definition: routerlist.h:106
int routerinfo_incompatible_with_extrainfo(const crypto_pk_t *ri, extrainfo_t *ei, signed_descriptor_t *sd, const char **msg)
Definition: routerlist.c:3060
routerlist_t * router_get_routerlist(void)
Definition: routerlist.c:898
signed_descriptor_t * router_get_by_extrainfo_digest(const char *digest)
Definition: routerlist.c:800
signed_descriptor_t * router_get_by_descriptor_digest(const char *digest)
Definition: routerlist.c:787
void router_reset_status_download_failures(void)
Definition: dirlist.c:151
void dump_routerlist_mem_usage(int severity)
Definition: routerlist.c:1063
int hex_digest_nickname_decode(const char *hexdigest, char *digest_out, char *nickname_qualifier_out, char *nickname_out)
Definition: routerlist.c:687
uint32_t router_get_advertised_bandwidth(const routerinfo_t *router)
Definition: routerlist.c:646
void routerlist_retry_directory_downloads(time_t now)
Definition: routerlist.c:2347
const routerinfo_t * router_get_by_id_digest(const char *digest)
Definition: routerlist.c:779
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
Definition: routerlist.c:618
const char * signed_descriptor_get_annotations(const signed_descriptor_t *desc)
Definition: routerlist.c:891
static int WRA_WAS_OUTDATED(was_router_added_t s)
Definition: routerlist.h:116
void routerlist_assert_ok(const routerlist_t *rl)
Definition: routerlist.c:3197
int router_load_single_router(const char *s, uint8_t purpose, int cache, const char **msg)
Definition: routerlist.c:2079
was_router_added_t
Definition: routerlist.h:17
int router_reload_router_list(void)
Definition: routerlist.c:458
static int WRA_WAS_REJECTED(was_router_added_t s)
Definition: routerlist.h:126
void refresh_all_country_info(void)
Definition: routerlist.c:3326
void update_router_descriptor_downloads(time_t now)
Definition: routerlist.c:2807
void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now)
Definition: routerlist.c:1278
was_router_added_t router_add_extrainfo_to_routerlist(extrainfo_t *ei, const char **msg, int from_cache, int from_fetch)
Definition: routerlist.c:1759
void extrainfo_free_(extrainfo_t *extrainfo)
Definition: routerlist.c:953
int hexdigest_to_digest(const char *hexdigest, char *digest)
Definition: routerlist.c:752
void list_pending_downloads(digestmap_t *result, digest256map_t *result256, int purpose, const char *prefix)
Definition: routerlist.c:2374
int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2)
Definition: routerlist.c:507
void routers_sort_by_identity(smartlist_t *routers)
Definition: routerlist.c:3317
was_router_added_t router_add_to_routerlist(routerinfo_t *router, const char **msg, int from_cache, int from_fetch)
Definition: routerlist.c:1576
void update_extrainfo_downloads(time_t now)
Definition: routerlist.c:2821
signed_descriptor_t * extrainfo_get_by_descriptor_digest(const char *digest)
Definition: routerlist.c:813
int router_differences_are_cosmetic(const routerinfo_t *r1, const routerinfo_t *r2)
Definition: routerlist.c:2964
void routerlist_descriptors_added(smartlist_t *sl, int from_cache)
Definition: routerlist.c:2050
void routerlist_remove_old_routers(void)
Definition: routerlist.c:1902
void routerlist_reset_warnings(void)
Definition: routerlist.c:1536
uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router)
Definition: routerlist.c:660
static int WRA_NEVER_DOWNLOADABLE(was_router_added_t s)
Definition: routerlist.h:132
void router_reset_descriptor_download_failures(void)
Definition: routerlist.c:2932
int router_load_routers_from_string(const char *s, const char *eos, saved_location_t saved_location, smartlist_t *requested_fingerprints, int descriptor_digests, const char *prepend_annotations)
Definition: routerlist.c:2146
routerinfo_t * router_get_mutable_by_digest(const char *digest)
Definition: routerlist.c:765
const routerinfo_t * routerlist_find_my_routerinfo(void)
Definition: routerlist.c:630
void update_all_descriptor_downloads(time_t now)
Definition: routerlist.c:2336
Definition: node_st.h:34
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127