consdiffmgr.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Copyright (c) 2017-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_CONSDIFFMGR_H
  4. #define TOR_CONSDIFFMGR_H
  5. enum compress_method_t;
  6. /**
  7. * Possible outcomes from trying to look up a given consensus diff.
  8. */
  9. typedef enum consdiff_status_t {
  10. CONSDIFF_AVAILABLE,
  11. CONSDIFF_NOT_FOUND,
  12. CONSDIFF_IN_PROGRESS,
  13. } consdiff_status_t;
  14. typedef struct consdiff_cfg_t {
  15. int32_t cache_max_num;
  16. } consdiff_cfg_t;
  17. struct consensus_cache_entry_t; // from conscache.h
  18. int consdiffmgr_add_consensus(const char *consensus,
  19. size_t consensus_len,
  20. const networkstatus_t *as_parsed);
  21. consdiff_status_t consdiffmgr_find_consensus(
  22. struct consensus_cache_entry_t **entry_out,
  23. consensus_flavor_t flavor,
  24. enum compress_method_t method);
  25. consdiff_status_t consdiffmgr_find_diff_from(
  26. struct consensus_cache_entry_t **entry_out,
  27. consensus_flavor_t flavor,
  28. int digest_type,
  29. const uint8_t *digest,
  30. size_t digestlen,
  31. enum compress_method_t method);
  32. int consensus_cache_entry_get_voter_id_digests(
  33. const struct consensus_cache_entry_t *ent,
  34. smartlist_t *out);
  35. int consensus_cache_entry_get_fresh_until(
  36. const struct consensus_cache_entry_t *ent,
  37. time_t *out);
  38. int consensus_cache_entry_get_valid_until(
  39. const struct consensus_cache_entry_t *ent,
  40. time_t *out);
  41. int consensus_cache_entry_get_valid_after(
  42. const struct consensus_cache_entry_t *ent,
  43. time_t *out);
  44. void consdiffmgr_rescan(void);
  45. int consdiffmgr_cleanup(void);
  46. void consdiffmgr_enable_background_compression(void);
  47. void consdiffmgr_configure(const consdiff_cfg_t *cfg);
  48. struct sandbox_cfg_elem;
  49. int consdiffmgr_register_with_sandbox(struct sandbox_cfg_elem **cfg);
  50. void consdiffmgr_free_all(void);
  51. int consdiffmgr_validate(void);
  52. #ifdef CONSDIFFMGR_PRIVATE
  53. STATIC unsigned n_diff_compression_methods(void);
  54. STATIC unsigned n_consensus_compression_methods(void);
  55. STATIC consensus_cache_t *cdm_cache_get(void);
  56. STATIC consensus_cache_entry_t *cdm_cache_lookup_consensus(
  57. consensus_flavor_t flavor, time_t valid_after);
  58. STATIC int cdm_entry_get_sha3_value(uint8_t *digest_out,
  59. consensus_cache_entry_t *ent,
  60. const char *label);
  61. STATIC int uncompress_or_set_ptr(const char **out, size_t *outlen,
  62. char **owned_out,
  63. consensus_cache_entry_t *ent);
  64. #endif /* defined(CONSDIFFMGR_PRIVATE) */
  65. #ifdef TOR_UNIT_TESTS
  66. int consdiffmgr_add_consensus_nulterm(const char *consensus,
  67. const networkstatus_t *as_parsed);
  68. #endif
  69. #endif /* !defined(TOR_CONSDIFFMGR_H) */