replaycache.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (c) 2012-2017, 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_s replaycache_t;
  10. #ifdef REPLAYCACHE_PRIVATE
  11. struct replaycache_s {
  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. replaycache_t * replaycache_new(time_t horizon, time_t interval);
  30. #ifdef REPLAYCACHE_PRIVATE
  31. /*
  32. * replaycache_t internal functions:
  33. *
  34. * These take the time to treat as the present as an argument for easy unit
  35. * testing. For everything else, use the wrappers below instead.
  36. */
  37. STATIC int replaycache_add_and_test_internal(
  38. time_t present, replaycache_t *r, const void *data, size_t len,
  39. time_t *elapsed);
  40. STATIC void replaycache_scrub_if_needed_internal(
  41. time_t present, replaycache_t *r);
  42. #endif /* defined(REPLAYCACHE_PRIVATE) */
  43. /*
  44. * replaycache_t methods
  45. */
  46. int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len);
  47. int replaycache_add_test_and_elapsed(
  48. replaycache_t *r, const void *data, size_t len, time_t *elapsed);
  49. void replaycache_scrub_if_needed(replaycache_t *r);
  50. #endif /* !defined(TOR_REPLAYCACHE_H) */