tor  0.4.0.1-alpha
replaycache.h
Go to the documentation of this file.
1 /* Copyright (c) 2012-2019, The Tor Project, Inc. */
2 /* See LICENSE for licensing information */
3 
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 #define replaycache_free(r) \
38  FREE_AND_NULL(replaycache_t, replaycache_free_, (r))
39 replaycache_t * replaycache_new(time_t horizon, time_t interval);
40 
41 #ifdef REPLAYCACHE_PRIVATE
42 
43 /*
44  * replaycache_t internal functions:
45  *
46  * These take the time to treat as the present as an argument for easy unit
47  * testing. For everything else, use the wrappers below instead.
48  */
49 
51  time_t present, replaycache_t *r, const void *data, size_t len,
52  time_t *elapsed);
54  time_t present, replaycache_t *r);
55 
56 #endif /* defined(REPLAYCACHE_PRIVATE) */
57 
58 /*
59  * replaycache_t methods
60  */
61 
62 int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len);
64  replaycache_t *r, const void *data, size_t len, time_t *elapsed);
65 void replaycache_scrub_if_needed(replaycache_t *r);
66 
67 #endif /* !defined(TOR_REPLAYCACHE_H) */
int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len)
Definition: replaycache.c:186
int replaycache_add_test_and_elapsed(replaycache_t *r, const void *data, size_t len, time_t *elapsed)
Definition: replaycache.c:195
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_scrub_if_needed(replaycache_t *r)
Definition: replaycache.c:205
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
void replaycache_free_(replaycache_t *r)
Definition: replaycache.c:30