diff options
author | David Goulet <dgoulet@torproject.org> | 2017-08-22 11:30:11 -0400 |
---|---|---|
committer | David Goulet <dgoulet@torproject.org> | 2017-08-24 13:03:28 -0400 |
commit | e046e6fb4816e118f1bb32bd709b5dce5b729994 (patch) | |
tree | f463657adf9d56abee2299d58fd8843f083c0be0 /src/or/hs_cache.c | |
parent | 68887fdc5d4ff94cb8e88480e160349007d8a6a5 (diff) | |
download | tor-e046e6fb4816e118f1bb32bd709b5dce5b729994.tar.gz tor-e046e6fb4816e118f1bb32bd709b5dce5b729994.zip |
prop224: Update OOM counters when storing a client descriptor cache object
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/or/hs_cache.c')
-rw-r--r-- | src/or/hs_cache.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/or/hs_cache.c b/src/or/hs_cache.c index e0d89a70e1..6962c5ce44 100644 --- a/src/or/hs_cache.c +++ b/src/or/hs_cache.c @@ -329,6 +329,14 @@ static digest256map_t *hs_cache_v3_client; * objects all related to a specific service. */ static digest256map_t *hs_cache_client_intro_state; +/* Return the size of a client cache entry in bytes. */ +static size_t +cache_get_client_entry_size(const hs_cache_client_descriptor_t *entry) +{ + return sizeof(*entry) + + strlen(entry->encoded_desc) + hs_desc_obj_size(entry->desc); +} + /* Remove a given descriptor from our cache. */ static void remove_v3_desc_as_client(const hs_cache_client_descriptor_t *desc) @@ -345,6 +353,8 @@ store_v3_desc_as_client(hs_cache_client_descriptor_t *desc) { tor_assert(desc); digest256map_set(hs_cache_v3_client, desc->key.pubkey, desc); + /* Update cache size with this entry for the OOM handler. */ + rend_cache_increment_allocation(cache_get_client_entry_size(desc)); } /* Query our cache and return the entry or NULL if not found. */ @@ -355,14 +365,6 @@ lookup_v3_desc_as_client(const uint8_t *key) return digest256map_get(hs_cache_v3_client, key); } -/* Return the size of a client cache entry in bytes. */ -static size_t -cache_get_client_entry_size(const hs_cache_client_descriptor_t *entry) -{ - return sizeof(*entry) + - strlen(entry->encoded_desc) + hs_desc_obj_size(entry->desc); -} - /* Parse the encoded descriptor in <b>desc_str</b> using * <b>service_identity_pk<b> to decrypt it first. * @@ -616,9 +618,6 @@ cache_store_as_client(hs_cache_client_descriptor_t *client_desc) /* Store descriptor in cache */ store_v3_desc_as_client(client_desc); - /* Update cache size with this entry for the OOM handler. */ - rend_cache_increment_allocation(cache_get_client_entry_size(client_desc)); - done: return 0; } |