Tor  0.4.7.0-alpha-dev
directory.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 directory.h
9  * \brief Header file for directory.c.
10  **/
11 
12 #ifndef TOR_DIRECTORY_H
13 #define TOR_DIRECTORY_H
14 
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 
84 int parse_http_response(const char *headers, int *code, time_t *date,
85  enum compress_method_t *compression, char **response);
86 int parse_http_command(const char *headers,
87  char **command_out, char **url_out);
88 char *http_get_header(const char *headers, const char *which);
89 
97 
98 #define DSR_HEX (1<<0)
99 #define DSR_BASE64 (1<<1)
100 #define DSR_DIGEST256 (1<<2)
101 #define DSR_SORT_UNIQ (1<<3)
102 int dir_split_resource_into_fingerprints(const char *resource,
103  smartlist_t *fp_out, int *compressed_out,
104  int flags);
106  smartlist_t *pairs_out);
107 char *directory_dump_request_log(void);
108 void note_request(const char *key, size_t bytes);
109 
110 int purpose_needs_anonymity(uint8_t dir_purpose, uint8_t router_purpose,
111  const char *resource);
112 
114 
115 #define X_ADDRESS_HEADER "X-Your-Address-Is: "
116 #define X_OR_DIFF_FROM_CONSENSUS_HEADER "X-Or-Diff-From-Consensus: "
117 
118 #endif /* !defined(TOR_DIRECTORY_H) */
compress_method_t
Definition: compress.h:21
int connection_dir_finished_flushing(dir_connection_t *conn)
Definition: directory.c:503
int connection_dir_finished_connecting(dir_connection_t *conn)
Definition: directory.c:549
int purpose_needs_anonymity(uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
Definition: directory.c:113
dir_connection_t * TO_DIR_CONN(connection_t *c)
Definition: directory.c:88
char * authdir_type_to_string(dirinfo_type_t auth)
Definition: directory.c:160
int dir_split_resource_into_fingerprint_pairs(const char *res, smartlist_t *pairs_out)
Definition: directory.c:581
const dir_connection_t * CONST_TO_DIR_CONN(const connection_t *c)
Definition: directory.c:101
int parse_http_response(const char *headers, int *code, time_t *date, enum compress_method_t *compression, char **response)
Definition: directory.c:360
int connection_dir_is_encrypted(const dir_connection_t *conn)
Definition: directory.c:180
char * http_get_header(const char *headers, const char *which)
Definition: directory.c:325
bool connection_dir_is_anonymous(const dir_connection_t *conn)
Definition: directory.c:200
int dir_split_resource_into_fingerprints(const char *resource, smartlist_t *fp_out, int *compressed_out, int flags)
Definition: directory.c:640
int connection_dir_reached_eof(dir_connection_t *conn)
Definition: dirclient.c:2810
int parse_http_command(const char *headers, char **command_out, char **url_out)
Definition: directory.c:271
void connection_dir_about_to_close(dir_connection_t *dir_conn)
Definition: directory.c:485
int connection_dir_process_inbuf(dir_connection_t *conn)
Definition: directory.c:443
dirinfo_type_t
Definition: or.h:785