|
Tor 0.4.9.8
|
Download directory information. More...
#include "core/or/or.h"#include "app/config/config.h"#include "core/mainloop/connection.h"#include "core/mainloop/mainloop.h"#include "core/or/connection_edge.h"#include "core/or/policies.h"#include "feature/client/bridges.h"#include "feature/client/entrynodes.h"#include "feature/control/control_events.h"#include "feature/dirauth/authmode.h"#include "feature/dirclient/dirclient.h"#include "feature/dirauth/dirvote.h"#include "feature/dirauth/shared_random.h"#include "feature/dircache/dirserv.h"#include "feature/dirclient/dirclient_modes.h"#include "feature/dirclient/dlstatus.h"#include "feature/dircommon/consdiff.h"#include "feature/dircommon/directory.h"#include "feature/dircommon/fp_pair.h"#include "feature/hs/hs_cache.h"#include "feature/hs/hs_client.h"#include "feature/hs/hs_control.h"#include "feature/nodelist/authcert.h"#include "feature/nodelist/describe.h"#include "feature/nodelist/dirlist.h"#include "feature/nodelist/microdesc.h"#include "feature/nodelist/networkstatus.h"#include "feature/nodelist/node_select.h"#include "feature/nodelist/nodelist.h"#include "feature/nodelist/routerinfo.h"#include "feature/nodelist/routerlist.h"#include "feature/nodelist/routerset.h"#include "feature/relay/relay_find_addr.h"#include "feature/relay/routermode.h"#include "feature/relay/selftest.h"#include "feature/rend/rendcommon.h"#include "feature/stats/predict_ports.h"#include "lib/cc/ctassert.h"#include "lib/compress/compress.h"#include "lib/crypt_ops/crypto_format.h"#include "lib/crypt_ops/crypto_util.h"#include "lib/encoding/confline.h"#include "lib/err/backtrace.h"#include "core/or/entry_connection_st.h"#include "feature/dircache/cached_dir_st.h"#include "feature/dirclient/dir_server_st.h"#include "feature/dircommon/dir_connection_st.h"#include "feature/nodelist/networkstatus_st.h"#include "feature/nodelist/node_st.h"#include "feature/nodelist/routerinfo_st.h"Go to the source code of this file.
Macros | |
| #define | DIRCLIENT_PRIVATE |
| #define | MAX_DIR_DL_SIZE ((1<<24)-1) /* 16 MB - 1 */ |
| #define | ALLOW_DIRECTORY_TIME_SKEW (30*60) |
| #define | CONDITIONAL_CONSENSUS_FPR_LEN 3 |
Variables | |
| static uint64_t | total_dl [DIR_PURPOSE_MAX_][2] |
| static compress_method_t | client_meth_pref [] |
| static compress_method_t | client_meth_allowed_anonymous_compression [] |
Download directory information.
Definition in file dirclient.c.
| #define ALLOW_DIRECTORY_TIME_SKEW (30*60) |
How far in the future do we allow a directory server to tell us it is before deciding that one of us has the wrong time?
Definition at line 73 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
| #define CONDITIONAL_CONSENSUS_FPR_LEN 3 |
Definition at line 1454 of file dirclient.c.
| #define DIRCLIENT_PRIVATE |
Definition at line 11 of file dirclient.c.
| #define MAX_DIR_DL_SIZE ((1<<24)-1) /* 16 MB - 1 */ |
Maximum size, in bytes, for any directory object that we've downloaded.
Definition at line 69 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
| STATIC char * accept_encoding_header | ( | void | ) |
Return a newly allocated string containing a comma separated list of supported encodings.
Definition at line 2893 of file dirclient.c.
Referenced by directory_send_command().
| STATIC int allowed_anonymous_connection_compression_method | ( | compress_method_t | method | ) |
Check if the given compression method is allowed for a connection that is supposed to be anonymous. Returns 1 if the compression method is allowed, otherwise 0.
Definition at line 2916 of file dirclient.c.
|
static |
Return true iff body doesn't start with a plausible router or network-status or microdescriptor opening. This is a sign of possible compression.
Definition at line 1763 of file dirclient.c.
|
static |
Helper for sorting
sort strings alphabetically
XXXX we have a smartlist_sort_strings() function, right?
Definition at line 1448 of file dirclient.c.
Referenced by directory_get_consensus_url().
|
static |
Called when an attempt to download a bridge's routerdesc from one of the authorities failed due to a network error. If possible attempt to download descriptors from the bridge directly.
Definition at line 811 of file dirclient.c.
Referenced by connection_dir_client_request_failed().
|
static |
We are a client, and we've finished reading the server's response. Parse it and act appropriately.
If we're still happy with using this directory server in the future, return
The caller will take care of marking the connection for close.
Definition at line 2011 of file dirclient.c.
Referenced by connection_dir_reached_eof().
| void connection_dir_client_refetch_hsdesc_if_needed | ( | dir_connection_t * | dir_conn | ) |
We are closing a dir connection: If dir_conn is a dir connection that tried to fetch an HS descriptor, check if it successfully fetched it, or if we need to try again.
Definition at line 2860 of file dirclient.c.
Referenced by connection_dir_about_to_close().
| void connection_dir_client_request_failed | ( | dir_connection_t * | conn | ) |
Called when we are unable to complete the client's request to a directory server due to a network error: Mark the router as down and try again if possible.
Definition at line 711 of file dirclient.c.
Referenced by connection_dir_about_to_close().
|
static |
Definition at line 2959 of file dirclient.c.
|
static |
Called when an attempt to fetch a certificate fails.
Definition at line 835 of file dirclient.c.
Referenced by connection_dir_client_request_failed(), and handle_response_fetch_certificate().
|
static |
Called when an attempt to download one or more router descriptors or extra-info documents on connection conn failed.
Definition at line 792 of file dirclient.c.
Referenced by connection_dir_client_request_failed(), and handle_response_fetch_desc().
| int connection_dir_reached_eof | ( | dir_connection_t * | conn | ) |
Called when a directory connection reaches EOF.
Definition at line 2839 of file dirclient.c.
Referenced by connection_reached_eof(), and run_connection_housekeeping().
|
static |
Helper: Attempt to fetch directly the descriptors of each bridge listed in failed.
Definition at line 774 of file dirclient.c.
Referenced by connection_dir_bridge_routerdesc_failed(), and dir_routerdesc_download_failed().
|
static |
Copies the ipv6 from source to destination, subject to buffer size limit size. If decorate is true, makes sure the copied address is decorated.
Definition at line 1512 of file dirclient.c.
Referenced by directory_send_command().
|
static |
Definition at line 1841 of file dirclient.c.
| STATIC const char * dir_conn_purpose_to_string | ( | int | purpose | ) |
Return a string describing a given directory connection purpose.
Definition at line 97 of file dirclient.c.
Referenced by connection_dir_client_reached_eof(), connection_dir_client_request_failed(), dirclient_dump_total_dls(), directory_get_from_dirserver(), directory_initiate_request(), directory_pick_generic_dirserver(), directory_post_to_dirservers(), and directory_request_set_dir_from_routerstatus().
|
static |
Set the extra fields in req that are used when requesting a consensus of type resource.
Right now, these fields are if-modified-since and x-or-diff-from-consensus.
Definition at line 369 of file dirclient.c.
Referenced by directory_get_from_dirserver().
| STATIC dirinfo_type_t dir_fetch_type | ( | int | dir_purpose, |
| int | router_purpose, | ||
| const char * | resource ) |
Return the requisite directory information types.
Definition at line 133 of file dirclient.c.
Referenced by directory_get_from_dirserver().
|
static |
Called when a connection to download microdescriptors from relay with dir_id has failed in whole or in part. failed is a list of every microdesc digest we didn't get. status_code is the http status code we received. Reschedule the microdesc downloads as appropriate.
Definition at line 3023 of file dirclient.c.
Referenced by handle_response_fetch_microdesc().
|
static |
Called when one or more routerdesc (or extrainfo, if was_extrainfo) fetches have failed (with uppercase fingerprints listed in failed, either as descriptor digests or as identity digests based on was_descriptor_digests).
Definition at line 2980 of file dirclient.c.
Referenced by handle_response_fetch_desc().
| void dirclient_dump_total_dls | ( | void | ) |
Heartbeat: dump a summary of how many bytes of which purpose we've downloaded, when bootstrapping and when not bootstrapping.
Definition at line 1973 of file dirclient.c.
Referenced by log_heartbeat().
| 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.
Definition at line 198 of file dirclient.c.
Referenced by getinfo_helper_events(), and handle_response_upload_dir().
|
static |
Definition at line 629 of file dirclient.c.
|
static |
Evaluate the situation and decide if we should use an encrypted "begindir-style" connection for this directory request. 0) If there is no DirPort, yes. 1) If or_port is 0, or it's a direct conn and or_port is firewalled or we're a dir mirror, no. 2) If we prefer to avoid begindir conns, and we're not fetching or publishing a bridge relay descriptor, no. 3) Else yes. If returning 0, return in *reason why we can't use begindir. reason must not be NULL.
Definition at line 891 of file dirclient.c.
Referenced by directory_initiate_request().
|
static |
Return the URL we should use for a consensus download.
Use the "conditional consensus downloading" feature described in dir-spec.txt, i.e. GET .../consensus/fpr+fpr+fpr
If 'resource' is provided, it is the name of a consensus flavor to request.
Definition at line 1466 of file dirclient.c.
Referenced by directory_send_command().
| 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.
Definition at line 585 of file dirclient.c.
Referenced by dirvote_fetch_missing_signatures(), and dirvote_fetch_missing_votes().
| 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 ) |
Start a connection to a random running directory server, using connection purpose dir_purpose, intending to fetch descriptors of purpose router_purpose, and requesting resource. Use pds_flags as arguments to router_pick_directory_server() or router_pick_trusteddirserver().
Definition at line 453 of file dirclient.c.
Referenced by fetch_bridge_descriptors(), initiate_descriptor_downloads(), update_consensus_bootstrap_attempt_downloads(), and update_consensus_networkstatus_downloads().
| void directory_initiate_request | ( | directory_request_t * | request | ) |
Launch the provided directory request, configured in request. After this function is called, you can free request.
Definition at line 1249 of file dirclient.c.
Referenced by directory_get_from_all_authorities(), directory_get_from_dirserver(), directory_launch_v3_desc_fetch(), directory_post_to_dirservers(), hs_service_upload_desc_to_dir(), initiate_descriptor_downloads(), and launch_direct_bridge_descriptor_fetch().
|
static |
Pick an unconstrained directory server from among our guards, the latest networkstatus, or the fallback dirservers, for use in downloading information of type type, and return its routerstatus.
Definition at line 335 of file dirclient.c.
Referenced by directory_get_from_dirserver().
| 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.
Definition at line 229 of file dirclient.c.
Referenced by dirvote_compute_consensuses(), dirvote_perform_vote(), and router_upload_dir_desc_to_dirservers().
| 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.
Definition at line 1081 of file dirclient.c.
Referenced by dir_consensus_request_set_additional_headers().
|
static |
Internal: Return true if any information for contacting the directory in req has been set, other than by the routerstatus.
Definition at line 1129 of file dirclient.c.
Referenced by directory_initiate_request().
| 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.
Definition at line 1107 of file dirclient.c.
Referenced by directory_launch_v3_desc_fetch().
| void directory_request_free_ | ( | directory_request_t * | req | ) |
Release all resources held by req.
Definition at line 967 of file dirclient.c.
| directory_request_t * directory_request_new | ( | uint8_t | dir_purpose | ) |
Create and return a new directory_request_t with purpose dir_purpose.
Definition at line 946 of file dirclient.c.
Referenced by directory_get_from_all_authorities(), directory_get_from_dirserver(), directory_launch_v3_desc_fetch(), directory_post_to_dirservers(), hs_service_upload_desc_to_dir(), initiate_descriptor_downloads(), and launch_direct_bridge_descriptor_fetch().
| 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.)
Definition at line 991 of file dirclient.c.
Referenced by directory_request_set_dir_from_routerstatus().
|
static |
Helper: update the addresses, ports, and identities in req from the routerstatus object in req. Return 0 on success. On failure, warn and return -1.
Definition at line 1156 of file dirclient.c.
Referenced by directory_initiate_request().
| 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.
Definition at line 1001 of file dirclient.c.
Referenced by directory_get_from_dirserver(), directory_request_set_dir_from_routerstatus(), and launch_direct_bridge_descriptor_fetch().
| 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.
Definition at line 1119 of file dirclient.c.
Referenced by directory_get_from_dirserver(), and launch_direct_bridge_descriptor_fetch().
| 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).
Definition at line 1067 of file dirclient.c.
Referenced by dir_consensus_request_set_additional_headers().
| 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.
Definition at line 1029 of file dirclient.c.
Referenced by directory_get_from_dirserver(), directory_launch_v3_desc_fetch(), directory_post_to_dirservers(), and hs_service_upload_desc_to_dir().
| 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.)
Definition at line 980 of file dirclient.c.
Referenced by directory_get_from_dirserver(), directory_request_set_dir_from_routerstatus(), and launch_direct_bridge_descriptor_fetch().
| 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.
Definition at line 1053 of file dirclient.c.
Referenced by directory_post_to_dirservers(), and hs_service_upload_desc_to_dir().
| 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.
Definition at line 1042 of file dirclient.c.
Referenced by directory_get_from_all_authorities(), directory_get_from_dirserver(), directory_launch_v3_desc_fetch(), hs_service_upload_desc_to_dir(), initiate_descriptor_downloads(), and launch_direct_bridge_descriptor_fetch().
| 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.
Definition at line 1013 of file dirclient.c.
Referenced by directory_get_from_all_authorities(), directory_get_from_dirserver(), directory_post_to_dirservers(), and launch_direct_bridge_descriptor_fetch().
| 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.
Definition at line 1144 of file dirclient.c.
Referenced by directory_get_from_all_authorities(), directory_get_from_dirserver(), directory_launch_v3_desc_fetch(), directory_post_to_dirservers(), hs_service_upload_desc_to_dir(), and initiate_descriptor_downloads().
| 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.
Definition at line 1093 of file dirclient.c.
Referenced by hs_service_upload_desc_to_dir().
|
static |
Queue an appropriate HTTP command for request on conn->outbuf. If direct is true, we're making a non-anonymized connection to the dirport.
Definition at line 1529 of file dirclient.c.
Referenced by directory_initiate_request().
|
static |
Return true iff ind requires a multihop circuit.
Definition at line 616 of file dirclient.c.
Referenced by directory_initiate_request(), directory_request_set_dir_from_routerstatus(), and directory_send_command().
|
static |
Handler function: processes a response to a request for one or more authority certificates
Definition at line 2336 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
| STATIC int handle_response_fetch_consensus | ( | dir_connection_t * | conn, |
| const response_handler_args_t * | args ) |
Handler function: processes a response to a request for a networkstatus consensus document by checking the consensus, storing it, and marking router requests as reachable.
Definition at line 2218 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to a request for a group of server descriptors or an extrainfo documents.
Definition at line 2469 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to a request for the signatures that an authority knows about on a given consensus.
Definition at line 2434 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
| STATIC int handle_response_fetch_hsdesc_v3 | ( | dir_connection_t * | conn, |
| const response_handler_args_t * | args ) |
Handler function: processes a response to a request for a v3 hidden service descriptor.
Definition at line 2771 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
| STATIC int handle_response_fetch_microdesc | ( | dir_connection_t * | conn, |
| const response_handler_args_t * | args ) |
Handler function: processes a response to a request for a group of microdescriptors
Definition at line 2570 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to a request for an authority's current networkstatus vote.
Definition at line 2397 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to a POST request to upload our router descriptor.
Definition at line 2630 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to a POST request to upload an hidden service descriptor.
Definition at line 2793 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to POST request to upload our view of the signatures on the current consensus.
Definition at line 2734 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Handler function: processes a response to POST request to upload our own networkstatus vote.
Definition at line 2698 of file dirclient.c.
Referenced by connection_dir_client_reached_eof().
|
static |
Called when we've just fetched a bunch of router descriptors in body. The list which, if present, holds digests for descriptors we requested: descriptor digests if descriptor_digests is true, or identity digests otherwise. Parse the descriptors, validate them, and annotate them as having purpose purpose and as having been downloaded from source.
Return the number of routers actually added.
Definition at line 1794 of file dirclient.c.
Referenced by handle_response_fetch_desc().
| 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.)
Definition at line 175 of file dirclient.c.
Referenced by directory_post_to_dirservers().
| STATIC int should_use_directory_guards | ( | const or_options_t * | options | ) |
Return true iff, according to the values in options, we should be using directory guards for direct downloads of directory information.
Definition at line 314 of file dirclient.c.
Referenced by directory_pick_generic_dirserver().
| STATIC void warn_disallowed_anonymous_compression_method | ( | compress_method_t | method | ) |
Log a warning when a remote server has sent us a document using a compression method that is not allowed for anonymous directory requests.
Definition at line 2938 of file dirclient.c.
|
static |
Array of allowed compression methods to use (if supported) when receiving a response from a request that was required to be anonymous.
Definition at line 2884 of file dirclient.c.
Referenced by allowed_anonymous_connection_compression_method().
|
static |
Array of compression methods to use (if supported) for requesting compressed data, ordered from best to worst.
Definition at line 2874 of file dirclient.c.
Referenced by accept_encoding_header().
|
static |
Total number of bytes downloaded of each directory purpose, when bootstrapped, and when not bootstrapped.
(For example, the number of bytes downloaded of purpose p while not fully bootstrapped is total_dl[p][false].)
Definition at line 1966 of file dirclient.c.
Referenced by connection_dir_client_reached_eof(), and dirclient_dump_total_dls().