Tor 0.4.9.0-alpha-dev
Macros | Functions
directory.h File Reference

Header file for directory.c. More...

Go to the source code of this file.

Macros

#define DIR_CONN_STATE_MIN_   1
 
#define DIR_CONN_STATE_CONNECTING   1
 
#define DIR_CONN_STATE_CLIENT_SENDING   2
 
#define DIR_CONN_STATE_CLIENT_READING   3
 
#define DIR_CONN_STATE_CLIENT_FINISHED   4
 
#define DIR_CONN_STATE_SERVER_COMMAND_WAIT   5
 
#define DIR_CONN_STATE_SERVER_WRITING   6
 
#define DIR_CONN_STATE_MAX_   6
 
#define DIR_PURPOSE_MIN_   6
 
#define DIR_PURPOSE_FETCH_SERVERDESC   6
 
#define DIR_PURPOSE_FETCH_EXTRAINFO   7
 
#define DIR_PURPOSE_UPLOAD_DIR   8
 
#define DIR_PURPOSE_UPLOAD_VOTE   10
 
#define DIR_PURPOSE_UPLOAD_SIGNATURES   11
 
#define DIR_PURPOSE_FETCH_STATUS_VOTE   12
 
#define DIR_PURPOSE_FETCH_DETACHED_SIGNATURES   13
 
#define DIR_PURPOSE_FETCH_CONSENSUS   14
 
#define DIR_PURPOSE_FETCH_CERTIFICATE   15
 
#define DIR_PURPOSE_SERVER   16
 
#define DIR_PURPOSE_FETCH_MICRODESC   19
 
#define DIR_PURPOSE_UPLOAD_HSDESC   20
 
#define DIR_PURPOSE_FETCH_HSDESC   21
 
#define DIR_PURPOSE_HAS_FETCHED_HSDESC   22
 
#define DIR_PURPOSE_MAX_   22
 
#define DIR_PURPOSE_IS_UPLOAD(p)
 
#define DIR_PURPOSE_IS_HS(p)
 
#define DSR_HEX   (1<<0)
 
#define DSR_BASE64   (1<<1)
 
#define DSR_DIGEST256   (1<<2)
 
#define DSR_SORT_UNIQ   (1<<3)
 
#define X_ADDRESS_HEADER   "X-Your-Address-Is: "
 
#define X_OR_DIFF_FROM_CONSENSUS_HEADER   "X-Or-Diff-From-Consensus: "
 

Functions

dir_connection_tTO_DIR_CONN (connection_t *c)
 
const dir_connection_tCONST_TO_DIR_CONN (const connection_t *c)
 
int parse_http_response (const char *headers, int *code, time_t *date, enum compress_method_t *compression, char **response)
 
int parse_http_command (const char *headers, char **command_out, char **url_out)
 
char * http_get_header (const char *headers, const char *which)
 
int connection_dir_is_encrypted (const dir_connection_t *conn)
 
bool connection_dir_is_anonymous (const dir_connection_t *conn)
 
int connection_dir_reached_eof (dir_connection_t *conn)
 
int connection_dir_process_inbuf (dir_connection_t *conn)
 
int connection_dir_finished_flushing (dir_connection_t *conn)
 
int connection_dir_finished_connecting (dir_connection_t *conn)
 
void connection_dir_about_to_close (dir_connection_t *dir_conn)
 
int dir_split_resource_into_fingerprints (const char *resource, smartlist_t *fp_out, int *compressed_out, int flags)
 
int dir_split_resource_into_fingerprint_pairs (const char *res, smartlist_t *pairs_out)
 
char * directory_dump_request_log (void)
 
void note_request (const char *key, size_t bytes)
 
