consdiffmgr.h 2.8 KB

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