Tor  0.4.7.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-2021, 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 
17 void dirclient_dump_total_dls(void);
18 
20 void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
21  dirinfo_type_t type, const char *payload,
22  size_t payload_len, size_t extrainfo_len);
24  uint8_t dir_purpose,
25  uint8_t router_purpose,
26  const char *resource,
27  int pds_flags,
28  download_want_authority_t want_authority));
29 void directory_get_from_all_authorities(uint8_t dir_purpose,
30  uint8_t router_purpose,
31  const char *resource);
32 
33 /** Enumeration of ways to connect to a directory server */
34 typedef enum {
35  /** Default: connect over a one-hop Tor circuit. Relays fall back to direct
36  * DirPort connections, clients, onion services, and bridges do not */
38  /** Connect over a multi-hop anonymizing Tor circuit */
40  /** Connect to the DirPort directly */
42  /** Connect over a multi-hop anonymizing Tor circuit to our dirport */
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 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  /** Extra headers to append to the request */
127  struct config_line_t *additional_headers;
128  /** Hidden-service-specific information for v3+. */
129  const hs_ident_dir_conn_t *hs_ident;
130  /** Used internally to directory.c: gets informed when the attempt to
131  * connect to the directory succeeds or fails, if that attempt bears on the
132  * directory's usability as a directory guard. */
133  struct circuit_guard_state_t *guard_state;
134 };
135 
136 /** A structure to hold arguments passed into each directory response
137  * handler */
138 typedef struct response_handler_args_t {
139  int status_code;
140  const char *reason;
141  const char *body;
142  size_t body_len;
143  const char *headers;
144 } response_handler_args_t;
145 
146 enum compress_method_t;
148  enum compress_method_t);
150  enum compress_method_t);
151 
153 STATIC char *accept_encoding_header(void);
154 STATIC const char *dir_conn_purpose_to_string(int purpose);
155 
157  const response_handler_args_t *args);
159  const response_handler_args_t *args);
160 
162  const response_handler_args_t *args);
163 
164 STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose,
165  const char *resource);
166 #endif /* defined(DIRCLIENT_PRIVATE) */
167 
168 #endif /* !defined(TOR_DIRCLIENT_H) */
compress_method_t
Definition: compress.h:21
#define DIGEST_LEN
Definition: digest_sizes.h:20
STATIC void warn_disallowed_anonymous_compression_method(compress_method_t method)
Definition: dirclient.c:2909
STATIC int handle_response_fetch_consensus(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2194
STATIC int should_use_directory_guards(const or_options_t *options)
Definition: dirclient.c:309
STATIC int allowed_anonymous_connection_compression_method(compress_method_t method)
Definition: dirclient.c:2887
STATIC char * accept_encoding_header(void)
Definition: dirclient.c:2864
STATIC const char * dir_conn_purpose_to_string(int purpose)
Definition: dirclient.c:97
STATIC int handle_response_fetch_hsdesc_v3(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2742
STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose, const char *resource)
Definition: dirclient.c:133
STATIC int handle_response_fetch_microdesc(dir_connection_t *conn, const response_handler_args_t *args)
Definition: dirclient.c:2541
void directory_request_set_resource(directory_request_t *req, const char *resource)
Definition: dirclient.c:1015
void directory_request_set_or_addr_port(directory_request_t *req, const tor_addr_port_t *p)
Definition: dirclient.c:953
void directory_get_from_all_authorities(uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
Definition: dirclient.c:580
dir_indirection_t
Definition: dirclient.h:34
@ DIRIND_ONEHOP
Definition: dirclient.h:37
@ DIRIND_ANON_DIRPORT
Definition: dirclient.h:43
@ DIRIND_ANONYMOUS
Definition: dirclient.h:39
@ DIRIND_DIRECT_CONN
Definition: dirclient.h:41
void directory_request_set_if_modified_since(directory_request_t *req, time_t if_modified_since)
Definition: dirclient.c:1040
void connection_dir_client_request_failed(dir_connection_t *conn)
Definition: dirclient.c:704
void directory_request_set_guard_state(directory_request_t *req, struct circuit_guard_state_t *state)
Definition: dirclient.c:1092
void directory_request_set_dir_addr_port(directory_request_t *req, const tor_addr_port_t *p)
Definition: dirclient.c:964
void directory_request_set_routerstatus(directory_request_t *req, const routerstatus_t *rs)
Definition: dirclient.c:1117
void connection_dir_client_refetch_hsdesc_if_needed(dir_connection_t *dir_conn)
Definition: dirclient.c:2831
void dirclient_dump_total_dls(void)
Definition: dirclient.c:1949
void directory_request_set_indirection(directory_request_t *req, dir_indirection_t indirection)
Definition: dirclient.c:1002
void directory_request_free_(directory_request_t *req)
Definition: dirclient.c:940
struct directory_request_t directory_request_t
Definition: dirclient.h:52
directory_request_t * directory_request_new(uint8_t dir_purpose)
Definition: dirclient.c:919
void directory_request_set_router_purpose(directory_request_t *req, uint8_t router_purpose)
Definition: dirclient.c:986
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:448
void directory_request_set_directory_id_digest(directory_request_t *req, const char *digest)
Definition: dirclient.c:974
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:229
void directory_initiate_request(directory_request_t *request)
Definition: dirclient.c:1222
void directory_request_set_payload(directory_request_t *req, const char *payload, size_t payload_len)
Definition: dirclient.c:1026
void directory_request_fetch_set_hs_ident(directory_request_t *req, const hs_ident_dir_conn_t *ident)
Definition: dirclient.c:1080
int router_supports_extrainfo(const char *identity_digest, int is_authority)
Definition: dirclient.c:175
int directories_have_accepted_server_descriptor(void)
Definition: dirclient.c:198
void directory_request_add_header(directory_request_t *req, const char *key, const char *val)
Definition: dirclient.c:1054
void directory_request_upload_set_hs_ident(directory_request_t *req, const hs_ident_dir_conn_t *ident)
Definition: dirclient.c:1066
Header file containing circuit and connection identifier data for the whole HS subsystem.
download_want_authority_t
Definition: or.h:659
dirinfo_type_t
Definition: or.h:785
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127