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