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-2010, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for dirserv.c.
12 #ifndef _TOR_DIRSERV_H
13 #define _TOR_DIRSERV_H
15 /** Maximum length of an exit policy summary. */
16 #define MAX_EXITPOLICY_SUMMARY_LEN 1000
18 /** Maximum allowable length of a version line in a networkstatus. */
19 #define MAX_V_LINE_LEN 128
20 /** Length of "r Authority BadDirectory BadExit Exit Fast Guard HSDir Named
21 * Running Stable Unnamed V2Dir Valid\n". */
22 #define MAX_FLAG_LINE_LEN 96
23 /** Length of "w" line for weighting. Currently at most
24 * "w Bandwidth=<uint32t> Measured=<uint32t>\n" */
25 #define MAX_WEIGHT_LINE_LEN (12+10+10+10+1)
26 /** Maximum length of an exit policy summary line. */
27 #define MAX_POLICY_LINE_LEN (3+MAX_EXITPOLICY_SUMMARY_LEN)
28 /** Amount of space to allocate for each entry: r, s, and v lines. */
29 #define RS_ENTRY_LEN \
31 MAX_NICKNAME_LEN+BASE64_DIGEST_LEN*2+ISO_TIME_LEN+INET_NTOA_BUF_LEN+ \
32 5*2 /* ports */ + 10 /* punctuation */ + \
36 MAX_WEIGHT_LINE_LEN + \
38 MAX_POLICY_LINE_LEN + \
43 #define UNNAMED_ROUTER_NICKNAME "Unnamed"
45 int connection_dirserv_flushed_some(dir_connection_t
*conn
);
47 int dirserv_add_own_fingerprint(const char *nickname
, crypto_pk_env_t
*pk
);
48 int dirserv_load_fingerprint_file(void);
49 void dirserv_free_fingerprint_list(void);
50 const char *dirserv_get_nickname_by_digest(const char *digest
);
51 enum was_router_added_t
dirserv_add_multiple_descriptors(
52 const char *desc
, uint8_t purpose
,
55 enum was_router_added_t
dirserv_add_descriptor(routerinfo_t
*ri
,
58 void dirserv_set_router_is_running(routerinfo_t
*router
, time_t now
);
59 int list_server_status_v1(smartlist_t
*routers
, char **router_status_out
,
61 int dirserv_dump_directory_to_string(char **dir_out
,
62 crypto_pk_env_t
*private_key
);
64 int directory_fetches_from_authorities(or_options_t
*options
);
65 int directory_fetches_dir_info_early(or_options_t
*options
);
66 int directory_fetches_dir_info_later(or_options_t
*options
);
67 int directory_caches_v2_dir_info(or_options_t
*options
);
68 #define directory_caches_v1_dir_info(o) directory_caches_v2_dir_info(o)
69 int directory_caches_dir_info(or_options_t
*options
);
70 int directory_permits_begindir_requests(or_options_t
*options
);
71 int directory_permits_controller_requests(or_options_t
*options
);
72 int directory_too_idle_to_fetch_descriptors(or_options_t
*options
, time_t now
);
74 void directory_set_dirty(void);
75 cached_dir_t
*dirserv_get_directory(void);
76 cached_dir_t
*dirserv_get_runningrouters(void);
77 cached_dir_t
*dirserv_get_consensus(const char *flavor_name
);
78 void dirserv_set_cached_directory(const char *directory
, time_t when
,
79 int is_running_routers
);
80 void dirserv_set_cached_networkstatus_v2(const char *directory
,
83 void dirserv_set_cached_consensus_networkstatus(const char *consensus
,
84 const char *flavor_name
,
85 const digests_t
*digests
,
87 void dirserv_clear_old_networkstatuses(time_t cutoff
);
88 void dirserv_clear_old_v1_info(time_t now
);
89 void dirserv_get_networkstatus_v2(smartlist_t
*result
, const char *key
);
90 void dirserv_get_networkstatus_v2_fingerprints(smartlist_t
*result
,
92 int dirserv_get_routerdesc_fingerprints(smartlist_t
*fps_out
, const char *key
,
94 int for_unencrypted_conn
,
96 int dirserv_get_routerdescs(smartlist_t
*descs_out
, const char *key
,
98 void dirserv_orconn_tls_done(const char *address
,
100 const char *digest_rcvd
,
102 void dirserv_single_reachability_test(time_t now
, routerinfo_t
*router
);
103 void dirserv_test_reachability(time_t now
);
104 int authdir_wants_to_reject_router(routerinfo_t
*ri
, const char **msg
,
106 int dirserv_would_reject_router(routerstatus_t
*rs
);
107 int dirserv_remove_old_statuses(smartlist_t
*fps
, time_t cutoff
);
108 int dirserv_have_any_serverdesc(smartlist_t
*fps
, int spool_src
);
109 int dirserv_have_any_microdesc(const smartlist_t
*fps
);
110 size_t dirserv_estimate_data_size(smartlist_t
*fps
, int is_serverdescs
,
112 size_t dirserv_estimate_microdesc_size(const smartlist_t
*fps
, int compressed
);
114 int routerstatus_format_entry(char *buf
, size_t buf_len
,
115 routerstatus_t
*rs
, const char *platform
,
116 routerstatus_format_type_t format
);
117 void dirserv_free_all(void);
118 void cached_dir_decref(cached_dir_t
*d
);
119 cached_dir_t
*new_cached_dir(char *s
, time_t published
);
121 #ifdef DIRSERV_PRIVATE
122 int measured_bw_line_parse(measured_bw_line_t
*out
, const char *line
);
124 int measured_bw_line_apply(measured_bw_line_t
*parsed_line
,
125 smartlist_t
*routerstatuses
);
128 int dirserv_read_measured_bandwidths(const char *from_file
,
129 smartlist_t
*routerstatuses
);