tor  0.4.1.0-alpha-dev
Data Structures | Macros | Typedefs | Enumerations | Functions
rendcache.h File Reference
#include "core/or/or.h"
#include "feature/rend/rendcommon.h"

Go to the source code of this file.

Data Structures

struct  rend_cache_entry_t
 
struct  rend_cache_failure_intro_t
 
struct  rend_cache_failure_t
 

Macros

#define REND_CACHE_MAX_AGE   (2*24*60*60)
 
#define REND_CACHE_MAX_SKEW   (24*60*60)
 
#define REND_CACHE_FAILURE_MAX_AGE   (5*60)
 
#define MAX_INTRO_POINTS   10
 

Typedefs

typedef struct rend_cache_entry_t rend_cache_entry_t
 
typedef struct rend_cache_failure_intro_t rend_cache_failure_intro_t
 
typedef struct rend_cache_failure_t rend_cache_failure_t
 

Enumerations

enum  rend_cache_type_t { REND_CACHE_TYPE_CLIENT = 1, REND_CACHE_TYPE_SERVICE = 2 }
 

Functions

static time_t rend_cache_max_entry_lifetime (void)
 
void rend_cache_init (void)
 
void rend_cache_clean (time_t now, rend_cache_type_t cache_type)
 
void rend_cache_failure_clean (time_t now)
 
size_t rend_cache_clean_v2_descs_as_dir (time_t cutoff)
 
void rend_cache_purge (void)
 
void rend_cache_free_all (void)
 
int rend_cache_lookup_entry (const char *query, int version, rend_cache_entry_t **entry_out)
 
int rend_cache_lookup_v2_desc_as_service (const char *query, rend_cache_entry_t **entry_out)
 
int rend_cache_lookup_v2_desc_as_dir (const char *query, const char **desc)
 
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)
 
size_t rend_cache_get_total_allocation (void)
 
void rend_cache_intro_failure_note (rend_intro_point_failure_t failure, const uint8_t *identity, const char *service_id)
 
void rend_cache_failure_purge (void)
 
void rend_cache_decrement_allocation (size_t n)
 
void rend_cache_increment_allocation (size_t n)
 

Detailed Description

Header file for rendcache.c.

Definition in file rendcache.h.

Macro Definition Documentation

◆ REND_CACHE_FAILURE_MAX_AGE

#define REND_CACHE_FAILURE_MAX_AGE   (5*60)

How old do we keep an intro point failure entry in the failure cache?

Definition at line 22 of file rendcache.h.

Referenced by rend_cache_failure_clean().

◆ REND_CACHE_MAX_AGE

#define REND_CACHE_MAX_AGE   (2*24*60*60)

How old do we let hidden service descriptors get before discarding them as too old?

Definition at line 17 of file rendcache.h.

Referenced by rend_cache_clean(), and rend_cache_store_v2_desc_as_dir().

◆ REND_CACHE_MAX_SKEW

#define REND_CACHE_MAX_SKEW   (24*60*60)

How wrong do we assume our clock may be when checking whether hidden services are too old or too new?

Definition at line 20 of file rendcache.h.

Referenced by rend_cache_clean(), and rend_cache_store_v2_desc_as_dir().

Typedef Documentation

◆ rend_cache_entry_t

A cached rendezvous descriptor.

◆ rend_cache_failure_t

Cache failure object indexed by service ID.

Function Documentation

◆ rend_cache_clean()

void rend_cache_clean ( time_t  now,
rend_cache_type_t  cache_type 
)

Removes all old entries from the client or service descriptor cache.

Definition at line 276 of file rendcache.c.

References REND_CACHE_MAX_AGE, and REND_CACHE_MAX_SKEW.

Referenced by clean_caches_callback().

◆ rend_cache_clean_v2_descs_as_dir()

size_t rend_cache_clean_v2_descs_as_dir ( time_t  cutoff)

Remove all old v2 descriptors and those for which this hidden service directory is not responsible for any more. The cutoff is the time limit for which we want to keep the cache entry. In other words, any entry created before will be removed.

Definition at line 473 of file rendcache.c.

References base32_encode(), DIGEST_LEN, rend_cache_entry_t::parsed, rend_cache_v2_dir, REND_DESC_ID_V2_LEN_BASE32, and rend_service_descriptor_t::timestamp.

◆ rend_cache_decrement_allocation()

void rend_cache_decrement_allocation ( size_t  n)

Decrement the total bytes attributed to the rendezvous cache by n.

Definition at line 94 of file rendcache.c.

Referenced by rend_cache_entry_free_().

◆ rend_cache_failure_clean()

void rend_cache_failure_clean ( time_t  now)

Remove all entries that re REND_CACHE_FAILURE_MAX_AGE old. This is called every second.

We have to clean these regurlarly else if for whatever reasons an hidden service goes offline and a client tries to connect to it during that time, a failure entry is created and the client will be unable to connect for a while even though the service has return online.

Definition at line 252 of file rendcache.c.

References REND_CACHE_FAILURE_MAX_AGE.

Referenced by rend_cache_failure_clean_callback().

