directory.c File Reference

Code to send and fetch directories and router descriptors via HTTP. Directories use dirserv.c to generate the results; clients use routers.c to parse them. More...

#include "or.h"

Defines

#define ALLOW_DIRECTORY_TIME_SKEW   (30*60)
#define X_ADDRESS_HEADER   "X-Your-Address-Is: "
#define FULL_DIR_CACHE_LIFETIME   (60*60)
#define RUNNINGROUTERS_CACHE_LIFETIME   (20*60)
#define DIRPORTFRONTPAGE_CACHE_LIFETIME   (20*60)
#define NETWORKSTATUS_CACHE_LIFETIME   (5*60)
#define ROUTERDESC_CACHE_LIFETIME   (30*60)
#define ROUTERDESC_BY_DIGEST_CACHE_LIFETIME   (48*60*60)
#define ROBOTS_CACHE_LIFETIME   (24*60*60)
#define MICRODESC_CACHE_LIFETIME   (48*60*60)
#define CONDITIONAL_CONSENSUS_FPR_LEN   3
#define MAX_DIRECTORY_OBJECT_SIZE   (10*(1<<20))
#define CONSENSUS_URL_PREFIX   "/tor/status-vote/current/consensus/"
#define CONSENSUS_FLAVORED_PREFIX   "/tor/status-vote/current/consensus-"

Functions

static void directory_send_command (dir_connection_t *conn, int purpose, int direct, const char *resource, const char *payload, size_t payload_len, int supports_conditional_consensus, time_t if_modified_since)
static int directory_handle_command (dir_connection_t *conn)
static int body_is_plausible (const char *body, size_t body_len, int purpose)
static int purpose_needs_anonymity (uint8_t dir_purpose, uint8_t router_purpose)
static char * http_get_header (const char *headers, const char *which)
static void http_set_address_origin (const char *headers, connection_t *conn)
static void connection_dir_download_networkstatus_failed (dir_connection_t *conn, int status_code)
static void connection_dir_download_routerdesc_failed (dir_connection_t *conn)
static void connection_dir_download_cert_failed (dir_connection_t *conn, int status_code)
static void dir_networkstatus_download_failed (smartlist_t *failed, int status_code)
static void dir_routerdesc_download_failed (smartlist_t *failed, int status_code, int router_purpose, int was_extrainfo, int was_descriptor_digests)
static void note_client_request (int purpose, int compressed, size_t bytes)
static int client_likes_consensus (networkstatus_t *v, const char *want_url)
static void directory_initiate_command_rend (const char *address, const tor_addr_t *addr, uint16_t or_port, uint16_t dir_port, int supports_conditional_consensus, int supports_begindir, const char *digest, uint8_t dir_purpose, uint8_t router_purpose, int anonymized_connection, const char *resource, const char *payload, size_t payload_len, time_t if_modified_since, const rend_data_t *rend_query)
char * authority_type_to_string (authority_type_t auth)
static const char * dir_conn_purpose_to_string (int purpose)
int router_supports_extrainfo (const char *identity_digest, int is_authority)
int directories_have_accepted_server_descriptor (void)
void directory_post_to_dirservers (uint8_t dir_purpose, uint8_t router_purpose, authority_type_t type, const char *payload, size_t payload_len, size_t extrainfo_len)
void directory_get_from_dirserver (uint8_t dir_purpose, uint8_t router_purpose, const char *resource, int pds_flags)
void directory_get_from_all_authorities (uint8_t dir_purpose, uint8_t router_purpose, const char *resource)
void directory_initiate_command_routerstatus_rend (routerstatus_t *status, uint8_t dir_purpose, uint8_t router_purpose, int anonymized_connection, const char *resource, const char *payload, size_t payload_len, time_t if_modified_since, const rend_data_t *rend_query)
void directory_initiate_command_routerstatus (routerstatus_t *status, uint8_t dir_purpose, uint8_t router_purpose, int anonymized_connection, const char *resource, const char *payload, size_t payload_len, time_t if_modified_since)
static int directory_conn_is_self_reachability_test (dir_connection_t *conn)
void connection_dir_request_failed (dir_connection_t *conn)
static int directory_command_should_use_begindir (or_options_t *options, const tor_addr_t *addr, int or_port, uint8_t router_purpose, int anonymized_connection)
void directory_initiate_command (const char *address, const tor_addr_t *_addr, uint16_t or_port, uint16_t dir_port, int supports_conditional_consensus, int supports_begindir, const char *digest, uint8_t dir_purpose, uint8_t router_purpose, int anonymized_connection, const char *resource, const char *payload, size_t payload_len, time_t if_modified_since)
int connection_dir_is_encrypted (dir_connection_t *conn)
static int _compare_strs (const void **a, const void **b)
static char * directory_get_consensus_url (int supports_conditional_consensus)
static int parse_http_url (const char *headers, char **url)
int parse_http_response (const char *headers, int *code, time_t *date, compress_method_t *compression, char **reason)
static int load_downloaded_routers (const char *body, smartlist_t *which, int descriptor_digests, int router_purpose, const char *source)
static int connection_dir_client_reached_eof (dir_connection_t *conn)
int connection_dir_reached_eof (dir_connection_t *conn)
int connection_dir_process_inbuf (dir_connection_t *conn)
static void write_http_status_line (dir_connection_t *conn, int status, const char *reason_phrase)
static void write_http_response_header_impl (dir_connection_t *conn, ssize_t length, const char *type, const char *encoding, const char *extra_headers, long cache_lifetime)
static void write_http_response_header (dir_connection_t *conn, ssize_t length, int compressed, long cache_lifetime)
void note_request (const char *key, size_t bytes)
char * directory_dump_request_log (void)
static int directory_handle_command_get (dir_connection_t *conn, const char *headers, const char *body, size_t body_len)
static int directory_handle_command_post (dir_connection_t *conn, const char *headers, const char *body, size_t body_len)
int connection_dir_finished_flushing (dir_connection_t *conn)
int connection_dir_finished_connecting (dir_connection_t *conn)
static void find_dl_schedule_and_len (download_status_t *dls, int server, const int **schedule, size_t *schedule_len)
time_t download_status_increment_failure (download_status_t *dls, int status_code, const char *item, int server, time_t now)
void download_status_reset (download_status_t *dls)
static int _compare_pairs (const void **a, const void **b)
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)

