tor  0.4.2.1-alpha-dev
hs_cache.h
Go to the documentation of this file.
1 /* Copyright (c) 2016-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
9 #ifndef TOR_HS_CACHE_H
10 #define TOR_HS_CACHE_H
11 
12 #include <stdint.h>
13 
14 #include "feature/hs/hs_common.h"
17 #include "feature/nodelist/torcert.h"
18 
20 
21 /* This is the maximum time an introduction point state object can stay in the
22  * client cache in seconds (2 mins or 120 seconds). */
23 #define HS_CACHE_CLIENT_INTRO_STATE_MAX_AGE (2 * 60)
24 
25 /* Introduction point state. */
26 typedef struct hs_cache_intro_state_t {
27  /* When this entry was created and put in the cache. */
28  time_t created_ts;
29 
30  /* Did it suffered a generic error? */
31  unsigned int error : 1;
32 
33  /* Did it timed out? */
34  unsigned int timed_out : 1;
35 
36  /* How many times we tried to reached it and it was unreachable. */
37  uint32_t unreachable_count;
39 
41  /* Contains hs_cache_intro_state_t object indexed by introduction point
42  * authentication key. */
43  digest256map_t *intro_points;
45 
46 /* Descriptor representation on the directory side which is a subset of
47  * information that the HSDir can decode and serve it. */
48 typedef struct hs_cache_dir_descriptor_t {
49  /* This object is indexed using the blinded pubkey located in the plaintext
50  * data which is populated only once the descriptor has been successfully
51  * decoded and validated. This simply points to that pubkey. */
52  const uint8_t *key;
53 
54  /* When does this entry has been created. Used to expire entries. */
55  time_t created_ts;
56 
57  /* Descriptor plaintext information. Obviously, we can't decrypt the
58  * encrypted part of the descriptor. */
59  hs_desc_plaintext_data_t *plaintext_data;
60 
61  /* Encoded descriptor which is basically in text form. It's a NUL terminated
62  * string thus safe to strlen(). */
63  char *encoded_desc;
65 
66 /* Public API */
67 
68 void hs_cache_init(void);
69 void hs_cache_free_all(void);
70 void hs_cache_clean_as_dir(time_t now);
71 size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes);
72 
73 unsigned int hs_cache_get_max_descriptor_size(void);
74 
75 /* Store and Lookup function. They are version agnostic that is depending on
76  * the requested version of the descriptor, it will be re-routed to the
77  * right function. */
78 int hs_cache_store_as_dir(const char *desc);
79 int hs_cache_lookup_as_dir(uint32_t version, const char *query,
80  const char **desc_out);
81 
82 const hs_descriptor_t *
84 const char *
86 int hs_cache_store_as_client(const char *desc_str,
87  const struct ed25519_public_key_t *identity_pk);
88 void hs_cache_clean_as_client(time_t now);
89 void hs_cache_purge_as_client(void);
90 
91 /* Client failure cache. */
92 void hs_cache_client_intro_state_note(
93  const struct ed25519_public_key_t *service_pk,
94  const struct ed25519_public_key_t *auth_key,
95  rend_intro_point_failure_t failure);
96 const hs_cache_intro_state_t *hs_cache_client_intro_state_find(
97  const struct ed25519_public_key_t *service_pk,
98  const struct ed25519_public_key_t *auth_key);
99 void hs_cache_client_intro_state_clean(time_t now);
100 void hs_cache_client_intro_state_purge(void);
101 
102 #ifdef HS_CACHE_PRIVATE
104 
106 typedef struct hs_cache_client_descriptor_t {
107  /* This object is indexed using the service identity public key */
108  struct ed25519_public_key_t key;
109 
110  /* When will this entry expire? We expire cached client descriptors in the
111  * start of the next time period, since that's when clients need to start
112  * using the next blinded key of the service. */
113  time_t expiration_ts;
114 
115  /* The cached descriptor, this object is the owner. It can't be NULL. A
116  * cache object without a valid descriptor is not possible. */
117  hs_descriptor_t *desc;
118 
119  /* Encoded descriptor in string form. Can't be NULL. */
120  char *encoded_desc;
121 } hs_cache_client_descriptor_t;
122 
123 STATIC size_t cache_clean_v3_as_dir(time_t now, time_t global_cutoff);
124 
125 STATIC hs_cache_client_descriptor_t *
126 lookup_v3_desc_as_client(const uint8_t *key);
127 
128 #endif /* defined(HS_CACHE_PRIVATE) */
129 
130 #endif /* !defined(TOR_HS_CACHE_H) */
Header file for rendcommon.c.
Header file containing common data for the whole HS subsytem.
int hs_cache_store_as_client(const char *desc_str, const ed25519_public_key_t *identity_pk)
Definition: hs_cache.c:775
const char * hs_cache_lookup_encoded_as_client(const ed25519_public_key_t *key)
Definition: hs_cache.c:739
Header for crypto_ed25519.c.
Header file for hs_descriptor.c.
const hs_descriptor_t * hs_cache_lookup_as_client(const ed25519_public_key_t *key)
Definition: hs_cache.c:757