Tor  0.4.5.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-2020, 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_ 4
34 /** A connection to a directory server: set after a v2 rendezvous
35  * descriptor is downloaded. */
36 #define DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2 4
37 /** A connection to a directory server: download one or more server
38  * descriptors. */
39 #define DIR_PURPOSE_FETCH_SERVERDESC 6
40 /** A connection to a directory server: download one or more extra-info
41  * documents. */
42 #define DIR_PURPOSE_FETCH_EXTRAINFO 7
43 /** A connection to a directory server: upload a server descriptor. */
44 #define DIR_PURPOSE_UPLOAD_DIR 8
45 /** A connection to a directory server: upload a v3 networkstatus vote. */
46 #define DIR_PURPOSE_UPLOAD_VOTE 10
47 /** A connection to a directory server: upload a v3 consensus signature */
48 #define DIR_PURPOSE_UPLOAD_SIGNATURES 11
49 /** A connection to a directory server: download one or more v3 networkstatus
50  * votes. */
51 #define DIR_PURPOSE_FETCH_STATUS_VOTE 12
52 /** A connection to a directory server: download a v3 detached signatures
53  * object for a consensus. */
54 #define DIR_PURPOSE_FETCH_DETACHED_SIGNATURES 13
55 /** A connection to a directory server: download a v3 networkstatus
56  * consensus. */
57 #define DIR_PURPOSE_FETCH_CONSENSUS 14
58 /** A connection to a directory server: download one or more directory
59  * authority certificates. */
60 #define DIR_PURPOSE_FETCH_CERTIFICATE 15
61 
62 /** Purpose for connection at a directory server. */
63 #define DIR_PURPOSE_SERVER 16
64 /** A connection to a hidden service directory server: upload a v2 rendezvous
65  * descriptor. */
66 #define DIR_PURPOSE_UPLOAD_RENDDESC_V2 17
67 /** A connection to a hidden service directory server: download a v2 rendezvous
68  * descriptor. */
69 #define DIR_PURPOSE_FETCH_RENDDESC_V2 18
70 /** A connection to a directory server: download a microdescriptor. */
71 #define DIR_PURPOSE_FETCH_MICRODESC 19
72 /** A connection to a hidden service directory: upload a v3 descriptor. */
73 #define DIR_PURPOSE_UPLOAD_HSDESC 20
74 /** A connection to a hidden service directory: fetch a v3 descriptor. */
75 #define DIR_PURPOSE_FETCH_HSDESC 21
76 /** A connection to a directory server: set after a hidden service descriptor
77  * is downloaded. */
78 #define DIR_PURPOSE_HAS_FETCHED_HSDESC 22
79 #define DIR_PURPOSE_MAX_ 22
80 
81 /** True iff <b>p</b> is a purpose corresponding to uploading
82  * data to a directory server. */
83 #define DIR_PURPOSE_IS_UPLOAD(p) \
84  ((p)==DIR_PURPOSE_UPLOAD_DIR || \
85  (p)==DIR_PURPOSE_UPLOAD_VOTE || \
86  (p)==DIR_PURPOSE_UPLOAD_SIGNATURES || \
87  (p)==DIR_PURPOSE_UPLOAD_RENDDESC_V2 || \
88  (p)==DIR_PURPOSE_UPLOAD_HSDESC)
89 
91 int parse_http_response(const char *headers, int *code, time_t *date,
92  enum compress_method_t *compression, char **response);
93 int parse_http_command(const char *headers,
94  char **command_out, char **url_out);
95 char *http_get_header(const char *headers, const char *which);
96 
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);
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 
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) */
connection_dir_is_encrypted
int connection_dir_is_encrypted(const dir_connection_t *conn)
Definition: directory.c:184
parse_http_command
int parse_http_command(const char *headers, char **command_out, char **url_out)
Definition: directory.c:275
purpose_needs_anonymity
int purpose_needs_anonymity(uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
Definition: directory.c:114
connection_dir_reached_eof
int connection_dir_reached_eof(dir_connection_t *conn)
Definition: dirclient.c:2995
connection_dir_finished_flushing
int connection_dir_finished_flushing(dir_connection_t *conn)
Definition: directory.c:507
authdir_type_to_string
char * authdir_type_to_string(dirinfo_type_t auth)
Definition: directory.c:164
connection_dir_is_anonymous
bool connection_dir_is_anonymous(const dir_connection_t *conn)
Definition: directory.c:204
dir_split_resource_into_fingerprint_pairs
int dir_split_resource_into_fingerprint_pairs(const char *res, smartlist_t *pairs_out)
Definition: directory.c:585
connection_dir_process_inbuf
int connection_dir_process_inbuf(dir_connection_t *conn)
Definition: directory.c:447
CONST_TO_DIR_CONN
const dir_connection_t * CONST_TO_DIR_CONN(const connection_t *c)
Definition: directory.c:102
TO_DIR_CONN
dir_connection_t * TO_DIR_CONN(connection_t *c)
Definition: directory.c:89
connection_t
Definition: connection_st.h:45
http_get_header
char * http_get_header(const char *headers, const char *which)
Definition: directory.c:329
compress_method_t
compress_method_t
Definition: compress.h:21
dir_split_resource_into_fingerprints
int dir_split_resource_into_fingerprints(const char *resource, smartlist_t *fp_out, int *compressed_out, int flags)
Definition: directory.c:644
dirinfo_type_t
dirinfo_type_t
Definition: or.h:905
parse_http_response
int parse_http_response(const char *headers, int *code, time_t *date, enum compress_method_t *compression, char **response)
Definition: directory.c:364
dir_connection_t
Definition: dir_connection_st.h:21
connection_dir_finished_connecting
int connection_dir_finished_connecting(dir_connection_t *conn)
Definition: directory.c:553
smartlist_t
Definition: smartlist_core.h:26
connection_dir_about_to_close
void connection_dir_about_to_close(dir_connection_t *dir_conn)
Definition: directory.c:489