Tor
0.4.7.0-alpha-dev
|
Consensus and diff on-disk cache. More...
#include "core/or/or.h"
#include "app/config/config.h"
#include "feature/dircache/conscache.h"
#include "lib/crypt_ops/crypto_util.h"
#include "lib/fs/storagedir.h"
#include "lib/encoding/confline.h"
Go to the source code of this file.
Data Structures | |
struct | consensus_cache_entry_t |
struct | consensus_cache_t |
Macros | |
#define | CCE_MAGIC 0x17162253 |
Consensus and diff on-disk cache.
Definition in file conscache.c.
consensus_cache_entry_t* consensus_cache_add | ( | consensus_cache_t * | cache, |
const config_line_t * | labels, | ||
const uint8_t * | data, | ||
size_t | datalen | ||
) |
Write datalen bytes of data at data into the cache, labeling that data with labels. On failure, return NULL. On success, return a newly created consensus_cache_entry_t.
The returned value will be owned by the cache, and you will have a reference to it. Call consensus_cache_entry_decref() when you are done with it.
The provided labels MUST have distinct keys: if they don't, this API does not specify which values (if any) for the duplicate keys will be considered.
Definition at line 221 of file conscache.c.
|
static |
Helper: clear all entries from cache (but do not delete any that aren't marked for removal
Definition at line 179 of file conscache.c.
Referenced by consensus_cache_free_(), and consensus_cache_rescan().
void consensus_cache_delete_pending | ( | consensus_cache_t * | cache, |
int | force | ||
) |
Delete every element of cache has been marked with consensus_cache_entry_mark_for_removal. If force is false, retain those entries which are in use by something other than the cache.
Definition at line 509 of file conscache.c.
Referenced by consdiffmgr_ensure_space_for_files(), and consensus_cache_clear().
void consensus_cache_entry_decref | ( | consensus_cache_entry_t * | ent | ) |
Release a reference held to ent.
If it was the last reference, ent will be freed. Therefore, you must not use ent after calling this function.
Definition at line 370 of file conscache.c.
Referenced by consensus_cache_clear(), and spooled_resource_free_().
int consensus_cache_entry_get_body | ( | const consensus_cache_entry_t * | ent, |
const uint8_t ** | body_out, | ||
size_t * | sz_out | ||
) |
Try to read the body of ent into memory if it isn't already loaded. On success, set *body_out to the body, *sz_out to its size, and return 0. On failure return -1.
The resulting body pointer will only be valid for as long as you hold a reference to ent.
Definition at line 437 of file conscache.c.
Referenced by consensus_diff_worker_threadfn(), and uncompress_or_set_ptr().
const config_line_t* consensus_cache_entry_get_labels | ( | const consensus_cache_entry_t * | ent | ) |
Return a pointer to the labels in ent.
This pointer is only guaranteed to be valid for as long as you hold a reference to ent.
Definition at line 346 of file conscache.c.
const char* consensus_cache_entry_get_value | ( | const consensus_cache_entry_t * | ent, |
const char * | key | ||
) |
If ent has a label with the given key, return its value. Otherwise return NULL.
The return value is only guaranteed to be valid for as long as you hold a reference to ent.
Definition at line 329 of file conscache.c.
Referenced by cdm_entry_get_sha3_value(), compare_by_staleness_(), compare_by_valid_after_(), consensus_cache_entry_get_fresh_until(), consensus_cache_entry_get_valid_after(), consensus_cache_entry_get_valid_until(), consensus_cache_entry_get_voter_id_digests(), consensus_cache_find_all(), consensus_diff_worker_replyfn(), and uncompress_or_set_ptr().
void consensus_cache_entry_incref | ( | consensus_cache_entry_t * | ent | ) |
Increase the reference count of ent.
Definition at line 355 of file conscache.c.
Referenced by consensus_diff_queue_diff_work().
|
static |
Make sure that ent is mapped into RAM.
Definition at line 597 of file conscache.c.
void consensus_cache_entry_mark_for_aggressive_release | ( | consensus_cache_entry_t * | ent | ) |
Mark ent as the kind of entry that we don't need to keep mmap'd for any longer than we're actually using it.
Definition at line 423 of file conscache.c.
void consensus_cache_entry_mark_for_removal | ( | consensus_cache_entry_t * | ent | ) |
Mark ent for deletion from the cache. Deletion will not occur until the cache is the only place that holds a reference to ent.
Definition at line 413 of file conscache.c.
Referenced by consdiffmgr_ensure_space_for_files().
|
static |
Unmap ent from RAM.
Do not call this if something other than the cache is holding a reference to ent
Definition at line 615 of file conscache.c.
void consensus_cache_filter_list | ( | smartlist_t * | lst, |
const char * | key, | ||
const char * | value | ||
) |
Given a list of consensus_cache_entry_t, remove all those entries that do not have key=value in their labels.
Does not adjust reference counts.
Definition at line 305 of file conscache.c.
void consensus_cache_find_all | ( | smartlist_t * | out, |
consensus_cache_t * | cache, | ||
const char * | key, | ||
const char * | value | ||
) |
Given a cache, add every entry to out for which key=value. If key is NULL, add every entry.
Do not add any entry that has been marked for removal.
Does not adjust reference counts.
Definition at line 277 of file conscache.c.
Referenced by consdiffmgr_consensus_load(), consdiffmgr_diffs_load(), consdiffmgr_ensure_space_for_files(), consdiffmgr_rescan_flavor_(), consdiffmgr_set_cache_flags(), consdiffmgr_validate(), and consensus_cache_find_first().
consensus_cache_entry_t* consensus_cache_find_first | ( | consensus_cache_t * | cache, |
const char * | key, | ||
const char * | value | ||
) |
Given a cache, return some entry for which key=value. Return NULL if no such entry exists.
Does not adjust reference counts.
Definition at line 255 of file conscache.c.
void consensus_cache_free_ | ( | consensus_cache_t * | cache | ) |
Drop all storage held by cache.
Definition at line 195 of file conscache.c.
int consensus_cache_get_n_filenames_available | ( | consensus_cache_t * | cache | ) |
Return the number of currently unused filenames available in this cache.
Definition at line 489 of file conscache.c.
Referenced by consdiffmgr_ensure_space_for_files().
int consensus_cache_may_overallocate | ( | consensus_cache_t * | cache | ) |
Return true if it's okay to put more entries in this cache than its official file limit.
(We need this method on Windows, where we can't unlink files that are still in use, and therefore might need to temporarily exceed the file limit until the no-longer-wanted files are deletable.)
Definition at line 125 of file conscache.c.
consensus_cache_t* consensus_cache_open | ( | const char * | subdir, |
int | max_entries | ||
) |
Helper: Open a consensus cache in subdirectory subdir of the data directory, to hold up to max_entries of data.
Definition at line 85 of file conscache.c.
Referenced by cdm_cache_init().
int consensus_cache_register_with_sandbox | ( | consensus_cache_t * | cache, |
struct sandbox_cfg_elem_t ** | cfg | ||
) |
Tell the sandbox (if any) configured by cfg to allow the operations that cache will need.
Definition at line 149 of file conscache.c.
Referenced by consdiffmgr_register_with_sandbox().
|
static |
Internal helper: rescan cache and rebuild its list of entries.
Definition at line 548 of file conscache.c.
void consensus_cache_unmap_lazy | ( | consensus_cache_t * | cache, |
time_t | cutoff | ||
) |
Unmap every mmap'd element of cache that has been unused since cutoff.
Definition at line 465 of file conscache.c.