tor  0.4.2.0-alpha-dev
networkstatus.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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_NETWORKSTATUS_H
13 #define TOR_NETWORKSTATUS_H
14 
16 
19 tor_mmap_t *networkstatus_map_cached_consensus(const char *flavorname);
22 #define routerstatus_free(rs) \
23  FREE_AND_NULL(routerstatus_t, routerstatus_free_, (rs))
25 #define networkstatus_vote_free(ns) \
26  FREE_AND_NULL(networkstatus_t, networkstatus_vote_free_, (ns))
28  networkstatus_t *vote,
29  const char *identity);
31  const networkstatus_voter_info_t *voter,
32  digest_algorithm_t alg);
33 
35  int warn);
38  const authority_cert_t *cert);
39 int compare_digest_to_routerstatus_entry(const void *_key,
40  const void **_member);
42  const void **_member);
43 MOCK_DECL(const routerstatus_t *,networkstatus_vote_find_entry,(
44  networkstatus_t *ns,
45  const char *digest));
47  const char *digest);
49  const char *digest, int *found_out);
50 
52  networkstatus_get_dl_status_by_flavor,
53  (consensus_flavor_t flavor));
55  networkstatus_get_dl_status_by_flavor_bootstrap,
56  (consensus_flavor_t flavor));
58  networkstatus_get_dl_status_by_flavor_running,
59  (consensus_flavor_t flavor));
60 
61 MOCK_DECL(smartlist_t *, router_get_descriptor_digests, (void));
62 MOCK_DECL(download_status_t *,router_get_dl_status_by_descriptor_digest,
63  (const char *d));
64 
65 const routerstatus_t *router_get_consensus_status_by_id(const char *digest);
67  const char *digest);
69  networkstatus_t *consensus,
70  const char *digest);
72  router_get_mutable_consensus_status_by_descriptor_digest,
73  (networkstatus_t *consensus, const char *digest));
74 int we_want_to_fetch_flavor(const or_options_t *options, int flavor);
76 void networkstatus_consensus_download_failed(int status_code,
77  const char *flavname);
79 int should_delay_dir_fetches(const or_options_t *options,const char **msg_out);
80 void update_networkstatus_downloads(time_t now);
81 void update_certificate_downloads(time_t now);
83 int client_would_use_router(const routerstatus_t *rs, time_t now);
84 MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus,(void));
85 MOCK_DECL(networkstatus_t *,networkstatus_get_latest_consensus_by_flavor,
86  (consensus_flavor_t f));
87 MOCK_DECL(networkstatus_t *, networkstatus_get_live_consensus,(time_t now));
88 int networkstatus_is_live(const networkstatus_t *ns, time_t now);
90  time_t now);
92  time_t now);
94  time_t now);
95 MOCK_DECL(networkstatus_t *,networkstatus_get_reasonably_live_consensus,
96  (time_t now,
97  int flavor));
98 MOCK_DECL(int, networkstatus_consensus_is_bootstrapping,(time_t now));
100  const or_options_t *options);
101 MOCK_DECL(int, networkstatus_consensus_can_use_extra_fallbacks,(
102  const or_options_t *options));
103 int networkstatus_consensus_is_already_downloading(const char *resource);
104 int networkstatus_consensus_has_ipv6(const or_options_t* options);
105 
106 #define NSSET_FROM_CACHE 1
107 #define NSSET_WAS_WAITING_FOR_CERTS 2
108 #define NSSET_DONT_DOWNLOAD_CERTS 4
109 #define NSSET_ACCEPT_OBSOLETE 8
110 #define NSSET_REQUIRE_FLAVOR 16
111 int networkstatus_set_current_consensus(const char *consensus,
112  size_t consensus_len,
113  const char *flavor,
114  unsigned flags,
115  const char *source_dir);
116 void networkstatus_note_certs_arrived(const char *source_dir);
117 void routers_update_all_from_networkstatus(time_t now, int dir_version);
119  int reset_failures);
121  smartlist_t *descs);
122 
124 char *networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now);
125 MOCK_DECL(int32_t, networkstatus_get_param,
126  (const networkstatus_t *ns, const char *param_name,
127  int32_t default_val, int32_t min_val, int32_t max_val));
129  int32_t torrc_value,
130  const char *param_name,
131  int32_t default_val,
132  int32_t min_val, int32_t max_val);
134  const char *question, char **answer,
135  const char **errmsg);
136 int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight,
137  int32_t default_val);
139 int networkstatus_parse_flavor_name(const char *flavname);
141 #define document_signature_free(sig) \
142  FREE_AND_NULL(document_signature_t, document_signature_free_, (sig))
144 void networkstatus_free_all(void);
146 
148 #define vote_routerstatus_free(rs) \
149  FREE_AND_NULL(vote_routerstatus_t, vote_routerstatus_free_, (rs))
150 
152  const node_t *node,
153  const routerinfo_t *ri);
154 
155 #ifdef NETWORKSTATUS_PRIVATE
156 #ifdef TOR_UNIT_TESTS
157 STATIC int networkstatus_set_current_consensus_from_ns(networkstatus_t *c,
158  const char *flavor);
159 STATIC void warn_early_consensus(const networkstatus_t *c, const char *flavor,
160  time_t now);
163 #endif /* defined(TOR_UNIT_TESTS) */
164 #endif /* defined(NETWORKSTATUS_PRIVATE) */
165 
166 #endif /* !defined(TOR_NETWORKSTATUS_H) */
STATIC networkstatus_t * current_ns_consensus
char * networkstatus_getinfo_helper_single(const routerstatus_t *rs)
void set_routerstatus_from_routerinfo(routerstatus_t *rs, const node_t *node, const routerinfo_t *ri)
int networkstatus_get_weight_scale_param(networkstatus_t *ns)
Definition: node_st.h:28
const routerstatus_t * router_get_consensus_status_by_descriptor_digest(networkstatus_t *consensus, const char *digest)
int networkstatus_consensus_reasonably_live(const networkstatus_t *consensus, time_t now)
int32_t networkstatus_get_bw_weight(networkstatus_t *ns, const char *weight, int32_t default_val)
int networkstatus_set_current_consensus(const char *consensus, size_t consensus_len, const char *flavor, unsigned flags, const char *source_dir)
void update_consensus_networkstatus_fetch_time(time_t now)
void update_networkstatus_downloads(time_t now)
void routers_update_status_from_consensus_networkstatus(smartlist_t *routers, int reset_failures)
STATIC void warn_early_consensus(const networkstatus_t *c, const char *flavor, time_t now)
routerstatus_t * networkstatus_vote_find_mutable_entry(networkstatus_t *ns, const char *digest)
int compare_digest_to_vote_routerstatus_entry(const void *_key, const void **_member)
const routerstatus_t * router_get_consensus_status_by_id(const char *digest)
tor_mmap_t * networkstatus_map_cached_consensus(const char *flavorname)
document_signature_t * networkstatus_get_voter_sig_by_alg(const networkstatus_voter_info_t *voter, digest_algorithm_t alg)
void vote_routerstatus_free_(vote_routerstatus_t *rs)
int32_t networkstatus_get_overridable_param(const networkstatus_t *ns, int32_t torrc_value, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
int networkstatus_check_consensus_signature(networkstatus_t *consensus, int warn)
void networkstatus_reset_download_failures(void)
document_signature_t * document_signature_dup(const document_signature_t *sig)
int client_would_use_router(const routerstatus_t *rs, time_t now)
void routerstatus_free_(routerstatus_t *rs)
int getinfo_helper_networkstatus(control_connection_t *conn, const char *question, char **answer, const char **errmsg)
STATIC networkstatus_t * current_md_consensus
int compare_digest_to_routerstatus_entry(const void *_key, const void **_member)
int consensus_is_waiting_for_certs(void)
void networkstatus_vote_free_(networkstatus_t *ns)
void signed_descs_update_status_from_consensus_networkstatus(smartlist_t *descs)
void routers_update_all_from_networkstatus(time_t now, int dir_version)
int networkstatus_vote_find_entry_idx(networkstatus_t *ns, const char *digest, int *found_out)
routerstatus_t * router_get_mutable_consensus_status_by_id(const char *digest)
void networkstatus_free_all(void)
int networkstatus_consensus_can_use_multiple_directories(const or_options_t *options)
int networkstatus_check_document_signature(const networkstatus_t *consensus, document_signature_t *sig, const authority_cert_t *cert)
void document_signature_free_(document_signature_t *sig)
void networkstatus_consensus_download_failed(int status_code, const char *flavname)
int networkstatus_is_live(const networkstatus_t *ns, time_t now)
int networkstatus_valid_after_is_reasonably_live(time_t valid_after, time_t now)
const char * networkstatus_get_flavor_name(consensus_flavor_t flav)
int should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
consensus_flavor_t
Definition: or.h:863
void networkstatus_reset_warnings(void)
networkstatus_voter_info_t * networkstatus_get_voter_by_id(networkstatus_t *vote, const char *identity)
Macros to implement mocking and selective exposure for the test code.
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
int we_want_to_fetch_unknown_auth_certs(const or_options_t *options)
void update_certificate_downloads(time_t now)
int networkstatus_valid_until_is_reasonably_live(time_t valid_until, time_t now)
void networkstatus_note_certs_arrived(const char *source_dir)
char * networkstatus_getinfo_by_purpose(const char *purpose_string, time_t now)
int we_want_to_fetch_flavor(const or_options_t *options, int flavor)
int networkstatus_parse_flavor_name(const char *flavname)
int router_reload_consensus_networkstatus(void)