directory.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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-2015, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file directory.h
  8. * \brief Header file for directory.c.
  9. **/
  10. #ifndef TOR_DIRECTORY_H
  11. #define TOR_DIRECTORY_H
  12. int directories_have_accepted_server_descriptor(void);
  13. void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
  14. dirinfo_type_t type, const char *payload,
  15. size_t payload_len, size_t extrainfo_len);
  16. MOCK_DECL(void, directory_get_from_dirserver, (uint8_t dir_purpose,
  17. uint8_t router_purpose,
  18. const char *resource,
  19. int pds_flags));
  20. void directory_get_from_all_authorities(uint8_t dir_purpose,
  21. uint8_t router_purpose,
  22. const char *resource);
  23. /** Enumeration of ways to connect to a directory server */
  24. typedef enum {
  25. /** Default: connect over a one-hop Tor circuit but fall back to direct
  26. * connection */
  27. DIRIND_ONEHOP=0,
  28. /** Connect over a multi-hop anonymizing Tor circuit */
  29. DIRIND_ANONYMOUS=1,
  30. /** Connect to the DirPort directly */
  31. DIRIND_DIRECT_CONN,
  32. /** Connect over a multi-hop anonymizing Tor circuit to our dirport */
  33. DIRIND_ANON_DIRPORT,
  34. } dir_indirection_t;
  35. void directory_initiate_command_routerstatus(const routerstatus_t *status,
  36. uint8_t dir_purpose,
  37. uint8_t router_purpose,
  38. dir_indirection_t indirection,
  39. const char *resource,
  40. const char *payload,
  41. size_t payload_len,
  42. time_t if_modified_since);
  43. void directory_initiate_command_routerstatus_rend(const routerstatus_t *status,
  44. uint8_t dir_purpose,
  45. uint8_t router_purpose,
  46. dir_indirection_t indirection,
  47. const char *resource,
  48. const char *payload,
  49. size_t payload_len,
  50. time_t if_modified_since,
  51. const rend_data_t *rend_query);
  52. int parse_http_response(const char *headers, int *code, time_t *date,
  53. compress_method_t *compression, char **response);
  54. int connection_dir_is_encrypted(dir_connection_t *conn);
  55. int connection_dir_reached_eof(dir_connection_t *conn);
  56. int connection_dir_process_inbuf(dir_connection_t *conn);
  57. int connection_dir_finished_flushing(dir_connection_t *conn);
  58. int connection_dir_finished_connecting(dir_connection_t *conn);
  59. void connection_dir_about_to_close(dir_connection_t *dir_conn);
  60. void directory_initiate_command(const tor_addr_t *addr,
  61. uint16_t or_port, uint16_t dir_port,
  62. const char *digest,
  63. uint8_t dir_purpose, uint8_t router_purpose,
  64. dir_indirection_t indirection,
  65. const char *resource,
  66. const char *payload, size_t payload_len,
  67. time_t if_modified_since);
  68. #define DSR_HEX (1<<0)
  69. #define DSR_BASE64 (1<<1)
  70. #define DSR_DIGEST256 (1<<2)
  71. #define DSR_SORT_UNIQ (1<<3)
  72. int dir_split_resource_into_fingerprints(const char *resource,
  73. smartlist_t *fp_out, int *compressed_out,
  74. int flags);
  75. int dir_split_resource_into_fingerprint_pairs(const char *res,
  76. smartlist_t *pairs_out);
  77. char *directory_dump_request_log(void);
  78. void note_request(const char *key, size_t bytes);
  79. int router_supports_extrainfo(const char *identity_digest, int is_authority);
  80. time_t download_status_increment_failure(download_status_t *dls,
  81. int status_code, const char *item,
  82. int server, time_t now);
  83. /** Increment the failure count of the download_status_t <b>dls</b>, with
  84. * the optional status code <b>sc</b>. */
  85. #define download_status_failed(dls, sc) \
  86. download_status_increment_failure((dls), (sc), NULL, \
  87. get_options()->DirPort_set, time(NULL))
  88. void download_status_reset(download_status_t *dls);
  89. static int download_status_is_ready(download_status_t *dls, time_t now,
  90. int max_failures);
  91. /** Return true iff, as of <b>now</b>, the resource tracked by <b>dls</b> is
  92. * ready to get its download reattempted. */
  93. static INLINE int
  94. download_status_is_ready(download_status_t *dls, time_t now,
  95. int max_failures)
  96. {
  97. return (dls->n_download_failures <= max_failures
  98. && dls->next_attempt_at <= now);
  99. }
  100. static void download_status_mark_impossible(download_status_t *dl);
  101. /** Mark <b>dl</b> as never downloadable. */
  102. static INLINE void
  103. download_status_mark_impossible(download_status_t *dl)
  104. {
  105. dl->n_download_failures = IMPOSSIBLE_TO_DOWNLOAD;
  106. }
  107. int download_status_get_n_failures(const download_status_t *dls);
  108. #ifdef TOR_UNIT_TESTS
  109. /* Used only by directory.c and test_dir.c */
  110. STATIC int parse_http_url(const char *headers, char **url);
  111. STATIC int purpose_needs_anonymity(uint8_t dir_purpose,
  112. uint8_t router_purpose);
  113. STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose,
  114. const char *resource);
  115. #endif
  116. #endif