fix typo
[tor.git] / src / or / dirserv.h
blob3c914e9311bcfc77ca82760570728b47e84dd70a
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 */
7 /**
8 * \file dirserv.h
9 * \brief Header file for dirserv.c.
10 **/
12 #ifndef TOR_DIRSERV_H
13 #define TOR_DIRSERV_H
15 #include "testsupport.h"
17 /** What fraction (1 over this number) of the relay ID space do we
18 * (as a directory authority) launch connections to at each reachability
19 * test? */
20 #define REACHABILITY_MODULO_PER_TEST 128
22 /** How often (in seconds) do we launch reachability tests? */
23 #define REACHABILITY_TEST_INTERVAL 10
25 /** How many seconds apart are the reachability tests for a given relay? */
26 #define REACHABILITY_TEST_CYCLE_PERIOD \
27 (REACHABILITY_TEST_INTERVAL*REACHABILITY_MODULO_PER_TEST)
29 /** Maximum length of an exit policy summary. */
30 #define MAX_EXITPOLICY_SUMMARY_LEN 1000
32 /** Maximum allowable length of a version line in a networkstatus. */
33 #define MAX_V_LINE_LEN 128
35 int connection_dirserv_flushed_some(dir_connection_t *conn);
37 int dirserv_add_own_fingerprint(crypto_pk_t *pk);
38 int dirserv_load_fingerprint_file(void);
39 void dirserv_free_fingerprint_list(void);
40 enum was_router_added_t dirserv_add_multiple_descriptors(
41 const char *desc, uint8_t purpose,
42 const char *source,
43 const char **msg);
44 enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
45 const char **msg,
46 const char *source);
47 void dirserv_set_router_is_running(routerinfo_t *router, time_t now);
48 int list_server_status_v1(smartlist_t *routers, char **router_status_out,
49 int for_controller);
50 char *dirserv_get_flag_thresholds_line(void);
51 void dirserv_compute_bridge_flag_thresholds(void);
53 int directory_fetches_from_authorities(const or_options_t *options);
54 int directory_fetches_dir_info_early(const or_options_t *options);
55 int directory_fetches_dir_info_later(const or_options_t *options);
56 int directory_caches_unknown_auth_certs(const or_options_t *options);
57 int directory_caches_dir_info(const or_options_t *options);
58 int directory_permits_begindir_requests(const or_options_t *options);
59 int directory_too_idle_to_fetch_descriptors(const or_options_t *options,
60 time_t now);
62 cached_dir_t *dirserv_get_consensus(const char *flavor_name);
63 void dirserv_set_cached_consensus_networkstatus(const char *consensus,
64 const char *flavor_name,
65 const common_digests_t *digests,
66 time_t published);
67 void dirserv_clear_old_networkstatuses(time_t cutoff);
68 int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key,
69 const char **msg,
70 int for_unencrypted_conn,
71 int is_extrainfo);
72 int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
73 const char **msg);
74 void dirserv_orconn_tls_done(const tor_addr_t *addr,
75 uint16_t or_port,
76 const char *digest_rcvd);
77 int dirserv_should_launch_reachability_test(const routerinfo_t *ri,
78 const routerinfo_t *ri_old);
79 void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
80 void dirserv_test_reachability(time_t now);
81 int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
82 int complain,
83 int *valid_out);
84 uint32_t dirserv_router_get_status(const routerinfo_t *router,
85 const char **msg,
86 int severity);
87 void dirserv_set_node_flags_from_authoritative_status(node_t *node,
88 uint32_t authstatus);
90 int dirserv_would_reject_router(const routerstatus_t *rs);
91 int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
92 int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
93 int dirserv_have_any_microdesc(const smartlist_t *fps);
94 size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
95 int compressed);
96 size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
98 char *routerstatus_format_entry(
99 const routerstatus_t *rs, const char *platform,
100 routerstatus_format_type_t format,
101 const vote_routerstatus_t *vrs);
102 void dirserv_free_all(void);
103 void cached_dir_decref(cached_dir_t *d);
104 cached_dir_t *new_cached_dir(char *s, time_t published);
106 int validate_recommended_package_line(const char *line);
108 #ifdef DIRSERV_PRIVATE
110 STATIC void dirserv_set_routerstatus_testing(routerstatus_t *rs);
112 /* Put the MAX_MEASUREMENT_AGE #define here so unit tests can see it */
113 #define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */
115 STATIC int measured_bw_line_parse(measured_bw_line_t *out, const char *line);
117 STATIC int measured_bw_line_apply(measured_bw_line_t *parsed_line,
118 smartlist_t *routerstatuses);
120 STATIC void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line,
121 time_t as_of);
122 STATIC void dirserv_clear_measured_bw_cache(void);
123 STATIC void dirserv_expire_measured_bw_cache(time_t now);
124 STATIC int dirserv_get_measured_bw_cache_size(void);
125 STATIC int dirserv_query_measured_bw_cache_kb(const char *node_id,
126 long *bw_out,
127 time_t *as_of_out);
128 STATIC int dirserv_has_measured_bw(const char *node_id);
130 STATIC int
131 dirserv_read_guardfraction_file_from_str(const char *guardfraction_file_str,
132 smartlist_t *vote_routerstatuses);
133 #endif
135 int dirserv_read_measured_bandwidths(const char *from_file,
136 smartlist_t *routerstatuses);
138 int dirserv_read_guardfraction_file(const char *fname,
139 smartlist_t *vote_routerstatuses);
141 #endif