tor  0.4.1.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-2019, The Tor Project, Inc. */
4 /* See LICENSE for licensing information */
5 
11 #ifndef TOR_ROUTERLIST_H
12 #define TOR_ROUTERLIST_H
13 
15 
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 'NOT_NEW' */
41  /* DOCDOC */
42  ROUTER_CERTS_EXPIRED = -8
44 
46 #define DIR_503_TIMEOUT (60*60)
47 
49 
50 int router_skip_or_reachability(const or_options_t *options, int try_ip_pref);
51 int router_skip_dir_reachability(const or_options_t *options, int try_ip_pref);
53 int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2);
54 void router_add_running_nodes_to_smartlist(smartlist_t *sl, int need_uptime,
55  int need_capacity, int need_guard,
56  int need_desc, int pref_addr,
57  int direct_conn);
58 
60 uint32_t router_get_advertised_bandwidth(const routerinfo_t *router);
62 
63 int hexdigest_to_digest(const char *hexdigest, char *digest);
64 const routerinfo_t *router_get_by_id_digest(const char *digest);
65 routerinfo_t *router_get_mutable_by_digest(const char *digest);
67 MOCK_DECL(signed_descriptor_t *,router_get_by_extrainfo_digest,
68  (const char *digest));
69 MOCK_DECL(signed_descriptor_t *,extrainfo_get_by_descriptor_digest,
70  (const char *digest));
71 const char *signed_descriptor_get_body(const signed_descriptor_t *desc);
74 void routerinfo_free_(routerinfo_t *router);
75 #define routerinfo_free(router) \
76  FREE_AND_NULL(routerinfo_t, routerinfo_free_, (router))
77 void extrainfo_free_(extrainfo_t *extrainfo);
78 #define extrainfo_free(ei) FREE_AND_NULL(extrainfo_t, extrainfo_free_, (ei))
80 #define routerlist_free(rl) FREE_AND_NULL(routerlist_t, routerlist_free_, (rl))
81 void dump_routerlist_mem_usage(int severity);
82 void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old,
83  time_t now);
84 void routerlist_free_all(void);
85 void routerlist_reset_warnings(void);
86 
87 /* XXXX move this */
88 void list_pending_downloads(digestmap_t *result,
89  digest256map_t *result256,
90  int purpose, const char *prefix);
91 
92 static int WRA_WAS_ADDED(was_router_added_t s);
100 static inline int
102  return s == ROUTER_ADDED_SUCCESSFULLY;
103 }
112 {
113  return (s == ROUTER_WAS_TOO_OLD ||
114  s == ROUTER_IS_ALREADY_KNOWN ||
115  s == ROUTER_NOT_IN_CONSENSUS ||
116  s == ROUTER_NOT_IN_CONSENSUS_OR_NETWORKSTATUS ||
117  s == ROUTER_CERTS_EXPIRED);
118 }
122 {
123  return (s == ROUTER_AUTHDIR_REJECTS);
124 }
128 {
129  return (s == ROUTER_AUTHDIR_REJECTS ||
130  s == ROUTER_BAD_EI ||
131  s == ROUTER_WAS_TOO_OLD ||
132  s == ROUTER_CERTS_EXPIRED);
133 }
135  const char **msg,
136  int from_cache,
137  int from_fetch);
139  extrainfo_t *ei, const char **msg,
140  int from_cache, int from_fetch);
141 void routerlist_descriptors_added(smartlist_t *sl, int from_cache);
143 int router_load_single_router(const char *s, uint8_t purpose, int cache,
144  const char **msg);
145 int router_load_routers_from_string(const char *s, const char *eos,
146  saved_location_t saved_location,
147  smartlist_t *requested_fingerprints,
148  int descriptor_digests,
149  const char *prepend_annotations);
150 void router_load_extrainfo_from_string(const char *s, const char *eos,
151  saved_location_t saved_location,
152  smartlist_t *requested_fingerprints,
153  int descriptor_digests);
154 
155 void routerlist_retry_directory_downloads(time_t now);
156 
158 
159 void update_consensus_router_descriptor_downloads(time_t now, int is_vote,
160  networkstatus_t *consensus);
161 void update_router_descriptor_downloads(time_t now);
162 void update_all_descriptor_downloads(time_t now);
163 void update_extrainfo_downloads(time_t now);
166  const routerinfo_t *r2);
168  extrainfo_t *ei,
170  const char **msg);
171 int routerinfo_has_curve25519_onion_key(const routerinfo_t *ri);
172 int routerstatus_version_supports_extend2_cells(const routerstatus_t *rs,
173  int allow_unknown_versions);
174 
175 void routerlist_assert_ok(const routerlist_t *rl);
176 const char *esc_router_info(const routerinfo_t *router);
178 
179 void refresh_all_country_info(void);
180 
181 void list_pending_microdesc_downloads(digest256map_t *result);
182 void launch_descriptor_downloads(int purpose,
183  smartlist_t *downloadable,
184  const routerstatus_t *source,
185  time_t now);
186 
187 int hex_digest_nickname_decode(const char *hexdigest,
188  char *digest_out,
189  char *nickname_qualifier_out,
190  char *nickname_out);
191 int hex_digest_nickname_matches(const char *hexdigest,
192  const char *identity_digest,
193  const char *nickname);
194 
195 #ifdef ROUTERLIST_PRIVATE
196 MOCK_DECL(int, router_descriptor_is_older_than, (const routerinfo_t *router,
197  int seconds));
198 MOCK_DECL(STATIC was_router_added_t, extrainfo_insert,
199  (routerlist_t *rl, extrainfo_t *ei, int warn_if_incompatible));
200 
201 MOCK_DECL(STATIC void, initiate_descriptor_downloads,
202  (const routerstatus_t *source, int purpose, smartlist_t *digests,
203  int lo, int hi, int pds_flags));
204 
205 #endif /* defined(ROUTERLIST_PRIVATE) */
206 
207 #endif /* !defined(TOR_ROUTERLIST_H) */
void routerinfo_free_(routerinfo_t *router)
Definition: routerlist.c:834
void update_consensus_router_descriptor_downloads(time_t now, int is_vote, networkstatus_t *consensus)
Definition: routerlist.c:2526
void extrainfo_free_(extrainfo_t *extrainfo)
Definition: routerlist.c:864
int hex_digest_nickname_decode(const char *hexdigest, char *digest_out, char *nickname_qualifier_out, char *nickname_out)
Definition: routerlist.c:598
const char * signed_descriptor_get_annotations(const signed_descriptor_t *desc)
Definition: routerlist.c:802
was_router_added_t
Definition: routerlist.h:17
void refresh_all_country_info(void)
Definition: routerlist.c:3216
static int WRA_WAS_ADDED(was_router_added_t s)
Definition: routerlist.h:101
void update_router_descriptor_downloads(time_t now)
Definition: routerlist.c:2699
int router_reload_router_list(void)
Definition: routerlist.c:457
uint32_t router_get_advertised_bandwidth_capped(const routerinfo_t *router)
Definition: routerlist.c:571
void launch_descriptor_downloads(int purpose, smartlist_t *downloadable, const routerstatus_t *source, time_t now)
Definition: routerlist.c:2428
int hexdigest_to_digest(const char *hexdigest, char *digest)
Definition: routerlist.c:663
void routerlist_assert_ok(const routerlist_t *rl)
Definition: routerlist.c:3087
void routerlist_free_(routerlist_t *rl)
Definition: routerlist.c:942
saved_location_t
Definition: or.h:746
routerinfo_t * router_get_mutable_by_digest(const char *digest)
Definition: routerlist.c:676
const routerinfo_t * routerlist_find_my_routerinfo(void)
Definition: routerlist.c:541
int router_exit_policy_rejects_all(const routerinfo_t *router)
Definition: routerlist.c:2238
const routerinfo_t * router_get_by_id_digest(const char *digest)
Definition: routerlist.c:690
int router_load_single_router(const char *s, uint8_t purpose, int cache, const char **msg)
Definition: routerlist.c:1954
int hex_digest_nickname_matches(const char *hexdigest, const char *identity_digest, const char *nickname)
Definition: routerlist.c:634
void list_pending_microdesc_downloads(digest256map_t *result)
Definition: routerlist.c:2304
void routerlist_reset_warnings(void)
Definition: routerlist.c:1443
static int WRA_WAS_REJECTED(was_router_added_t s)
Definition: routerlist.h:121
static int WRA_NEVER_DOWNLOADABLE(was_router_added_t s)
Definition: routerlist.h:127
void dump_routerlist_mem_usage(int severity)
Definition: routerlist.c:976
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:2120
void list_pending_downloads(digestmap_t *result, digest256map_t *result256, int purpose, const char *prefix)
Definition: routerlist.c:2250
void routerlist_descriptors_added(smartlist_t *sl, int from_cache)
Definition: routerlist.c:1927
void router_reset_status_download_failures(void)
Definition: dirlist.c:103
was_router_added_t router_add_to_routerlist(routerinfo_t *router, const char **msg, int from_cache, int from_fetch)
Definition: routerlist.c:1482
void router_add_running_nodes_to_smartlist(smartlist_t *sl, int need_uptime, int need_capacity, int need_guard, int need_desc, int pref_addr, int direct_conn)
Definition: routerlist.c:504
void routers_sort_by_identity(smartlist_t *routers)
Definition: routerlist.c:3207
int router_differences_are_cosmetic(const routerinfo_t *r1, const routerinfo_t *r2)
Definition: routerlist.c:2856
void routerlist_remove(routerlist_t *rl, routerinfo_t *ri, int make_old, time_t now)
Definition: routerlist.c:1187
routerlist_t * router_get_routerlist(void)
Definition: routerlist.c:809
was_router_added_t router_add_extrainfo_to_routerlist(extrainfo_t *ei, const char **msg, int from_cache, int from_fetch)
Definition: routerlist.c:1658
int routerinfo_incompatible_with_extrainfo(const crypto_pk_t *ri, extrainfo_t *ei, signed_descriptor_t *sd, const char **msg)
Definition: routerlist.c:2950
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:2021
void router_reset_descriptor_download_failures(void)
Definition: routerlist.c:2824
const char * esc_router_info(const routerinfo_t *router)
Definition: routerlist.c:3175
int routers_have_same_or_addrs(const routerinfo_t *r1, const routerinfo_t *r2)
Definition: routerlist.c:493
const char * signed_descriptor_get_body(const signed_descriptor_t *desc)
Definition: routerlist.c:794
Macros to implement mocking and selective exposure for the test code.
signed_descriptor_t * router_get_by_descriptor_digest(const char *digest)
Definition: routerlist.c:698
static int WRA_WAS_OUTDATED(was_router_added_t s)
Definition: routerlist.h:111
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
void routerlist_remove_old_routers(void)
Definition: routerlist.c:1801
void update_extrainfo_downloads(time_t now)
Definition: routerlist.c:2713
void routerlist_free_all(void)
Definition: routerlist.c:1427
void routerlist_retry_directory_downloads(time_t now)
Definition: routerlist.c:2223
uint32_t router_get_advertised_bandwidth(const routerinfo_t *router)
Definition: routerlist.c:557
void update_all_descriptor_downloads(time_t now)
Definition: routerlist.c:2211