diff options
author | Andrea Shepard <andrea@persephoneslair.org> | 2012-07-05 14:01:42 -0700 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2012-07-31 17:08:05 -0400 |
commit | 8f63ef10ad3e10dada545b28b7a66c58edc70d75 (patch) | |
tree | dcd1852c71717c77b810dc568dce633efc70ec4a /src/or/replaycache.h | |
parent | 43b81325b5782ce7986421bdfefae57cd4c8ab81 (diff) | |
download | tor-8f63ef10ad3e10dada545b28b7a66c58edc70d75.tar.gz tor-8f63ef10ad3e10dada545b28b7a66c58edc70d75.zip |
Implement replaycache_t for bug 6177, and unit tests for the preceding
Diffstat (limited to 'src/or/replaycache.h')
-rw-r--r-- | src/or/replaycache.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/or/replaycache.h b/src/or/replaycache.h new file mode 100644 index 0000000000..9f3107c513 --- /dev/null +++ b/src/or/replaycache.h @@ -0,0 +1,66 @@ +/* Copyright (c) 2012, 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. + */ + +int replaycache_add_and_test_internal( + time_t present, replaycache_t *r, const void *data, int len, + time_t *elapsed); +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 + |