17 #define CCE_MAGIC 0x17162253
24 #define MUST_UNMAP_TO_UNLINK
87 int storagedir_max_entries;
89 char *directory = get_cachedir_fname(subdir);
92 #ifdef MUST_UNMAP_TO_UNLINK
98 #define VERY_LARGE_STORAGEDIR_LIMIT (1000*1000)
99 storagedir_max_entries = VERY_LARGE_STORAGEDIR_LIMIT;
103 storagedir_max_entries = max_entries;
128 #ifdef MUST_UNMAP_TO_UNLINK
139 #pragma GCC diagnostic push
140 #pragma GCC diagnostic ignored "-Wsuggest-attribute=noreturn"
150 struct sandbox_cfg_elem_t **cfg)
152 #ifdef MUST_UNMAP_TO_UNLINK
170 #pragma GCC diagnostic pop
184 ent->in_cache = NULL;
186 } SMARTLIST_FOREACH_END(ent);
187 smartlist_free(cache->
entries);
203 storage_dir_free(cache->
dir);
228 labels, data, datalen, &fname);
229 if (r < 0 || fname == NULL) {
234 ent->
magic = CCE_MAGIC;
262 if (smartlist_len(tmp))
263 ent = smartlist_get(tmp, 0);
283 if (ent->can_remove == 1) {
292 if (found_val && !strcmp(value, found_val)) {
295 } SMARTLIST_FOREACH_END(ent);
309 if (BUG(lst == NULL))
315 if (! found_val || strcmp(value, found_val)) {
318 } SMARTLIST_FOREACH_END(ent);
357 if (BUG(ent->
magic != CCE_MAGIC))
374 if (BUG(ent->
refcnt <= 0))
376 if (BUG(ent->
magic != CCE_MAGIC))
402 config_free_lines(ent->
labels);
403 consensus_cache_entry_handles_clear(ent);
438 const uint8_t **body_out,
441 if (BUG(ent->
magic != CCE_MAGIC))
455 *body_out = ent->
body;
468 tor_assert_nonfatal(ent->in_cache == cache);
469 if (ent->refcnt > 1 || BUG(ent->in_cache == NULL)) {
473 if (ent->unused_since > cutoff) {
477 if (ent->map == NULL) {
482 } SMARTLIST_FOREACH_END(ent);
494 #ifdef MUST_UNMAP_TO_UNLINK
498 tor_assert_nonfatal(max >= used);
512 tor_assert_nonfatal(ent->in_cache == cache);
513 int force_ent = force;
514 #ifdef MUST_UNMAP_TO_UNLINK
522 if (ent->refcnt > 1 || BUG(ent->in_cache == NULL)) {
527 if (ent->can_remove == 0) {
531 if (BUG(ent->refcnt <= 0)) {
536 ent->in_cache = NULL;
537 char *fname = tor_strdup(ent->fname);
541 } SMARTLIST_FOREACH_END(ent);
562 &labels, &body, &bodylen);
568 if (errno == ERANGE || errno == EINVAL) {
569 log_warn(
LD_FS,
"Found %s file %s in consensus cache; removing it.",
570 errno == ERANGE ?
"empty" :
"misformatted",
575 log_warn(
LD_FS,
"Unable to map file %s from consensus cache: %s",
576 escaped(fname), strerror(errno));
582 ent->
magic = CCE_MAGIC;
583 ent->
fname = tor_strdup(fname);
589 tor_munmap_file(map);
590 } SMARTLIST_FOREACH_END(fname);
621 tor_munmap_file(ent->
map);
630 #ifdef TOR_UNIT_TESTS
Header file for config.c.
const config_line_t * config_line_find(const config_line_t *lines, const char *key)
config_line_t * config_lines_dup(const config_line_t *inp)
void consensus_cache_entry_incref(consensus_cache_entry_t *ent)
const config_line_t * consensus_cache_entry_get_labels(const consensus_cache_entry_t *ent)
static void consensus_cache_rescan(consensus_cache_t *)
consensus_cache_entry_t * consensus_cache_add(consensus_cache_t *cache, const config_line_t *labels, const uint8_t *data, size_t datalen)
static void consensus_cache_entry_map(consensus_cache_t *, consensus_cache_entry_t *)
void consensus_cache_find_all(smartlist_t *out, consensus_cache_t *cache, const char *key, const char *value)
void consensus_cache_delete_pending(consensus_cache_t *cache, int force)
void consensus_cache_entry_mark_for_aggressive_release(consensus_cache_entry_t *ent)
int consensus_cache_get_n_filenames_available(consensus_cache_t *cache)
const char * consensus_cache_entry_get_value(const consensus_cache_entry_t *ent, const char *key)
consensus_cache_entry_t * consensus_cache_find_first(consensus_cache_t *cache, const char *key, const char *value)
int consensus_cache_may_overallocate(consensus_cache_t *cache)
void consensus_cache_free_(consensus_cache_t *cache)
int consensus_cache_register_with_sandbox(consensus_cache_t *cache, struct sandbox_cfg_elem_t **cfg)
void consensus_cache_filter_list(smartlist_t *lst, const char *key, const char *value)
void consensus_cache_entry_mark_for_removal(consensus_cache_entry_t *ent)
void consensus_cache_unmap_lazy(consensus_cache_t *cache, time_t cutoff)
static void consensus_cache_entry_unmap(consensus_cache_entry_t *ent)
void consensus_cache_entry_decref(consensus_cache_entry_t *ent)
int consensus_cache_entry_get_body(const consensus_cache_entry_t *ent, const uint8_t **body_out, size_t *sz_out)
consensus_cache_t * consensus_cache_open(const char *subdir, int max_entries)
static void consensus_cache_clear(consensus_cache_t *cache)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
const char * escaped(const char *s)
Master header file for Tor-specific functionality.
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_DEL_CURRENT(sl, var)
const smartlist_t * storage_dir_list(storage_dir_t *d)
int storage_dir_save_labeled_to_file(storage_dir_t *d, const config_line_t *labels, const uint8_t *data, size_t length, char **fname_out)
tor_mmap_t * storage_dir_map_labeled(storage_dir_t *dir, const char *fname, config_line_t **labels_out, const uint8_t **data_out, size_t *sz_out)
storage_dir_t * storage_dir_new(const char *dirname, int max_files)
void storage_dir_remove_file(storage_dir_t *d, const char *fname)
int storage_dir_register_with_sandbox(storage_dir_t *d, sandbox_cfg_t **cfg)
consensus_cache_t * in_cache
unsigned release_aggressively
#define tor_assert_nonfatal_unreached()