conscache.h 3.0 KB

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