Tor  0.4.3.0-alpha-dev
dirclient.h
Go to the documentation of this file.
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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file dirclient.h
9  * \brief Header file for dirclient.c.
10  **/
11 
12 #ifndef TOR_DIRCLIENT_H
13 #define TOR_DIRCLIENT_H
14 
15 #include "feature/hs/hs_ident.h"
16 
18 void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
19  dirinfo_type_t type, const char *payload,
20  size_t payload_len, size_t extrainfo_len);
22  uint8_t dir_purpose,
23  uint8_t router_purpose,
24  const char *resource,
25  int pds_flags,
26  download_want_authority_t want_authority));
27 void directory_get_from_all_authorities(uint8_t dir_purpose,
28  uint8_t router_purpose,
29  const char *resource);
30 
31 /** Enumeration of ways to connect to a directory server */
32 typedef enum {
33  /** Default: connect over a one-hop Tor circuit. Relays fall back to direct
34  * DirPort connections, clients, onion services, and bridges do not */
36  /** Connect over a multi-hop anonymizing Tor circuit */
38  /** Connect to the DirPort directly */
40  /** Connect over a multi-hop anonymizing Tor circuit to our dirport */
43 
44 int directory_must_use_begindir(const or_options_t *options);
45 
46 /**
47  * A directory_request_t describes the information about a directory request
48  * at the client side. It describes what we're going to ask for, which
49  * directory we're going to ask for it, how we're going to contact that
50  * directory, and (in some cases) what to do with it when we're done.
51  */
53 directory_request_t *directory_request_new(uint8_t dir_purpose);
55 #define directory_request_free(req) \
56  FREE_AND_NULL(directory_request_t, directory_request_free_, (req))
58  const tor_addr_port_t *p);
60  const tor_addr_port_t *p);
62  const char *digest);
63 struct circuit_guard_state_t;
65  struct circuit_guard_state_t *state);
67  uint8_t router_purpose);
69  dir_indirection_t indirection);
71  const char *resource);
73  const char *payload,
74  size_t payload_len);
76  time_t if_modified_since);
78  const rend_data_t *query);
80  const hs_ident_dir_conn_t *ident);
82  const hs_ident_dir_conn_t *ident);
83 
85  const routerstatus_t *rs);
87  const char *key,
88  const char *val);
90 
91 int router_supports_extrainfo(const char *identity_digest, int is_authority);
92 
95  dir_connection_t *dir_conn);
96 
97 #ifdef DIRCLIENT_PRIVATE
98 struct directory_request_t {
99  /**
100  * These fields specify which directory we're contacting. Routerstatus,
101  * if present, overrides the other fields.
102  *
103  * @{ */
104  tor_addr_port_t or_addr_port;
105  tor_addr_port_t dir_addr_port;
106  char digest[DIGEST_LEN];
107 
108  const routerstatus_t *routerstatus;
109  /** @} */
110  /** One of DIR_PURPOSE_* other than DIR_PURPOSE_SERVER. Describes what
111  * kind of operation we'll be doing (upload/download), and of what kind
112  * of document. */
113  uint8_t dir_purpose;
114  /** One of ROUTER_PURPOSE_*; used for uploads and downloads of routerinfo
115  * and extrainfo docs. */
116  uint8_t router_purpose;
117  /** Enum: determines whether to anonymize, and whether to use dirport or
118  * orport. */
119  dir_indirection_t indirection;
120  /** Alias to the variable part of the URL for this request */
121  const char *resource;
122  /** Alias to the payload to upload (if any) */
123  const char *payload;
124  /** Number of bytes to upload from payload</b> */
125  size_t payload_len;
126  /** Value to send in an if-modified-since header, or 0 for none. */
127  time_t if_modified_since;
128  /** Hidden-service-specific information v2. */
129  const rend_data_t *rend_query;
130  /** Extra headers to append to the request */
131  struct config_line_t *additional_headers;
132  /** Hidden-service-specific information for v3+. */
133  const hs_ident_dir_conn_t *hs_ident;
134  /** Used internally to directory.c: gets informed when the attempt to
135  * connect to the directory succeeds or fails, if that attempt bears on the
136  * directory's usability as a directory guard. */
137  struct circuit_guard_state_t *guard_state;
138 };
139 
140 /** A structure to hold arguments passed into each directory response
141  * handler */
142 typedef struct response_handler_args_t {
143  int status_code;
144  const char *reason;
145  const char *body;
146  size_t body_len;
147  const char *headers;
148 } response_handler_args_t;
149 
150 enum compress_method_t;
152  enum compress_method_t);
154  enum compress_method_t);
155 
157 STATIC char *accept_encoding_header(void);
158 STATIC const char *dir_conn_purpose_to_string(int purpose);
159 
161  const response_handler_args_t *args);
163  const response_handler_args_t *args);
164 
166  const response_handler_args_t *args);
167 
168 STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose,
169  const char *resource);
170 #endif /* defined(DIRCLIENT_PRIVATE) */
171 
172 #endif /* !defined(TOR_DIRCLIENT_H) */
void directory_request_set_dir_addr_port(directory_request_t *req, const tor_addr_port_t *p)
Definition: dirclient.c:997
STATIC int should_use_directory_guards(const or_options_t *options)
Definition: dirclient.c:313
void directory_request_set_routerstatus(directory_request_t *req, const routerstatus_t *rs)
Definition: dirclient.c:1165
STATIC void warn_disallowed_anonymous_compression_method(compress_method_t method)
Definition: dirclient.c:3103
dir_indirection_t
Definition: dirclient.h:32
STATIC const char * dir_conn_purpose_to_string(int purpose)
Definition: dirclient.c:97
int router_supports_extrainfo(const char *identity_digest, int is_authority)
Definition: dirclient.c:179
void directory_get_from_all_authorities(uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
Definition: dirclient.c:584
STATIC char * accept_encoding_header(void)
Definition: dirclient.c:3058
download_want_authority_t
Definition: or.h:778
STATIC int allowed_anonymous_connection_compression_method(compress_method_t method)
Definition: dirclient.c:3081
struct directory_request_t directory_request_t
Definition: dirclient.h:52
void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose, dirinfo_type_t type, const char *payload, size_t payload_len, size_t extrainfo_len)
Definition: dirclient.c:233
dirinfo_type_t
Definition: or.h:891
STATIC int handle_response_fetch_consensus(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2183
void connection_dir_client_request_failed(dir_connection_t *conn)
Definition: dirclient.c:724
#define STATIC
Definition: testsupport.h:32
void directory_request_set_indirection(directory_request_t *req, dir_indirection_t indirection)
Definition: dirclient.c:1035
directory_request_t * directory_request_new(uint8_t dir_purpose)
Definition: dirclient.c:951
void directory_request_set_guard_state(directory_request_t *req, struct circuit_guard_state_t *state)
Definition: dirclient.c:1140
#define DIGEST_LEN
Definition: digest_sizes.h:20
void directory_request_fetch_set_hs_ident(directory_request_t *req, const hs_ident_dir_conn_t *ident)
Definition: dirclient.c:1128
int directories_have_accepted_server_descriptor(void)
Definition: dirclient.c:202
Header file containing circuit and connection identifier data for the whole HS subsytem.
void directory_request_set_router_purpose(directory_request_t *req, uint8_t router_purpose)
Definition: dirclient.c:1019
void directory_request_add_header(directory_request_t *req, const char *key, const char *val)
Definition: dirclient.c:1087
void directory_request_set_if_modified_since(directory_request_t *req, time_t if_modified_since)
Definition: dirclient.c:1073
void directory_request_set_or_addr_port(directory_request_t *req, const tor_addr_port_t *p)
Definition: dirclient.c:986
void directory_request_set_rend_query(directory_request_t *req, const rend_data_t *query)
Definition: dirclient.c:1099
void directory_get_from_dirserver(uint8_t dir_purpose, uint8_t router_purpose, const char *resource, int pds_flags, download_want_authority_t want_authority)
Definition: dirclient.c:452
void directory_initiate_request(directory_request_t *request)
Definition: dirclient.c:1238
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
void directory_request_free_(directory_request_t *req)
Definition: dirclient.c:973
void directory_request_set_directory_id_digest(directory_request_t *req, const char *digest)
Definition: dirclient.c:1007
void directory_request_upload_set_hs_ident(directory_request_t *req, const hs_ident_dir_conn_t *ident)
Definition: dirclient.c:1114
STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose, const char *resource)
Definition: dirclient.c:137
compress_method_t
Definition: compress.h:21
void connection_dir_client_refetch_hsdesc_if_needed(dir_connection_t *dir_conn)
Definition: dirclient.c:3014
STATIC int handle_response_fetch_hsdesc_v3(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2723
void directory_request_set_resource(directory_request_t *req, const char *resource)
Definition: dirclient.c:1048
STATIC int handle_response_fetch_microdesc(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2523
void directory_request_set_payload(directory_request_t *req, const char *payload, size_t payload_len)
Definition: dirclient.c:1059