tor  0.4.0.1-alpha
Macros | Functions
directory.h File Reference

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_   4
 
#define DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2   4
 
#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_UPLOAD_RENDDESC_V2   17
 
#define DIR_PURPOSE_FETCH_RENDDESC_V2   18
 
#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 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)
 
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)
 
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_spoolable (const char *resource, enum dir_spool_source_t source, smartlist_t *spool_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 25 of file directory.h.

Referenced by connection_dir_about_to_close().

◆ DIR_CONN_STATE_CLIENT_READING

#define DIR_CONN_STATE_CLIENT_READING   3

State for connection to directory server: reading HTTP response.

Definition at line 23 of file directory.h.

Referenced by connection_dir_reached_eof().

◆ DIR_CONN_STATE_CLIENT_SENDING

#define DIR_CONN_STATE_CLIENT_SENDING   2

State for connection to directory server: sending HTTP request.

Definition at line 21 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 19 of file directory.h.

Referenced by connection_dir_finished_connecting(), and connection_state_is_connecting().

◆ 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 27 of file directory.h.

Referenced by connection_dir_process_inbuf().

◆ DIR_CONN_STATE_SERVER_WRITING

#define DIR_CONN_STATE_SERVER_WRITING   6

State for connection at directory server: sending HTTP response.

Definition at line 29 of file directory.h.

Referenced by connection_dirserv_flushed_some(), and connection_flushed_some().

◆ 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 59 of file directory.h.

Referenced by list_pending_fpsk_downloads(), and purpose_needs_anonymity().

◆ DIR_PURPOSE_FETCH_CONSENSUS

#define DIR_PURPOSE_FETCH_CONSENSUS   14

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

Definition at line 56 of file directory.h.

Referenced by connection_ap_handshake_attach_circuit(), purpose_needs_anonymity(), and update_consensus_networkstatus_downloads().

◆ 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 53 of file directory.h.

Referenced by directory_get_from_all_authorities(), and purpose_needs_anonymity().

◆ 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 41 of file directory.h.

Referenced by connection_dir_client_request_failed(), list_pending_descriptor_downloads(), and purpose_needs_anonymity().

◆ DIR_PURPOSE_FETCH_HSDESC

#define DIR_PURPOSE_FETCH_HSDESC   21

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

Definition at line 74 of file directory.h.

Referenced by directory_request_fetch_set_hs_ident(), and purpose_needs_anonymity().

◆ DIR_PURPOSE_FETCH_MICRODESC

#define DIR_PURPOSE_FETCH_MICRODESC   19

A connection to a directory server: download a microdescriptor.

Definition at line 70 of file directory.h.

Referenced by guards_choose_dirguard(), launch_descriptor_downloads(), list_pending_microdesc_downloads(), max_dl_per_request(), and purpose_needs_anonymity().

◆ DIR_PURPOSE_FETCH_RENDDESC_V2

#define DIR_PURPOSE_FETCH_RENDDESC_V2   18

A connection to a hidden service directory server: download a v2 rendezvous descriptor.

Definition at line 68 of file directory.h.

Referenced by connection_dir_client_refetch_hsdesc_if_needed(), directory_request_set_rend_query(), purpose_needs_anonymity(), and rend_client_cancel_descriptor_fetches().

◆ 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 38 of file directory.h.

Referenced by connection_dir_client_request_failed(), launch_direct_bridge_descriptor_fetch(), launch_dummy_descriptor_download_as_needed(), list_pending_descriptor_downloads(), and purpose_needs_anonymity().

◆ 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 50 of file directory.h.

Referenced by directory_get_from_all_authorities(), and purpose_needs_anonymity().

◆ 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 77 of file directory.h.

Referenced by purpose_needs_anonymity().

◆ DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2

#define DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2   4

A connection to a directory server: set after a v2 rendezvous descriptor is downloaded.

Definition at line 35 of file directory.h.

Referenced by purpose_needs_anonymity().

◆ DIR_PURPOSE_IS_UPLOAD

#define DIR_PURPOSE_IS_UPLOAD (   p)
Value:
#define DIR_PURPOSE_UPLOAD_HSDESC
Definition: directory.h:72
#define DIR_PURPOSE_UPLOAD_DIR
Definition: directory.h:43
#define DIR_PURPOSE_UPLOAD_SIGNATURES
Definition: directory.h:47
#define DIR_PURPOSE_UPLOAD_VOTE
Definition: directory.h:45
#define DIR_PURPOSE_UPLOAD_RENDDESC_V2
Definition: directory.h:65

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

Definition at line 82 of file directory.h.

Referenced by directory_request_set_payload().

◆ DIR_PURPOSE_SERVER

#define DIR_PURPOSE_SERVER   16

Purpose for connection at a directory server.

Definition at line 62 of file directory.h.

Referenced by connection_expire_held_open(), purpose_needs_anonymity(), and record_num_bytes_transferred_impl().

◆ DIR_PURPOSE_UPLOAD_DIR

#define DIR_PURPOSE_UPLOAD_DIR   8

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

Definition at line 43 of file directory.h.

Referenced by purpose_needs_anonymity().

◆ DIR_PURPOSE_UPLOAD_HSDESC

#define DIR_PURPOSE_UPLOAD_HSDESC   20

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

Definition at line 72 of file directory.h.

Referenced by directory_request_upload_set_hs_ident(), and purpose_needs_anonymity().

◆ DIR_PURPOSE_UPLOAD_RENDDESC_V2

#define DIR_PURPOSE_UPLOAD_RENDDESC_V2   17

A connection to a hidden service directory server: upload a v2 rendezvous descriptor.

Definition at line 65 of file directory.h.

Referenced by directory_request_set_rend_query(), and purpose_needs_anonymity().

◆ DIR_PURPOSE_UPLOAD_SIGNATURES

#define DIR_PURPOSE_UPLOAD_SIGNATURES   11

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

Definition at line 47 of file directory.h.

Referenced by purpose_needs_anonymity().

◆ DIR_PURPOSE_UPLOAD_VOTE

#define DIR_PURPOSE_UPLOAD_VOTE   10

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

Definition at line 45 of file directory.h.

Referenced by purpose_needs_anonymity().

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 140 of file directory.c.

References BRIDGE_DIRINFO, smartlist_add(), and V3_DIRINFO.

◆ 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 389 of file directory.c.

References connection_dir_client_refetch_hsdesc_if_needed(), connection_dir_client_request_failed(), DIR_CONN_STATE_CLIENT_FINISHED, connection_t::state, and TO_CONN.

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 453 of file directory.c.

References CONN_TYPE_DIR, DIR_CONN_STATE_CONNECTING, connection_t::state, tor_assert(), and connection_t::type.

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 407 of file directory.c.

References CONN_TYPE_DIR, dir_connection_t::dirreq_id, geoip_change_dirreq_state(), connection_t::marked_for_close, tor_assert(), and connection_t::type.

Referenced by connection_finished_flushing().

◆ 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 160 of file directory.c.

References TO_CONN.

Referenced by 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 347 of file directory.c.

References CONN_TYPE_DIR, DIR_CONN_STATE_SERVER_COMMAND_WAIT, directory_handle_command(), connection_t::state, tor_assert(), and connection_t::type.

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 2988 of file dirclient.c.

References DIR_CONN_STATE_CLIENT_READING, and connection_t::state.

Referenced by connection_reached_eof().

◆ 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 485 of file directory.c.

References smartlist_split_string().

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 544 of file directory.c.

Referenced by dirserv_get_routerdescs().

◆ dir_split_resource_into_spoolable()

int dir_split_resource_into_spoolable ( const char *  resource,
dir_spool_source_t  source,
smartlist_t spool_out,
int *  compressed_out,
int  flags 
)

As dir_split_resource_into_fingerprints, but instead fills spool_out with a list of spoolable_resource_t for the resource identified through source.

Definition at line 626 of file directory.c.

References tor_assert().

◆ 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 229 of file directory.c.

References strcasecmpstart().

◆ 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 175 of file directory.c.

References eat_whitespace_no_nl(), find_whitespace(), and strcmpstart().

◆ 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 264 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 90 of file directory.c.

References DIR_PURPOSE_FETCH_CERTIFICATE, DIR_PURPOSE_FETCH_CONSENSUS, DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, DIR_PURPOSE_FETCH_EXTRAINFO, DIR_PURPOSE_FETCH_HSDESC, DIR_PURPOSE_FETCH_MICRODESC, DIR_PURPOSE_FETCH_RENDDESC_V2, DIR_PURPOSE_FETCH_SERVERDESC, DIR_PURPOSE_FETCH_STATUS_VOTE, DIR_PURPOSE_HAS_FETCHED_HSDESC, DIR_PURPOSE_HAS_FETCHED_RENDDESC_V2, DIR_PURPOSE_SERVER, DIR_PURPOSE_UPLOAD_DIR, DIR_PURPOSE_UPLOAD_HSDESC, DIR_PURPOSE_UPLOAD_RENDDESC_V2, DIR_PURPOSE_UPLOAD_SIGNATURES, and DIR_PURPOSE_UPLOAD_VOTE.

◆ TO_DIR_CONN()

dir_connection_t* TO_DIR_CONN ( connection_t c)