hs_cache.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /* Copyright (c) 2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file hs_cache.h
  5. * \brief Header file for hs_cache.c
  6. **/
  7. #ifndef TOR_HS_CACHE_H
  8. #define TOR_HS_CACHE_H
  9. #include <stdint.h>
  10. #include "crypto.h"
  11. #include "crypto_ed25519.h"
  12. #include "hs_common.h"
  13. #include "hs_descriptor.h"
  14. #include "torcert.h"
  15. /* Descriptor representation on the directory side which is a subset of
  16. * information that the HSDir can decode and serve it. */
  17. typedef struct hs_cache_dir_descriptor_t {
  18. /* This object is indexed using the blinded pubkey located in the plaintext
  19. * data which is populated only once the descriptor has been successfully
  20. * decoded and validated. This simply points to that pubkey. */
  21. const uint8_t *key;
  22. /* When does this entry has been created. Used to expire entries. */
  23. time_t created_ts;
  24. /* Descriptor plaintext information. Obviously, we can't decrypt the
  25. * encrypted part of the descriptor. */
  26. hs_desc_plaintext_data_t *plaintext_data;
  27. /* Encoded descriptor which is basically in text form. It's a NUL terminated
  28. * string thus safe to strlen(). */
  29. char *encoded_desc;
  30. } hs_cache_dir_descriptor_t;
  31. /* Public API */
  32. void hs_cache_init(void);
  33. void hs_cache_clean_as_dir(time_t now);
  34. size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes);
  35. /* Store and Lookup function. They are version agnostic that is depending on
  36. * the requested version of the descriptor, it will be re-routed to the
  37. * right function. */
  38. int hs_cache_store_as_dir(const char *desc);
  39. int hs_cache_lookup_as_dir(uint32_t version, const char *query,
  40. char **desc_out);
  41. #ifdef HS_CACHE_PRIVATE
  42. STATIC size_t cache_clean_v3_as_dir(time_t now, time_t global_cutoff);
  43. #endif /* HS_CACHE_PRIVATE */
  44. #endif /* TOR_HS_CACHE_H */