commit c300fd7e65b699c3d2704737cd0c73276ca0a346 Author: Nick Mathewson nickm@torproject.org Date: Fri Apr 21 14:31:35 2017 -0400
Have directory_get_from_all_authorities use requests. --- src/or/directory.c | 16 +++++++++------- src/or/directory.h | 2 +- src/test/test_dir.c | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 11 deletions(-)
diff --git a/src/or/directory.c b/src/or/directory.c index ea3683d..1996e56 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -655,15 +655,17 @@ directory_get_from_all_authorities(uint8_t dir_purpose,
SMARTLIST_FOREACH_BEGIN(router_get_trusted_dir_servers(), dir_server_t *, ds) { - routerstatus_t *rs; if (router_digest_is_me(ds->digest)) continue; if (!(ds->type & V3_DIRINFO)) continue; - rs = &ds->fake_status; - directory_initiate_command_routerstatus(rs, dir_purpose, router_purpose, - DIRIND_ONEHOP, resource, NULL, - 0, 0, NULL); + const routerstatus_t *rs = &ds->fake_status; + directory_request_t *req = directory_request_new(dir_purpose); + directory_request_set_routerstatus(req, rs); + directory_request_set_router_purpose(req, router_purpose); + directory_request_set_resource(req, resource); + directory_initiate_request(req); + directory_request_free(req); } SMARTLIST_FOREACH_END(ds); }
@@ -1320,8 +1322,8 @@ directory_request_set_dir_from_routerstatus(directory_request_t *req) return 0; }
-void -directory_initiate_request(directory_request_t *request) +MOCK_IMPL(void, +directory_initiate_request,(directory_request_t *request)) { tor_assert(request); if (request->routerstatus) { diff --git a/src/or/directory.h b/src/or/directory.h index 5d27767..56bbfe4 100644 --- a/src/or/directory.h +++ b/src/or/directory.h @@ -91,7 +91,7 @@ void directory_initiate_command_routerstatus_rend(const routerstatus_t *status, const rend_data_t *rend_query, struct circuit_guard_state_t *guard_state);
-void directory_initiate_request(directory_request_t *request); +MOCK_DECL(void, directory_initiate_request, (directory_request_t *request));
int parse_http_response(const char *headers, int *code, time_t *date, compress_method_t *compression, char **response); diff --git a/src/test/test_dir.c b/src/test/test_dir.c index e0c92a7..048b714 100644 --- a/src/test/test_dir.c +++ b/src/test/test_dir.c @@ -4541,6 +4541,8 @@ directory_initiate_command_routerstatus, (const routerstatus_t *status, size_t payload_len, time_t if_modified_since, circuit_guard_state_t *guardstate)); +NS_DECL(void, +directory_initiate_request, (directory_request_t *req));
static void test_dir_should_not_init_request_to_ourselves(void *data) @@ -4616,7 +4618,7 @@ test_dir_should_init_request_to_dir_auths(void *data) dir_server_t *ds = NULL; (void) data;
- NS_MOCK(directory_initiate_command_routerstatus); + NS_MOCK(directory_initiate_request);
clear_dir_servers(); routerlist_free_all(); @@ -4627,11 +4629,11 @@ test_dir_should_init_request_to_dir_auths(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, 1); + tt_int_op(CALLED(directory_initiate_request), OP_EQ, 1);
directory_get_from_all_authorities(DIR_PURPOSE_FETCH_DETACHED_SIGNATURES, 0, NULL); - tt_int_op(CALLED(directory_initiate_command_routerstatus), OP_EQ, 2); + tt_int_op(CALLED(directory_initiate_request), OP_EQ, 2);
done: NS_UNMOCK(directory_initiate_command_routerstatus); @@ -4662,6 +4664,13 @@ NS(directory_initiate_command_routerstatus)(const routerstatus_t *status, CALLED(directory_initiate_command_routerstatus)++; }
+void +NS(directory_initiate_request)(directory_request_t *req) +{ + (void)req; + CALLED(directory_initiate_request)++; +} + static void test_dir_choose_compression_level(void* data) {
tor-commits@lists.torproject.org