2010-07-22 11:54:50 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2015-01-02 20:27:39 +01:00
|
|
|
* Copyright (c) 2007-2015, The Tor Project, Inc. */
|
2010-07-22 11:54:50 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file directory.h
|
|
|
|
* \brief Header file for directory.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_DIRECTORY_H
|
|
|
|
#define TOR_DIRECTORY_H
|
2010-07-22 11:54:50 +02:00
|
|
|
|
|
|
|
int directories_have_accepted_server_descriptor(void);
|
|
|
|
void directory_post_to_dirservers(uint8_t dir_purpose, uint8_t router_purpose,
|
2010-11-08 20:27:36 +01:00
|
|
|
dirinfo_type_t type, const char *payload,
|
2010-07-22 11:54:50 +02:00
|
|
|
size_t payload_len, size_t extrainfo_len);
|
2015-12-07 07:47:10 +01:00
|
|
|
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));
|
2010-07-22 11:54:50 +02:00
|
|
|
void directory_get_from_all_authorities(uint8_t dir_purpose,
|
|
|
|
uint8_t router_purpose,
|
|
|
|
const char *resource);
|
2012-09-12 16:15:58 +02:00
|
|
|
|
|
|
|
/** Enumeration of ways to connect to a directory server */
|
|
|
|
typedef enum {
|
|
|
|
/** Default: connect over a one-hop Tor circuit but fall back to direct
|
|
|
|
* connection */
|
|
|
|
DIRIND_ONEHOP=0,
|
|
|
|
/** Connect over a multi-hop anonymizing Tor circuit */
|
|
|
|
DIRIND_ANONYMOUS=1,
|
2014-02-10 22:05:35 +01:00
|
|
|
/** Connect to the DirPort directly */
|
2012-09-12 16:15:58 +02:00
|
|
|
DIRIND_DIRECT_CONN,
|
|
|
|
/** Connect over a multi-hop anonymizing Tor circuit to our dirport */
|
|
|
|
DIRIND_ANON_DIRPORT,
|
|
|
|
} dir_indirection_t;
|
|
|
|
|
2010-09-29 07:35:08 +02:00
|
|
|
void directory_initiate_command_routerstatus(const routerstatus_t *status,
|
2010-07-22 11:54:50 +02:00
|
|
|
uint8_t dir_purpose,
|
|
|
|
uint8_t router_purpose,
|
2012-09-12 16:15:58 +02:00
|
|
|
dir_indirection_t indirection,
|
2010-07-22 11:54:50 +02:00
|
|
|
const char *resource,
|
|
|
|
const char *payload,
|
|
|
|
size_t payload_len,
|
|
|
|
time_t if_modified_since);
|
2010-09-29 07:35:08 +02:00
|
|
|
void directory_initiate_command_routerstatus_rend(const routerstatus_t *status,
|
2010-07-22 11:54:50 +02:00
|
|
|
uint8_t dir_purpose,
|
|
|
|
uint8_t router_purpose,
|
2012-09-12 22:28:46 +02:00
|
|
|
dir_indirection_t indirection,
|
2010-07-22 11:54:50 +02:00
|
|
|
const char *resource,
|
|
|
|
const char *payload,
|
|
|
|
size_t payload_len,
|
|
|
|
time_t if_modified_since,
|
|
|
|
const rend_data_t *rend_query);
|
|
|
|
|
|
|
|
int parse_http_response(const char *headers, int *code, time_t *date,
|
|
|
|
compress_method_t *compression, char **response);
|
|
|
|
|
|
|
|
int connection_dir_is_encrypted(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);
|
2011-06-22 19:57:19 +02:00
|
|
|
void connection_dir_about_to_close(dir_connection_t *dir_conn);
|
2013-02-10 02:29:02 +01:00
|
|
|
void directory_initiate_command(const tor_addr_t *addr,
|
2010-07-22 11:54:50 +02:00
|
|
|
uint16_t or_port, uint16_t dir_port,
|
2012-09-08 05:21:18 +02:00
|
|
|
const char *digest,
|
2010-07-22 11:54:50 +02:00
|
|
|
uint8_t dir_purpose, uint8_t router_purpose,
|
2012-09-12 16:15:58 +02:00
|
|
|
dir_indirection_t indirection,
|
2010-07-22 11:54:50 +02:00
|
|
|
const char *resource,
|
|
|
|
const char *payload, size_t payload_len,
|
|
|
|
time_t if_modified_since);
|
2015-12-07 08:07:44 +01:00
|
|
|
int connection_dir_avoid_extra_connection_for_purpose(unsigned int purpose);
|
|
|
|
int connection_dir_close_consensus_conn_if_extra(dir_connection_t *conn);
|
|
|
|
void connection_dir_close_extra_consensus_conns(void);
|
2010-07-22 11:54:50 +02:00
|
|
|
|
|
|
|
#define DSR_HEX (1<<0)
|
|
|
|
#define DSR_BASE64 (1<<1)
|
|
|
|
#define DSR_DIGEST256 (1<<2)
|
|
|
|
#define DSR_SORT_UNIQ (1<<3)
|
|
|
|
int dir_split_resource_into_fingerprints(const char *resource,
|
|
|
|
smartlist_t *fp_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);
|
2015-12-07 07:55:38 +01:00
|
|
|
time_t download_status_increment_attempt(download_status_t *dls,
|
|
|
|
const char *item, time_t now);
|
2010-07-22 11:54:50 +02:00
|
|
|
/** Increment the failure count of the download_status_t <b>dls</b>, with
|
|
|
|
* the optional status code <b>sc</b>. */
|
|
|
|
#define download_status_failed(dls, sc) \
|
|
|
|
download_status_increment_failure((dls), (sc), NULL, \
|
2014-10-28 23:01:06 +01:00
|
|
|
dir_server_mode(get_options()), \
|
|
|
|
time(NULL))
|
2010-07-22 11:54:50 +02:00
|
|
|
|
|
|
|
void download_status_reset(download_status_t *dls);
|
|
|
|
static int download_status_is_ready(download_status_t *dls, time_t now,
|
|
|
|
int max_failures);
|
|
|
|
/** Return true iff, as of <b>now</b>, the resource tracked by <b>dls</b> is
|
|
|
|
* ready to get its download reattempted. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline int
|
2010-07-22 11:54:50 +02:00
|
|
|
download_status_is_ready(download_status_t *dls, time_t now,
|
|
|
|
int max_failures)
|
|
|
|
{
|
2015-12-07 07:55:38 +01:00
|
|
|
int under_failure_limit = (dls->n_download_failures <= max_failures
|
|
|
|
&& dls->n_download_attempts <= max_failures);
|
|
|
|
return (under_failure_limit && dls->next_attempt_at <= now);
|
2010-07-22 11:54:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void download_status_mark_impossible(download_status_t *dl);
|
|
|
|
/** Mark <b>dl</b> as never downloadable. */
|
2015-12-10 16:19:43 +01:00
|
|
|
static inline void
|
2010-07-22 11:54:50 +02:00
|
|
|
download_status_mark_impossible(download_status_t *dl)
|
|
|
|
{
|
|
|
|
dl->n_download_failures = IMPOSSIBLE_TO_DOWNLOAD;
|
2015-12-07 07:55:38 +01:00
|
|
|
dl->n_download_attempts = IMPOSSIBLE_TO_DOWNLOAD;
|
2010-07-22 11:54:50 +02:00
|
|
|
}
|
|
|
|
|
2010-09-02 22:42:18 +02:00
|
|
|
int download_status_get_n_failures(const download_status_t *dls);
|
2015-12-07 07:55:38 +01:00
|
|
|
int download_status_get_n_attempts(const download_status_t *dls);
|
|
|
|
time_t download_status_get_next_attempt_at(const download_status_t *dls);
|
2010-09-02 22:42:18 +02:00
|
|
|
|
2013-09-03 02:14:43 +02:00
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
/* Used only by directory.c and test_dir.c */
|
2014-09-23 18:12:57 +02:00
|
|
|
|
2013-09-03 02:14:43 +02:00
|
|
|
STATIC int parse_http_url(const char *headers, char **url);
|
2015-01-23 17:18:28 +01:00
|
|
|
STATIC int purpose_needs_anonymity(uint8_t dir_purpose,
|
|
|
|
uint8_t router_purpose);
|
2014-09-23 18:12:57 +02:00
|
|
|
STATIC dirinfo_type_t dir_fetch_type(int dir_purpose, int router_purpose,
|
|
|
|
const char *resource);
|
2015-09-07 19:22:33 +02:00
|
|
|
STATIC int directory_handle_command_get(dir_connection_t *conn,
|
|
|
|
const char *headers,
|
|
|
|
const char *req_body,
|
|
|
|
size_t req_body_len);
|
2015-12-15 19:03:21 +01:00
|
|
|
STATIC int connection_dir_would_close_consensus_conn_helper(void);
|
2015-12-07 07:55:38 +01:00
|
|
|
STATIC int download_status_schedule_get_delay(download_status_t *dls,
|
|
|
|
const smartlist_t *schedule,
|
|
|
|
time_t now);
|
2013-09-03 02:14:43 +02:00
|
|
|
#endif
|
|
|
|
|
2010-07-22 11:54:50 +02:00
|
|
|
#endif
|
|
|
|
|