Tor  0.4.7.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() */
17 typedef 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 
53 int router_or_conn_should_skip_reachable_address_check(
54  const or_options_t *options,
55  int try_ip_pref);
56 int router_dir_conn_should_skip_reachable_address_check(
57  const or_options_t *options,
58  int try_ip_pref);
60 int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2);
61 bool router_can_choose_node(const node_t *node, int flags);
63 
65 uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);
67 
68 int hexdigest_to_digest(const char *hexdigest, char *digest);
69 const routerinfo_t *router_get_by_id_digest(const char *digest);
70 routerinfo_t *router_get_mutable_by_digest(const char *digest);
73  (const char *digest));
75  (const char *digest));
76 const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
79 void routerinfo_free_(routerinfo_t *router);
80 #define routerinfo_free(router) \
81  FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router))
82 void 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))
86 void dump_routerlist_mem_usage(int severity);
87 void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
88  time_t now);
89 void routerlist_free_all(void);
90 void routerlist_reset_warnings(void);
91 
92 /* XXXX move this */
93 void list_pending_downloads(digestmap_t *result,
94  digest256map_t *result256,
95  int purpose, const char *prefix);
96 
97 static int WRA_WAS_ADDED(was_router_added_t s);
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  */
105 static 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);
146 void routerlist_descriptors_added(smartlist_t *sl, int from_cache);
148 int router_load_single_router(const char *s, uint8_t purpose, int cache,
149  const char **msg);
150 int router_load_routers_from_string(const char *s, const char *eos,
151  saved_location_t saved_location,
152  smartlist_t *requested_fingerprints,
153  int descriptor_digests,
154  const char *prepend_annotations);
155 void router_load_extrainfo_from_string(const char *s, const char *eos,
156  saved_location_t saved_location,
157  smartlist_t *requested_fingerprints,
158  int descriptor_digests);
159 
160 void routerlist_retry_directory_downloads(time_t now);
161 
163 
164 void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
165  networkstatus_t *consensus);
166 void update_router_descriptor_downloads(time_t now);
167 void update_all_descriptor_downloads(time_t now);
168 void update_extrainfo_downloads(time_t now);
171  const routerinfo_t *r2);
173  extrainfo_t *ei,
175  const char **msg);
176 int routerinfo_has_curve25519_onion_key(const routerinfo_t *ri);
177 int routerstatus_version_supports_extend2_cells(const routerstatus_t *rs,
178  int allow_unknown_versions);
179 
180 void routerlist_assert_ok(const routerlist_t *rl);
181 const char *esc_router_info(const routerinfo_t *router);
183 
184 void refresh_all_country_info(void);
185 
186 void list_pending_microdesc_downloads(digest256map_t *result);
187 void launch_descriptor_downloads(int purpose,
188  smartlist_t *downloadable,
189  const routerstatus_t *source,
190  time_t now);
191 
192 int hex_digest_nickname_decode(const char *hexdigest,
193  char *digest_out,
194  char *nickname_qualifier_out,
195  char *nickname_out);
196 int hex_digest_nickname_matches(const char *hexdigest,
197  const char *identity_digest,
198  const char *nickname);
199 
200 #ifdef ROUTERLIST_PRIVATE
202  int seconds));
204  (routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible));
205 
207  (const routerstatus_t *source, int purpose, smartlist_t *digests,
208  int lo, int hi, int pds_flags));
209 
210 #endif /* defined(ROUTERLIST_PRIVATE) */
211 
212 #endif /* !defined(TOR_ROUTERLIST_H) */
saved_location_t
Definition: or.h:627
STATIC void initiate_descriptor_downloads(const routerstatus_t *source, int purpose, smartlist_t *digests, int lo, int hi, int pds_flags)
Definition: routerlist.c:2409
int router_descriptor_is_older_than(const routerinfo_t *router, int seconds)
Definition: routerlist.c:1546
STATIC was_router_added_t extrainfo_insert(routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible)
Definition: routerlist.c:1150
void routerinfo_free_(routerinfo_t *router)
Definition: routerlist.c:920
void routerlist_free_all(void)
Definition: routerlist.c:1515
void list_pending_microdesc_downloads(digest256map_t *result)
Definition: routerlist.c:2396
void update_consensus_router_descriptor_downloads(time_t now, int is_vote, networkstatus_t *consensus)
Definition: routerlist.c:2618
int router_exit_policy_rejects_all(const routerinfo_t *router)
Definition: routerlist.c:2330
void routerlist_free_(routerlist_t *rl)
Definition: routerlist.c:1028
int hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest, const char *nickname)
Definition: routerlist.c:720
void launch_descriptor_downloads(int purpose, smartlist_t *downloadable, const routerstatus_t *source, time_t now)
Definition: routerlist.c:2520
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:2213
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:3018
void router_reset_status_download_failures(void)
Definition: dirlist.c:151
void dump_routerlist_mem_usage(int severity)
Definition: routerlist.c:1060
int hex_digest_nickname_decode(const char *hexdigest, char *digest_out, char *nickname_qualifier_out, char *nickname_out)
Definition: routerlist.c:684
uint32_t router_get_advertised_bandwidth(const routerinfo_t *router)
Definition: routerlist.c:643
void routerlist_retry_directory_downloads(time_t now)
Definition: routerlist.c:2315
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int flags)
Definition: routerlist.c:615
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:3155
int router_load_single_router(const char *s, uint8_t purpose, int cache, const char **msg)
Definition: routerlist.c:2047
was_router_added_t
Definition: routerlist.h:17
routerinfo_t * router_get_mutable_by_digest(const char *digest)
Definition: routerlist.c:762
int router_reload_router_list(void)
Definition: routerlist.c:460
static int WRA_WAS_REJECTED(was_router_added_t s)
Definition: routerlist.h:126
void refresh_all_country_info(void)
Definition: routerlist.c:3284
void update_router_descriptor_downloads(time_t now)
Definition: routerlist.c:2765
void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now)
Definition: routerlist.c:1275
routerlist_t * router_get_routerlist(void)
Definition: routerlist.c:895
was_router_added_t router_add_extrainfo_to_routerlist(extrainfo_t *ei, const char **msg, int from_cache, int from_fetch)
Definition: routerlist.c:1749
void extrainfo_free_(extrainfo_t *extrainfo)
Definition: routerlist.c:950
int hexdigest_to_digest(const char *hexdigest, char *digest)
Definition: routerlist.c:749
void list_pending_downloads(digestmap_t *result, digest256map_t *result256, int purpose, const char *prefix)
Definition: routerlist.c:2342
int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2)
Definition: routerlist.c:509
const routerinfo_t * router_get_by_id_digest(const char *digest)
Definition: routerlist.c:776
const char * signed_descriptor_get_annotations(const signed_descriptor_t *desc)
Definition: routerlist.c:888
signed_descriptor_t * router_get_by_descriptor_digest(const char *digest)
Definition: routerlist.c:784
void routers_sort_by_identity(smartlist_t *routers)
Definition: routerlist.c:3275
was_router_added_t router_add_to_routerlist(routerinfo_t *router, const char **msg, int from_cache, int from_fetch)
Definition: routerlist.c:1573
signed_descriptor_t * extrainfo_get_by_descriptor_digest(const char *digest)
Definition: routerlist.c:810
void update_extrainfo_downloads(time_t now)
Definition: routerlist.c:2779
int router_differences_are_cosmetic(const routerinfo_t *r1, const routerinfo_t *r2)
Definition: routerlist.c:2922
void routerlist_descriptors_added(smartlist_t *sl, int from_cache)
Definition: routerlist.c:2018
void routerlist_remove_old_routers(void)
Definition: routerlist.c:1892
void routerlist_reset_warnings(void)
Definition: routerlist.c:1533
uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router)
Definition: routerlist.c:657
static int WRA_NEVER_DOWNLOADABLE(was_router_added_t s)
Definition: routerlist.h:132
void router_reset_descriptor_download_failures(void)
Definition: routerlist.c:2890
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:2114
signed_descriptor_t * router_get_by_extrainfo_digest(const char *digest)
Definition: routerlist.c:797
const char * signed_descriptor_get_body(const signed_descriptor_t *desc)
Definition: routerlist.c:880
const routerinfo_t * routerlist_find_my_routerinfo(void)
Definition: routerlist.c:627
const char * esc_router_info(const routerinfo_t *router)
Definition: routerlist.c:3243
void update_all_descriptor_downloads(time_t now)
Definition: routerlist.c:2304
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