Tor 0.4.9.2-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 "lib/cc/torint.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_desc_free | ( | val | ) | FREE_AND_NULL(hs_cache_client_descriptor_t, cache_client_desc_free_, (val)) |
Definition at line 439 of file hs_cache.c.
#define cache_client_intro_state_free | ( | val | ) |
Definition at line 631 of file hs_cache.c.
#define cache_dir_desc_free | ( | val | ) | FREE_AND_NULL(hs_cache_dir_descriptor_t, cache_dir_desc_free_, (val)) |
Definition at line 79 of file hs_cache.c.
#define cache_intro_state_free | ( | val | ) | FREE_AND_NULL(hs_cache_intro_state_t, cache_intro_state_free_, (val)) |
Definition at line 604 of file hs_cache.c.
#define HS_CACHE_PRIVATE |
Definition at line 10 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 858 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 299 of file hs_cache.c.
Referenced by hs_cache_clean_as_dir().
STATIC size_t cache_clean_v3_by_downloaded_as_dir | ( | const uint64_t | target, |
const size_t | max_remove_bytes, | ||
uint64_t * | next_lowest | ||
) |
Clean the v3 cache by removing entries that are below or equal the downloaded target.
Stop when the max_remove_bytes is reached. It is possible that more bytes are removed if max_remove_bytes is not aligned on cache entry size.
Return the amount of bytes freed. The next_lowest param is set to the lowest n_downloaded value in the cache that is above target.
If both next_lowest and returned value are 0, the cache is empty.
Definition at line 239 of file hs_cache.c.
Referenced by hs_cache_handle_oom().
|
static |
Free memory allocated by desc.
Definition at line 444 of file hs_cache.c.
|
static |
Helper function: Use by the free all function to clear the client cache
Definition at line 458 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 547 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 717 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 749 of file hs_cache.c.
|
static |
Free a cache_client_intro_state object.
Definition at line 637 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 648 of file hs_cache.c.
|
static |
Return true iff no intro points are in this cache.
Definition at line 765 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 658 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 624 of file hs_cache.c.
Referenced by cache_client_intro_state_add().
|
static |
Note the given failure in state.
Definition at line 692 of file hs_cache.c.
Referenced by hs_cache_client_intro_state_note().
|
static |
Free a directory descriptor object.
Definition at line 84 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 97 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 106 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 466 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 134 of file hs_cache.c.
|
static |
Free an hs_cache_intro_state_t object.
Definition at line 609 of file hs_cache.c.
Referenced by cache_intro_state_free_void().
|
static |
Helper function: used by the free all function.
Definition at line 616 of file hs_cache.c.
|
static |
Return a newly allocated and initialized hs_cache_intro_state_t object.
Definition at line 597 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 199 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 774 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 145 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 833 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 44 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 1027 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 422 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 1086 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 1076 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 1054 of file hs_cache.c.
Referenced by send_introduce1().
void hs_cache_client_intro_state_purge | ( | void | ) |
Purge the client introduction state cache.
Definition at line 1106 of file hs_cache.c.
bool hs_cache_client_new_auth_parse | ( | const ed25519_public_key_t * | service_pk | ) |
Definition at line 1123 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 1233 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 1210 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 1186 of file hs_cache.c.
size_t hs_cache_get_total_allocation | ( | void | ) |
Definition at line 1226 of file hs_cache.c.
size_t hs_cache_handle_oom | ( | 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 1157 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 1250 of file hs_cache.c.
void hs_cache_init | ( | void | ) |
Initialize the hidden service cache subsystem.
Definition at line 1195 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 928 of file hs_cache.c.
Referenced by client_desc_has_arrived(), client_get_random_intro(), close_or_reextend_intro_circ(), hs_client_setup_intro_circ_auth_key(), intro_points_all_timed_out(), pow_worker_replyfn(), and setup_rendezvous_circ_congestion_control().
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 385 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 908 of file hs_cache.c.
void hs_cache_mark_dowloaded_as_dir | ( | const hs_ident_dir_conn_t * | ident | ) |
Using the given directory identifier, lookup the descriptor in our cache and if present, increment the downloaded counter. This is done when the directory connection fetching this descriptor is closed.
Definition at line 408 of file hs_cache.c.
Referenced by connection_dir_about_to_close().
void hs_cache_purge_as_client | ( | void | ) |
Purge the client descriptor cache.
Definition at line 1036 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 995 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 959 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 348 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 520 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 hs_cache_dir_descriptor_t * lookup_v3_desc_as_dir | ( | const uint8_t * | key | ) |
Query our cache and return the entry or NULL if not found.
Definition at line 73 of file hs_cache.c.
Referenced by cache_store_v3_as_dir(), and hs_cache_mark_dowloaded_as_dir().
|
static |
Remove a given descriptor from our cache.
Definition at line 489 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 57 of file hs_cache.c.
|
static |
Store a given descriptor in our cache.
Definition at line 499 of file hs_cache.c.
|
static |
Store a given descriptor in our cache.
Definition at line 65 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 437 of file hs_cache.c.
Referenced by cache_client_intro_state_add(), and hs_cache_init().
|
static |
Definition at line 30 of file hs_cache.c.
|
static |
Client-side HS descriptor cache. Map indexed by service identity key.
Definition at line 432 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 53 of file hs_cache.c.
Referenced by cache_clean_v3_as_dir(), cache_clean_v3_by_downloaded_as_dir(), hs_cache_init(), lookup_v3_desc_as_dir(), remove_v3_desc_as_dir(), and store_v3_desc_as_dir().