mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-26 07:31:33 +01:00
prop224 test: Improve desc_reupload_logic() test with more nodes.
This commit is contained in:
parent
ac9066660e
commit
d3cefddfc5
1 changed files with 62 additions and 10 deletions
|
@ -21,6 +21,7 @@
|
||||||
#include "networkstatus.h"
|
#include "networkstatus.h"
|
||||||
#include "directory.h"
|
#include "directory.h"
|
||||||
#include "nodelist.h"
|
#include "nodelist.h"
|
||||||
|
#include "routerlist.h"
|
||||||
#include "statefile.h"
|
#include "statefile.h"
|
||||||
|
|
||||||
/** Test the validation of HS v3 addresses */
|
/** Test the validation of HS v3 addresses */
|
||||||
|
@ -378,8 +379,10 @@ helper_add_hsdir_to_networkstatus(networkstatus_t *ns,
|
||||||
memcpy(rs->identity_digest, identity, DIGEST_LEN);
|
memcpy(rs->identity_digest, identity, DIGEST_LEN);
|
||||||
rs->is_hs_dir = is_hsdir;
|
rs->is_hs_dir = is_hsdir;
|
||||||
rs->supports_v3_hsdir = 1;
|
rs->supports_v3_hsdir = 1;
|
||||||
|
strlcpy(rs->nickname, nickname, sizeof(rs->nickname));
|
||||||
tor_addr_parse(&ipv4_addr, "1.2.3.4");
|
tor_addr_parse(&ipv4_addr, "1.2.3.4");
|
||||||
ri->addr = tor_addr_to_ipv4h(&ipv4_addr);
|
ri->addr = tor_addr_to_ipv4h(&ipv4_addr);
|
||||||
|
rs->addr = tor_addr_to_ipv4h(&ipv4_addr);
|
||||||
ri->nickname = tor_strdup(nickname);
|
ri->nickname = tor_strdup(nickname);
|
||||||
ri->protocol_list = tor_strdup("HSDir=1-2 LinkAuth=3");
|
ri->protocol_list = tor_strdup("HSDir=1-2 LinkAuth=3");
|
||||||
memcpy(ri->cache_info.identity_digest, identity, DIGEST_LEN);
|
memcpy(ri->cache_info.identity_digest, identity, DIGEST_LEN);
|
||||||
|
@ -392,7 +395,7 @@ helper_add_hsdir_to_networkstatus(networkstatus_t *ns,
|
||||||
smartlist_add(ns->routerstatus_list, rs);
|
smartlist_add(ns->routerstatus_list, rs);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
;
|
routerinfo_free(ri);
|
||||||
}
|
}
|
||||||
|
|
||||||
static networkstatus_t *mock_ns = NULL;
|
static networkstatus_t *mock_ns = NULL;
|
||||||
|
@ -416,6 +419,7 @@ mock_networkstatus_get_latest_consensus(void)
|
||||||
mock_ns->valid_until = now+2;
|
mock_ns->valid_until = now+2;
|
||||||
/* Create routerstatus list */
|
/* Create routerstatus list */
|
||||||
mock_ns->routerstatus_list = smartlist_new();
|
mock_ns->routerstatus_list = smartlist_new();
|
||||||
|
mock_ns->type = NS_TYPE_CONSENSUS;
|
||||||
|
|
||||||
return mock_ns;
|
return mock_ns;
|
||||||
}
|
}
|
||||||
|
@ -562,18 +566,19 @@ test_desc_reupload_logic(void *arg)
|
||||||
tt_int_op(hs_service_get_num_services(), OP_EQ, 1);
|
tt_int_op(hs_service_get_num_services(), OP_EQ, 1);
|
||||||
|
|
||||||
/* Now let's create our hash ring: */
|
/* Now let's create our hash ring: */
|
||||||
{ /* First HSDir */
|
{
|
||||||
helper_add_hsdir_to_networkstatus(ns, 1, "dingus", 1);
|
helper_add_hsdir_to_networkstatus(ns, 1, "dingus", 1);
|
||||||
}
|
|
||||||
|
|
||||||
{ /* Second HSDir */
|
|
||||||
helper_add_hsdir_to_networkstatus(ns, 2, "clive", 1);
|
helper_add_hsdir_to_networkstatus(ns, 2, "clive", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 3, "aaron", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 4, "lizzie", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 5, "daewon", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 6, "clarke", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now let's upload our desc to all hsdirs */
|
/* Now let's upload our desc to all hsdirs */
|
||||||
upload_descriptor_to_all(service, desc, 0);
|
upload_descriptor_to_all(service, desc, 0);
|
||||||
/* Check that previous hsdirs were populated */
|
/* Check that previous hsdirs were populated */
|
||||||
tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 2);
|
tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 6);
|
||||||
|
|
||||||
/* Poison next upload time so that we can see if it was changed by
|
/* Poison next upload time so that we can see if it was changed by
|
||||||
* router_dir_info_changed(). No changes in hash ring so far, so the upload
|
* router_dir_info_changed(). No changes in hash ring so far, so the upload
|
||||||
|
@ -582,10 +587,23 @@ test_desc_reupload_logic(void *arg)
|
||||||
router_dir_info_changed();
|
router_dir_info_changed();
|
||||||
tt_int_op(desc->next_upload_time, OP_EQ, 42);
|
tt_int_op(desc->next_upload_time, OP_EQ, 42);
|
||||||
|
|
||||||
/* Now change the HSDir hash ring by adding another node */
|
/* Now change the HSDir hash ring by swapping nora for aaron.
|
||||||
|
* Start by clearing the hash ring */
|
||||||
|
{
|
||||||
|
SMARTLIST_FOREACH(ns->routerstatus_list,
|
||||||
|
routerstatus_t *, rs, routerstatus_free(rs));
|
||||||
|
smartlist_clear(ns->routerstatus_list);
|
||||||
|
nodelist_free_all();
|
||||||
|
routerlist_free_all();
|
||||||
|
}
|
||||||
|
|
||||||
{ /* Third HSDir */
|
{ /* Now add back all the nodes */
|
||||||
helper_add_hsdir_to_networkstatus(ns, 3, "ringo", 1);
|
helper_add_hsdir_to_networkstatus(ns, 1, "dingus", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 2, "clive", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 4, "lizzie", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 5, "daewon", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 6, "clarke", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 7, "nora", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now call service_desc_hsdirs_changed() and see that it detected the hash
|
/* Now call service_desc_hsdirs_changed() and see that it detected the hash
|
||||||
|
@ -593,6 +611,35 @@ test_desc_reupload_logic(void *arg)
|
||||||
time_t now = approx_time();
|
time_t now = approx_time();
|
||||||
tt_assert(now);
|
tt_assert(now);
|
||||||
tt_int_op(service_desc_hsdirs_changed(service, desc), OP_EQ, 1);
|
tt_int_op(service_desc_hsdirs_changed(service, desc), OP_EQ, 1);
|
||||||
|
tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 6);
|
||||||
|
|
||||||
|
/* Now order another upload and see how we end up with 7 hsdirs */
|
||||||
|
upload_descriptor_to_all(service, desc, 0);
|
||||||
|
/* Check that previous hsdirs were populated */
|
||||||
|
tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 7);
|
||||||
|
|
||||||
|
/* Now restore the HSDir hash ring to its original state by swapping back
|
||||||
|
aaron for nora */
|
||||||
|
/* First clear up the hash ring */
|
||||||
|
{
|
||||||
|
SMARTLIST_FOREACH(ns->routerstatus_list,
|
||||||
|
routerstatus_t *, rs, routerstatus_free(rs));
|
||||||
|
smartlist_clear(ns->routerstatus_list);
|
||||||
|
nodelist_free_all();
|
||||||
|
routerlist_free_all();
|
||||||
|
}
|
||||||
|
|
||||||
|
{ /* Now populate the hash ring again */
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 1, "dingus", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 2, "clive", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 3, "aaron", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 4, "lizzie", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 5, "daewon", 1);
|
||||||
|
helper_add_hsdir_to_networkstatus(ns, 6, "clarke", 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check that our algorithm catches this change of hsdirs */
|
||||||
|
tt_int_op(service_desc_hsdirs_changed(service, desc), OP_EQ, 1);
|
||||||
|
|
||||||
/* Now pretend that the descriptor changed, and order a reupload to all
|
/* Now pretend that the descriptor changed, and order a reupload to all
|
||||||
HSDirs. Make sure that the set of previous HSDirs was cleared. */
|
HSDirs. Make sure that the set of previous HSDirs was cleared. */
|
||||||
|
@ -601,9 +648,14 @@ test_desc_reupload_logic(void *arg)
|
||||||
|
|
||||||
/* Now reupload again: see that the prev hsdir set got populated again. */
|
/* Now reupload again: see that the prev hsdir set got populated again. */
|
||||||
upload_descriptor_to_all(service, desc, 0);
|
upload_descriptor_to_all(service, desc, 0);
|
||||||
tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 3);
|
tt_int_op(smartlist_len(desc->previous_hsdirs), OP_EQ, 6);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
SMARTLIST_FOREACH(ns->routerstatus_list,
|
||||||
|
routerstatus_t *, rs, routerstatus_free(rs));
|
||||||
|
smartlist_clear(ns->routerstatus_list);
|
||||||
|
networkstatus_vote_free(ns);
|
||||||
|
nodelist_free_all();
|
||||||
hs_free_all();
|
hs_free_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue