Remove old directory_initiate_command_*() functions.

This commit is contained in:
Nick Mathewson 2017-04-21 15:14:52 -04:00
parent 8aadd60eac
commit 3327e675fd
3 changed files with 12 additions and 201 deletions

View File

@ -772,78 +772,6 @@ directory_choose_address_routerstatus(const routerstatus_t *status,
return 0;
}
/** Same as directory_initiate_command_routerstatus(), but accepts
* rendezvous data to fetch a hidden service descriptor. */
void
directory_initiate_command_routerstatus_rend(const routerstatus_t *status,
uint8_t dir_purpose,
uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload,
size_t payload_len,
time_t if_modified_since,
const rend_data_t *rend_query,
circuit_guard_state_t *guard_state)
{
directory_request_t *req = directory_request_new(dir_purpose);
directory_request_set_routerstatus(req, status);
directory_request_set_router_purpose(req, router_purpose);
directory_request_set_indirection(req, indirection);
if (resource)
directory_request_set_resource(req, resource);
if (payload)
directory_request_set_payload(req, payload, payload_len);
if (if_modified_since)
directory_request_set_if_modified_since(req, if_modified_since);
if (rend_query)
directory_request_set_rend_query(req, rend_query);
if (guard_state)
directory_request_set_guard_state(req, guard_state);
/* We don't retry the alternate OR/Dir address for the same directory if
* the address we choose fails (#6772).
* Instead, we'll retry another directory on failure. */
directory_initiate_request(req);
directory_request_free(req);
}
/** Launch a new connection to the directory server <b>status</b> to
* upload or download a server or rendezvous
* descriptor. <b>dir_purpose</b> determines what
* kind of directory connection we're launching, and must be one of
* DIR_PURPOSE_{FETCH|UPLOAD}_{DIR|RENDDESC_V2}. <b>router_purpose</b>
* specifies the descriptor purposes we have in mind (currently only
* used for FETCH_DIR).
*
* When uploading, <b>payload</b> and <b>payload_len</b> determine the content
* of the HTTP post. Otherwise, <b>payload</b> should be NULL.
*
* When fetching a rendezvous descriptor, <b>resource</b> is the service ID we
* want to fetch.
*/
MOCK_IMPL(void, directory_initiate_command_routerstatus,
(const routerstatus_t *status,
uint8_t dir_purpose,
uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload,
size_t payload_len,
time_t if_modified_since,
circuit_guard_state_t *guard_state))
{
directory_initiate_command_routerstatus_rend(status, dir_purpose,
router_purpose,
indirection, resource,
payload, payload_len,
if_modified_since, NULL,
guard_state);
}
/** Return true iff <b>conn</b> is the client side of a directory connection
* we launched to ourself in order to determine the reachability of our
* dir_port. */
@ -1085,62 +1013,6 @@ directory_command_should_use_begindir(const or_options_t *options,
return 1;
}
/** Helper for directory_initiate_command_rend: send the
* command to a server whose OR address/port is <b>or_addr</b>/<b>or_port</b>,
* whose directory address/port is <b>dir_addr</b>/<b>dir_port</b>, whose
* identity key digest is <b>digest</b>, with purposes <b>dir_purpose</b> and
* <b>router_purpose</b>, making an (in)direct connection as specified in
* <b>indirection</b>, with command <b>resource</b>, <b>payload</b> of
* <b>payload_len</b>, and asking for a result only <b>if_modified_since</b>.
*/
void
directory_initiate_command(const tor_addr_t *or_addr, uint16_t or_port,
const tor_addr_t *dir_addr, uint16_t dir_port,
const char *digest,
uint8_t dir_purpose, uint8_t router_purpose,
dir_indirection_t indirection, const char *resource,
const char *payload, size_t payload_len,
time_t if_modified_since)
{
tor_addr_port_t or_ap, dir_ap;
/* Use the null tor_addr and 0 port if the address or port isn't valid. */
if (tor_addr_port_is_valid(or_addr, or_port, 0)) {
tor_addr_copy(&or_ap.addr, or_addr);
or_ap.port = or_port;
} else {
/* the family doesn't matter here, so make it IPv4 */
tor_addr_make_null(&or_ap.addr, AF_INET);
or_ap.port = or_port = 0;
}
if (tor_addr_port_is_valid(dir_addr, dir_port, 0)) {
tor_addr_copy(&dir_ap.addr, dir_addr);
dir_ap.port = dir_port;
} else {
/* the family doesn't matter here, so make it IPv4 */
tor_addr_make_null(&dir_ap.addr, AF_INET);
dir_ap.port = dir_port = 0;
}
directory_request_t *req = directory_request_new(dir_purpose);
directory_request_set_or_addr_port(req, &or_ap);
directory_request_set_dir_addr_port(req, &dir_ap);
directory_request_set_directory_id_digest(req, digest);
directory_request_set_router_purpose(req, router_purpose);
directory_request_set_indirection(req, indirection);
if (resource)
directory_request_set_resource(req, resource);
if (payload)
directory_request_set_payload(req, payload, payload_len);
if (if_modified_since)
directory_request_set_if_modified_since(req, if_modified_since);
directory_initiate_request(req);
directory_request_free(req);
}
struct directory_request_t {
tor_addr_port_t or_addr_port;
tor_addr_port_t dir_addr_port;
@ -1630,7 +1502,9 @@ copy_ipv6_address(char* destination, const char* source, size_t len,
}
/** Queue an appropriate HTTP command on conn-\>outbuf. The other args
* are as in directory_initiate_command().
* are as in directory_request_set_...()
*
*
*/
static void
directory_send_command(dir_connection_t *conn,

View File

@ -69,28 +69,6 @@ void directory_request_set_guard_state(directory_request_t *req,
void directory_request_set_routerstatus(directory_request_t *req,
const routerstatus_t *rs);
MOCK_DECL(void, directory_initiate_command_routerstatus,
(const routerstatus_t *status,
uint8_t dir_purpose,
uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload,
size_t payload_len,
time_t if_modified_since,
struct circuit_guard_state_t *guard_state));
void directory_initiate_command_routerstatus_rend(const routerstatus_t *status,
uint8_t dir_purpose,
uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload,
size_t payload_len,
time_t if_modified_since,
const rend_data_t *rend_query,
struct circuit_guard_state_t *guard_state);
MOCK_DECL(void, directory_initiate_request, (directory_request_t *request));
int parse_http_response(const char *headers, int *code, time_t *date,
@ -102,14 +80,6 @@ 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);
void directory_initiate_command(const tor_addr_t *or_addr, uint16_t or_port,
const tor_addr_t *dir_addr, uint16_t dir_port,
const char *digest,
uint8_t dir_purpose, uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload, size_t payload_len,
time_t if_modified_since);
#define DSR_HEX (1<<0)
#define DSR_BASE64 (1<<1)

View File

@ -4531,16 +4531,6 @@ test_dir_should_use_directory_guards(void *data)
tor_free(errmsg);
}
NS_DECL(void,
directory_initiate_command_routerstatus, (const routerstatus_t *status,
uint8_t dir_purpose,
uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload,
size_t payload_len,
time_t if_modified_since,
circuit_guard_state_t *guardstate));
NS_DECL(void,
directory_initiate_request, (directory_request_t *req));
@ -4552,7 +4542,7 @@ test_dir_should_not_init_request_to_ourselves(void *data)
crypto_pk_t *key = pk_generate(2);
(void) data;
NS_MOCK(directory_initiate_command_routerstatus);
NS_MOCK(directory_initiate_request);
clear_dir_servers();
routerlist_free_all();
@ -4567,15 +4557,15 @@ test_dir_should_not_init_request_to_ourselves(void *data)
dir_server_add(ourself);
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_STATUS_VOTE, 0, NULL);
tt_int_op(CALLED(directory_initiate_command_routerstatus), OP_EQ, 0);
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, 0,
NULL);
tt_int_op(CALLED(directory_initiate_command_routerstatus), OP_EQ, 0);
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
done:
NS_UNMOCK(directory_initiate_command_routerstatus);
NS_UNMOCK(directory_initiate_request);
clear_dir_servers();
routerlist_free_all();
crypto_pk_free(key);
@ -4589,7 +4579,7 @@ test_dir_should_not_init_request_to_dir_auths_without_v3_info(void *data)
| MICRODESC_DIRINFO;
(void) data;
NS_MOCK(directory_initiate_command_routerstatus);
NS_MOCK(directory_initiate_request);
clear_dir_servers();
routerlist_free_all();
@ -4600,14 +4590,14 @@ test_dir_should_not_init_request_to_dir_auths_without_v3_info(void *data)
dir_server_add(ds);
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_STATUS_VOTE, 0, NULL);
tt_int_op(CALLED(directory_initiate_command_routerstatus), OP_EQ, 0);
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, 0,
NULL);
tt_int_op(CALLED(directory_initiate_command_routerstatus), OP_EQ, 0);
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 0);
done:
NS_UNMOCK(directory_initiate_command_routerstatus);
NS_UNMOCK(directory_initiate_request);
clear_dir_servers();
routerlist_free_all();
}
@ -4636,34 +4626,11 @@ test_dir_should_init_request_to_dir_auths(void *data)
tt_int_op(CALLED(directory_initiate_request), OP_EQ, 2);
done:
NS_UNMOCK(directory_initiate_command_routerstatus);
NS_UNMOCK(directory_initiate_request);
clear_dir_servers();
routerlist_free_all();
}
void
NS(directory_initiate_command_routerstatus)(const routerstatus_t *status,
uint8_t dir_purpose,
uint8_t router_purpose,
dir_indirection_t indirection,
const char *resource,
const char *payload,
size_t payload_len,
time_t if_modified_since,
circuit_guard_state_t *guardstate)
{
(void)status;
(void)dir_purpose;
(void)router_purpose;
(void)indirection;
(void)resource;
(void)payload;
(void)payload_len;
(void)if_modified_since;
(void)guardstate;
CALLED(directory_initiate_command_routerstatus)++;
}
void
NS(directory_initiate_request)(directory_request_t *req)
{