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-2016, 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 int router_reload_consensus_networkstatus(void);
20 void routerstatus_free(routerstatus_t
*rs
);
21 void networkstatus_vote_free(networkstatus_t
*ns
);
22 networkstatus_voter_info_t
*networkstatus_get_voter_by_id(
23 networkstatus_t
*vote
,
24 const char *identity
);
25 int networkstatus_check_consensus_signature(networkstatus_t
*consensus
,
27 int networkstatus_check_document_signature(const networkstatus_t
*consensus
,
28 document_signature_t
*sig
,
29 const authority_cert_t
*cert
);
30 int compare_digest_to_routerstatus_entry(const void *_key
,
31 const void **_member
);
32 int compare_digest_to_vote_routerstatus_entry(const void *_key
,
33 const void **_member
);
34 const routerstatus_t
*networkstatus_vote_find_entry(networkstatus_t
*ns
,
36 routerstatus_t
*networkstatus_vote_find_mutable_entry(networkstatus_t
*ns
,
38 int networkstatus_vote_find_entry_idx(networkstatus_t
*ns
,
39 const char *digest
, int *found_out
);
41 MOCK_DECL(download_status_t
*,
42 networkstatus_get_dl_status_by_flavor
,
43 (consensus_flavor_t flavor
));
44 MOCK_DECL(download_status_t
*,
45 networkstatus_get_dl_status_by_flavor_bootstrap
,
46 (consensus_flavor_t flavor
));
47 MOCK_DECL(download_status_t
*,
48 networkstatus_get_dl_status_by_flavor_running
,
49 (consensus_flavor_t flavor
));
51 MOCK_DECL(smartlist_t
*, router_get_descriptor_digests
, (void));
52 MOCK_DECL(download_status_t
*,router_get_dl_status_by_descriptor_digest
,
55 const routerstatus_t
*router_get_consensus_status_by_id(const char *digest
);
56 routerstatus_t
*router_get_mutable_consensus_status_by_id(
58 const routerstatus_t
*router_get_consensus_status_by_descriptor_digest(
59 networkstatus_t
*consensus
,
61 MOCK_DECL(routerstatus_t
*,
62 router_get_mutable_consensus_status_by_descriptor_digest
,
63 (networkstatus_t
*consensus
, const char *digest
));
64 const routerstatus_t
*router_get_consensus_status_by_nickname(
67 const char *networkstatus_get_router_digest_by_nickname(const char *nickname
);
68 int networkstatus_nickname_is_unnamed(const char *nickname
);
69 void networkstatus_consensus_download_failed(int status_code
,
70 const char *flavname
);
71 void update_consensus_networkstatus_fetch_time(time_t now
);
72 int should_delay_dir_fetches(const or_options_t
*options
,const char **msg_out
);
73 void update_networkstatus_downloads(time_t now
);
74 void update_certificate_downloads(time_t now
);
75 int consensus_is_waiting_for_certs(void);
76 int client_would_use_router(const routerstatus_t
*rs
, time_t now
,
77 const or_options_t
*options
);
78 MOCK_DECL(networkstatus_t
*,networkstatus_get_latest_consensus
,(void));
79 MOCK_DECL(networkstatus_t
*,networkstatus_get_latest_consensus_by_flavor
,
80 (consensus_flavor_t f
));
81 MOCK_DECL(networkstatus_t
*, networkstatus_get_live_consensus
,(time_t now
));
82 networkstatus_t
*networkstatus_get_reasonably_live_consensus(time_t now
,
84 MOCK_DECL(int, networkstatus_consensus_is_bootstrapping
,(time_t now
));
85 int networkstatus_consensus_can_use_multiple_directories(
86 const or_options_t
*options
);
87 MOCK_DECL(int, networkstatus_consensus_can_use_extra_fallbacks
,(
88 const or_options_t
*options
));
89 int networkstatus_consensus_is_already_downloading(const char *resource
);
91 #define NSSET_FROM_CACHE 1
92 #define NSSET_WAS_WAITING_FOR_CERTS 2
93 #define NSSET_DONT_DOWNLOAD_CERTS 4
94 #define NSSET_ACCEPT_OBSOLETE 8
95 #define NSSET_REQUIRE_FLAVOR 16
96 int networkstatus_set_current_consensus(const char *consensus
,
99 const char *source_dir
);
100 void networkstatus_note_certs_arrived(const char *source_dir
);
101 void routers_update_all_from_networkstatus(time_t now
, int dir_version
);
102 void routers_update_status_from_consensus_networkstatus(smartlist_t
*routers
,
104 void signed_descs_update_status_from_consensus_networkstatus(
107 char *networkstatus_getinfo_helper_single(const routerstatus_t
*rs
);
108 char *networkstatus_getinfo_by_purpose(const char *purpose_string
, time_t now
);
109 void networkstatus_dump_bridge_status_to_file(time_t now
);
110 int32_t networkstatus_get_param(const networkstatus_t
*ns
,
111 const char *param_name
,
112 int32_t default_val
, int32_t min_val
,
114 int getinfo_helper_networkstatus(control_connection_t
*conn
,
115 const char *question
, char **answer
,
116 const char **errmsg
);
117 int32_t networkstatus_get_bw_weight(networkstatus_t
*ns
, const char *weight
,
118 int32_t default_val
);
119 const char *networkstatus_get_flavor_name(consensus_flavor_t flav
);
120 int networkstatus_parse_flavor_name(const char *flavname
);
121 void document_signature_free(document_signature_t
*sig
);
122 document_signature_t
*document_signature_dup(const document_signature_t
*sig
);
123 void networkstatus_free_all(void);
124 int networkstatus_get_weight_scale_param(networkstatus_t
*ns
);
126 #ifdef NETWORKSTATUS_PRIVATE
127 STATIC
void vote_routerstatus_free(vote_routerstatus_t
*rs
);
128 #ifdef TOR_UNIT_TESTS
129 STATIC
int networkstatus_set_current_consensus_from_ns(networkstatus_t
*c
,
131 #endif // TOR_UNIT_TESTS