Tor  0.4.3.1-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-2020, 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 /**
45  * A directory_request_t describes the information about a directory request
46  * at the client side. It describes what we're going to ask for, which
47  * directory we're going to ask for it, how we're going to contact that
48  * directory, and (in some cases) what to do with it when we're done.
49  */
51 directory_request_t *directory_request_new(uint8_t dir_purpose);
53 #define directory_request_free(req) \
54  FREE_AND_NULL(directory_request_t, directory_request_free_, (req))
56  const tor_addr_port_t *p);
58  const tor_addr_port_t *p);
60  const char *digest);
61 struct circuit_guard_state_t;
63  struct circuit_guard_state_t *state);
65  uint8_t router_purpose);
67  dir_indirection_t indirection);
69  const char *resource);
71  const char *payload,
72  size_t payload_len);
74  time_t if_modified_since);
76  const rend_data_t *query);
78  const hs_ident_dir_conn_t *ident);
80  const hs_ident_dir_conn_t *ident);
81 
83  const routerstatus_t *rs);
85  const char *key,
86  const char *val);
88 
89 int router_supports_extrainfo(const char *identity_digest, int is_authority);
90 
93  dir_connection_t *dir_conn);
94 
95 #ifdef DIRCLIENT_PRIVATE
96 struct directory_request_t {
97  /**
98  * These fields specify which directory we're contacting. Routerstatus,
99  * if present, overrides the other fields.
100  *
101  * @{ */
102  tor_addr_port_t or_addr_port;
103  tor_addr_port_t dir_addr_port;
104  char digest[DIGEST_LEN];
105 
106  const routerstatus_t *routerstatus;
107  /** @} */
108  /** One of DIR_PURPOSE_* other than DIR_PURPOSE_SERVER. Describes what
109  * kind of operation we'll be doing (upload/download), and of what kind
110  * of document. */
111  uint8_t dir_purpose;
112  /** One of ROUTER_PURPOSE_*; used for uploads and downloads of routerinfo
113  * and extrainfo docs. */
114  uint8_t router_purpose;
115  /** Enum: determines whether to anonymize, and whether to use dirport or
116  * orport. */
117  dir_indirection_t indirection;
118  /** Alias to the variable part of the URL for this request */
119  const char *resource;
120  /** Alias to the payload to upload (if any) */
121  const char *payload;
122  /** Number of bytes to upload from payload</b> */
123  size_t payload_len;
124  /** Value to send in an if-modified-since header, or 0 for none. */
125  time_t if_modified_since;
126  /** Hidden-service-specific information v2. */
127  const rend_data_t *rend_query;
128  /** Extra headers to append to the request */
129  struct config_line_t *additional_headers;
130  /** Hidden-service-specific information for v3+. */
131  const hs_ident_dir_conn_t *hs_ident;
132  /** Used internally to directory.c: gets informed when the attempt to
133  * connect to the directory succeeds or fails, if that attempt bears on the
134  * directory's usability as a directory guard. */
135  struct circuit_guard_state_t *guard_state;
136 };
137 
138 /** A structure to hold arguments passed into each directory response
139  * handler */
140 typedef struct response_handler_args_t {
141  int status_code;
142  const char *reason;
143  const char *body;
144  size_t body_len;
145  const char *headers;
146 } response_handler_args_t;
147 
148 enum compress_method_t;
150  enum compress_method_t);
152  enum compress_method_t);
153 
155 STATIC char *accept_encoding_header(void);
156 STATIC const char *dir_conn_purpose_to_string(int purpose);
157 
159  const response_handler_args_t *args);
161  const response_handler_args_t *args);
162 
164  const response_handler_args_t *args);
165 
166 STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose,
167  const char *resource);
168 #endif /* defined(DIRCLIENT_PRIVATE) */
169 
170 #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:988
STATIC int should_use_directory_guards(const or_options_t *options)
Definition: dirclient.c:314
void directory_request_set_routerstatus(directory_request_t *req, const routerstatus_t *rs)
Definition: dirclient.c:1156
STATIC void warn_disallowed_anonymous_compression_method(compress_method_t method)
Definition: dirclient.c:3039
dir_indirection_t
Definition: dirclient.h:32
STATIC const char * dir_conn_purpose_to_string(int purpose)
Definition: dirclient.c:98
int router_supports_extrainfo(const char *identity_digest, int is_authority)
Definition: dirclient.c:180
void directory_get_from_all_authorities(uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
Definition: dirclient.c:585
STATIC char * accept_encoding_header(void)
Definition: dirclient.c:2994
download_want_authority_t
Definition: or.h:778
STATIC int allowed_anonymous_connection_compression_method(compress_method_t method)
Definition: dirclient.c:3017
struct directory_request_t directory_request_t
Definition: dirclient.h:50
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:234
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:2174
void connection_dir_client_request_failed(dir_connection_t *conn)
Definition: dirclient.c:725
#define STATIC
Definition: testsupport.h:32
void directory_request_set_indirection(directory_request_t *req, dir_indirection_t indirection)
Definition: dirclient.c:1026
directory_request_t * directory_request_new(uint8_t dir_purpose)
Definition: dirclient.c:942
void directory_request_set_guard_state(directory_request_t *req, struct circuit_guard_state_t *state)
Definition: dirclient.c:1131
#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:1119
int directories_have_accepted_server_descriptor(void)
Definition: dirclient.c:203
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:1010
void directory_request_add_header(directory_request_t *req, const char *key, const char *val)
Definition: dirclient.c:1078
void directory_request_set_if_modified_since(directory_request_t *req, time_t if_modified_since)
Definition: dirclient.c:1064
void directory_request_set_or_addr_port(directory_request_t *req, const tor_addr_port_t *p)
Definition: dirclient.c:977
void directory_request_set_rend_query(directory_request_t *req, const rend_data_t *query)
Definition: dirclient.c:1090
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:453
void directory_initiate_request(directory_request_t *request)
Definition: dirclient.c:1229
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
void directory_request_free_(directory_request_t *req)
Definition: dirclient.c:964
void directory_request_set_directory_id_digest(directory_request_t *req, const char *digest)
Definition: dirclient.c:998
void directory_request_upload_set_hs_ident(directory_request_t *req, const hs_ident_dir_conn_t *ident)
Definition: dirclient.c:1105
STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose, const char *resource)
Definition: dirclient.c:138
compress_method_t
Definition: compress.h:21
void connection_dir_client_refetch_hsdesc_if_needed(dir_connection_t *dir_conn)
Definition: dirclient.c:2950
STATIC int handle_response_fetch_hsdesc_v3(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2714
void directory_request_set_resource(directory_request_t *req, const char *resource)
Definition: dirclient.c:1039
STATIC int handle_response_fetch_microdesc(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2514
void directory_request_set_payload(directory_request_t *req, const char *payload, size_t payload_len)
Definition: dirclient.c:1050