hs_cache.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2016-2017, 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_free_all(void);
  34. void hs_cache_clean_as_dir(time_t now);
  35. size_t hs_cache_handle_oom(time_t now, size_t min_remove_bytes);
  36. unsigned int hs_cache_get_max_descriptor_size(void);
  37. /* Store and Lookup function. They are version agnostic that is depending on
  38. * the requested version of the descriptor, it will be re-routed to the
  39. * right function. */
  40. int hs_cache_store_as_dir(const char *desc);
  41. int hs_cache_lookup_as_dir(uint32_t version, const char *query,
  42. const char **desc_out);
  43. const hs_descriptor_t *
  44. hs_cache_lookup_as_client(const ed25519_public_key_t *key);
  45. int hs_cache_store_as_client(const char *desc_str,
  46. const ed25519_public_key_t *identity_pk);
  47. void hs_cache_clean_as_client(time_t now);
  48. #ifdef HS_CACHE_PRIVATE
  49. /** Represents a locally cached HS descriptor on a hidden service client. */
  50. typedef struct hs_cache_client_descriptor_t {
  51. /* This object is indexed using the service identity public key */
  52. ed25519_public_key_t key;
  53. /* When was this entry created. Used to expire entries. */
  54. time_t created_ts;
  55. /* The cached descriptor, this object is the owner. It can't be NULL. A
  56. * cache object without a valid descriptor is not possible. */
  57. hs_descriptor_t *desc;
  58. /* Encoded descriptor in string form. Can't be NULL. */
  59. char *encoded_desc;
  60. } hs_cache_client_descriptor_t;
  61. STATIC size_t cache_clean_v3_as_dir(time_t now, time_t global_cutoff);
  62. STATIC hs_cache_client_descriptor_t *
  63. lookup_v3_desc_as_client(const uint8_t *key);
  64. #endif /* HS_CACHE_PRIVATE */
  65. #endif /* TOR_HS_CACHE_H */