dirclient.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. * \file dirclient.h
  8. * \brief Header file for dirclient.c.
  9. **/
  10. #ifndef TOR_DIRCLIENT_H
  11. #define TOR_DIRCLIENT_H
  12. #include "feature/hs/hs_ident.h"
  13. int directories_have_accepted_server_descriptor(void);
  14. void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
  15. dirinfo_type_t type, const char *payload,
  16. size_t payload_len, size_t extrainfo_len);
  17. MOCK_DECL(void, directory_get_from_dirserver, (
  18. uint8_t dir_purpose,
  19. uint8_t router_purpose,
  20. const char *resource,
  21. int pds_flags,
  22. download_want_authority_t want_authority));
  23. void directory_get_from_all_authorities(uint8_t dir_purpose,
  24. uint8_t router_purpose,
  25. const char *resource);
  26. /** Enumeration of ways to connect to a directory server */
  27. typedef enum {
  28. /** Default: connect over a one-hop Tor circuit. Relays fall back to direct
  29. * DirPort connections, clients, onion services, and bridges do not */
  30. DIRIND_ONEHOP=0,
  31. /** Connect over a multi-hop anonymizing Tor circuit */
  32. DIRIND_ANONYMOUS=1,
  33. /** Connect to the DirPort directly */
  34. DIRIND_DIRECT_CONN,
  35. /** Connect over a multi-hop anonymizing Tor circuit to our dirport */
  36. DIRIND_ANON_DIRPORT,
  37. } dir_indirection_t;
  38. int directory_must_use_begindir(const or_options_t *options);
  39. /**
  40. * A directory_request_t describes the information about a directory request
  41. * at the client side. It describes what we're going to ask for, which
  42. * directory we're going to ask for it, how we're going to contact that
  43. * directory, and (in some cases) what to do with it when we're done.
  44. */
  45. typedef struct directory_request_t directory_request_t;
  46. directory_request_t *directory_request_new(uint8_t dir_purpose);
  47. void directory_request_free_(directory_request_t *req);
  48. #define directory_request_free(req) \
  49. FREE_AND_NULL(directory_request_t, directory_request_free_, (req))
  50. void directory_request_set_or_addr_port(directory_request_t *req,
  51. const tor_addr_port_t *p);
  52. void directory_request_set_dir_addr_port(directory_request_t *req,
  53. const tor_addr_port_t *p);
  54. void directory_request_set_directory_id_digest(directory_request_t *req,
  55. const char *digest);
  56. struct circuit_guard_state_t;
  57. void directory_request_set_guard_state(directory_request_t *req,
  58. struct circuit_guard_state_t *state);
  59. void directory_request_set_router_purpose(directory_request_t *req,
  60. uint8_t router_purpose);
  61. void directory_request_set_indirection(directory_request_t *req,
  62. dir_indirection_t indirection);
  63. void directory_request_set_resource(directory_request_t *req,
  64. const char *resource);
  65. void directory_request_set_payload(directory_request_t *req,
  66. const char *payload,
  67. size_t payload_len);
  68. void directory_request_set_if_modified_since(directory_request_t *req,
  69. time_t if_modified_since);
  70. void directory_request_set_rend_query(directory_request_t *req,
  71. const rend_data_t *query);
  72. void directory_request_upload_set_hs_ident(directory_request_t *req,
  73. const hs_ident_dir_conn_t *ident);
  74. void directory_request_fetch_set_hs_ident(directory_request_t *req,
  75. const hs_ident_dir_conn_t *ident);
  76. void directory_request_set_routerstatus(directory_request_t *req,
  77. const routerstatus_t *rs);
  78. void directory_request_add_header(directory_request_t *req,
  79. const char *key,
  80. const char *val);
  81. MOCK_DECL(void, directory_initiate_request, (directory_request_t *request));
  82. int router_supports_extrainfo(const char *identity_digest, int is_authority);
  83. void connection_dir_client_request_failed(dir_connection_t *conn);
  84. void connection_dir_client_refetch_hsdesc_if_needed(
  85. dir_connection_t *dir_conn);
  86. #ifdef DIRCLIENT_PRIVATE
  87. struct directory_request_t {
  88. /**
  89. * These fields specify which directory we're contacting. Routerstatus,
  90. * if present, overrides the other fields.
  91. *
  92. * @{ */
  93. tor_addr_port_t or_addr_port;
  94. tor_addr_port_t dir_addr_port;
  95. char digest[DIGEST_LEN];
  96. const routerstatus_t *routerstatus;
  97. /** @} */
  98. /** One of DIR_PURPOSE_* other than DIR_PURPOSE_SERVER. Describes what
  99. * kind of operation we'll be doing (upload/download), and of what kind
  100. * of document. */
  101. uint8_t dir_purpose;
  102. /** One of ROUTER_PURPOSE_*; used for uploads and downloads of routerinfo
  103. * and extrainfo docs. */
  104. uint8_t router_purpose;
  105. /** Enum: determines whether to anonymize, and whether to use dirport or
  106. * orport. */
  107. dir_indirection_t indirection;
  108. /** Alias to the variable part of the URL for this request */
  109. const char *resource;
  110. /** Alias to the payload to upload (if any) */
  111. const char *payload;
  112. /** Number of bytes to upload from payload</b> */
  113. size_t payload_len;
  114. /** Value to send in an if-modified-since header, or 0 for none. */
  115. time_t if_modified_since;
  116. /** Hidden-service-specific information v2. */
  117. const rend_data_t *rend_query;
  118. /** Extra headers to append to the request */
  119. struct config_line_t *additional_headers;
  120. /** Hidden-service-specific information for v3+. */
  121. const hs_ident_dir_conn_t *hs_ident;
  122. /** Used internally to directory.c: gets informed when the attempt to
  123. * connect to the directory succeeds or fails, if that attempt bears on the
  124. * directory's usability as a directory guard. */
  125. struct circuit_guard_state_t *guard_state;
  126. };
  127. /** A structure to hold arguments passed into each directory response
  128. * handler */
  129. typedef struct response_handler_args_t {
  130. int status_code;
  131. const char *reason;
  132. const char *body;
  133. size_t body_len;
  134. const char *headers;
  135. } response_handler_args_t;
  136. enum compress_method_t;
  137. STATIC int allowed_anonymous_connection_compression_method(
  138. enum compress_method_t);
  139. STATIC void warn_disallowed_anonymous_compression_method(
  140. enum compress_method_t);
  141. STATIC int should_use_directory_guards(const or_options_t *options);
  142. STATIC char *accept_encoding_header(void);
  143. STATIC const char *dir_conn_purpose_to_string(int purpose);
  144. STATIC int handle_response_fetch_hsdesc_v3(dir_connection_t *conn,
  145. const response_handler_args_t *args);
  146. STATIC int handle_response_fetch_microdesc(dir_connection_t *conn,
  147. const response_handler_args_t *args);
  148. STATIC int handle_response_fetch_consensus(dir_connection_t *conn,
  149. const response_handler_args_t *args);
  150. STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose,
  151. const char *resource);
  152. #endif /* defined(DIRCLIENT_PRIVATE) */
  153. #endif /* !defined(TOR_DIRCLIENT_H) */