tor  0.4.1.0-alpha-dev
rendcache.h
Go to the documentation of this file.
1 /* Copyright (c) 2015-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
9 #ifndef TOR_RENDCACHE_H
10 #define TOR_RENDCACHE_H
11 
12 #include "core/or/or.h"
14 
17 #define REND_CACHE_MAX_AGE (2*24*60*60)
18 
20 #define REND_CACHE_MAX_SKEW (24*60*60)
21 
22 #define REND_CACHE_FAILURE_MAX_AGE (5*60)
23 
24 /* Do not allow more than this many introduction points in a hidden service
25  * descriptor */
26 #define MAX_INTRO_POINTS 10
27 
29 typedef struct rend_cache_entry_t {
30  size_t len;
31  time_t last_served;
33  char *desc;
36 
37 /* Introduction point failure type. */
39  /* When this intro point failure occurred thus we allocated this object and
40  * cache it. */
41  time_t created_ts;
42  rend_intro_point_failure_t failure_type;
44 
46 typedef struct rend_cache_failure_t {
47  /* Contains rend_cache_failure_intro_t indexed by identity digest. */
48  digestmap_t *intro_failures;
50 
51 typedef enum {
52  REND_CACHE_TYPE_CLIENT = 1,
53  REND_CACHE_TYPE_SERVICE = 2,
54 } rend_cache_type_t;
55 
56 /* Return maximum lifetime in seconds of a cache entry. */
57 static inline time_t
58 rend_cache_max_entry_lifetime(void)
59 {
61 }
62 
63 void rend_cache_init(void);
64 void rend_cache_clean(time_t now, rend_cache_type_t cache_type);
65 void rend_cache_failure_clean(time_t now);
66 size_t rend_cache_clean_v2_descs_as_dir(time_t cutoff);
67 void rend_cache_purge(void);
68 void rend_cache_free_all(void);
69 int rend_cache_lookup_entry(const char *query, int version,
70  rend_cache_entry_t **entry_out);
71 int rend_cache_lookup_v2_desc_as_service(const char *query,
72  rend_cache_entry_t **entry_out);
73 int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
74 
75 int rend_cache_store_v2_desc_as_dir(const char *desc);
76 int rend_cache_store_v2_desc_as_service(const char *desc);
77 int rend_cache_store_v2_desc_as_client(const char *desc,
78  const char *desc_id_base32,
79  const rend_data_t *rend_query,
80  rend_cache_entry_t **entry);
81 size_t rend_cache_get_total_allocation(void);
82 
83 void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
84  const uint8_t *identity,
85  const char *service_id);
86 void rend_cache_failure_purge(void);
87 void rend_cache_decrement_allocation(size_t n);
88 void rend_cache_increment_allocation(size_t n);
89 
90 #ifdef RENDCACHE_PRIVATE
91 
92 STATIC size_t rend_cache_entry_allocation(const rend_cache_entry_t *e);
94 #define rend_cache_entry_free(e) \
95  FREE_AND_NULL(rend_cache_entry_t, rend_cache_entry_free_, (e))
97  *entry);
98 #define rend_cache_failure_intro_entry_free(e) \
99  FREE_AND_NULL(rend_cache_failure_intro_t, \
100  rend_cache_failure_intro_entry_free_, (e))
102 #define rend_cache_failure_entry_free(e) \
103  FREE_AND_NULL(rend_cache_failure_t, \
104  rend_cache_failure_entry_free_, (e))
105 STATIC int cache_failure_intro_lookup(const uint8_t *identity,
106  const char *service_id,
108  **intro_entry);
110  rend_intro_point_failure_t failure);
113 STATIC void cache_failure_intro_add(const uint8_t *identity,
114  const char *service_id,
115  rend_intro_point_failure_t failure);
117  const char *service_id);
118 
119 STATIC void rend_cache_failure_entry_free_void(void *entry);
120 
121 #ifdef TOR_UNIT_TESTS
122 extern strmap_t *rend_cache;
123 extern strmap_t *rend_cache_failure;
124 extern digestmap_t *rend_cache_v2_dir;
125 extern size_t rend_cache_total_allocation;
126 #endif /* defined(TOR_UNIT_TESTS) */
127 #endif /* defined(RENDCACHE_PRIVATE) */
128 
129 #endif /* !defined(TOR_RENDCACHE_H) */
130 
int rend_cache_store_v2_desc_as_dir(const char *desc)
Definition: rendcache.c:625
void rend_cache_free_all(void)
Definition: rendcache.c:231
STATIC strmap_t * rend_cache
Definition: rendcache.c:24
Header file for rendcommon.c.
void rend_cache_clean(time_t now, rend_cache_type_t cache_type)
Definition: rendcache.c:276
STATIC void rend_cache_failure_remove(rend_service_descriptor_t *desc)
Definition: rendcache.c:188
rend_service_descriptor_t * parsed
Definition: rendcache.h:34
STATIC void cache_failure_intro_add(const uint8_t *identity, const char *service_id, rend_intro_point_failure_t failure)
Definition: rendcache.c:377
STATIC strmap_t * rend_cache_failure
Definition: rendcache.c:58
size_t len
Definition: rendcache.h:30
STATIC void rend_cache_entry_free_(rend_cache_entry_t *e)
Definition: rendcache.c:208
STATIC int cache_failure_intro_lookup(const uint8_t *identity, const char *service_id, rend_cache_failure_intro_t **intro_entry)
Definition: rendcache.c:333
#define REND_CACHE_MAX_SKEW
Definition: rendcache.h:20
STATIC void rend_cache_failure_entry_free_(rend_cache_failure_t *entry)
Definition: rendcache.c:154
STATIC digestmap_t * rend_cache_v2_dir
Definition: rendcache.c:31
void rend_cache_intro_failure_note(rend_intro_point_failure_t failure, const uint8_t *identity, const char *service_id)
Definition: rendcache.c:452
STATIC void rend_cache_failure_entry_free_void(void *entry)
Definition: rendcache.c:170
Definition: rendcache.h:29
struct rend_cache_entry_t rend_cache_entry_t
size_t rend_cache_clean_v2_descs_as_dir(time_t cutoff)
Definition: rendcache.c:473
int rend_cache_lookup_entry(const char *query, int version, rend_cache_entry_t **entry_out)
Definition: rendcache.c:509
Master header file for Tor-specific functionality.
STATIC void rend_cache_failure_intro_entry_free_(rend_cache_failure_intro_t *entry)
Definition: rendcache.c:127
struct rend_cache_failure_t rend_cache_failure_t
void rend_cache_purge(void)
Definition: rendcache.c:307
time_t last_served
Definition: rendcache.h:31
STATIC rend_cache_failure_intro_t * rend_cache_failure_intro_entry_new(rend_intro_point_failure_t failure)
Definition: rendcache.c:144
void rend_cache_init(void)
Definition: rendcache.c:66
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)
Definition: rendcache.c:815
char * desc
Definition: rendcache.h:33
int rend_cache_store_v2_desc_as_service(const char *desc)
Definition: rendcache.c:734
#define REND_CACHE_MAX_AGE
Definition: rendcache.h:17
void rend_cache_failure_purge(void)
Definition: rendcache.c:319
STATIC void validate_intro_point_failure(const rend_service_descriptor_t *desc, const char *service_id)
Definition: rendcache.c:404
STATIC rend_cache_failure_t * rend_cache_failure_entry_new(void)
Definition: rendcache.c:178
STATIC size_t rend_cache_entry_allocation(const rend_cache_entry_t *e)
Definition: rendcache.c:76
void rend_cache_increment_allocation(size_t n)
Definition: rendcache.c:111
void rend_cache_decrement_allocation(size_t n)
Definition: rendcache.c:94
void rend_cache_failure_clean(time_t now)
Definition: rendcache.c:252
int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc)
Definition: rendcache.c:590