diff options
author | Reinaldo de Souza Jr <juniorz@gmail.com> | 2015-09-07 12:22:33 -0500 |
---|---|---|
committer | Reinaldo de Souza Jr <juniorz@gmail.com> | 2015-09-15 11:08:50 -0500 |
commit | 4ff08bb5811ddfe554e597d129ec48a774364480 (patch) | |
tree | ff8661a350d4d53d1ec3d7d51725453e2295909c /src/test/rend_test_helpers.c | |
parent | a444b11323799536b4cd7902e29f711b0806293a (diff) | |
download | tor-4ff08bb5811ddfe554e597d129ec48a774364480.tar.gz tor-4ff08bb5811ddfe554e597d129ec48a774364480.zip |
Add tests for directory_handle_command_get
Diffstat (limited to 'src/test/rend_test_helpers.c')
-rw-r--r-- | src/test/rend_test_helpers.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/test/rend_test_helpers.c b/src/test/rend_test_helpers.c new file mode 100644 index 0000000000..0a1b1c8967 --- /dev/null +++ b/src/test/rend_test_helpers.c @@ -0,0 +1,66 @@ +#include "rend_test_helpers.h" + +#include "test.h" +#include "rendcommon.h" + +void +generate_desc(int time_diff, rend_encoded_v2_service_descriptor_t **desc, + char **service_id, int intro_points) +{ + rend_service_descriptor_t *generated = NULL; + smartlist_t *descs = smartlist_new(); + time_t now; + + now = time(NULL) + time_diff; + create_descriptor(&generated, service_id, intro_points); + generated->timestamp = now; + + rend_encode_v2_descriptors(descs, generated, now, 0, REND_NO_AUTH, NULL, + NULL); + *desc = ((rend_encoded_v2_service_descriptor_t *)smartlist_get(descs, 0)); + + smartlist_free(descs); + rend_service_descriptor_free(generated); +} + +void +create_descriptor(rend_service_descriptor_t **generated, char **service_id, + int intro_points) +{ + crypto_pk_t *pk1 = NULL; + crypto_pk_t *pk2 = NULL; + int i; + + *service_id = tor_malloc(REND_SERVICE_ID_LEN_BASE32+1); + pk1 = pk_generate(0); + pk2 = pk_generate(1); + + *generated = tor_malloc_zero(sizeof(rend_service_descriptor_t)); + (*generated)->pk = crypto_pk_dup_key(pk1); + rend_get_service_id((*generated)->pk, *service_id); + + (*generated)->version = 2; + (*generated)->protocols = 42; + (*generated)->intro_nodes = smartlist_new(); + + for (i = 0; i < intro_points; i++) { + rend_intro_point_t *intro = tor_malloc_zero(sizeof(rend_intro_point_t)); + crypto_pk_t *okey = pk_generate(2 + i); + intro->extend_info = tor_malloc_zero(sizeof(extend_info_t)); + intro->extend_info->onion_key = okey; + crypto_pk_get_digest(intro->extend_info->onion_key, + intro->extend_info->identity_digest); + intro->extend_info->nickname[0] = '$'; + base16_encode(intro->extend_info->nickname + 1, + sizeof(intro->extend_info->nickname) - 1, + intro->extend_info->identity_digest, DIGEST_LEN); + tor_addr_from_ipv4h(&intro->extend_info->addr, crypto_rand_int(65536)); + intro->extend_info->port = 1 + crypto_rand_int(65535); + intro->intro_key = crypto_pk_dup_key(pk2); + smartlist_add((*generated)->intro_nodes, intro); + } + + crypto_pk_free(pk1); + crypto_pk_free(pk2); +} + |