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