consdiffmgr.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* Copyright (c) 2017-2018, 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. const networkstatus_t *as_parsed);
  20. consdiff_status_t consdiffmgr_find_consensus(
  21. struct consensus_cache_entry_t **entry_out,
  22. consensus_flavor_t flavor,
  23. enum compress_method_t method);
  24. consdiff_status_t consdiffmgr_find_diff_from(
  25. struct consensus_cache_entry_t **entry_out,
  26. consensus_flavor_t flavor,
  27. int digest_type,
  28. const uint8_t *digest,
  29. size_t digestlen,
  30. enum compress_method_t method);
  31. int consensus_cache_entry_get_voter_id_digests(
  32. const struct consensus_cache_entry_t *ent,
  33. smartlist_t *out);
  34. int consensus_cache_entry_get_fresh_until(
  35. const struct consensus_cache_entry_t *ent,
  36. time_t *out);
  37. int consensus_cache_entry_get_valid_until(
  38. const struct consensus_cache_entry_t *ent,
  39. time_t *out);
  40. int consensus_cache_entry_get_valid_after(
  41. const struct consensus_cache_entry_t *ent,
  42. time_t *out);
  43. void consdiffmgr_rescan(void);
  44. int consdiffmgr_cleanup(void);
  45. void consdiffmgr_enable_background_compression(void);
  46. void consdiffmgr_configure(const consdiff_cfg_t *cfg);
  47. struct sandbox_cfg_elem;
  48. int consdiffmgr_register_with_sandbox(struct sandbox_cfg_elem **cfg);
  49. void consdiffmgr_free_all(void);
  50. int consdiffmgr_validate(void);
  51. #ifdef CONSDIFFMGR_PRIVATE
  52. STATIC unsigned n_diff_compression_methods(void);
  53. STATIC unsigned n_consensus_compression_methods(void);
  54. STATIC consensus_cache_t *cdm_cache_get(void);
  55. STATIC consensus_cache_entry_t *cdm_cache_lookup_consensus(
  56. consensus_flavor_t flavor, time_t valid_after);
  57. STATIC int cdm_entry_get_sha3_value(uint8_t *digest_out,
  58. consensus_cache_entry_t *ent,
  59. const char *label);
  60. STATIC int uncompress_or_copy(char **out, size_t *outlen,
  61. consensus_cache_entry_t *ent);
  62. #endif /* defined(CONSDIFFMGR_PRIVATE) */
  63. #endif /* !defined(TOR_CONSDIFFMGR_H) */