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 directory.c.
12 #ifndef _TOR_DIRECTORY_H
13 #define _TOR_DIRECTORY_H
15 int directories_have_accepted_server_descriptor(void);
16 char *authority_type_to_string(authority_type_t auth
);
17 void directory_post_to_dirservers(uint8_t dir_purpose
, uint8_t router_purpose
,
18 authority_type_t type
, const char *payload
,
19 size_t payload_len
, size_t extrainfo_len
);
20 void directory_get_from_dirserver(uint8_t dir_purpose
, uint8_t router_purpose
,
23 void directory_get_from_all_authorities(uint8_t dir_purpose
,
24 uint8_t router_purpose
,
25 const char *resource
);
26 void directory_initiate_command_routerstatus(routerstatus_t
*status
,
28 uint8_t router_purpose
,
29 int anonymized_connection
,
33 time_t if_modified_since
);
34 void directory_initiate_command_routerstatus_rend(routerstatus_t
*status
,
36 uint8_t router_purpose
,
37 int anonymized_connection
,
41 time_t if_modified_since
,
42 const rend_data_t
*rend_query
);
44 int parse_http_response(const char *headers
, int *code
, time_t *date
,
45 compress_method_t
*compression
, char **response
);
47 int connection_dir_is_encrypted(dir_connection_t
*conn
);
48 int connection_dir_reached_eof(dir_connection_t
*conn
);
49 int connection_dir_process_inbuf(dir_connection_t
*conn
);
50 int connection_dir_finished_flushing(dir_connection_t
*conn
);
51 int connection_dir_finished_connecting(dir_connection_t
*conn
);
52 void connection_dir_request_failed(dir_connection_t
*conn
);
53 void directory_initiate_command(const char *address
, const tor_addr_t
*addr
,
54 uint16_t or_port
, uint16_t dir_port
,
55 int supports_conditional_consensus
,
56 int supports_begindir
, const char *digest
,
57 uint8_t dir_purpose
, uint8_t router_purpose
,
58 int anonymized_connection
,
60 const char *payload
, size_t payload_len
,
61 time_t if_modified_since
);
63 #define DSR_HEX (1<<0)
64 #define DSR_BASE64 (1<<1)
65 #define DSR_DIGEST256 (1<<2)
66 #define DSR_SORT_UNIQ (1<<3)
67 int dir_split_resource_into_fingerprints(const char *resource
,
68 smartlist_t
*fp_out
, int *compressed_out
,
71 int dir_split_resource_into_fingerprint_pairs(const char *res
,
72 smartlist_t
*pairs_out
);
73 char *directory_dump_request_log(void);
74 void note_request(const char *key
, size_t bytes
);
75 int router_supports_extrainfo(const char *identity_digest
, int is_authority
);
77 time_t download_status_increment_failure(download_status_t
*dls
,
78 int status_code
, const char *item
,
79 int server
, time_t now
);
80 /** Increment the failure count of the download_status_t <b>dls</b>, with
81 * the optional status code <b>sc</b>. */
82 #define download_status_failed(dls, sc) \
83 download_status_increment_failure((dls), (sc), NULL, \
84 get_options()->DirPort, time(NULL))
86 void download_status_reset(download_status_t
*dls
);
87 static int download_status_is_ready(download_status_t
*dls
, time_t now
,
89 /** Return true iff, as of <b>now</b>, the resource tracked by <b>dls</b> is
90 * ready to get its download reattempted. */
92 download_status_is_ready(download_status_t
*dls
, time_t now
,
95 return (dls
->n_download_failures
<= max_failures
96 && dls
->next_attempt_at
<= now
);
99 static void download_status_mark_impossible(download_status_t
*dl
);
100 /** Mark <b>dl</b> as never downloadable. */
102 download_status_mark_impossible(download_status_t
*dl
)
104 dl
->n_download_failures
= IMPOSSIBLE_TO_DOWNLOAD
;
107 int download_status_get_n_failures(const download_status_t
*dls
);