2017-03-15 21:13:17 +01:00
|
|
|
/* Copyright (c) 2015-2017, The Tor Project, Inc. */
|
2015-06-18 17:00:10 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file rendcache.h
|
|
|
|
* \brief Header file for rendcache.c
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef TOR_RENDCACHE_H
|
|
|
|
#define TOR_RENDCACHE_H
|
|
|
|
|
|
|
|
#include "or.h"
|
2015-06-18 22:09:18 +02:00
|
|
|
#include "rendcommon.h"
|
2015-06-18 17:00:10 +02:00
|
|
|
|
2015-06-18 17:23:08 +02:00
|
|
|
/** How old do we let hidden service descriptors get before discarding
|
|
|
|
* them as too old? */
|
|
|
|
#define REND_CACHE_MAX_AGE (2*24*60*60)
|
|
|
|
/** How wrong do we assume our clock may be when checking whether hidden
|
|
|
|
* services are too old or too new? */
|
|
|
|
#define REND_CACHE_MAX_SKEW (24*60*60)
|
2015-08-05 20:06:09 +02:00
|
|
|
/** How old do we keep an intro point failure entry in the failure cache? */
|
|
|
|
#define REND_CACHE_FAILURE_MAX_AGE (5*60)
|
2015-06-18 17:23:08 +02:00
|
|
|
|
|
|
|
/* Do not allow more than this many introduction points in a hidden service
|
|
|
|
* descriptor */
|
|
|
|
#define MAX_INTRO_POINTS 10
|
|
|
|
|
2015-06-18 17:00:10 +02:00
|
|
|
/** A cached rendezvous descriptor. */
|
|
|
|
typedef struct rend_cache_entry_t {
|
|
|
|
size_t len; /**< Length of <b>desc</b> */
|
|
|
|
time_t last_served; /**< When did we last write this one to somebody?
|
|
|
|
* (HSDir only) */
|
|
|
|
char *desc; /**< Service descriptor */
|
|
|
|
rend_service_descriptor_t *parsed; /**< Parsed value of 'desc' */
|
|
|
|
} rend_cache_entry_t;
|
|
|
|
|
2015-06-18 22:09:18 +02:00
|
|
|
/* Introduction point failure type. */
|
|
|
|
typedef struct rend_cache_failure_intro_t {
|
2015-08-05 19:48:12 +02:00
|
|
|
/* When this intro point failure occured thus we allocated this object and
|
|
|
|
* cache it. */
|
|
|
|
time_t created_ts;
|
2015-06-25 22:13:15 +02:00
|
|
|
rend_intro_point_failure_t failure_type;
|
2015-06-18 22:09:18 +02:00
|
|
|
} rend_cache_failure_intro_t;
|
|
|
|
|
|
|
|
/** Cache failure object indexed by service ID. */
|
|
|
|
typedef struct rend_cache_failure_t {
|
|
|
|
/* Contains rend_cache_failure_intro_t indexed by identity digest. */
|
|
|
|
digestmap_t *intro_failures;
|
|
|
|
} rend_cache_failure_t;
|
|
|
|
|
2015-08-03 17:33:28 +02:00
|
|
|
typedef enum {
|
|
|
|
REND_CACHE_TYPE_CLIENT = 1,
|
|
|
|
REND_CACHE_TYPE_SERVICE = 2,
|
|
|
|
} rend_cache_type_t;
|
|
|
|
|
2016-03-29 21:08:04 +02:00
|
|
|
/* Return maximum lifetime in seconds of a cache entry. */
|
|
|
|
static inline time_t
|
|
|
|
rend_cache_max_entry_lifetime(void)
|
|
|
|
{
|
|
|
|
return REND_CACHE_MAX_AGE + REND_CACHE_MAX_SKEW;
|
|
|
|
}
|
|
|
|
|
2015-06-18 17:23:08 +02:00
|
|
|
void rend_cache_init(void);
|
2015-08-25 16:35:35 +02:00
|
|
|
void rend_cache_clean(time_t now, rend_cache_type_t cache_type);
|
2015-08-05 20:06:09 +02:00
|
|
|
void rend_cache_failure_clean(time_t now);
|
2016-03-29 21:08:04 +02:00
|
|
|
size_t rend_cache_clean_v2_descs_as_dir(time_t cutoff);
|
2015-06-18 17:23:08 +02:00
|
|
|
void rend_cache_purge(void);
|
|
|
|
void rend_cache_free_all(void);
|
|
|
|
int rend_cache_lookup_entry(const char *query, int version,
|
2015-09-01 21:19:01 +02:00
|
|
|
rend_cache_entry_t **entry_out);
|
|
|
|
int rend_cache_lookup_v2_desc_as_service(const char *query,
|
|
|
|
rend_cache_entry_t **entry_out);
|
2015-06-18 17:23:08 +02:00
|
|
|
int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
|
|
|
|
|
2016-03-08 01:29:05 +01:00
|
|
|
int rend_cache_store_v2_desc_as_dir(const char *desc);
|
|
|
|
int rend_cache_store_v2_desc_as_service(const char *desc);
|
|
|
|
int rend_cache_store_v2_desc_as_client(const char *desc,
|
|
|
|
const char *desc_id_base32,
|
|
|
|
const rend_data_t *rend_query,
|
|
|
|
rend_cache_entry_t **entry);
|
2015-06-18 17:23:08 +02:00
|
|
|
size_t rend_cache_get_total_allocation(void);
|
|
|
|
|
2015-06-25 22:13:15 +02:00
|
|
|
void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
|
2015-06-18 22:09:18 +02:00
|
|
|
const uint8_t *identity,
|
|
|
|
const char *service_id);
|
2015-06-25 21:11:40 +02:00
|
|
|
void rend_cache_failure_purge(void);
|
2016-03-29 21:08:04 +02:00
|
|
|
void rend_cache_decrement_allocation(size_t n);
|
|
|
|
void rend_cache_increment_allocation(size_t n);
|
2015-06-18 22:09:18 +02:00
|
|
|
|
2015-09-15 16:21:50 +02:00
|
|
|
#ifdef RENDCACHE_PRIVATE
|
2015-10-05 21:31:10 +02:00
|
|
|
|
2015-09-15 16:21:50 +02:00
|
|
|
STATIC size_t rend_cache_entry_allocation(const rend_cache_entry_t *e);
|
|
|
|
STATIC void rend_cache_entry_free(rend_cache_entry_t *e);
|
2015-10-05 21:31:10 +02:00
|
|
|
STATIC void rend_cache_failure_intro_entry_free(rend_cache_failure_intro_t
|
|
|
|
*entry);
|
2015-09-15 16:21:50 +02:00
|
|
|
STATIC void rend_cache_failure_entry_free(rend_cache_failure_t *entry);
|
2015-10-05 21:31:10 +02:00
|
|
|
STATIC int cache_failure_intro_lookup(const uint8_t *identity,
|
|
|
|
const char *service_id,
|
|
|
|
rend_cache_failure_intro_t
|
|
|
|
**intro_entry);
|
|
|
|
STATIC rend_cache_failure_intro_t *rend_cache_failure_intro_entry_new(
|
|
|
|
rend_intro_point_failure_t failure);
|
2015-09-15 16:21:50 +02:00
|
|
|
STATIC rend_cache_failure_t *rend_cache_failure_entry_new(void);
|
|
|
|
STATIC void rend_cache_failure_remove(rend_service_descriptor_t *desc);
|
2015-10-05 21:31:10 +02:00
|
|
|
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);
|
2015-10-21 16:54:07 +02:00
|
|
|
|
|
|
|
STATIC void rend_cache_failure_entry_free_(void *entry);
|
2016-06-02 15:46:12 +02:00
|
|
|
|
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
extern strmap_t *rend_cache;
|
|
|
|
extern strmap_t *rend_cache_failure;
|
|
|
|
extern digestmap_t *rend_cache_v2_dir;
|
|
|
|
extern size_t rend_cache_total_allocation;
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(TOR_UNIT_TESTS) */
|
|
|
|
#endif /* defined(RENDCACHE_PRIVATE) */
|
2015-09-15 16:21:50 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_RENDCACHE_H) */
|
2015-07-16 17:10:14 +02:00
|
|
|
|