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