int purpose_needs_anonymity (uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
 
char * authdir_type_to_string (dirinfo_type_t auth)
 

Detailed Description

Header file for directory.c.

Definition in file directory.h.

Macro Definition Documentation

◆ DIR_CONN_STATE_CLIENT_FINISHED

#define DIR_CONN_STATE_CLIENT_FINISHED   4

State for connection to directory server: happy and finished.

Definition at line 26 of file directory.h.

◆ DIR_CONN_STATE_CLIENT_READING

#define DIR_CONN_STATE_CLIENT_READING   3

State for connection to directory server: reading HTTP response.

Definition at line 24 of file directory.h.

◆ DIR_CONN_STATE_CLIENT_SENDING

#define DIR_CONN_STATE_CLIENT_SENDING   2

State for connection to directory server: sending HTTP request.

Definition at line 22 of file directory.h.

◆ DIR_CONN_STATE_CONNECTING

#define DIR_CONN_STATE_CONNECTING   1

State for connection to directory server: waiting for connect().

Definition at line 20 of file directory.h.

◆ DIR_CONN_STATE_MAX_

#define DIR_CONN_STATE_MAX_   6

Definition at line 31 of file directory.h.

◆ DIR_CONN_STATE_MIN_

#define DIR_CONN_STATE_MIN_   1

Definition at line 18 of file directory.h.

◆ DIR_CONN_STATE_SERVER_COMMAND_WAIT

#define DIR_CONN_STATE_SERVER_COMMAND_WAIT   5

State for connection at directory server: waiting for HTTP request.

Definition at line 28 of file directory.h.

◆ DIR_CONN_STATE_SERVER_WRITING

#define DIR_CONN_STATE_SERVER_WRITING   6

State for connection at directory server: sending HTTP response.

Definition at line 30 of file directory.h.

◆ DIR_PURPOSE_FETCH_CERTIFICATE

#define DIR_PURPOSE_FETCH_CERTIFICATE   15

A connection to a directory server: download one or more directory authority certificates.

Definition at line 57 of file directory.h.

◆ DIR_PURPOSE_FETCH_CONSENSUS

#define DIR_PURPOSE_FETCH_CONSENSUS   14

A connection to a directory server: download a v3 networkstatus consensus.

Definition at line 54 of file directory.h.

◆ DIR_PURPOSE_FETCH_DETACHED_SIGNATURES

#define DIR_PURPOSE_FETCH_DETACHED_SIGNATURES   13

A connection to a directory server: download a v3 detached signatures object for a consensus.

Definition at line 51 of file directory.h.

◆ DIR_PURPOSE_FETCH_EXTRAINFO

#define DIR_PURPOSE_FETCH_EXTRAINFO   7

A connection to a directory server: download one or more extra-info documents.

Definition at line 39 of file directory.h.

◆ DIR_PURPOSE_FETCH_HSDESC

#define DIR_PURPOSE_FETCH_HSDESC   21

A connection to a hidden service directory: fetch a v3 descriptor.

Definition at line 69 of file directory.h.

◆ DIR_PURPOSE_FETCH_MICRODESC

#define DIR_PURPOSE_FETCH_MICRODESC   19

Value 17 and 18 were onion service v2 purposes. A connection to a directory server: download a microdescriptor.

Definition at line 65 of file directory.h.

◆ DIR_PURPOSE_FETCH_SERVERDESC

#define DIR_PURPOSE_FETCH_SERVERDESC   6

A connection to a directory server: download one or more server descriptors.

Definition at line 36 of file directory.h.

◆ DIR_PURPOSE_FETCH_STATUS_VOTE

#define DIR_PURPOSE_FETCH_STATUS_VOTE   12

A connection to a directory server: download one or more v3 networkstatus votes.

Definition at line 48 of file directory.h.

◆ DIR_PURPOSE_HAS_FETCHED_HSDESC

#define DIR_PURPOSE_HAS_FETCHED_HSDESC   22

A connection to a directory server: set after a hidden service descriptor is downloaded.

Definition at line 72 of file directory.h.

◆ DIR_PURPOSE_IS_HS

#define DIR_PURPOSE_IS_HS (   p)
Value:
#define DIR_PURPOSE_UPLOAD_HSDESC
Definition: directory.h:67
#define DIR_PURPOSE_FETCH_HSDESC
Definition: directory.h:69

True iff p is a purpose corresponding to onion service that is either uploading or fetching actions.

Definition at line 85 of file directory.h.

◆ DIR_PURPOSE_IS_UPLOAD

#define DIR_PURPOSE_IS_UPLOAD (   p)
Value:
#define DIR_PURPOSE_UPLOAD_VOTE
Definition: directory.h:43
#define DIR_PURPOSE_UPLOAD_SIGNATURES
Definition: directory.h:45
#define DIR_PURPOSE_UPLOAD_DIR
Definition: directory.h:41

True iff p is a purpose corresponding to uploading data to a directory server.

Definition at line 77 of file directory.h.

◆ DIR_PURPOSE_MAX_

#define DIR_PURPOSE_MAX_   22

Definition at line 73 of file directory.h.

◆ DIR_PURPOSE_MIN_

#define DIR_PURPOSE_MIN_   6

Definition at line 33 of file directory.h.

◆ DIR_PURPOSE_SERVER

#define DIR_PURPOSE_SERVER   16

Purpose for connection at a directory server.

Definition at line 60 of file directory.h.

◆ DIR_PURPOSE_UPLOAD_DIR

#define DIR_PURPOSE_UPLOAD_DIR   8

A connection to a directory server: upload a server descriptor.

Definition at line 41 of file directory.h.

◆ DIR_PURPOSE_UPLOAD_HSDESC

#define DIR_PURPOSE_UPLOAD_HSDESC   20

A connection to a hidden service directory: upload a v3 descriptor.

Definition at line 67 of file directory.h.

◆ DIR_PURPOSE_UPLOAD_SIGNATURES

#define DIR_PURPOSE_UPLOAD_SIGNATURES   11

A connection to a directory server: upload a v3 consensus signature

Definition at line 45 of file directory.h.

◆ DIR_PURPOSE_UPLOAD_VOTE

#define DIR_PURPOSE_UPLOAD_VOTE   10

A connection to a directory server: upload a v3 networkstatus vote.

Definition at line 43 of file directory.h.

◆ DSR_BASE64

#define DSR_BASE64   (1<<1)

Definition at line 105 of file directory.h.

◆ DSR_DIGEST256

#define DSR_DIGEST256   (1<<2)

Definition at line 106 of file directory.h.

◆ DSR_HEX

#define DSR_HEX   (1<<0)

Definition at line 104 of file directory.h.

◆ DSR_SORT_UNIQ

#define DSR_SORT_UNIQ   (1<<3)

Definition at line 107 of file directory.h.

◆ X_ADDRESS_HEADER

#define X_ADDRESS_HEADER   "X-Your-Address-Is: "

Definition at line 121 of file directory.h.

◆ X_OR_DIFF_FROM_CONSENSUS_HEADER

#define X_OR_DIFF_FROM_CONSENSUS_HEADER   "X-Or-Diff-From-Consensus: "

Definition at line 122 of file directory.h.

Function Documentation

◆ authdir_type_to_string()

char * authdir_type_to_string ( dirinfo_type_t  auth)

Return a newly allocated string describing auth. Only describes authority features.

Definition at line 160 of file directory.c.

◆ connection_dir_about_to_close()

void connection_dir_about_to_close ( dir_connection_t dir_conn)

Called when we're about to finally unlink and free a directory connection: perform necessary accounting and cleanup

Definition at line 485 of file directory.c.

Referenced by connection_about_to_close_connection().

◆ connection_dir_finished_connecting()

int connection_dir_finished_connecting ( dir_connection_t conn)

Connected handler for directory connections: begin sending data to the server, and return 0. Only used when connections don't immediately connect.

Definition at line 549 of file directory.c.

Referenced by connection_finished_connecting().

◆ connection_dir_finished_flushing()

int connection_dir_finished_flushing ( dir_connection_t conn)

Write handler for directory connections; called when all data has been flushed. Close the connection or wait for a response as appropriate.

Definition at line 503 of file directory.c.

Referenced by connection_finished_flushing().

◆ connection_dir_is_anonymous()

bool connection_dir_is_anonymous ( const dir_connection_t dir_conn)

Return true iff the given directory connection dir_conn is anonymous, that is, it is on a circuit via a public relay and not directly from a client or bridge.

For client circuits via relays: true for 2-hop+ paths. For client circuits via bridges: true for 3-hop+ paths.

This first test if the connection is encrypted since it is a strong requirement for anonymity.

Definition at line 200 of file directory.c.

Referenced by handle_get_hs_descriptor_v3().

◆ connection_dir_is_encrypted()

int connection_dir_is_encrypted ( const dir_connection_t conn)

Return true iff anything we say on conn is being encrypted before we send it to the client/server.

Definition at line 180 of file directory.c.

Referenced by connection_dir_is_anonymous(), handle_get_networkstatus_bridges(), spooled_resource_estimate_size(), and spooled_resource_flush_some().

◆ connection_dir_process_inbuf()

int connection_dir_process_inbuf ( dir_connection_t conn)

Read handler for directory connections. (That's connections to directory servers and connections at directory servers.)

Definition at line 443 of file directory.c.

Referenced by connection_process_inbuf().

◆ connection_dir_reached_eof()

int connection_dir_reached_eof ( dir_connection_t conn)

Called when a directory connection reaches EOF.

Definition at line 2847 of file dirclient.c.

Referenced by connection_reached_eof().

◆ CONST_TO_DIR_CONN()

const dir_connection_t * CONST_TO_DIR_CONN ( const connection_t c)

Cast a const connection_t * to a const dir_connection_t *.

Exit with an assertion failure if the input is not a dir_connection_t.

Definition at line 101 of file directory.c.

◆ dir_split_resource_into_fingerprint_pairs()

int dir_split_resource_into_fingerprint_pairs ( const char *  res,
smartlist_t pairs_out 
)

Divide a string res of the form FP1-FP2+FP3-FP4...[.z], where each FP is a hex-encoded fingerprint, into a sequence of distinct sorted fp_pair_t. Skip malformed pairs. On success, return 0 and add those fp_pair_t into pairs_out. On failure, return -1.

Definition at line 581 of file directory.c.

Referenced by list_pending_fpsk_downloads().

◆ dir_split_resource_into_fingerprints()

int dir_split_resource_into_fingerprints ( const char *  resource,
smartlist_t fp_out,
int *  compressed_out,
int  flags 
)

Given a directory resource request, containing zero or more strings separated by plus signs, followed optionally by ".z", store the strings, in order, into fp_out. If compressed_out is non-NULL, set it to 1 if the resource ends in ".z", else set it to 0.

If (flags & DSR_HEX), then delete all elements that aren't hex digests, and decode the rest. If (flags & DSR_BASE64), then use "-" rather than "+" as a separator, delete all the elements that aren't base64-encoded digests, and decode the rest. If (flags & DSR_DIGEST256), these digests should be 256 bits long; else they should be 160.

If (flags & DSR_SORT_UNIQ), then sort the list and remove all duplicates.

Definition at line 640 of file directory.c.

Referenced by connection_dir_bridge_routerdesc_failed(), controller_get_routerdescs(), and handle_get_keys().

◆ http_get_header()

char * http_get_header ( const char *  headers,
const char *  which 
)

Return a copy of the first HTTP header in headers whose key is which. The key should be given with a terminating colon and space; this function copies everything after, up to but not including the following \r\n.

Definition at line 325 of file directory.c.

Referenced by handle_response_upload_dir(), http_set_address_origin(), and parse_or_diff_from_header().

◆ parse_http_command()

int parse_http_command ( const char *  headers,
char **  command_out,
char **  url_out 
)

Parse an HTTP request line at the start of a headers string. On failure, return -1. On success, set *command_out to a copy of the HTTP command ("get", "post", etc), set *url_out to a copy of the URL, and return 0.

Definition at line 271 of file directory.c.

Referenced by metrics_connection_process_inbuf(), and parse_http_url().

◆ parse_http_response()

int parse_http_response ( const char *  headers,
int *  code,
time_t *  date,
compress_method_t compression,
char **  reason 
)

Parse an HTTP response string headers of the form

* "HTTP/1.\%d \%d\%s\r\n...".
* 

If it's well-formed, assign the status code to *code and return 0. Otherwise, return -1.

On success: If date is provided, set *date to the Date header in the http headers, or 0 if no such header is found. If compression is provided, set *compression to the compression method given in the Content-Encoding header, or 0 if no such header is found, or -1 if the value of the header is not recognized. If reason is provided, strdup the reason string into it.

Definition at line 360 of file directory.c.

◆ purpose_needs_anonymity()

int purpose_needs_anonymity ( uint8_t  dir_purpose,
uint8_t  router_purpose,
const char *  resource 
)

Return false if the directory purpose dir_purpose does not require an anonymous (three-hop) connection.

Return true 1) by default, 2) if all directory actions have specifically been configured to be over an anonymous connection, or 3) if the router is a bridge

Definition at line 113 of file directory.c.

Referenced by connection_dir_client_reached_eof().

◆ TO_DIR_CONN()

dir_connection_t * TO_DIR_CONN ( connection_t c)