22 #define REPLAYCACHE_PRIVATE
33 log_info(
LD_BUG,
"replaycache_free() called on NULL");
37 if (r->digests_seen) digest256map_free(r->digests_seen,
tor_free_);
49 replaycache_t *r = NULL;
52 log_info(
LD_BUG,
"replaycache_new() called with negative"
53 " horizon parameter");
58 log_info(
LD_BUG,
"replaycache_new() called with negative interval"
63 r = tor_malloc(
sizeof(*r));
64 r->scrub_interval = interval;
67 r->digests_seen = digest256map_new();
77 time_t present, replaycache_t *r,
const void *data,
size_t len,
85 if (present <= 0 || !r || !data || len == 0) {
86 log_info(
LD_BUG,
"replaycache_add_and_test_internal() called with stupid"
87 " parameters; please fix this.");
95 access_time = digest256map_get(r->digests_seen, digest);
98 if (access_time != NULL) {
103 if (*access_time >= present - r->horizon || r->horizon == 0) {
108 if (present >= *access_time) {
109 *elapsed = present - *access_time;
119 if (*access_time < present) {
120 *access_time = present;
124 access_time = tor_malloc(
sizeof(*access_time));
125 *access_time = present;
126 digest256map_set(r->digests_seen, digest, access_time);
141 digest256map_iter_t *itr = NULL;
142 const uint8_t *digest;
147 if (!r || !(r->digests_seen)) {
148 log_info(
LD_BUG,
"replaycache_scrub_if_needed_internal() called with"
149 " stupid parameters; please fix this.");
154 if (present - r->scrubbed < r->scrub_interval && r->scrubbed > 0)
return;
157 if (r->horizon == 0)
return;
160 itr = digest256map_iter_init(r->digests_seen);
161 while (!digest256map_iter_done(itr)) {
162 digest256map_iter_get(itr, &digest, &valp);
163 access_time = (time_t *)valp;
165 if (*access_time < present - r->horizon) {
167 itr = digest256map_iter_next_rmv(r->digests_seen, itr);
172 itr = digest256map_iter_next(r->digests_seen, itr);
177 if (present > r->scrubbed) r->scrubbed = present;
196 replaycache_t *r,
const void *data,
size_t len, time_t *elapsed)
int crypto_digest256(char *digest, const char *m, size_t len, digest_algorithm_t algorithm)
void tor_free_(void *mem)
Master header file for Tor-specific functionality.
replaycache_t * replaycache_new(time_t horizon, time_t interval)
void replaycache_free_(replaycache_t *r)
void replaycache_scrub_if_needed(replaycache_t *r)
int replaycache_add_test_and_elapsed(replaycache_t *r, const void *data, size_t len, time_t *elapsed)
STATIC int replaycache_add_and_test_internal(time_t present, replaycache_t *r, const void *data, size_t len, time_t *elapsed)
int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len)
STATIC void replaycache_scrub_if_needed_internal(time_t present, replaycache_t *r)
Header file for replaycache.c.