prop224: Update OOM counters when storing a client descriptor cache object

Signed-off-by: David Goulet <dgoulet@torproject.org>
This commit is contained in:
David Goulet 2017-08-22 11:30:11 -04:00
parent 68887fdc5d
commit e046e6fb48

View File

@ -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;
}