mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-24 12:23:32 +01:00
Merge remote-tracking branch 'twstrike/rendcache_tests'
Conflicts: src/test/include.am src/test/rend_test_helpers.c src/test/rend_test_helpers.h
This commit is contained in:
commit
f179abdca9
@ -6,6 +6,7 @@
|
||||
* \brief Hidden service descriptor cache.
|
||||
**/
|
||||
|
||||
#define RENDCACHE_PRIVATE
|
||||
#include "rendcache.h"
|
||||
|
||||
#include "config.h"
|
||||
@ -15,14 +16,14 @@
|
||||
|
||||
/** Map from service id (as generated by rend_get_service_id) to
|
||||
* rend_cache_entry_t. */
|
||||
static strmap_t *rend_cache = NULL;
|
||||
STATIC strmap_t *rend_cache = NULL;
|
||||
|
||||
/** Map from service id to rend_cache_entry_t; only for hidden services. */
|
||||
static strmap_t *rend_cache_local_service = NULL;
|
||||
|
||||
/** Map from descriptor id to rend_cache_entry_t; only for hidden service
|
||||
* directories. */
|
||||
static digestmap_t *rend_cache_v2_dir = NULL;
|
||||
STATIC digestmap_t *rend_cache_v2_dir = NULL;
|
||||
|
||||
/** (Client side only) Map from service id to rend_cache_failure_t. This
|
||||
* cache is used to track intro point(IP) failures so we know when to keep
|
||||
@ -49,10 +50,10 @@ static digestmap_t *rend_cache_v2_dir = NULL;
|
||||
* This scheme allows us to not realy on the descriptor's timestamp (which
|
||||
* is rounded down to the hour) to know if we have a newer descriptor. We
|
||||
* only rely on the usability of intro points from an internal state. */
|
||||
static strmap_t *rend_cache_failure = NULL;
|
||||
STATIC strmap_t *rend_cache_failure = NULL;
|
||||
|
||||
/** DOCDOC */
|
||||
static size_t rend_cache_total_allocation = 0;
|
||||
STATIC size_t rend_cache_total_allocation = 0;
|
||||
|
||||
/** Initializes the service descriptor cache.
|
||||
*/
|
||||
@ -66,7 +67,7 @@ rend_cache_init(void)
|
||||
}
|
||||
|
||||
/** Return the approximate number of bytes needed to hold <b>e</b>. */
|
||||
static size_t
|
||||
STATIC size_t
|
||||
rend_cache_entry_allocation(const rend_cache_entry_t *e)
|
||||
{
|
||||
if (!e)
|
||||
@ -84,7 +85,7 @@ rend_cache_get_total_allocation(void)
|
||||
}
|
||||
|
||||
/** Decrement the total bytes attributed to the rendezvous cache by n. */
|
||||
static void
|
||||
STATIC void
|
||||
rend_cache_decrement_allocation(size_t n)
|
||||
{
|
||||
static int have_underflowed = 0;
|
||||
@ -101,7 +102,7 @@ rend_cache_decrement_allocation(size_t n)
|
||||
}
|
||||
|
||||
/** Increase the total bytes attributed to the rendezvous cache by n. */
|
||||
static void
|
||||
STATIC void
|
||||
rend_cache_increment_allocation(size_t n)
|
||||
{
|
||||
static int have_overflowed = 0;
|
||||
@ -117,7 +118,7 @@ rend_cache_increment_allocation(size_t n)
|
||||
}
|
||||
|
||||
/** Helper: free a rend cache failure intro object. */
|
||||
static void
|
||||
STATIC void
|
||||
rend_cache_failure_intro_entry_free(rend_cache_failure_intro_t *entry)
|
||||
{
|
||||
if (entry == NULL) {
|
||||
@ -128,7 +129,7 @@ rend_cache_failure_intro_entry_free(rend_cache_failure_intro_t *entry)
|
||||
|
||||
/** Allocate a rend cache failure intro object and return it. <b>failure</b>
|
||||
* is set into the object. This function can not fail. */
|
||||
static rend_cache_failure_intro_t *
|
||||
STATIC rend_cache_failure_intro_t *
|
||||
rend_cache_failure_intro_entry_new(rend_intro_point_failure_t failure)
|
||||
{
|
||||
rend_cache_failure_intro_t *entry = tor_malloc(sizeof(*entry));
|
||||
@ -138,7 +139,7 @@ rend_cache_failure_intro_entry_new(rend_intro_point_failure_t failure)
|
||||
}
|
||||
|
||||
/** Helper: free a rend cache failure object. */
|
||||
static void
|
||||
STATIC void
|
||||
rend_cache_failure_entry_free(rend_cache_failure_t *entry)
|
||||
{
|
||||
if (entry == NULL) {
|
||||
@ -164,7 +165,7 @@ rend_cache_failure_entry_free_(void *entry)
|
||||
|
||||
/** Allocate a rend cache failure object and return it. This function can
|
||||
* not fail. */
|
||||
static rend_cache_failure_t *
|
||||
STATIC rend_cache_failure_t *
|
||||
rend_cache_failure_entry_new(void)
|
||||
{
|
||||
rend_cache_failure_t *entry = tor_malloc(sizeof(*entry));
|
||||
@ -174,7 +175,7 @@ rend_cache_failure_entry_new(void)
|
||||
|
||||
/** Remove failure cache entry for the service ID in the given descriptor
|
||||
* <b>desc</b>. */
|
||||
static void
|
||||
STATIC void
|
||||
rend_cache_failure_remove(rend_service_descriptor_t *desc)
|
||||
{
|
||||
char service_id[REND_SERVICE_ID_LEN_BASE32 + 1];
|
||||
@ -194,7 +195,7 @@ rend_cache_failure_remove(rend_service_descriptor_t *desc)
|
||||
}
|
||||
|
||||
/** Helper: free storage held by a single service descriptor cache entry. */
|
||||
static void
|
||||
STATIC void
|
||||
rend_cache_entry_free(rend_cache_entry_t *e)
|
||||
{
|
||||
if (!e)
|
||||
@ -319,7 +320,7 @@ rend_cache_failure_purge(void)
|
||||
* <b>identity</b> and service ID <b>service_id</b>. If found, the intro
|
||||
* failure is set in <b>intro_entry</b> else it stays untouched. Return 1
|
||||
* iff found else 0. */
|
||||
static int
|
||||
STATIC int
|
||||
cache_failure_intro_lookup(const uint8_t *identity, const char *service_id,
|
||||
rend_cache_failure_intro_t **intro_entry)
|
||||
{
|
||||
@ -363,7 +364,7 @@ cache_failure_intro_dup(const rend_cache_failure_intro_t *entry)
|
||||
/** Add an intro point failure to the failure cache using the relay
|
||||
* <b>identity</b> and service ID <b>service_id</b>. Record the
|
||||
* <b>failure</b> in that object. */
|
||||
static void
|
||||
STATIC void
|
||||
cache_failure_intro_add(const uint8_t *identity, const char *service_id,
|
||||
rend_intro_point_failure_t failure)
|
||||
{
|
||||
@ -387,7 +388,7 @@ cache_failure_intro_add(const uint8_t *identity, const char *service_id,
|
||||
* descriptor and kept into the failure cache. Then, each intro points that
|
||||
* are NOT in the descriptor but in the failure cache for the given
|
||||
* <b>service_id</b> are removed from the failure cache. */
|
||||
static void
|
||||
STATIC void
|
||||
validate_intro_point_failure(const rend_service_descriptor_t *desc,
|
||||
const char *service_id)
|
||||
{
|
||||
@ -703,7 +704,6 @@ rend_cache_store_v2_desc_as_dir(const char *desc)
|
||||
log_info(LD_REND, "Successfully stored service descriptor with desc ID "
|
||||
"'%s' and len %d.",
|
||||
safe_str(desc_id_base32), (int)encoded_size);
|
||||
|
||||
/* Statistics: Note down this potentially new HS. */
|
||||
if (options->HiddenServiceStatistics) {
|
||||
rep_hist_stored_maybe_new_hs(e->parsed->pk);
|
||||
|
@ -85,5 +85,29 @@ void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
|
||||
const char *service_id);
|
||||
void rend_cache_failure_purge(void);
|
||||
|
||||
#ifdef RENDCACHE_PRIVATE
|
||||
|
||||
STATIC size_t rend_cache_entry_allocation(const rend_cache_entry_t *e);
|
||||
STATIC void rend_cache_entry_free(rend_cache_entry_t *e);
|
||||
STATIC void rend_cache_failure_intro_entry_free(rend_cache_failure_intro_t
|
||||
*entry);
|
||||
STATIC void rend_cache_failure_entry_free(rend_cache_failure_t *entry);
|
||||
STATIC int cache_failure_intro_lookup(const uint8_t *identity,
|
||||
const char *service_id,
|
||||
rend_cache_failure_intro_t
|
||||
**intro_entry);
|
||||
STATIC void rend_cache_decrement_allocation(size_t n);
|
||||
STATIC void rend_cache_increment_allocation(size_t n);
|
||||
STATIC rend_cache_failure_intro_t *rend_cache_failure_intro_entry_new(
|
||||
rend_intro_point_failure_t failure);
|
||||
STATIC rend_cache_failure_t *rend_cache_failure_entry_new(void);
|
||||
STATIC void rend_cache_failure_remove(rend_service_descriptor_t *desc);
|
||||
STATIC void cache_failure_intro_add(const uint8_t *identity,
|
||||
const char *service_id,
|
||||
rend_intro_point_failure_t failure);
|
||||
STATIC void validate_intro_point_failure(const rend_service_descriptor_t *desc,
|
||||
const char *service_id);
|
||||
#endif
|
||||
|
||||
#endif /* TOR_RENDCACHE_H */
|
||||
|
||||
|
@ -5214,4 +5214,3 @@ MOCK_IMPL(int, hid_serv_responsible_for_desc_id,
|
||||
smartlist_free(responsible);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -243,4 +243,3 @@ MOCK_DECL(STATIC void, initiate_descriptor_downloads,
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -50,6 +50,7 @@ src_test_AM_CPPFLAGS = -DSHARE_DATADIR="\"$(datadir)\"" \
|
||||
|
||||
src_test_test_SOURCES = \
|
||||
src/test/log_test_helpers.c \
|
||||
src/test/rend_test_helpers.c \
|
||||
src/test/test.c \
|
||||
src/test/test_accounting.c \
|
||||
src/test/test_addr.c \
|
||||
@ -88,6 +89,7 @@ src_test_test_SOURCES = \
|
||||
src/test/test_pt.c \
|
||||
src/test/test_relay.c \
|
||||
src/test/test_relaycell.c \
|
||||
src/test/test_rendcache.c \
|
||||
src/test/test_replay.c \
|
||||
src/test/test_routerkeys.c \
|
||||
src/test/test_routerlist.c \
|
||||
@ -100,7 +102,6 @@ src_test_test_SOURCES = \
|
||||
src/test/test_util.c \
|
||||
src/test/test_util_format.c \
|
||||
src/test/test_helpers.c \
|
||||
src/test/rend_test_helpers.c \
|
||||
src/test/test_dns.c \
|
||||
src/test/testing_common.c \
|
||||
src/ext/tinytest.c
|
||||
|
@ -1,7 +1,10 @@
|
||||
#include "rend_test_helpers.h"
|
||||
/* Copyright (c) 2014-2015, The Tor Project, Inc. */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
#include "or.h"
|
||||
#include "test.h"
|
||||
#include "rendcommon.h"
|
||||
#include "rend_test_helpers.h"
|
||||
|
||||
void
|
||||
generate_desc(int time_diff, rend_encoded_v2_service_descriptor_t **desc,
|
||||
|
@ -1154,6 +1154,7 @@ extern struct testcase_t policy_tests[];
|
||||
extern struct testcase_t pt_tests[];
|
||||
extern struct testcase_t relay_tests[];
|
||||
extern struct testcase_t relaycell_tests[];
|
||||
extern struct testcase_t rend_cache_tests[];
|
||||
extern struct testcase_t replaycache_tests[];
|
||||
extern struct testcase_t router_tests[];
|
||||
extern struct testcase_t routerkeys_tests[];
|
||||
@ -1205,6 +1206,7 @@ struct testgroup_t testgroups[] = {
|
||||
{ "pt/", pt_tests },
|
||||
{ "relay/" , relay_tests },
|
||||
{ "relaycell/", relaycell_tests },
|
||||
{ "rend_cache/", rend_cache_tests },
|
||||
{ "replaycache/", replaycache_tests },
|
||||
{ "routerkeys/", routerkeys_tests },
|
||||
{ "routerlist/", routerlist_tests },
|
||||
|
1254
src/test/test_rendcache.c
Normal file
1254
src/test/test_rendcache.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user