rendcache.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (c) 2015, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file rendcache.h
  5. * \brief Header file for rendcache.c
  6. **/
  7. #ifndef TOR_RENDCACHE_H
  8. #define TOR_RENDCACHE_H
  9. #include "or.h"
  10. #include "rendcommon.h"
  11. /** How old do we let hidden service descriptors get before discarding
  12. * them as too old? */
  13. #define REND_CACHE_MAX_AGE (2*24*60*60)
  14. /** How wrong do we assume our clock may be when checking whether hidden
  15. * services are too old or too new? */
  16. #define REND_CACHE_MAX_SKEW (24*60*60)
  17. /* Do not allow more than this many introduction points in a hidden service
  18. * descriptor */
  19. #define MAX_INTRO_POINTS 10
  20. /** A cached rendezvous descriptor. */
  21. typedef struct rend_cache_entry_t {
  22. size_t len; /**< Length of <b>desc</b> */
  23. time_t last_served; /**< When did we last write this one to somebody?
  24. * (HSDir only) */
  25. char *desc; /**< Service descriptor */
  26. rend_service_descriptor_t *parsed; /**< Parsed value of 'desc' */
  27. } rend_cache_entry_t;
  28. /* Introduction point failure type. */
  29. typedef struct rend_cache_failure_intro_t {
  30. /* When this intro point failure occured thus we allocated this object and
  31. * cache it. */
  32. time_t created_ts;
  33. rend_intro_point_failure_t failure_type;
  34. } rend_cache_failure_intro_t;
  35. /** Cache failure object indexed by service ID. */
  36. typedef struct rend_cache_failure_t {
  37. /* Contains rend_cache_failure_intro_t indexed by identity digest. */
  38. digestmap_t *intro_failures;
  39. } rend_cache_failure_t;
  40. void rend_cache_init(void);
  41. void rend_cache_clean(time_t now);
  42. void rend_cache_clean_v2_descs_as_dir(time_t now, size_t min_to_remove);
  43. void rend_cache_purge(void);
  44. void rend_cache_free_all(void);
  45. int rend_cache_lookup_entry(const char *query, int version,
  46. rend_cache_entry_t **entry_out);
  47. int rend_cache_lookup_v2_desc_as_dir(const char *query, const char **desc);
  48. /** Return value from rend_cache_store_v2_desc_as_{dir,client}. */
  49. typedef enum {
  50. RCS_NOTDIR = -2, /**< We're not a directory */
  51. RCS_BADDESC = -1, /**< This descriptor is no good. */
  52. RCS_OKAY = 0 /**< All worked as expected */
  53. } rend_cache_store_status_t;
  54. rend_cache_store_status_t rend_cache_store_v2_desc_as_dir(const char *desc);
  55. rend_cache_store_status_t rend_cache_store_v2_desc_as_client(const char *desc,
  56. const char *desc_id_base32,
  57. const rend_data_t *rend_query,
  58. rend_cache_entry_t **entry);
  59. size_t rend_cache_get_total_allocation(void);
  60. void rend_cache_intro_failure_note(rend_intro_point_failure_t failure,
  61. const uint8_t *identity,
  62. const char *service_id);
  63. void rend_cache_failure_purge(void);
  64. #endif /* TOR_RENDCACHE_H */