Variables

static const int server_dl_schedule []
static const int client_dl_schedule []
static const int server_consensus_dl_schedule []
static const int client_consensus_dl_schedule []
static const int bridge_dl_schedule []


Detailed Description

Code to send and fetch directories and router descriptors via HTTP. Directories use dirserv.c to generate the results; clients use routers.c to parse them.


Define Documentation

#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?

Referenced by connection_dir_client_reached_eof().

#define FULL_DIR_CACHE_LIFETIME   (60*60)

HTTP cache control: how long do we tell proxies they can cache each kind of document we serve?

Referenced by directory_handle_command_get().

#define MAX_DIRECTORY_OBJECT_SIZE   (10*(1<<20))

If any directory object is arriving, and it's over 10MB large, we're getting DoS'd. (As of 0.1.2.x, raw directories are about 1MB, and we never ask for more than 96 router descriptors at a time.)

Referenced by connection_dir_process_inbuf().


Function Documentation

static int _compare_pairs ( const void **  a,
const void **  b 
) [static]

Helper. Compare two fp_pair_t objects, and return -1, 0, or 1 as appropriate.

References DIGEST_LEN, fp_pair_t::first, and fp_pair_t::second.

Referenced by dir_split_resource_into_fingerprint_pairs().

static int _compare_strs ( const void **  a,
const void **  b 
) [static]

Helper for sorting

sort strings alphabetically

Referenced by directory_get_consensus_url().

char* authority_type_to_string ( authority_type_t  auth  ) 

static int body_is_plausible ( const char *  body,
size_t  len,
int  purpose 
) [static]

Return true iff body doesn't start with a plausible router or running-list or directory opening. This is a sign of possible compression.

References DIR_PURPOSE_FETCH_RENDDESC, and strcmpstart().

Referenced by connection_dir_client_reached_eof().

int client_likes_consensus ( networkstatus_t v,
const char *  want_url 
) [static]

Decide whether a client would accept the consensus we have.

Clients can say they only want a consensus if it's signed by more than half the authorities in a list. They pass this list in the url as "...consensus/<b>fpr</b>+<b>fpr</b>+<b>fpr</b>".

