replaycache.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Copyright (c) 2012-2018, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. /**
  4. * \file replaycache.h
  5. * \brief Header file for replaycache.c.
  6. **/
  7. #ifndef TOR_REPLAYCACHE_H
  8. #define TOR_REPLAYCACHE_H
  9. typedef struct replaycache_t replaycache_t;
  10. #ifdef REPLAYCACHE_PRIVATE
  11. struct replaycache_t {
  12. /* Scrub interval */
  13. time_t scrub_interval;
  14. /* Last scrubbed */
  15. time_t scrubbed;
  16. /*
  17. * Horizon
  18. * (don't return true on digests in the cache but older than this)
  19. */
  20. time_t horizon;
  21. /*
  22. * Digest map: keys are digests, values are times the digest was last seen
  23. */
  24. digest256map_t *digests_seen;
  25. };
  26. #endif /* defined(REPLAYCACHE_PRIVATE) */
  27. /* replaycache_t free/new */
  28. void replaycache_free_(replaycache_t *r);
  29. #define replaycache_free(r) \
  30. FREE_AND_NULL(replaycache_t, replaycache_free_, (r))
  31. replaycache_t * replaycache_new(time_t horizon, time_t interval);
  32. #ifdef REPLAYCACHE_PRIVATE
  33. /*
  34. * replaycache_t internal functions:
  35. *
  36. * These take the time to treat as the present as an argument for easy unit
  37. * testing. For everything else, use the wrappers below instead.
  38. */
  39. STATIC int replaycache_add_and_test_internal(
  40. time_t present, replaycache_t *r, const void *data, size_t len,
  41. time_t *elapsed);
  42. STATIC void replaycache_scrub_if_needed_internal(
  43. time_t present, replaycache_t *r);
  44. #endif /* defined(REPLAYCACHE_PRIVATE) */
  45. /*
  46. * replaycache_t methods
  47. */
  48. int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len);
  49. int replaycache_add_test_and_elapsed(
  50. replaycache_t *r, const void *data, size_t len, time_t *elapsed);
  51. void replaycache_scrub_if_needed(replaycache_t *r);
  52. #endif /* !defined(TOR_REPLAYCACHE_H) */