diff options
author | Andrea Shepard <andrea@torproject.org> | 2013-03-07 15:41:22 -0800 |
---|---|---|
committer | Andrea Shepard <andrea@torproject.org> | 2013-03-07 15:41:22 -0800 |
commit | 6e978ab8294eda5bb9a658c8d062bdd0098a9ac5 (patch) | |
tree | 15cc6c2b36aede023bd38b739cb11c94f32dd8f4 /src/or | |
parent | 302d1dae6c468fd2bd5551de654e36b8464a7eab (diff) | |
download | tor-6e978ab8294eda5bb9a658c8d062bdd0098a9ac5.tar.gz tor-6e978ab8294eda5bb9a658c8d062bdd0098a9ac5.zip |
Add unit test for dirserv measured bandwidth cache
Diffstat (limited to 'src/or')
-rw-r--r-- | src/or/dirserv.c | 20 | ||||
-rw-r--r-- | src/or/dirserv.h | 12 |
2 files changed, 17 insertions, 15 deletions
diff --git a/src/or/dirserv.c b/src/or/dirserv.c index 3dfa1e74de..e97def7181 100644 --- a/src/or/dirserv.c +++ b/src/or/dirserv.c @@ -85,18 +85,8 @@ static const signed_descriptor_t *get_signed_descriptor_by_fp( time_t publish_cutoff); static was_router_added_t dirserv_add_extrainfo(extrainfo_t *ei, const char **msg); -static void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line, - time_t as_of); -static void dirserv_clear_measured_bw_cache(void); -static void dirserv_expire_measured_bw_cache(time_t now); -static int dirserv_get_measured_bw_cache_size(void); -static int dirserv_query_measured_bw_cache(const char *node_id, long *bw_out, - time_t *as_of_out); static uint32_t dirserv_get_bandwidth_for_router(const routerinfo_t *ri); -/************** Measured Bandwidth parsing code ******/ -#define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */ - /************** Fingerprint handling code ************/ #define FP_NAMED 1 /**< Listed in fingerprint file. */ @@ -2066,7 +2056,7 @@ static digestmap_t *mbw_cache = NULL; /** Store a measured bandwidth cache entry when reading the measured * bandwidths file. */ -static void +void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line, time_t as_of) { @@ -2096,7 +2086,7 @@ dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line, } /** Clear and free the measured bandwidth cache */ -static void +void dirserv_clear_measured_bw_cache(void) { if (mbw_cache) { @@ -2107,7 +2097,7 @@ dirserv_clear_measured_bw_cache(void) } /** Scan the measured bandwidth cache and remove expired entries */ -static void +void dirserv_expire_measured_bw_cache(time_t now) { digestmap_iter_t *itr = NULL; @@ -2152,7 +2142,7 @@ dirserv_expire_measured_bw_cache(time_t now) } /** Get the current size of the measured bandwidth cache */ -static int +int dirserv_get_measured_bw_cache_size(void) { if (mbw_cache) return digestmap_size(mbw_cache); @@ -2161,7 +2151,7 @@ dirserv_get_measured_bw_cache_size(void) /** Query the cache by identity digest, return value indicates whether * we found it. */ -static int +int dirserv_query_measured_bw_cache(const char *node_id, long *bw_out, time_t *as_of_out) { diff --git a/src/or/dirserv.h b/src/or/dirserv.h index 0caf55f830..887a4992ed 100644 --- a/src/or/dirserv.h +++ b/src/or/dirserv.h @@ -138,10 +138,22 @@ void cached_dir_decref(cached_dir_t *d); cached_dir_t *new_cached_dir(char *s, time_t published); #ifdef DIRSERV_PRIVATE + +/* Put the MAX_MEASUREMENT_AGE #define here so unit tests can see it */ +#define MAX_MEASUREMENT_AGE (3*24*60*60) /* 3 days */ + int measured_bw_line_parse(measured_bw_line_t *out, const char *line); int measured_bw_line_apply(measured_bw_line_t *parsed_line, smartlist_t *routerstatuses); + +void dirserv_cache_measured_bw(const measured_bw_line_t *parsed_line, + time_t as_of); +void dirserv_clear_measured_bw_cache(void); +void dirserv_expire_measured_bw_cache(time_t now); +int dirserv_get_measured_bw_cache_size(void); +int dirserv_query_measured_bw_cache(const char *node_id, long *bw_out, + time_t *as_of_out); #endif int dirserv_read_measured_bandwidths(const char *from_file, |