fpr may be an abbreviated fingerprint, i.e. only a left substring of the full authority identity digest. (Only strings of even length, i.e. encodings of full bytes, are handled correctly. In the case of an odd number of hex digits the last one is silently ignored.)

Returns 1 if more than half of the requested authorities signed the consensus, 0 otherwise.

References base16_decode(), DIGEST_LEN, dir_split_resource_into_fingerprints(), LD_DIR, smartlist_create(), smartlist_free(), tor_free, and networkstatus_t::voters.

Referenced by directory_handle_command_get().

static int connection_dir_client_reached_eof ( dir_connection_t conn  )  [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 0. Otherwise return -1; and the caller should consider trying the request again.

The caller will take care of marking the connection for close.

References dir_connection_t::_base, connection_t::address, ALLOW_DIRECTORY_TIME_SKEW, base16_encode(), body_is_plausible(), connection_dir_download_cert_failed(), connection_dir_download_networkstatus_failed(), connection_dir_download_routerdesc_failed(), control_event_general_status(), control_event_server_status(), detect_compression_method(), DIGEST_LEN, dir_networkstatus_download_failed(), DIR_PURPOSE_FETCH_CERTIFICATE, DIR_PURPOSE_FETCH_CONSENSUS, DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, DIR_PURPOSE_FETCH_EXTRAINFO, DIR_PURPOSE_FETCH_RENDDESC, DIR_PURPOSE_FETCH_RENDDESC_V2, DIR_PURPOSE_FETCH_SERVERDESC, DIR_PURPOSE_FETCH_STATUS_VOTE, DIR_PURPOSE_FETCH_V2_NETWORKSTATUS, DIR_PURPOSE_HAS_FETCHED_RENDDESC, DIR_PURPOSE_UPLOAD_DIR, DIR_PURPOSE_UPLOAD_RENDDESC, DIR_PURPOSE_UPLOAD_RENDDESC_V2, DIR_PURPOSE_UPLOAD_SIGNATURES, DIR_PURPOSE_UPLOAD_VOTE, dir_routerdesc_download_failed(), dir_split_resource_into_fingerprints(), dir_connection_t::dirconn_direct, directories_have_accepted_server_descriptor(), directory_conn_is_self_reachability_test(), directory_info_has_arrived(), dirvote_add_signatures(), dirvote_add_vote(), escaped(), trusted_dir_server_t::fake_status, fetch_from_buf_http(), format_time_interval(), get_options(), trusted_dir_server_t::has_accepted_serverdesc, HEX_DIGEST_LEN, http_get_header(), dir_connection_t::identity_digest, connection_t::inbuf, routerstatus_t::last_dir_503_at, LD_BUG, LD_DIR, LD_GENERAL, LD_HTTP, LD_PROTOCOL, LD_REND, load_downloaded_routers(), MAX_DIR_DL_SIZE, MAX_HEADERS_SIZE, networkstatus_consensus_download_failed(), networkstatus_set_current_consensus(), trusted_dir_server_t::nickname, rend_data_t::onion_address, parse_http_response(), connection_t::port, connection_t::purpose, rend_cache_store(), rend_cache_store_v2_desc_as_client(), rend_client_desc_trynow(), dir_connection_t::rend_data, dir_connection_t::requested_resource, router_dirport_found_reachable(), router_get_consensus_status_by_id(), router_get_trusted_dir_servers(), router_get_trusteddirserver_by_digest(), router_load_extrainfo_from_string(), router_new_address_suggestion(), dir_connection_t::router_purpose, router_set_networkstatus_v2(), routers_update_all_from_networkstatus(), SAVED_NOWHERE, smartlist_add(), smartlist_create(), smartlist_free(), strcmpstart(), connection_t::timestamp_lastwritten, tor_assert, tor_free, tor_gzip_uncompress(), and trusted_dirs_load_certs_from_string().

Referenced by connection_dir_reached_eof().

static void connection_dir_download_cert_failed ( dir_connection_t conn,
int  status 
) [static]

static void connection_dir_download_networkstatus_failed ( dir_connection_t conn,
int  status_code 
) [static]

static void connection_dir_download_routerdesc_failed ( dir_connection_t conn  )  [static]

Called when an attempt to download one or more router descriptors or extra-info documents on connection conn failed.

References dir_connection_t::_base, DIR_PURPOSE_FETCH_EXTRAINFO, DIR_PURPOSE_FETCH_SERVERDESC, connection_t::purpose, and tor_assert.

Referenced by connection_dir_client_reached_eof(), and connection_dir_request_failed().

int connection_dir_finished_connecting ( dir_connection_t conn  ) 

int connection_dir_finished_flushing ( dir_connection_t conn  ) 

int connection_dir_is_encrypted ( dir_connection_t conn  ) 

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

References TO_CONN.

Referenced by connection_dirserv_add_servers_to_outbuf(), and directory_handle_command_get().

int connection_dir_process_inbuf ( dir_connection_t conn  ) 

int connection_dir_reached_eof ( dir_connection_t conn  ) 

void connection_dir_request_failed ( dir_connection_t conn  ) 

static const char* dir_conn_purpose_to_string ( int  purpose  )  [static]

static void dir_networkstatus_download_failed ( smartlist_t failed,
int  status_code 
) [static]

Called when one or more networkstatus fetches have failed (with uppercase fingerprints listed in failed). Mark those fingerprints as having failed once, unless they failed with status code 503.

References base16_decode(), DIGEST_LEN, download_status_failed, escaped(), LD_BUG, router_get_trusteddirserver_by_digest(), and trusted_dir_server_t::v2_ns_dl_status.

Referenced by connection_dir_client_reached_eof(), and connection_dir_download_networkstatus_failed().

static void dir_routerdesc_download_failed ( smartlist_t failed,
int  status_code,
int  router_purpose,
int  was_extrainfo,
int  was_descriptor_digests 
) [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).

References base16_decode(), DIGEST_LEN, directory_fetches_from_authorities(), download_status_increment_failure(), signed_descriptor_t::ei_dl_status, escaped(), get_options(), LD_BUG, MAX_ROUTERDESC_DOWNLOAD_FAILURES, download_status_t::n_download_failures, retry_bridge_descriptor_fetch_directly(), router_get_by_extrainfo_digest(), router_get_dl_status_by_descriptor_digest(), ROUTER_PURPOSE_BRIDGE, and tor_assert.

Referenced by connection_dir_client_reached_eof().

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.

References _compare_pairs(), _tor_free(), base16_decode(), DIGEST_LEN, escaped(), fp_pair_t::first, HEX_DIGEST_LEN, LD_DIR, fp_pair_t::second, smartlist_add(), smartlist_add_all(), smartlist_create(), smartlist_free(), smartlist_sort(), smartlist_split_string(), smartlist_uniq(), and tor_free.

Referenced by directory_handle_command_get().

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.

References base16_decode(), base64_decode(), BASE64_DIGEST256_LEN, BASE64_DIGEST_LEN, DIGEST256_LEN, DIGEST_LEN, escaped(), HEX_DIGEST256_LEN, HEX_DIGEST_LEN, LD_DIR, smartlist_add_all(), smartlist_create(), smartlist_del_keeporder(), smartlist_free(), smartlist_sort_digests(), smartlist_sort_digests256(), smartlist_sort_strings(), smartlist_split_string(), smartlist_uniq_digests(), smartlist_uniq_digests256(), smartlist_uniq_strings(), tor_assert, and tor_free.

Referenced by client_likes_consensus(), connection_dir_client_reached_eof(), connection_dir_download_cert_failed(), connection_dir_download_networkstatus_failed(), directory_handle_command_get(), dirserv_get_networkstatus_v2_fingerprints(), dirserv_get_routerdesc_fingerprints(), dirserv_get_routerdescs(), and list_pending_downloads().

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.

References or_options_t::_PublishServerDescriptor, get_options(), and router_get_trusted_dir_servers().

Referenced by connection_dir_client_reached_eof(), and getinfo_helper_events().

static int directory_command_should_use_begindir ( or_options_t options,
const tor_addr_t addr,
int  or_port,
uint8_t  router_purpose,
int  anonymized_connection 
) [static]

Evaluate the situation and decide if we should use an encrypted "begindir-style" connection for this directory request. 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.

References or_options_t::Address, directory_fetches_from_authorities(), fascist_firewall_allows_address_or(), ROUTER_PURPOSE_BRIDGE, server_mode(), and or_options_t::TunnelDirConns.

Referenced by directory_initiate_command_rend().

static int directory_conn_is_self_reachability_test ( dir_connection_t conn  )  [static]

static char* directory_get_consensus_url ( int  supports_conditional_consensus  )  [static]

Return the URL we should use for a consensus download.

This url depends on whether or not the server we go to is sufficiently new to support conditional consensus downloading, i.e. GET .../consensus/fpr+fpr+fpr

References _compare_strs(), base16_encode(), router_get_trusted_dir_servers(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), smartlist_sort(), tor_free, tor_snprintf(), and V3_AUTHORITY.

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.

References DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, DIR_PURPOSE_FETCH_STATUS_VOTE, directory_initiate_command_routerstatus(), router_digest_is_me(), router_get_trusted_dir_servers(), tor_assert, and V3_AUTHORITY.

Referenced by dirvote_fetch_missing_signatures().

void directory_get_from_dirserver ( uint8_t  dir_purpose,
uint8_t  router_purpose,
const char *  resource,
int  pds_flags 
)

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

References routerinfo_t::addr, routerinfo_t::address, BRIDGE_AUTHORITY, routerinfo_t::cache_info, choose_random_entry(), dir_conn_purpose_to_string(), DIR_PURPOSE_FETCH_CERTIFICATE, DIR_PURPOSE_FETCH_CONSENSUS, DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, DIR_PURPOSE_FETCH_EXTRAINFO, DIR_PURPOSE_FETCH_RENDDESC, DIR_PURPOSE_FETCH_SERVERDESC, DIR_PURPOSE_FETCH_STATUS_VOTE, DIR_PURPOSE_FETCH_V2_NETWORKSTATUS, directory_all_unreachable(), directory_fetches_from_authorities(), directory_initiate_command(), directory_initiate_command_routerstatus(), EXTRAINFO_CACHE, or_options_t::FetchServerDescriptors, get_options(), HIDSERV_AUTHORITY, signed_descriptor_t::identity_digest, LD_BUG, LD_DIR, networkstatus_get_latest_consensus(), routerinfo_t::or_port, PDS_ALLOW_SELF, PDS_IGNORE_FASCISTFIREWALL, PDS_NO_EXISTING_SERVERDESC_FETCH, purpose_needs_anonymity(), router_pick_directory_server(), router_pick_trusteddirserver(), ROUTER_PURPOSE_BRIDGE, tor_addr_from_ipv4h, or_options_t::UseBridges, V2_AUTHORITY, V3_AUTHORITY, and networkstatus_t::valid_after.

Referenced by connection_dir_download_networkstatus_failed(), fetch_bridge_descriptors(), initiate_descriptor_downloads(), update_consensus_networkstatus_downloads(), update_router_descriptor_downloads(), and update_v2_networkstatus_cache_downloads().

static int directory_handle_command ( dir_connection_t conn  )  [static]

Called when a dirserver receives data on a directory connection; looks for an HTTP request. If the request is complete, remove it from the inbuf, try to process it; otherwise, leave it on the buffer. Return a 0 on success, or -1 on error.

References dir_connection_t::_base, connection_t::address, CONN_TYPE_DIR, directory_handle_command_get(), directory_handle_command_post(), escaped(), fetch_from_buf_http(), http_set_address_origin(), connection_t::inbuf, LD_DIRSERV, LD_PROTOCOL, MAX_DIR_UL_SIZE, MAX_HEADERS_SIZE, safe_str(), TO_CONN, tor_assert, tor_free, and connection_t::type.

Referenced by connection_dir_process_inbuf().

static int directory_handle_command_get ( dir_connection_t conn,
const char *  headers,
const char *  body,
size_t  body_len 
) [static]

Helper function: called when a dirserver gets a complete HTTP GET request. Look for a request for a directory or for a rendezvous service descriptor. On finding one, write a response into conn->outbuf. If the request is unrecognized, send a 400. Always return 0.

References dir_connection_t::_base, connection_t::addr, alloc_http_authenticator(), authdir_mode_tests_reachability(), authority_cert_get_all(), authority_cert_get_by_digests(), authority_cert_get_by_sk_digest(), authority_cert_get_newest_by_id(), or_options_t::BridgeAuthoritativeDir, or_options_t::BridgePassword, or_options_t::BridgeRelay, dir_connection_t::cached_dir, dir_connection_t::cached_dir_offset, client_likes_consensus(), connection_dir_is_encrypted(), connection_dirserv_flushed_some(), DIGEST_LEN, cached_dir_t::dir, DIR_CONN_STATE_SERVER_WRITING, cached_dir_t::dir_len, dir_split_resource_into_fingerprint_pairs(), dir_split_resource_into_fingerprints(), dir_connection_t::dir_spool_src, cached_dir_t::dir_z, cached_dir_t::dir_z_len, dirserv_estimate_data_size(), dirserv_estimate_microdesc_size(), dirserv_get_directory(), dirserv_get_networkstatus_v2_fingerprints(), dirserv_get_routerdesc_fingerprints(), dirserv_get_runningrouters(), dirserv_have_any_microdesc(), dirserv_have_any_serverdesc(), dirserv_remove_old_statuses(), dirvote_get_pending_consensus(), dirvote_get_pending_detached_signatures(), dirvote_get_vote(), dir_connection_t::fingerprint_stack, networkstatus_t::fresh_until, FULL_DIR_CACHE_LIFETIME, GEOIP_CLIENT_NETWORKSTATUS, GEOIP_CLIENT_NETWORKSTATUS_V2, geoip_note_client_seen(), geoip_note_ns_response(), GEOIP_REJECT_BUSY, GEOIP_REJECT_NOT_ENOUGH_SIGS, GEOIP_REJECT_NOT_FOUND, GEOIP_REJECT_NOT_MODIFIED, GEOIP_REJECT_UNAVAILABLE, geoip_start_dirreq(), GEOIP_SUCCESS, get_dirportfrontpage(), get_my_v3_authority_cert(), get_options(), global_write_bucket_low(), or_options_t::HidServDirectoryV2, or_options_t::HSAuthoritativeDir, http_get_header(), LD_DIRSERV, LD_REND, networkstatus_get_latest_consensus(), networkstatus_getinfo_by_purpose(), parse_http_time(), parse_http_url(), cached_dir_t::published, cached_dir_t::refcnt, rend_cache_lookup_desc(), rend_cache_lookup_v2_desc_as_dir(), REND_DESC_ID_V2_LEN_BASE32, rep_hist_get_router_stability_doc(), safe_str(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), connection_t::state, strcmpstart(), TO_CONN, tor_addr_eq_ipv4h(), tor_assert, tor_free, tor_inet_aton(), tor_timegm(), tor_zlib_new(), write_http_response_header(), write_http_response_header_impl(), write_http_status_line(), and dir_connection_t::zlib_state.

Referenced by directory_handle_command().

static int directory_handle_command_post ( dir_connection_t conn,
const char *  headers,
const char *  body,
size_t  body_len 
) [static]

void directory_initiate_command ( const char *  address,
const tor_addr_t _addr,
uint16_t  or_port,
uint16_t  dir_port,
int  supports_conditional_consensus,
int  supports_begindir,
const char *  digest,
uint8_t  dir_purpose,
uint8_t  router_purpose,
int  anonymized_connection,
const char *  resource,
const char *  payload,
size_t  payload_len,
time_t  if_modified_since 
)

Helper for directory_initiate_command_routerstatus: send the command to a server whose address is address, whose IP is addr, whose directory port is dir_port, whose tor version supports_begindir, and whose identity key digest is digest.

References directory_initiate_command_rend().

Referenced by consider_testing_reachability(), directory_get_from_dirserver(), and launch_direct_bridge_descriptor_fetch().

static void directory_initiate_command_rend ( const char *  address,
const tor_addr_t _addr,
uint16_t  or_port,
uint16_t  dir_port,
int  supports_conditional_consensus,
int  supports_begindir,
const char *  digest,
uint8_t  dir_purpose,
uint8_t  router_purpose,
int  anonymized_connection,
const char *  resource,
const char *  payload,
size_t  payload_len,
time_t  if_modified_since,
const rend_data_t rend_query 
) [static]

void directory_initiate_command_routerstatus ( routerstatus_t status,
uint8_t  dir_purpose,
uint8_t  router_purpose,
int  anonymized_connection,
const char *  resource,
const char *  payload,
size_t  payload_len,
time_t  if_modified_since 
)

Launch a new connection to the directory server status to upload or download a server or rendezvous descriptor. dir_purpose determines what kind of directory connection we're launching, and must be one of DIR_PURPOSE_{FETCH|UPLOAD}_{DIR|RENDDESC|RENDDESC_V2}. router_purpose specifies the descriptor purposes we have in mind (currently only used for FETCH_DIR).

When uploading, payload and payload_len determine the content of the HTTP post. Otherwise, payload should be NULL.

When fetching a rendezvous descriptor, resource is the service ID we want to fetch.

References directory_initiate_command_routerstatus_rend().

Referenced by directory_get_from_all_authorities(), directory_get_from_dirserver(), directory_post_to_dirservers(), directory_post_to_hs_dir(), initiate_descriptor_downloads(), and update_v2_networkstatus_cache_downloads().

void directory_initiate_command_routerstatus_rend ( routerstatus_t status,
uint8_t  dir_purpose,
uint8_t  router_purpose,
int  anonymized_connection,
const char *  resource,
const char *  payload,
size_t  payload_len,
time_t  if_modified_since,
const rend_data_t rend_query 
)

void directory_post_to_dirservers ( uint8_t  dir_purpose,
uint8_t  router_purpose,
authority_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 'purpose' and uploading the payload 'payload' (length 'payload_len'). dir_purpose should be one of 'DIR_PURPOSE_UPLOAD_DIR' or 'DIR_PURPOSE_UPLOAD_RENDDESC'.

type specifies what sort of dir authorities (V1, V2, HIDSERV, BRIDGE) 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.

References tor_addr_t::addr, authority_type_to_string(), DIR_PURPOSE_UPLOAD_DIR, directory_initiate_command_routerstatus(), fascist_firewall_allows_address_dir(), LD_DIR, purpose_needs_anonymity(), router_get_trusted_dir_servers(), router_supports_extrainfo(), tor_addr_from_ipv4h, tor_assert, and tor_free.

Referenced by dirvote_compute_consensuses(), dirvote_perform_vote(), and router_upload_dir_desc_to_dirservers().

static void directory_send_command ( dir_connection_t conn,
int  purpose,
int  direct,
const char *  resource,
const char *  payload,
size_t  payload_len,
int  supports_conditional_consensus,
time_t  if_modified_since 
) [static]

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

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) and set dls->next_attempt_at to an appropriate time in the future.

References find_dl_schedule_and_len(), IMPOSSIBLE_TO_DOWNLOAD, LD_DIR, download_status_t::n_download_failures, download_status_t::next_attempt_at, and tor_assert.

Referenced by dir_routerdesc_download_failed().

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.

(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; in the case of bridge descriptors, the zeroth element is an hour from now.)

References find_dl_schedule_and_len(), get_options(), download_status_t::n_download_failures, and download_status_t::next_attempt_at.

Referenced by authority_certs_fetch_missing(), learned_bridge_descriptor(), networkstatus_set_current_consensus(), router_reset_descriptor_download_failures(), and router_set_networkstatus_v2().

static void find_dl_schedule_and_len ( download_status_t dls,
int  server,
const int **  schedule,
size_t *  schedule_len 
) [static]

Decide which download schedule we want to use, and then return a pointer to it along with a pointer to its length. Helper function for download_status_increment_failure() and download_status_reset().

References download_status_t::schedule, and tor_assert.

Referenced by download_status_increment_failure(), and download_status_reset().

static char * http_get_header ( const char *  headers,
const char *  which 
) [static]

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.

References strcasecmpstart().

Referenced by connection_dir_client_reached_eof(), directory_handle_command_get(), and http_set_address_origin().

static void http_set_address_origin ( const char *  headers,
connection_t conn 
) [static]

If headers indicates that a proxy was involved, then rewrite conn->address to describe our best guess of the address that originated this HTTP request.

References connection_t::address, escaped(), http_get_header(), is_internal_IP(), LD_DIR, tor_free, and tor_inet_aton().

Referenced by directory_handle_command().

static int load_downloaded_routers ( const char *  body,
smartlist_t which,
int  descriptor_digests,
int  router_purpose,
const char *  source 
) [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.

References control_event_bootstrap(), count_loading_descriptors_progress(), escaped(), format_iso_time(), router_load_routers_from_string(), ROUTER_PURPOSE_GENERAL, router_purpose_to_string(), SAVED_NOWHERE, tor_assert, and tor_snprintf().

Referenced by connection_dir_client_reached_eof().

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.

References escaped(), LD_HTTP, parse_rfc1123_time(), smartlist_create(), smartlist_free(), smartlist_split_string(), strcmpstart(), tor_assert, tor_free, and tor_sscanf().

Referenced by connection_dir_client_reached_eof(), and connection_read_https_proxy_response().

static int parse_http_url ( const char *  headers,
char **  url 
) [static]

Parse an HTTP request string headers of the form

 * "\%s [http[s]://]\%s HTTP/1..."
 * 
If it's well-formed, strdup the second %s into *url, and nul-terminate it. If the url doesn't start with "/tor/", rewrite it so it does. Return 0. Otherwise, return -1.

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

Referenced by directory_handle_command_get(), and directory_handle_command_post().

static int purpose_needs_anonymity ( uint8_t  dir_purpose,
uint8_t  router_purpose 
) [static]

int router_supports_extrainfo ( const char *  identity_digest,
int  is_authority 
)

Return true iff identity_digest is the digest of a router we believe to support extrainfo downloads. (If is_authority we do additional checking that's only valid for authorities.)

References routerinfo_t::caches_extra_info, routerinfo_t::platform, router_get_by_digest(), router_get_consensus_status_by_id(), tor_version_as_new_as(), and routerstatus_t::version_supports_extrainfo_upload.

Referenced by directory_post_to_dirservers(), router_pick_directory_server_impl(), and router_pick_trusteddirserver_impl().

static void write_http_response_header ( dir_connection_t conn,
ssize_t  length,
int  compressed,
long  cache_lifetime 
) [static]

As write_http_response_header_impl, but sets encoding and content-typed based on whether the response will be compressed or not.

References write_http_response_header_impl().

Referenced by directory_handle_command_get().

static void write_http_response_header_impl ( dir_connection_t conn,
ssize_t  length,
const char *  type,
const char *  encoding,
const char *  extra_headers,
long  cache_lifetime 
) [static]

Write the header for an HTTP/1.0 response onto conn->outbuf, with type as the Content-Type.

If length is nonnegative, it is the Content-Length. If encoding is provided, it is the Content-Encoding. If cache_lifetime is greater than 0, the content may be cached for up to cache_lifetime seconds. Otherwise, the content may not be cached.

References dir_connection_t::_base, connection_t::addr, connection_t::address, format_rfc1123_time(), is_local_addr(), TO_CONN, tor_assert, and tor_snprintf().

Referenced by directory_handle_command_get(), directory_handle_command_post(), and write_http_response_header().

static void write_http_status_line ( dir_connection_t conn,
int  status,
const char *  reason_phrase 
) [static]

Create an http response for the client conn out of status and reason_phrase. Write it to conn.

References LD_BUG, TO_CONN, and tor_snprintf().

Referenced by directory_handle_command_get(), and directory_handle_command_post().


Variable Documentation

const int bridge_dl_schedule[] [static]

Initial value:

 {
  60*60, 15*60, 15*60, 60*60
}
Schedule for when clients should download bridge descriptors.

const int client_consensus_dl_schedule[] [static]

Initial value:

 {
  0, 0, 60, 60*5, 60*10, 60*30, 60*60, 60*60, 60*60, 60*60*3, 60*60*6, 60*60*12
}
Schedule for when clients should download consensuses.

const int client_dl_schedule[] [static]

Initial value:

 {
  0, 0, 60, 60*5, 60*10, INT_MAX
}
Schedule for when clients should download things in general.

const int server_consensus_dl_schedule[] [static]

Initial value:

 {
  0, 0, 60, 60*5, 60*10, 60*30, 60*30, 60*30, 60*30, 60*30, 60*60, 60*60*2
}
Schedule for when servers should download consensuses.

const int server_dl_schedule[] [static]

Initial value:

 {
  0, 0, 0, 60, 60, 60*2, 60*5, 60*15, INT_MAX
}
Schedule for when servers should download things in general.


Generated on Tue May 25 00:30:43 2010 for tor by  doxygen 1.5.6