2017-03-15 21:13:17 +01:00
|
|
|
/* Copyright (c) 2012-2017, The Tor Project, Inc. */
|
2012-07-05 23:01:42 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file replaycache.h
|
|
|
|
* \brief Header file for replaycache.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 18:13:10 +02:00
|
|
|
#ifndef TOR_REPLAYCACHE_H
|
|
|
|
#define TOR_REPLAYCACHE_H
|
2012-07-05 23:01:42 +02:00
|
|
|
|
|
|
|
typedef struct replaycache_s replaycache_t;
|
|
|
|
|
|
|
|
#ifdef REPLAYCACHE_PRIVATE
|
|
|
|
|
|
|
|
struct replaycache_s {
|
|
|
|
/* Scrub interval */
|
|
|
|
time_t scrub_interval;
|
|
|
|
/* Last scrubbed */
|
|
|
|
time_t scrubbed;
|
|
|
|
/*
|
|
|
|
* Horizon
|
|
|
|
* (don't return true on digests in the cache but older than this)
|
|
|
|
*/
|
|
|
|
time_t horizon;
|
|
|
|
/*
|
|
|
|
* Digest map: keys are digests, values are times the digest was last seen
|
|
|
|
*/
|
2015-11-23 23:08:53 +01:00
|
|
|
digest256map_t *digests_seen;
|
2012-07-05 23:01:42 +02:00
|
|
|
};
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(REPLAYCACHE_PRIVATE) */
|
2012-07-05 23:01:42 +02:00
|
|
|
|
|
|
|
/* replaycache_t free/new */
|
|
|
|
|
2017-11-21 15:37:47 +01:00
|
|
|
void replaycache_free_(replaycache_t *r);
|
2017-12-07 16:52:55 +01:00
|
|
|
#define replaycache_free(r) \
|
|
|
|
FREE_AND_NULL(replaycache_t, replaycache_free_, (r))
|
2012-07-05 23:01:42 +02:00
|
|
|
replaycache_t * replaycache_new(time_t horizon, time_t interval);
|
|
|
|
|
|
|
|
#ifdef REPLAYCACHE_PRIVATE
|
|
|
|
|
|
|
|
/*
|
|
|
|
* replaycache_t internal functions:
|
|
|
|
*
|
|
|
|
* These take the time to treat as the present as an argument for easy unit
|
|
|
|
* testing. For everything else, use the wrappers below instead.
|
|
|
|
*/
|
|
|
|
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC int replaycache_add_and_test_internal(
|
2013-08-04 07:36:32 +02:00
|
|
|
time_t present, replaycache_t *r, const void *data, size_t len,
|
2012-07-05 23:01:42 +02:00
|
|
|
time_t *elapsed);
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC void replaycache_scrub_if_needed_internal(
|
2012-07-05 23:01:42 +02:00
|
|
|
time_t present, replaycache_t *r);
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(REPLAYCACHE_PRIVATE) */
|
2012-07-05 23:01:42 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* replaycache_t methods
|
|
|
|
*/
|
|
|
|
|
2013-08-04 07:36:32 +02:00
|
|
|
int replaycache_add_and_test(replaycache_t *r, const void *data, size_t len);
|
2012-07-05 23:01:42 +02:00
|
|
|
int replaycache_add_test_and_elapsed(
|
2013-08-04 07:36:32 +02:00
|
|
|
replaycache_t *r, const void *data, size_t len, time_t *elapsed);
|
2012-07-05 23:01:42 +02:00
|
|
|
void replaycache_scrub_if_needed(replaycache_t *r);
|
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_REPLAYCACHE_H) */
|
2012-07-05 23:01:42 +02:00
|
|
|
|