Loading src/or/dirserv.c +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ typedef struct fingerprint_entry_t { static fingerprint_entry_t fingerprint_list[MAX_ROUTERS_IN_DIR]; static int n_fingerprints = 0; static void void /* Should be static; exposed for testing */ add_fingerprint_to_dir(const char *nickname, const char *fp) { int i; Loading src/or/routerlist.c +2 −4 Original line number Diff line number Diff line Loading @@ -111,7 +111,7 @@ static int router_get_list_from_string_impl(const char **s, routerlist_t **dest, int n_good_nicknames, const char **good_nickname_lst); static int int /* Exposed for unit tests */ router_get_routerlist_from_directory_impl(const char *s, routerlist_t **dest, crypto_pk_env_t *pkey); static int Loading @@ -119,8 +119,6 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok); static int router_resolve_routerlist(routerlist_t *dir); static int router_get_hash_impl(const char *s, char *digest, const char *start_str, const char *end_str); static void token_free(directory_token_t *tok); Loading Loading @@ -575,7 +573,7 @@ static int parse_time(const char *cp, time_t *t) * resulting routerlist in *dest, freeing the old value if necessary. * If pkey is provided, we check the directory signature with pkey. */ static int int /* Should be static; exposed for unit tests */ router_get_routerlist_from_directory_impl(const char *str, routerlist_t **dest, crypto_pk_env_t *pkey) Loading src/or/test.c +27 −16 Original line number Diff line number Diff line Loading @@ -17,6 +17,11 @@ int have_failed = 0; /* These functions are file-local, but are exposed so we can test. */ int router_get_routerlist_from_directory_impl( const char *s, routerlist_t **dest, crypto_pk_env_t *pkey); void add_fingerprint_to_dir(const char *nickname, const char *fp); void dump_hex(char *s, int len) { Loading Loading @@ -667,6 +672,7 @@ test_dir_format() r2.link_pkey = pk2; r2.bandwidthrate = r2.bandwidthburst = 3000; r2.exit_policy = &ex1; r2.nickname = "Fred"; test_assert(!crypto_pk_write_public_key_to_string(pk1, &pk1_str, &pk1_str_len)); Loading Loading @@ -740,22 +746,27 @@ test_dir_format() test_assert(rp2->exit_policy->next->next == NULL); #endif #if 0 /* XXX To re-enable this test, we need to separate directory generation * XXX from the directory backend again. Do this the next time we have * XXX directory trouble. */ /* Okay, now for the directories. */ dir1 = (directory_t*) tor_malloc(sizeof(directory_t)); dir1->n_routers = 2; dir1->routers = (routerinfo_t**) tor_malloc(sizeof(routerinfo_t*)*2); dir1->routers[0] = &r1; dir1->routers[1] = &r2; test_assert(! dump_signed_directory_to_string_impl(buf, 4096, dir1, pk1)); /* puts(buf); */ test_assert(! router_get_dir_from_string_impl(buf, &dir2, pk1)); test_eq(2, dir2->n_routers); #endif crypto_pk_get_fingerprint(pk2, buf); add_fingerprint_to_dir("Magri", buf); crypto_pk_get_fingerprint(pk1, buf); add_fingerprint_to_dir("Fred", buf); /* Make sure routers aren't too far in the past any more. */ r1.published_on = time(NULL); r2.published_on = time(NULL)-3*60*60; test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0); cp = buf; test_eq(dirserv_add_descriptor((const char**)&cp), 1); test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0); cp = buf; test_eq(dirserv_add_descriptor((const char**)&cp), 1); extern or_options_t options; options.Nickname = "DirServer"; test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3)); cp = buf; test_assert(!router_get_routerlist_from_directory_impl(buf, &dir1, pk3)); test_eq(2, dir1->n_routers); dirserv_free_fingerprint_list(); tor_free(pk1_str); tor_free(pk2_str); Loading @@ -763,7 +774,7 @@ test_dir_format() if (pk2) crypto_free_pk_env(pk2); if (rp1) routerinfo_free(rp1); if (rp2) routerinfo_free(rp2); tor_free(dir1); /* And more !*/ tor_free(dir1); /* XXXX And more !*/ tor_free(dir2); /* And more !*/ /* make sure is_recommended_version() works */ Loading Loading
src/or/dirserv.c +1 −1 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ typedef struct fingerprint_entry_t { static fingerprint_entry_t fingerprint_list[MAX_ROUTERS_IN_DIR]; static int n_fingerprints = 0; static void void /* Should be static; exposed for testing */ add_fingerprint_to_dir(const char *nickname, const char *fp) { int i; Loading
src/or/routerlist.c +2 −4 Original line number Diff line number Diff line Loading @@ -111,7 +111,7 @@ static int router_get_list_from_string_impl(const char **s, routerlist_t **dest, int n_good_nicknames, const char **good_nickname_lst); static int int /* Exposed for unit tests */ router_get_routerlist_from_directory_impl(const char *s, routerlist_t **dest, crypto_pk_env_t *pkey); static int Loading @@ -119,8 +119,6 @@ router_add_exit_policy(routerinfo_t *router, directory_token_t *tok); static int router_resolve_routerlist(routerlist_t *dir); static int router_get_hash_impl(const char *s, char *digest, const char *start_str, const char *end_str); static void token_free(directory_token_t *tok); Loading Loading @@ -575,7 +573,7 @@ static int parse_time(const char *cp, time_t *t) * resulting routerlist in *dest, freeing the old value if necessary. * If pkey is provided, we check the directory signature with pkey. */ static int int /* Should be static; exposed for unit tests */ router_get_routerlist_from_directory_impl(const char *str, routerlist_t **dest, crypto_pk_env_t *pkey) Loading
src/or/test.c +27 −16 Original line number Diff line number Diff line Loading @@ -17,6 +17,11 @@ int have_failed = 0; /* These functions are file-local, but are exposed so we can test. */ int router_get_routerlist_from_directory_impl( const char *s, routerlist_t **dest, crypto_pk_env_t *pkey); void add_fingerprint_to_dir(const char *nickname, const char *fp); void dump_hex(char *s, int len) { Loading Loading @@ -667,6 +672,7 @@ test_dir_format() r2.link_pkey = pk2; r2.bandwidthrate = r2.bandwidthburst = 3000; r2.exit_policy = &ex1; r2.nickname = "Fred"; test_assert(!crypto_pk_write_public_key_to_string(pk1, &pk1_str, &pk1_str_len)); Loading Loading @@ -740,22 +746,27 @@ test_dir_format() test_assert(rp2->exit_policy->next->next == NULL); #endif #if 0 /* XXX To re-enable this test, we need to separate directory generation * XXX from the directory backend again. Do this the next time we have * XXX directory trouble. */ /* Okay, now for the directories. */ dir1 = (directory_t*) tor_malloc(sizeof(directory_t)); dir1->n_routers = 2; dir1->routers = (routerinfo_t**) tor_malloc(sizeof(routerinfo_t*)*2); dir1->routers[0] = &r1; dir1->routers[1] = &r2; test_assert(! dump_signed_directory_to_string_impl(buf, 4096, dir1, pk1)); /* puts(buf); */ test_assert(! router_get_dir_from_string_impl(buf, &dir2, pk1)); test_eq(2, dir2->n_routers); #endif crypto_pk_get_fingerprint(pk2, buf); add_fingerprint_to_dir("Magri", buf); crypto_pk_get_fingerprint(pk1, buf); add_fingerprint_to_dir("Fred", buf); /* Make sure routers aren't too far in the past any more. */ r1.published_on = time(NULL); r2.published_on = time(NULL)-3*60*60; test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0); cp = buf; test_eq(dirserv_add_descriptor((const char**)&cp), 1); test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0); cp = buf; test_eq(dirserv_add_descriptor((const char**)&cp), 1); extern or_options_t options; options.Nickname = "DirServer"; test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3)); cp = buf; test_assert(!router_get_routerlist_from_directory_impl(buf, &dir1, pk3)); test_eq(2, dir1->n_routers); dirserv_free_fingerprint_list(); tor_free(pk1_str); tor_free(pk2_str); Loading @@ -763,7 +774,7 @@ test_dir_format() if (pk2) crypto_free_pk_env(pk2); if (rp1) routerinfo_free(rp1); if (rp2) routerinfo_free(rp2); tor_free(dir1); /* And more !*/ tor_free(dir1); /* XXXX And more !*/ tor_free(dir2); /* And more !*/ /* make sure is_recommended_version() works */ Loading