conscache.h (3161B)
1 /* Copyright (c) 2017-2021, The Tor Project, Inc. */ 2 /* See LICENSE for licensing information */ 3 4 /** 5 * @file conscache.h 6 * @brief Header for conscache.c 7 **/ 8 9 #ifndef TOR_CONSCACHE_H 10 #define TOR_CONSCACHE_H 11 12 #include "lib/container/handles.h" 13 14 typedef struct consensus_cache_entry_t consensus_cache_entry_t; 15 typedef struct consensus_cache_t consensus_cache_t; 16 17 struct config_line_t; 18 19 HANDLE_DECL(consensus_cache_entry, consensus_cache_entry_t, ) 20 #define consensus_cache_entry_handle_free(h) \ 21 FREE_AND_NULL(consensus_cache_entry_handle_t, \ 22 consensus_cache_entry_handle_free_, (h)) 23 24 consensus_cache_t *consensus_cache_open(const char *subdir, int max_entries); 25 void consensus_cache_free_(consensus_cache_t *cache); 26 #define consensus_cache_free(cache) \ 27 FREE_AND_NULL(consensus_cache_t, consensus_cache_free_, (cache)) 28 struct sandbox_cfg_elem_t; 29 int consensus_cache_may_overallocate(consensus_cache_t *cache); 30 int consensus_cache_register_with_sandbox(consensus_cache_t *cache, 31 struct sandbox_cfg_elem_t **cfg); 32 void consensus_cache_unmap_lazy(consensus_cache_t *cache, time_t cutoff); 33 void consensus_cache_delete_pending(consensus_cache_t *cache, 34 int force); 35 int consensus_cache_get_n_filenames_available(consensus_cache_t *cache); 36 consensus_cache_entry_t *consensus_cache_add(consensus_cache_t *cache, 37 const struct config_line_t *labels, 38 const uint8_t *data, 39 size_t datalen); 40 41 consensus_cache_entry_t *consensus_cache_find_first( 42 consensus_cache_t *cache, 43 const char *key, 44 const char *value); 45 46 void consensus_cache_find_all(smartlist_t *out, 47 consensus_cache_t *cache, 48 const char *key, 49 const char *value); 50 void consensus_cache_filter_list(smartlist_t *lst, 51 const char *key, 52 const char *value); 53 54 const char *consensus_cache_entry_get_value(const consensus_cache_entry_t *ent, 55 const char *key); 56 const struct config_line_t *consensus_cache_entry_get_labels( 57 const consensus_cache_entry_t *ent); 58 59 void consensus_cache_entry_incref(consensus_cache_entry_t *ent); 60 void consensus_cache_entry_decref(consensus_cache_entry_t *ent); 61 62 void consensus_cache_entry_mark_for_removal(consensus_cache_entry_t *ent); 63 void consensus_cache_entry_mark_for_aggressive_release( 64 consensus_cache_entry_t *ent); 65 int consensus_cache_entry_get_body(const consensus_cache_entry_t *ent, 66 const uint8_t **body_out, 67 size_t *sz_out); 68 69 #ifdef TOR_UNIT_TESTS 70 int consensus_cache_entry_is_mapped(consensus_cache_entry_t *ent); 71 #endif 72 73 #endif /* !defined(TOR_CONSCACHE_H) */