tor  master
Macros | Typedefs | Enumerations | Functions
directory.h File Reference

Header file for directory.c. More...

#include "hs_ident.h"
Include dependency graph for directory.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define directory_request_free(req)   FREE_AND_NULL(directory_request_t, directory_request_free_, (req))
 
#define DSR_HEX   (1<<0)
 
#define DSR_BASE64   (1<<1)
 
#define DSR_DIGEST256   (1<<2)
 
#define DSR_SORT_UNIQ   (1<<3)
 
#define download_status_failed(dls, sc)
 

Typedefs

typedef struct directory_request_t directory_request_t
 

Enumerations

enum  dir_indirection_t { DIRIND_ONEHOP =0, DIRIND_ANONYMOUS =1, DIRIND_DIRECT_CONN, DIRIND_ANON_DIRPORT }
 

Functions

int directories_have_accepted_server_descriptor (void)
 
void directory_post_to_dirservers (uint8_t dir_purpose, uint8_t router_purpose, dirinfo_type_t type, const char *payload, size_t payload_len, size_t extrainfo_len)
 
 MOCK_DECL (void, directory_get_from_dirserver,(uint8_t dir_purpose, uint8_t router_purpose, const char *resource, int pds_flags, download_want_authority_t want_authority))
 
void directory_get_from_all_authorities (uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
 
int directory_must_use_begindir (const or_options_t *options)
 
directory_request_tdirectory_request_new (uint8_t dir_purpose)
 
void directory_request_free_ (directory_request_t *req)
 
void directory_request_set_or_addr_port (directory_request_t *req, const tor_addr_port_t *p)
 
void directory_request_set_dir_addr_port (directory_request_t *req, const tor_addr_port_t *p)
 
void directory_request_set_directory_id_digest (directory_request_t *req, const char *digest)
 
void directory_request_set_guard_state (directory_request_t *req, struct circuit_guard_state_t *state)
 
void directory_request_set_router_purpose (directory_request_t *req, uint8_t router_purpose)
 
void directory_request_set_indirection (directory_request_t *req, dir_indirection_t indirection)
 
void directory_request_set_resource (directory_request_t *req, const char *resource)
 
void directory_request_set_payload (directory_request_t *req, const char *payload, size_t payload_len)
 
void directory_request_set_if_modified_since (directory_request_t *req, time_t if_modified_since)
 
void directory_request_set_rend_query (directory_request_t *req, const rend_data_t *query)
 
void directory_request_upload_set_hs_ident (directory_request_t *req, const hs_ident_dir_conn_t *ident)
 
void directory_request_fetch_set_hs_ident (directory_request_t *req, const hs_ident_dir_conn_t *ident)
 
void directory_request_set_routerstatus (directory_request_t *req, const routerstatus_t *rs)
 
void directory_request_add_header (directory_request_t *req, const char *key, const char *val)
 
 MOCK_DECL (void, directory_initiate_request,(directory_request_t *request))
 
int parse_http_response (const char *headers, int *code, time_t *date, 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 router_supports_extrainfo (const char *identity_digest, int is_authority)
 
time_t download_status_increment_failure (download_status_t *dls, int status_code, const char *item, int server, time_t now)
 
time_t download_status_increment_attempt (download_status_t *dls, const char *item, time_t now)
 
void download_status_reset (download_status_t *dls)
 
time_t download_status_get_next_attempt_at (const download_status_t *dls)
 
int download_status_get_n_failures (const download_status_t *dls)
 
int download_status_get_n_attempts (const download_status_t *dls)
 
int purpose_needs_anonymity (uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
 

Detailed Description

Header file for directory.c.

Macro Definition Documentation

◆ download_status_failed

#define download_status_failed (   dls,
  sc 
)
Value:
dir_server_mode(get_options()), \
time(NULL))
int dir_server_mode(const or_options_t *options)
Definition: router.c:1387
time_t download_status_increment_failure(download_status_t *dls, int status_code, const char *item, int server, time_t now)
Definition: directory.c:5487

Increment the failure count of the download_status_t dls, with the optional status code sc.

Typedef Documentation

◆ directory_request_t

A directory_request_t describes the information about a directory request at the client side. It describes what we're going to ask for, which directory we're going to ask for it, how we're going to contact that directory, and (in some cases) what to do with it when we're done.

Enumeration Type Documentation

◆ dir_indirection_t

Enumeration of ways to connect to a directory server

Enumerator
DIRIND_ONEHOP 

Default: connect over a one-hop Tor circuit. Relays fall back to direct DirPort connections, clients, onion services, and bridges do not

DIRIND_ANONYMOUS 

Connect over a multi-hop anonymizing Tor circuit

DIRIND_DIRECT_CONN 

Connect to the DirPort directly

DIRIND_ANON_DIRPORT 

Connect over a multi-hop anonymizing Tor circuit to our dirport

Function Documentation

◆ 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

Here is the caller graph for this function:

◆ 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.

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the caller graph for this function:

◆ 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.)

