add another heuristic for changes stanzas
[tor.git] / src / or / dirserv.h
blob569abfca2ee500736b17e4bfe0a68b96c7545eb1
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-2011, 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 /** What fraction (1 over this number) of the relay ID space do we
16 * (as a directory authority) launch connections to at each reachability
17 * test? */
18 #define REACHABILITY_MODULO_PER_TEST 128
20 /** How often (in seconds) do we launch reachability tests? */
21 #define REACHABILITY_TEST_INTERVAL 10
23 /** How many seconds apart are the reachability tests for a given relay? */
24 #define REACHABILITY_TEST_CYCLE_PERIOD \
25 (REACHABILITY_TEST_INTERVAL*REACHABILITY_MODULO_PER_TEST)
27 /** Maximum length of an exit policy summary. */
28 #define MAX_EXITPOLICY_SUMMARY_LEN 1000
30 /** Maximum allowable length of a version line in a networkstatus. */
31 #define MAX_V_LINE_LEN 128
32 /** Length of "r Authority BadDirectory BadExit Exit Fast Guard HSDir Named
33 * Running Stable Unnamed V2Dir Valid\n". */
34 #define MAX_FLAG_LINE_LEN 96
35 /** Length of "w" line for weighting. Currently at most
36 * "w Bandwidth=<uint32t> Measured=<uint32t>\n" */
37 #define MAX_WEIGHT_LINE_LEN (12+10+10+10+1)
38 /** Maximum length of an exit policy summary line. */
39 #define MAX_POLICY_LINE_LEN (3+MAX_EXITPOLICY_SUMMARY_LEN)
40 /** Amount of space to allocate for each entry: r, s, and v lines. */
41 #define RS_ENTRY_LEN \
42 ( /* first line */ \
43 MAX_NICKNAME_LEN+BASE64_DIGEST_LEN*2+ISO_TIME_LEN+INET_NTOA_BUF_LEN+ \
44 5*2 /* ports */ + 10 /* punctuation */ + \
45 /* second line */ \
46 MAX_FLAG_LINE_LEN + \
47 /* weight line */ \
48 MAX_WEIGHT_LINE_LEN + \
49 /* p line. */ \
50 MAX_POLICY_LINE_LEN + \
51 /* v line. */ \
52 MAX_V_LINE_LEN \
55 #define UNNAMED_ROUTER_NICKNAME "Unnamed"
57 int connection_dirserv_flushed_some(dir_connection_t *conn);
59 int dirserv_add_own_fingerprint(const char *nickname, crypto_pk_env_t *pk);
60 int dirserv_load_fingerprint_file(void);
61 void dirserv_free_fingerprint_list(void);
62 const char *dirserv_get_nickname_by_digest(const char *digest);
63 enum was_router_added_t dirserv_add_multiple_descriptors(
64 const char *desc, uint8_t purpose,
65 const char *source,
66 const char **msg);
67 enum was_router_added_t dirserv_add_descriptor(routerinfo_t *ri,
68 const char **msg,
69 const char *source);
70 void dirserv_set_router_is_running(routerinfo_t *router, time_t now);
71 int list_server_status_v1(smartlist_t *routers, char **router_status_out,
72 int for_controller);
73 int dirserv_dump_directory_to_string(char **dir_out,
74 crypto_pk_env_t *private_key);
76 int directory_fetches_from_authorities(or_options_t *options);
77 int directory_fetches_dir_info_early(or_options_t *options);
78 int directory_fetches_dir_info_later(or_options_t *options);
79 int directory_caches_v2_dir_info(or_options_t *options);
80 #define directory_caches_v1_dir_info(o) directory_caches_v2_dir_info(o)
81 int directory_caches_dir_info(or_options_t *options);
82 int directory_permits_begindir_requests(or_options_t *options);
83 int directory_permits_controller_requests(or_options_t *options);
84 int directory_too_idle_to_fetch_descriptors(or_options_t *options, time_t now);
86 void directory_set_dirty(void);
87 cached_dir_t *dirserv_get_directory(void);
88 cached_dir_t *dirserv_get_runningrouters(void);
89 cached_dir_t *dirserv_get_consensus(const char *flavor_name);
90 void dirserv_set_cached_directory(const char *directory, time_t when,
91 int is_running_routers);
92 void dirserv_set_cached_networkstatus_v2(const char *directory,
93 const char *identity,
94 time_t published);
95 void dirserv_set_cached_consensus_networkstatus(const char *consensus,
96 const char *flavor_name,
97 const digests_t *digests,
98 time_t published);
99 void dirserv_clear_old_networkstatuses(time_t cutoff);
100 void dirserv_clear_old_v1_info(time_t now);
101 void dirserv_get_networkstatus_v2(smartlist_t *result, const char *key);
102 void dirserv_get_networkstatus_v2_fingerprints(smartlist_t *result,
103 const char *key);
104 int dirserv_get_routerdesc_fingerprints(smartlist_t *fps_out, const char *key,
105 const char **msg,
106 int for_unencrypted_conn,
107 int is_extrainfo);
108 int dirserv_get_routerdescs(smartlist_t *descs_out, const char *key,
109 const char **msg);
110 void dirserv_orconn_tls_done(const char *address,
111 uint16_t or_port,
112 const char *digest_rcvd,
113 int as_advertised);
114 int dirserv_should_launch_reachability_test(routerinfo_t *ri,
115 routerinfo_t *ri_old);
116 void dirserv_single_reachability_test(time_t now, routerinfo_t *router);
117 void dirserv_test_reachability(time_t now);
118 int authdir_wants_to_reject_router(routerinfo_t *ri, const char **msg,
119 int complain);
120 int dirserv_would_reject_router(routerstatus_t *rs);
121 int dirserv_remove_old_statuses(smartlist_t *fps, time_t cutoff);
122 int dirserv_have_any_serverdesc(smartlist_t *fps, int spool_src);
123 int dirserv_have_any_microdesc(const smartlist_t *fps);
124 size_t dirserv_estimate_data_size(smartlist_t *fps, int is_serverdescs,
125 int compressed);
126 size_t dirserv_estimate_microdesc_size(const smartlist_t *fps, int compressed);
128 int routerstatus_format_entry(char *buf, size_t buf_len,
129 routerstatus_t *rs, const char *platform,
130 routerstatus_format_type_t format);
131 void dirserv_free_all(void);
132 void cached_dir_decref(cached_dir_t *d);
133 cached_dir_t *new_cached_dir(char *s, time_t published);
135 #ifdef DIRSERV_PRIVATE
136 int measured_bw_line_parse(measured_bw_line_t *out, const char *line);
138 int measured_bw_line_apply(measured_bw_line_t *parsed_line,
139 smartlist_t *routerstatuses);
140 #endif
142 int dirserv_read_measured_bandwidths(const char *from_file,
143 smartlist_t *routerstatuses);
145 #endif