Tor
0.4.7.0-alpha-dev
|
Handle hidden service descriptor caches. More...
#include "core/or/or.h"
#include "app/config/config.h"
#include "lib/crypt_ops/crypto_format.h"
#include "lib/crypt_ops/crypto_util.h"
#include "feature/hs/hs_ident.h"
#include "feature/hs/hs_common.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_descriptor.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/stats/rephist.h"
#include "feature/hs/hs_cache.h"
#include "feature/nodelist/networkstatus_st.h"
Go to the source code of this file.
Macros | |
#define | HS_CACHE_PRIVATE |
#define | cache_dir_desc_free(val) FREE_AND_NULL(hs_cache_dir_descriptor_t, cache_dir_desc_free_, (val)) |
#define | cache_client_desc_free(val) FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val)) |
#define | cache_intro_state_free(val) FREE_AND_NULL(hs_cache_intro_state_t, cache_intro_state_free_, (val)) |
#define | cache_client_intro_state_free(val) |
Variables | |
static size_t | hs_cache_total_allocation = 0 |
static digest256map_t * | hs_cache_v3_dir |
static digest256map_t * | hs_cache_v3_client |
static digest256map_t * | hs_cache_client_intro_state |
Handle hidden service descriptor caches.
Definition in file hs_cache.c.
#define cache_client_intro_state_free | ( | val | ) |
Definition at line 548 of file hs_cache.c.
|
static |
clean the client cache using now as the current time. Return the total size of removed bytes from the cache.
Definition at line 773 of file hs_cache.c.
Referenced by hs_cache_clean_as_client().
STATIC size_t cache_clean_v3_as_dir | ( | time_t | now, |
time_t | global_cutoff | ||
) |
Clean the v3 cache by removing any entry that has expired using the global_cutoff value. If global_cutoff is 0, the cleaning process will use the lifetime found in the plaintext data section. Return the number of bytes cleaned.
Definition at line 232 of file hs_cache.c.
Referenced by hs_cache_clean_as_dir().
|
static |
Free memory allocated by desc.
Definition at line 361 of file hs_cache.c.
|
static |
Helper function: Use by the free all function to clear the client cache
Definition at line 375 of file hs_cache.c.
|
static |
Parse the encoded descriptor in desc_str using service_identity_pk to decrypt it first.
If everything goes well, allocate and return a new hs_cache_client_descriptor_t object. In case of error, return NULL.
Definition at line 464 of file hs_cache.c.
Referenced by hs_cache_store_as_client().
|
static |
For the given service identity key service_pk and an introduction authentication key auth_key, add an entry in the client intro state cache If no entry exists for the service, it will create one. If state is non NULL, it will point to the new intro state entry.
Definition at line 632 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_note().
|
static |
Remove every intro point state entry from cache that has been created before or at the cutoff.
Definition at line 664 of file hs_cache.c.
|
static |
Free a cache_client_intro_state object.
Definition at line 554 of file hs_cache.c.
Referenced by cache_client_intro_state_free_void().
|
static |
Helper function: used by the free all function.
Definition at line 565 of file hs_cache.c.
|
static |
Return true iff no intro points are in this cache.
Definition at line 680 of file hs_cache.c.
|
static |
For the given service identity key service_pk and an introduction authentication key auth_key, lookup the intro state object. Return 1 if found and put it in entry if not NULL. Return 0 if not found and entry is untouched.
Definition at line 575 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_find(), and hs_cache_client_intro_state_note().
|
static |
Return a newly allocated and initialized hs_cache_client_intro_state_t object.
Definition at line 541 of file hs_cache.c.
Referenced by cache_client_intro_state_add().
|
static |
Note the given failure in state.
Definition at line 607 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_note().
|
static |
Free a directory descriptor object.
Definition at line 83 of file hs_cache.c.
Referenced by cache_dir_desc_free_void().
|
static |
Helper function: Use by the free all function using the digest256map interface to cache entries.
Definition at line 96 of file hs_cache.c.
|
static |
Create a new directory cache descriptor object from a encoded descriptor. On success, return the heap-allocated cache object, otherwise return NULL if we can't decode the descriptor.
Definition at line 105 of file hs_cache.c.
Referenced by hs_cache_store_as_dir().
|
static |
Return the size of a client cache entry in bytes.
Definition at line 383 of file hs_cache.c.
Referenced by remove_v3_desc_as_client().
|
static |
Return the size of a cache entry in bytes.
Definition at line 133 of file hs_cache.c.
|
static |
Free an hs_cache_intro_state_t object.
Definition at line 526 of file hs_cache.c.
Referenced by cache_intro_state_free_void().
|
static |
Helper function: used by the free all function.
Definition at line 533 of file hs_cache.c.
|
static |
Return a newly allocated and initialized hs_cache_intro_state_t object.
Definition at line 514 of file hs_cache.c.
Referenced by cache_client_intro_state_add().
|
static |
Using the query which is the base64 encoded blinded key of a version 3 descriptor, lookup in our directory cache the entry. If found, 1 is returned and desc_out is populated with a newly allocated string being the encoded descriptor. If not found, 0 is returned and desc_out is untouched. On error, a negative value is returned and desc_out is untouched.
Definition at line 198 of file hs_cache.c.
Referenced by hs_cache_lookup_as_dir().
|
static |
Check whether client_desc is useful for us, and store it in the client-side HS cache if so. The client_desc is freed if we already have a fresher (higher revision counter count) in the cache.
Definition at line 689 of file hs_cache.c.
|
static |
Try to store a valid version 3 descriptor in the directory cache. Return 0 on success else a negative value is returned indicating that we have a newer version in our cache. On error, caller is responsible to free the given descriptor desc.
Definition at line 144 of file hs_cache.c.
Referenced by hs_cache_store_as_dir().
|
static |
Return true iff the cached client descriptor at cached_desc has expired.
Definition at line 748 of file hs_cache.c.
Referenced by lookup_v3_desc_as_client().
|
inlinestatic |
Helper function: Return true iff the cache entry has a decrypted descriptor.
A NULL desc object in the entry means that we were not able to decrypt the descriptor because we are likely lacking client authorization. It is still a valid entry but some operations can't be done without the decrypted descriptor thus this function MUST be used to safe guard access to the decrypted desc object.
Definition at line 43 of file hs_cache.c.
Referenced by cache_get_client_entry_size(), cache_store_as_client(), hs_cache_lookup_as_client(), and hs_cache_remove_as_client().
void hs_cache_clean_as_client | ( | time_t | now | ) |
Clean all client caches using the current time now.
Definition at line 942 of file hs_cache.c.
Referenced by clean_caches_callback().
void hs_cache_clean_as_dir | ( | time_t | now | ) |
Clean all directory caches using the current time now.
Definition at line 339 of file hs_cache.c.
Referenced by clean_caches_callback().
void hs_cache_client_intro_state_clean | ( | time_t | now | ) |
Cleanup the client introduction state cache.
Definition at line 1001 of file hs_cache.c.
Referenced by rend_cache_failure_clean_callback().
const hs_cache_intro_state_t* hs_cache_client_intro_state_find | ( | const ed25519_public_key_t * | service_pk, |
const ed25519_public_key_t * | auth_key | ||
) |
For a given service identity public key and an introduction authentication key, return true iff it is present in the failure cache.
Definition at line 991 of file hs_cache.c.
Referenced by intro_point_is_usable().
void hs_cache_client_intro_state_note | ( | const ed25519_public_key_t * | service_pk, |
const ed25519_public_key_t * | auth_key, | ||
rend_intro_point_failure_t | failure | ||
) |
For a given service identity public key and an introduction authentication key, note the given failure in the client intro state cache.
Definition at line 969 of file hs_cache.c.
void hs_cache_client_intro_state_purge | ( | void | ) |
Purge the client introduction state cache.
Definition at line 1021 of file hs_cache.c.
void hs_cache_decrement_allocation | ( | size_t | n | ) |
Decrement the total bytes attributed to the rendezvous cache by n.
Definition at line 1164 of file hs_cache.c.
Referenced by remove_v3_desc_as_client().
void hs_cache_free_all | ( | void | ) |
Cleanup the hidden service cache subsystem.
Definition at line 1141 of file hs_cache.c.
Referenced by hs_free_all().
unsigned int hs_cache_get_max_descriptor_size | ( | void | ) |
Return the maximum size of a v3 HS descriptor.
Definition at line 1117 of file hs_cache.c.
size_t hs_cache_handle_oom | ( | time_t | now, |
size_t | min_remove_bytes | ||
) |
Do a round of OOM cleanup on all directory caches. Return the amount of removed bytes. It is possible that the returned value is lower than min_remove_bytes if the caches get emptied out so the caller should be aware of this.
Definition at line 1072 of file hs_cache.c.
void hs_cache_increment_allocation | ( | size_t | n | ) |
Increase the total bytes attributed to the rendezvous cache by n.
Definition at line 1181 of file hs_cache.c.
void hs_cache_init | ( | void | ) |
Initialize the hidden service cache subsystem.
Definition at line 1126 of file hs_cache.c.
Referenced by hs_init().
const hs_descriptor_t* hs_cache_lookup_as_client | ( | const ed25519_public_key_t * | key | ) |
Public API: Given the HS ed25519 identity public key in key, return its HS descriptor if it's stored in our cache, or NULL if not or if the descriptor was never decrypted. The later can happen if we are waiting for client authorization to be added.
Definition at line 843 of file hs_cache.c.
Referenced by client_desc_has_arrived(), client_get_random_intro(), close_or_reextend_intro_circ(), intro_points_all_timed_out(), and setup_intro_circ_auth_key().
int hs_cache_lookup_as_dir | ( | uint32_t | version, |
const char * | query, | ||
const char ** | desc_out | ||
) |
Using the query, lookup in our directory cache the entry. If found, 1 is returned and desc_out is populated with a newly allocated string being the encoded descriptor. If not found, 0 is returned and desc_out is untouched. On error, a negative value is returned and desc_out is untouched.
Definition at line 318 of file hs_cache.c.
Referenced by handle_get_hs_descriptor_v3().
const char* hs_cache_lookup_encoded_as_client | ( | const ed25519_public_key_t * | key | ) |
Public API: Given the HS ed25519 identity public key in key, return its HS encoded descriptor if it's stored in our cache, or NULL if not.
Definition at line 823 of file hs_cache.c.
void hs_cache_purge_as_client | ( | void | ) |
Purge the client descriptor cache.
Definition at line 951 of file hs_cache.c.
void hs_cache_remove_as_client | ( | const ed25519_public_key_t * | key | ) |
Remove and free a client cache descriptor entry for the given onion service ed25519 public key. If the descriptor is decoded, the intro circuits are closed if any.
This does nothing if no descriptor exists for the given key.
Definition at line 910 of file hs_cache.c.
hs_desc_decode_status_t hs_cache_store_as_client | ( | const char * | desc_str, |
const ed25519_public_key_t * | identity_pk | ||
) |
Public API: Given an encoded descriptor, store it in the client HS cache. Return a decode status which changes how we handle the SOCKS connection depending on its value:
HS_DESC_DECODE_OK: Returned on success. Descriptor was properly decoded and is now stored.
HS_DESC_DECODE_NEED_CLIENT_AUTH: Client authorization is needed but the descriptor was still stored.
HS_DESC_DECODE_BAD_CLIENT_AUTH: Client authorization for this descriptor was not usable but the descriptor was still stored.
Any other codes means indicate where the error occurred and the descriptor was not stored.
Definition at line 874 of file hs_cache.c.
Referenced by client_dir_fetch_200().
int hs_cache_store_as_dir | ( | const char * | desc | ) |
Given an encoded descriptor, store it in the directory cache depending on which version it is. Return a negative value on error. On success, 0 is returned.
Definition at line 281 of file hs_cache.c.
STATIC hs_cache_client_descriptor_t* lookup_v3_desc_as_client | ( | const uint8_t * | key | ) |
Query our cache and return the entry or NULL if not found or if expired.
Definition at line 437 of file hs_cache.c.
Referenced by cache_store_as_client(), hs_cache_lookup_as_client(), hs_cache_lookup_encoded_as_client(), and hs_cache_remove_as_client().
|
static |
Query our cache and return the entry or NULL if not found.
Definition at line 72 of file hs_cache.c.
Referenced by cache_store_v3_as_dir().
|
static |
Remove a given descriptor from our cache.
Definition at line 406 of file hs_cache.c.
Referenced by cache_store_as_client(), and hs_cache_remove_as_client().
|
static |
Remove a given descriptor from our cache.
Definition at line 56 of file hs_cache.c.
|
static |
Store a given descriptor in our cache.
Definition at line 416 of file hs_cache.c.
|
static |
Store a given descriptor in our cache.
Definition at line 64 of file hs_cache.c.
|
static |
Client-side introduction point state cache. Map indexed by service public identity key (onion address). It contains hs_cache_client_intro_state_t objects all related to a specific service.
Definition at line 354 of file hs_cache.c.
Referenced by cache_client_intro_state_add(), cache_client_intro_state_lookup(), and hs_cache_init().
|
static |
Client-side HS descriptor cache. Map indexed by service identity key.
Definition at line 349 of file hs_cache.c.
Referenced by cache_clean_v3_as_client(), hs_cache_init(), lookup_v3_desc_as_client(), remove_v3_desc_as_client(), and store_v3_desc_as_client().
|
static |
Directory descriptor cache. Map indexed by blinded key.
Definition at line 52 of file hs_cache.c.
Referenced by cache_clean_v3_as_dir(), hs_cache_init(), lookup_v3_desc_as_dir(), remove_v3_desc_as_dir(), and store_v3_desc_as_dir().