◆ rend_cache_failure_purge()

void rend_cache_failure_purge ( void  )

Remove ALL entries from the failure cache. This is also called when a NEWNYM signal is received.

Definition at line 319 of file rendcache.c.

References rend_cache_failure.

Referenced by rend_client_purge_state().

◆ rend_cache_free_all()

void rend_cache_free_all ( void  )

Free all storage held by the service descriptor cache.

Definition at line 231 of file rendcache.c.

◆ rend_cache_increment_allocation()

void rend_cache_increment_allocation ( size_t  n)

Increase the total bytes attributed to the rendezvous cache by n.

Definition at line 111 of file rendcache.c.

◆ rend_cache_init()

void rend_cache_init ( void  )

Initializes the service descriptor cache.

Definition at line 66 of file rendcache.c.

References rend_cache, rend_cache_failure, rend_cache_local_service, and rend_cache_v2_dir.

Referenced by tor_init().

◆ rend_cache_intro_failure_note()

void rend_cache_intro_failure_note ( rend_intro_point_failure_t  failure,
const uint8_t *  identity,
const char *  service_id 
)

Note down an intro failure in the rend failure cache using the type of failure in failure for the relay identity digest in identity and service ID service_id. If an entry already exists in the cache, the failure type is changed with failure.

Definition at line 452 of file rendcache.c.

References cache_failure_intro_add(), and cache_failure_intro_lookup().

◆ rend_cache_lookup_entry()

int rend_cache_lookup_entry ( const char *  query,
int  version,
rend_cache_entry_t **  e 
)

Lookup in the client cache the given service ID query for version.

Return 0 if found and if e is non NULL, set it with the entry found. Else, a negative value is returned and e is untouched. -EINVAL means that query is not a valid service id. -ENOENT means that no entry in the cache was found.

Definition at line 509 of file rendcache.c.

References rend_cache, REND_SERVICE_ID_LEN_BASE32, rend_valid_v2_service_id(), and tor_assert().

◆ rend_cache_lookup_v2_desc_as_dir()

int rend_cache_lookup_v2_desc_as_dir ( const char *  desc_id,
const char **  desc 
)

Lookup the v2 service descriptor with base32-encoded desc_id and copy the pointer to it to *desc. Return 1 on success, 0 on well-formed-but-not-found, and -1 on failure.

Definition at line 590 of file rendcache.c.

References base32_decode(), DIGEST_LEN, log_fn, rend_cache_v2_dir, REND_DESC_ID_V2_LEN_BASE32, and tor_assert().

◆ rend_cache_purge()

void rend_cache_purge ( void  )

Remove ALL entries from the rendezvous service descriptor cache.

Definition at line 307 of file rendcache.c.

References rend_cache.

Referenced by rend_client_purge_state().

◆ rend_cache_store_v2_desc_as_client()

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 
)

Parse the v2 service descriptor in desc, decrypt the included list of introduction points with descriptor_cookie (which may also be NULL if decryption is not necessary), and store the descriptor to the local cache under its version and service id.

If we have a newer v2 descriptor with the same ID, ignore this one. If we have an older descriptor with the same ID, replace it. If the descriptor's service ID does not match rend_query->onion_address, reject it.

If the descriptor's descriptor ID doesn't match desc_id_base32, reject it.

Return 0 on success, or -1 if we rejected the descriptor. If entry is not NULL, set it with the cache entry pointer of the descriptor.

Definition at line 815 of file rendcache.c.

References DIGEST_LEN, and REND_SERVICE_ID_LEN_BASE32.

◆ rend_cache_store_v2_desc_as_dir()

int rend_cache_store_v2_desc_as_dir ( const char *  desc)

Parse the v2 service descriptor(s) in desc and store it/them to the local rend cache. Don't attempt to decrypt the included list of introduction points (as we don't have a descriptor cookie for it).

If we have a newer descriptor with the same ID, ignore this one. If we have an older descriptor with the same ID, replace it.

Return 0 on success, or -1 if we couldn't parse any of them.

We should only call this function for public (e.g. non bridge) relays.

Definition at line 625 of file rendcache.c.

References base32_encode(), DIGEST_LEN, REND_CACHE_MAX_AGE, REND_CACHE_MAX_SKEW, rend_cache_v2_dir, REND_DESC_ID_V2_LEN_BASE32, rend_parse_v2_service_descriptor(), rend_service_descriptor_t::timestamp, tor_assert(), and tor_free.

◆ rend_cache_store_v2_desc_as_service()

int rend_cache_store_v2_desc_as_service ( const char *  desc)

Parse the v2 service descriptor in desc and store it to the local service rend cache. Don't attempt to decrypt the included list of introduction points.

If we have a newer descriptor with the same ID, ignore this one. If we have an older descriptor with the same ID, replace it.

Return 0 on success, or -1 if we couldn't understand the descriptor.

Definition at line 734 of file rendcache.c.

References DIGEST_LEN, rend_cache_local_service, rend_parse_v2_service_descriptor(), REND_SERVICE_ID_LEN_BASE32, and tor_assert().