mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 13:43:47 +01:00
a3e0a87d95
We previously used FILENAME_PRIVATE identifiers mostly for identifiers exposed only to the unit tests... but also for identifiers exposed to the benchmarker, and sometimes for identifiers exposed to a similar module, and occasionally for no really good reason at all. Now, we use FILENAME_PRIVATE identifiers for identifiers shared by Tor and the unit tests. They should be defined static when we aren't building the unit test, and globally visible otherwise. (The STATIC macro will keep us honest here.) For identifiers used only by the unit tests and never by Tor at all, on the other hand, we wrap them in #ifdef TOR_UNIT_TESTS. This is not the motivating use case for the split test/non-test build system; it's just a test example to see how it works, and to take a chance to clean up the code a little.
67 lines
1.5 KiB
C
67 lines
1.5 KiB
C
/* Copyright (c) 2012-2013, The Tor Project, Inc. */
|
|
/* See LICENSE for licensing information */
|
|
|
|
/**
|
|
* \file replaycache.h
|
|
* \brief Header file for replaycache.c.
|
|
**/
|
|
|
|
#ifndef TOR_REPLAYCACHE_H
|
|
#define TOR_REPLAYCACHE_H
|
|
|
|
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
|
|
*/
|
|
digestmap_t *digests_seen;
|
|
};
|
|
|
|
#endif /* REPLAYCACHE_PRIVATE */
|
|
|
|
/* replaycache_t free/new */
|
|
|
|
void replaycache_free(replaycache_t *r);
|
|
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.
|
|
*/
|
|
|
|
STATIC int replaycache_add_and_test_internal(
|
|
time_t present, replaycache_t *r, const void *data, int len,
|
|
time_t *elapsed);
|
|
STATIC void replaycache_scrub_if_needed_internal(
|
|
time_t present, replaycache_t *r);
|
|
|
|
#endif /* REPLAYCACHE_PRIVATE */
|
|
|
|
/*
|
|
* replaycache_t methods
|
|
*/
|
|
|
|
int replaycache_add_and_test(replaycache_t *r, const void *data, int len);
|
|
int replaycache_add_test_and_elapsed(
|
|
replaycache_t *r, const void *data, int len, time_t *elapsed);
|
|
void replaycache_scrub_if_needed(replaycache_t *r);
|
|
|
|
#endif
|
|
|