Here is the call graph for this function:

◆ connection_dir_reached_eof()

int connection_dir_reached_eof ( dir_connection_t conn)

Called when a directory connection reaches 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.

Here is the call graph for this function:

◆ 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.

◆ 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.

◆ directories_have_accepted_server_descriptor()

int directories_have_accepted_server_descriptor ( void  )

Return true iff any trusted directory authority has accepted our server descriptor.

We consider any authority sufficient because waiting for all of them means it never happens while any authority is down; we don't go for something more complex in the middle (like >1/3 or >1/2 or >=1/2) because that doesn't seem necessary yet.

Here is the call graph for this function:

◆ directory_get_from_all_authorities()

void directory_get_from_all_authorities ( uint8_t  dir_purpose,
uint8_t  router_purpose,
const char *  resource 
)

As directory_get_from_dirserver, but initiates a request to every directory authority other than ourself. Only for use by authorities when searching for missing information while voting.

Here is the call graph for this function:

◆ directory_post_to_dirservers()

void directory_post_to_dirservers ( uint8_t  dir_purpose,
uint8_t  router_purpose,
dirinfo_type_t  type,
const char *  payload,
size_t  payload_len,
size_t  extrainfo_len 
)

Start a connection to every suitable directory authority, using connection purpose dir_purpose and uploading payload (of length payload_len). The dir_purpose should be one of 'DIR_PURPOSE_UPLOAD_{DIR|VOTE|SIGNATURES}'.

router_purpose describes the type of descriptor we're publishing, if we're publishing a descriptor – e.g. general or bridge.

type specifies what sort of dir authorities (V3, BRIDGE, etc) we should upload to.

If extrainfo_len is nonzero, the first payload_len bytes of payload hold a router descriptor, and the next extrainfo_len bytes of payload hold an extra-info document. Upload the descriptor to all authorities, and the extra-info document to all authorities that support it.

◆ directory_request_add_header()

void directory_request_add_header ( directory_request_t req,
const char *  key,
const char *  val 
)

Include a header of name key with content val in the request. Neither may include newlines or other odd characters. Their ordering is not currently guaranteed.

Note that, as elsewhere in this module, header keys include a trailing colon and space.

◆ directory_request_fetch_set_hs_ident()

void directory_request_fetch_set_hs_ident ( directory_request_t req,
const hs_ident_dir_conn_t ident 
)

Set an object containing HS connection identifier to be associated with this fetch request. Note that only an alias to ident is stored, so the ident object must outlive the request.

◆ directory_request_free_()

void directory_request_free_ ( directory_request_t req)

Release all resources held by req.

◆ directory_request_new()

directory_request_t* directory_request_new ( uint8_t  dir_purpose)

Create and return a new directory_request_t with purpose dir_purpose.

Here is the caller graph for this function:

◆ directory_request_set_dir_addr_port()

void directory_request_set_dir_addr_port ( directory_request_t req,
const tor_addr_port_t p 
)

Set the address and dirport to use for this directory request. If there is no dirport, we'll have to connect over the OR port. (If there are both, the indirection setting determines which to use.)

◆ directory_request_set_directory_id_digest()

void directory_request_set_directory_id_digest ( directory_request_t req,
const char *  digest 
)

Set the RSA identity digest of the directory to use for this directory request.

◆ directory_request_set_guard_state()

void directory_request_set_guard_state ( directory_request_t req,
circuit_guard_state_t *  state 
)

Set a static circuit_guard_state_t object to affliate with the request in req. This object will receive notification when the attempt to connect to the guard either succeeds or fails.

◆ directory_request_set_if_modified_since()

void directory_request_set_if_modified_since ( directory_request_t req,
time_t  if_modified_since 
)

Set an if-modified-since date to send along with the request. The default is 0 (meaning, send no if-modified-since header).

◆ directory_request_set_indirection()

void directory_request_set_indirection ( directory_request_t req,
dir_indirection_t  indirection 
)

