tor
master
|
Header file for directory.c. More...
#include "hs_ident.h"
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 } |
Header file for directory.c.
#define download_status_failed | ( | dls, | |
sc | |||
) |
Increment the failure count of the download_status_t dls, with the optional status code sc.
typedef struct directory_request_t 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.
enum dir_indirection_t |
Enumeration of ways to connect to a directory server
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
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.
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.
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.
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.)
int connection_dir_reached_eof | ( | dir_connection_t * | conn | ) |
Called when a directory connection reaches EOF.
int dir_split_resource_into_fingerprint_pairs | ( | const char * | res, |
smartlist_t * | pairs_out | ||
) |
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.
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.
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.
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.
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.
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.
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.
void directory_request_free_ | ( | directory_request_t * | req | ) |
Release all resources held by req.
directory_request_t* directory_request_new | ( | uint8_t | dir_purpose | ) |
Create and return a new directory_request_t with purpose dir_purpose.
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.)
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.
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.
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).
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.
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.)
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.
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.
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.
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.
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.
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.
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.
int download_status_get_n_failures | ( | const download_status_t * | dls | ) |
Return the number of failures on dls since the last success (if any).
time_t download_status_get_next_attempt_at | ( | const download_status_t * | dls | ) |
Return the next time to attempt to download dls.
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).
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).
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.)
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.
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.
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.
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
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.)