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 */
8 * \file networkstatus.h
9 * \brief Header file for networkstatus.c.
12 #ifndef TOR_NETWORKSTATUS_H
13 #define TOR_NETWORKSTATUS_H
15 #include "testsupport.h"
17 void networkstatus_reset_warnings(void);
18 void networkstatus_reset_download_failures(void);
19 char *networkstatus_read_cached_consensus(const char *flavorname
);
20 int router_reload_consensus_networkstatus(void);
21 void routerstatus_free(routerstatus_t
*rs
);
22 void networkstatus_vote_free(networkstatus_t
*ns
);
23 networkstatus_voter_info_t
*networkstatus_get_voter_by_id(
24 networkstatus_t
*vote
,
25 const char *identity
);
26 int networkstatus_check_consensus_signature(networkstatus_t
*consensus
,
28 int networkstatus_check_document_signature(const networkstatus_t
*consensus
,
29 document_signature_t
*sig
,
30 const authority_cert_t
*cert
);
31 int compare_digest_to_routerstatus_entry(const void *_key
,
32 const void **_member
);
33 int compare_digest_to_vote_routerstatus_entry(const void *_key
,
34 const void **_member
);
35 const routerstatus_t
*networkstatus_vote_find_entry(networkstatus_t
*ns
,
37 routerstatus_t
*networkstatus_vote_find_mutable_entry(networkstatus_t
*ns
,
39 int networkstatus_vote_find_entry_idx(networkstatus_t
*ns
,
40 const char *digest
, int *found_out
);
42 MOCK_DECL(download_status_t
*,
43 networkstatus_get_dl_status_by_flavor
,
44 (consensus_flavor_t flavor
));
45 MOCK_DECL(download_status_t
*,
46 networkstatus_get_dl_status_by_flavor_bootstrap
,
47 (consensus_flavor_t flavor
));
48 MOCK_DECL(download_status_t
*,
49 networkstatus_get_dl_status_by_flavor_running
,
50 (consensus_flavor_t flavor
));
52 MOCK_DECL(smartlist_t
*, router_get_descriptor_digests
, (void));
53 MOCK_DECL(download_status_t
*,router_get_dl_status_by_descriptor_digest
,
56 const routerstatus_t
*router_get_consensus_status_by_id(const char *digest
);
57 routerstatus_t
*router_get_mutable_consensus_status_by_id(
59 const routerstatus_t
*router_get_consensus_status_by_descriptor_digest(
60 networkstatus_t
*consensus
,
62 MOCK_DECL(routerstatus_t
*,
63 router_get_mutable_consensus_status_by_descriptor_digest
,
64 (networkstatus_t
*consensus
, const char *digest
));
65 int we_want_to_fetch_flavor(const or_options_t
*options
, int flavor
);
66 int we_want_to_fetch_unknown_auth_certs(const or_options_t
*options
);
67 void networkstatus_consensus_download_failed(int status_code
,
68 const char *flavname
);
69 void update_consensus_networkstatus_fetch_time(time_t now
);
70 int should_delay_dir_fetches(const or_options_t
*options
,const char **msg_out
);
71 void update_networkstatus_downloads(time_t now
);
72 void update_certificate_downloads(time_t now
);
73 int consensus_is_waiting_for_certs(void);
74 int client_would_use_router(const routerstatus_t
*rs
, time_t now
);
75 MOCK_DECL(networkstatus_t
*,networkstatus_get_latest_consensus
,(void));
76 MOCK_DECL(networkstatus_t
*,networkstatus_get_latest_consensus_by_flavor
,
77 (consensus_flavor_t f
));
78 MOCK_DECL(networkstatus_t
*, networkstatus_get_live_consensus
,(time_t now
));
79 int networkstatus_is_live(const networkstatus_t
*ns
, time_t now
);
80 int networkstatus_consensus_reasonably_live(const networkstatus_t
*consensus
,
82 int networkstatus_valid_until_is_reasonably_live(time_t valid_until
,
84 networkstatus_t
*networkstatus_get_reasonably_live_consensus(time_t now
,
86 MOCK_DECL(int, networkstatus_consensus_is_bootstrapping
,(time_t now
));
87 int networkstatus_consensus_can_use_multiple_directories(
88 const or_options_t
*options
);
89 MOCK_DECL(int, networkstatus_consensus_can_use_extra_fallbacks
,(
90 const or_options_t
*options
));
91 int networkstatus_consensus_is_already_downloading(const char *resource
);
93 #define NSSET_FROM_CACHE 1
94 #define NSSET_WAS_WAITING_FOR_CERTS 2
95 #define NSSET_DONT_DOWNLOAD_CERTS 4
96 #define NSSET_ACCEPT_OBSOLETE 8
97 #define NSSET_REQUIRE_FLAVOR 16
98 int networkstatus_set_current_consensus(const char *consensus
,
101 const char *source_dir
);
102 void networkstatus_note_certs_arrived(const char *source_dir
);
103 void routers_update_all_from_networkstatus(time_t now
, int dir_version
);
104 void routers_update_status_from_consensus_networkstatus(smartlist_t
*routers
,
106 void signed_descs_update_status_from_consensus_networkstatus(
109 char *networkstatus_getinfo_helper_single(const routerstatus_t
*rs
);
110 char *networkstatus_getinfo_by_purpose(const char *purpose_string
, time_t now
);
111 void networkstatus_dump_bridge_status_to_file(time_t now
);
112 MOCK_DECL(int32_t, networkstatus_get_param
,
113 (const networkstatus_t
*ns
, const char *param_name
,
114 int32_t default_val
, int32_t min_val
, int32_t max_val
));
115 int32_t networkstatus_get_overridable_param(const networkstatus_t
*ns
,
117 const char *param_name
,
119 int32_t min_val
, int32_t max_val
);
120 int getinfo_helper_networkstatus(control_connection_t
*conn
,
121 const char *question
, char **answer
,
122 const char **errmsg
);
123 int32_t networkstatus_get_bw_weight(networkstatus_t
*ns
, const char *weight
,
124 int32_t default_val
);
125 const char *networkstatus_get_flavor_name(consensus_flavor_t flav
);
126 int networkstatus_parse_flavor_name(const char *flavname
);
127 void document_signature_free(document_signature_t
*sig
);
128 document_signature_t
*document_signature_dup(const document_signature_t
*sig
);
129 void networkstatus_free_all(void);
130 int networkstatus_get_weight_scale_param(networkstatus_t
*ns
);
132 void vote_routerstatus_free(vote_routerstatus_t
*rs
);
134 #ifdef NETWORKSTATUS_PRIVATE
135 #ifdef TOR_UNIT_TESTS
136 STATIC
int networkstatus_set_current_consensus_from_ns(networkstatus_t
*c
,
138 extern networkstatus_t
*current_ns_consensus
;
139 extern networkstatus_t
*current_md_consensus
;
140 #endif /* defined(TOR_UNIT_TESTS) */
141 #endif /* defined(NETWORKSTATUS_PRIVATE) */
143 #endif /* !defined(TOR_NETWORKSTATUS_H) */