directory.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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-2018, 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. dir_connection_t *TO_DIR_CONN(connection_t *c);
  13. #define DIR_CONN_STATE_MIN_ 1
  14. /** State for connection to directory server: waiting for connect(). */
  15. #define DIR_CONN_STATE_CONNECTING 1
  16. /** State for connection to directory server: sending HTTP request. */
  17. #define DIR_CONN_STATE_CLIENT_SENDING 2
  18. /** State for connection to directory server: reading HTTP response. */
  19. #define DIR_CONN_STATE_CLIENT_READING 3
  20. /** State for connection to directory server: happy and finished. */
  21. #define DIR_CONN_STATE_CLIENT_FINISHED 4
  22. /** State for connection at directory server: waiting for HTTP request. */
  23. #define DIR_CONN_STATE_SERVER_COMMAND_WAIT 5
  24. /** State for connection at directory server: sending HTTP response. */
  25. #define DIR_CONN_STATE_SERVER_WRITING 6
  26. #define DIR_CONN_STATE_MAX_ 6
  27. #define DIR_PURPOSE_MIN_ 4
  28. /** A connection to a directory server: set after a v2 rendezvous
  29. * descriptor is downloaded. */
  30. #define DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2 4
  31. /** A connection to a directory server: download one or more server
  32. * descriptors. */
  33. #define DIR_PURPOSE_FETCH_SERVERDESC 6
  34. /** A connection to a directory server: download one or more extra-info
  35. * documents. */
  36. #define DIR_PURPOSE_FETCH_EXTRAINFO 7
  37. /** A connection to a directory server: upload a server descriptor. */
  38. #define DIR_PURPOSE_UPLOAD_DIR 8
  39. /** A connection to a directory server: upload a v3 networkstatus vote. */
  40. #define DIR_PURPOSE_UPLOAD_VOTE 10
  41. /** A connection to a directory server: upload a v3 consensus signature */
  42. #define DIR_PURPOSE_UPLOAD_SIGNATURES 11
  43. /** A connection to a directory server: download one or more v3 networkstatus
  44. * votes. */
  45. #define DIR_PURPOSE_FETCH_STATUS_VOTE 12
  46. /** A connection to a directory server: download a v3 detached signatures
  47. * object for a consensus. */
  48. #define DIR_PURPOSE_FETCH_DETACHED_SIGNATURES 13
  49. /** A connection to a directory server: download a v3 networkstatus
  50. * consensus. */
  51. #define DIR_PURPOSE_FETCH_CONSENSUS 14
  52. /** A connection to a directory server: download one or more directory
  53. * authority certificates. */
  54. #define DIR_PURPOSE_FETCH_CERTIFICATE 15
  55. /** Purpose for connection at a directory server. */
  56. #define DIR_PURPOSE_SERVER 16
  57. /** A connection to a hidden service directory server: upload a v2 rendezvous
  58. * descriptor. */
  59. #define DIR_PURPOSE_UPLOAD_RENDDESC_V2 17
  60. /** A connection to a hidden service directory server: download a v2 rendezvous
  61. * descriptor. */
  62. #define DIR_PURPOSE_FETCH_RENDDESC_V2 18
  63. /** A connection to a directory server: download a microdescriptor. */
  64. #define DIR_PURPOSE_FETCH_MICRODESC 19
  65. /** A connection to a hidden service directory: upload a v3 descriptor. */
  66. #define DIR_PURPOSE_UPLOAD_HSDESC 20
  67. /** A connection to a hidden service directory: fetch a v3 descriptor. */
  68. #define DIR_PURPOSE_FETCH_HSDESC 21
  69. /** A connection to a directory server: set after a hidden service descriptor
  70. * is downloaded. */
  71. #define DIR_PURPOSE_HAS_FETCHED_HSDESC 22
  72. #define DIR_PURPOSE_MAX_ 22
  73. /** True iff <b>p</b> is a purpose corresponding to uploading
  74. * data to a directory server. */
  75. #define DIR_PURPOSE_IS_UPLOAD(p) \
  76. ((p)==DIR_PURPOSE_UPLOAD_DIR || \
  77. (p)==DIR_PURPOSE_UPLOAD_VOTE || \
  78. (p)==DIR_PURPOSE_UPLOAD_SIGNATURES || \
  79. (p)==DIR_PURPOSE_UPLOAD_RENDDESC_V2 || \
  80. (p)==DIR_PURPOSE_UPLOAD_HSDESC)
  81. enum compress_method_t;
  82. int parse_http_response(const char *headers, int *code, time_t *date,
  83. enum compress_method_t *compression, char **response);
  84. int parse_http_command(const char *headers,
  85. char **command_out, char **url_out);
  86. char *http_get_header(const char *headers, const char *which);
  87. int connection_dir_is_encrypted(const dir_connection_t *conn);
  88. int connection_dir_reached_eof(dir_connection_t *conn);
  89. int connection_dir_process_inbuf(dir_connection_t *conn);
  90. int connection_dir_finished_flushing(dir_connection_t *conn);
  91. int connection_dir_finished_connecting(dir_connection_t *conn);
  92. void connection_dir_about_to_close(dir_connection_t *dir_conn);
  93. #define DSR_HEX (1<<0)
  94. #define DSR_BASE64 (1<<1)
  95. #define DSR_DIGEST256 (1<<2)
  96. #define DSR_SORT_UNIQ (1<<3)
  97. int dir_split_resource_into_fingerprints(const char *resource,
  98. smartlist_t *fp_out, int *compressed_out,
  99. int flags);
  100. enum dir_spool_source_t;
  101. int dir_split_resource_into_spoolable(const char *resource,
  102. enum dir_spool_source_t source,
  103. smartlist_t *spool_out,
  104. int *compressed_out,
  105. int flags);
  106. int dir_split_resource_into_fingerprint_pairs(const char *res,
  107. smartlist_t *pairs_out);
  108. char *directory_dump_request_log(void);
  109. void note_request(const char *key, size_t bytes);
  110. int purpose_needs_anonymity(uint8_t dir_purpose, uint8_t router_purpose,
  111. const char *resource);
  112. char *authdir_type_to_string(dirinfo_type_t auth);
  113. #define X_ADDRESS_HEADER "X-Your-Address-Is: "
  114. #define X_OR_DIFF_FROM_CONSENSUS_HEADER "X-Or-Diff-From-Consensus: "
  115. #endif /* !defined(TOR_DIRECTORY_H) */