server_mode(options));
options->MaxMemInQueues_low_threshold = (options->MaxMemInQueues / 4) * 3;
- /* Process MaxHSDirCacheBytes. If not set (0), use MaxMemInQueues / 5 as
- * default. */
- if (options->MaxHSDirCacheBytes == 0) {
- /* Default to MaxMemInQueues / 5 for HS directory cache (20%) */
- options->MaxHSDirCacheBytes = options->MaxMemInQueues / 5;
- }
-
if (!options->SafeLogging ||
!strcasecmp(options->SafeLogging, "0")) {
options->SafeLogging_ = SAFELOG_SCRUB_NONE;
/* If we're spending over the configured limit on hidden service
* descriptors, free them until we're down to 50% of the limit. */
- if (hs_cache_total > get_options()->MaxHSDirCacheBytes) {
+ if (hs_cache_total > hs_cache_get_max_bytes()) {
const size_t bytes_to_remove =
- hs_cache_total - (size_t)(get_options()->MaxHSDirCacheBytes / 2);
+ hs_cache_total - (size_t)(hs_cache_get_max_bytes() / 2);
removed = hs_cache_handle_oom(bytes_to_remove);
oom_stats_n_bytes_removed_hsdir += removed;
alloc -= removed;
log_fn_ratelim(&hs_cache_oom_ratelim, LOG_NOTICE, LD_REND,
"HSDir cache exceeded limit (%zu > %"PRIu64" bytes). "
"Pruned %zu bytes during cell_queues_check_size.",
- hs_cache_total, get_options()->MaxHSDirCacheBytes, removed);
+ hs_cache_total, hs_cache_get_max_bytes(), removed);
}
if (geoip_client_cache_total > get_options()->MaxMemInQueues / 5) {
const size_t bytes_to_remove =
/* Check if we've exceeded the MaxHSDirCacheBytes limit after adding
* this descriptor. If so, prune excess bytes leaving room for more. */
- const size_t max_cache_bytes = get_options()->MaxHSDirCacheBytes;
+ const size_t max_cache_bytes = hs_cache_get_max_bytes();
const size_t current_cache_bytes = hs_cache_get_total_allocation();
if (max_cache_bytes > 0 && current_cache_bytes > max_cache_bytes) {
/* We prune only 1000 descriptors worth of memory here because
hs_cache_total_allocation = 0;
}
+/** Get the configured maximum cache size. */
+uint64_t
+hs_cache_get_max_bytes(void)
+{
+ uint64_t opt = get_options()->MaxHSDirCacheBytes;
+ return opt != 0 ? opt : get_options()->MaxMemInQueues / 5;
+}
+
/* Return total size of the cache. */
size_t
hs_cache_get_total_allocation(void)
bool hs_cache_client_new_auth_parse(const ed25519_public_key_t *service_pk);
+uint64_t hs_cache_get_max_bytes(void);
size_t hs_cache_get_total_allocation(void);
void hs_cache_decrement_allocation(size_t n);
void hs_cache_increment_allocation(size_t n);