aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_rendcache.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@ev0ke.net>2016-03-29 15:08:04 -0400
committerDavid Goulet <dgoulet@torproject.org>2016-11-04 10:31:35 -0400
commit025610612d78fe0a0ec95dd88c3d44e4bf643603 (patch)
tree165a149fe0534bb58711aa61c4b2c622e7c87b25 /src/test/test_rendcache.c
parent473f99bf7bdb7d23b914cd1b590451333baaf7fe (diff)
downloadtor-025610612d78fe0a0ec95dd88c3d44e4bf643603.tar.gz
tor-025610612d78fe0a0ec95dd88c3d44e4bf643603.zip
prop224: Directory cache support
This implements the proposal 224 directory descriptor cache store and lookup functionalities. Furthermore, it merges the OOM call for the HSDir cache with current protocol v2 and the new upcoming v3. Add hs_cache.{c|h} with store/lookup API. Closes #18572 Signed-off-by: David Goulet <dgoulet@torproject.org> Signed-off-by: George Kadianakis <desnacked@riseup.net>
Diffstat (limited to 'src/test/test_rendcache.c')
-rw-r--r--src/test/test_rendcache.c36
1 files changed, 7 insertions, 29 deletions
diff --git a/src/test/test_rendcache.c b/src/test/test_rendcache.c
index 05a0bcdfd5..afcd117350 100644
--- a/src/test/test_rendcache.c
+++ b/src/test/test_rendcache.c
@@ -1072,9 +1072,10 @@ static void
test_rend_cache_clean_v2_descs_as_dir(void *data)
{
rend_cache_entry_t *e;
- time_t now;
+ time_t now, cutoff;
rend_service_descriptor_t *desc;
now = time(NULL);
+ cutoff = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW);
const char key[DIGEST_LEN] = "abcde";
(void)data;
@@ -1082,7 +1083,7 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
rend_cache_init();
// Test running with an empty cache
- rend_cache_clean_v2_descs_as_dir(now, 0);
+ rend_cache_clean_v2_descs_as_dir(cutoff);
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
// Test with only one new entry
@@ -1094,38 +1095,15 @@ test_rend_cache_clean_v2_descs_as_dir(void *data)
e->parsed = desc;
digestmap_set(rend_cache_v2_dir, key, e);
- rend_cache_clean_v2_descs_as_dir(now, 0);
+ /* Set the cutoff to minus 10 seconds. */
+ rend_cache_clean_v2_descs_as_dir(cutoff - 10);
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
// Test with one old entry
- desc->timestamp = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW + 1000);
- rend_cache_clean_v2_descs_as_dir(now, 0);
- tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
-
- // Test with one entry that has an old last served
- e = tor_malloc_zero(sizeof(rend_cache_entry_t));
- e->last_served = now - (REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW + 1000);
- desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
- desc->timestamp = now;
- desc->pk = pk_generate(0);
- e->parsed = desc;
- digestmap_set(rend_cache_v2_dir, key, e);
-
- rend_cache_clean_v2_descs_as_dir(now, 0);
+ desc->timestamp = cutoff - 1000;
+ rend_cache_clean_v2_descs_as_dir(cutoff);
tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 0);
- // Test a run through asking for a large force_remove
- e = tor_malloc_zero(sizeof(rend_cache_entry_t));
- e->last_served = now;
- desc = tor_malloc_zero(sizeof(rend_service_descriptor_t));
- desc->timestamp = now;
- desc->pk = pk_generate(0);
- e->parsed = desc;
- digestmap_set(rend_cache_v2_dir, key, e);
-
- rend_cache_clean_v2_descs_as_dir(now, 20000);
- tt_int_op(digestmap_size(rend_cache_v2_dir), OP_EQ, 1);
-
done:
rend_cache_free_all();
}