Set the indirection to be used for the directory request. The indirection parameter configures whether to connect to a DirPort or ORPort, and whether to anonymize the connection. DIRIND_ONEHOP (use ORPort, don't anonymize) is the default. See dir_indirection_t for more information.

◆ directory_request_set_or_addr_port()

void directory_request_set_or_addr_port ( directory_request_t req,
const tor_addr_port_t p 
)

Set the address and OR port to use for this directory request. If there is no OR port, we'll have to connect over the dirport. (If there are both, the indirection setting determines which to use.)

◆ directory_request_set_payload()

void directory_request_set_payload ( directory_request_t req,
const char *  payload,
size_t  payload_len 
)

Set a pointer to the payload to include with this directory request, along with its length. Note that only an alias to payload is stored, so the payload must outlive the request.

◆ directory_request_set_rend_query()

void directory_request_set_rend_query ( directory_request_t req,
const rend_data_t query 
)

Set an object containing HS data to be associated with this request. Note that only an alias to query is stored, so the query object must outlive the request.

◆ directory_request_set_resource()

void directory_request_set_resource ( directory_request_t req,
const char *  resource 
)

Set a pointer to the resource to request from a directory. Different request types use resources to indicate different components of their URL. Note that only an alias to resource is stored, so the resource must outlive the request.

Here is the caller graph for this function:

◆ directory_request_set_router_purpose()

void directory_request_set_router_purpose ( directory_request_t req,
uint8_t  router_purpose 
)

Set the router purpose associated with uploaded and downloaded router descriptors and extrainfo documents in this directory request. The purpose must be one of ROUTER_PURPOSE_GENERAL (the default) or ROUTER_PURPOSE_BRIDGE.

Here is the caller graph for this function:

◆ directory_request_set_routerstatus()

void directory_request_set_routerstatus ( directory_request_t req,
const routerstatus_t status 
)

Set the routerstatus to use for the directory associated with this request. If this option is set, then no other function to set the directory's address or identity should be called.

Here is the caller graph for this function:

◆ directory_request_upload_set_hs_ident()

void directory_request_upload_set_hs_ident ( directory_request_t req,
const hs_ident_dir_conn_t ident 
)

Set an object containing HS connection identifier to be associated with this request. Note that only an alias to ident is stored, so the ident object must outlive the request.

◆ download_status_get_n_attempts()

int download_status_get_n_attempts ( const download_status_t dls)

Return the number of attempts to download dls since the last success (if any). This can differ from download_status_get_n_failures() due to outstanding concurrent attempts.

◆ download_status_get_n_failures()

int download_status_get_n_failures ( const download_status_t dls)

Return the number of failures on dls since the last success (if any).

Here is the caller graph for this function:

◆ download_status_get_next_attempt_at()

time_t download_status_get_next_attempt_at ( const download_status_t dls)

Return the next time to attempt to download dls.

◆ download_status_increment_attempt()

time_t download_status_increment_attempt ( download_status_t dls,
const char *  item,
time_t  now 
)

Determine when the next download attempt should be made when using an attempt-based (potentially concurrent) download schedule. Called when an attempt to download dls is being initiated. Increment the attempt count and set dls->next_attempt_at to an appropriate time in the future and return it. If dls->increment_on is DL_SCHED_INCREMENT_FAILURE, don't increment the attempts, and return a time in the far future (to avoid launching a concurrent attempt).

Here is the call graph for this function:

◆ download_status_increment_failure()

time_t download_status_increment_failure ( download_status_t dls,
int  status_code,
const char *  item,
int  server,
time_t  now 
)

Determine when a failed download attempt should be retried. Called when an attempt to download dls has failed with HTTP status status_code. Increment the failure count (if the code indicates a real failure, or if we're a server) and set dls->next_attempt_at to an appropriate time in the future and return it. If dls->increment_on is DL_SCHED_INCREMENT_ATTEMPT, increment the failure count, and return a time in the far future for the next attempt (to avoid an immediate retry).

Here is the call graph for this function:

◆ download_status_reset()

void download_status_reset ( download_status_t dls)

Reset dls so that it will be considered downloadable immediately, and/or to show that we don't need it anymore.

Must be called to initialise a download schedule, otherwise the zeroth item in the schedule will never be used.

(We find the zeroth element of the download schedule, and set next_attempt_at to be the appropriate offset from 'now'. In most cases this means setting it to 'now', so the item will be immediately downloadable; when using authorities with fallbacks, there is a few seconds' delay.)

Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

◆ 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

◆ router_supports_extrainfo()

int router_supports_extrainfo ( const char *  identity_digest,
int  is_authority 
)

Return true iff identity_digest is the digest of a router which says that it caches extrainfos. (If is_authority we always believe that to be true.)