]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Fix test_parseconf on MaxHSDirCacheBytes default
authorAlex Xu (Hello71) <alex_y_xu@yahoo.ca>
Mon, 15 Sep 2025 23:39:08 +0000 (19:39 -0400)
committerDavid Goulet <dgoulet@torproject.org>
Tue, 16 Sep 2025 14:15:13 +0000 (10:15 -0400)
Change the logic to evaluate the default when fetching the value, matching
other default options like ExtORPortCookieAuthFile.

src/app/config/config.c
src/core/or/relay.c
src/feature/hs/hs_cache.c
src/feature/hs/hs_cache.h

index 6fb892748f5206ab2f49b2f82f9d475c9c0a0f7b..a1520820a921806390811d4140395de0281560a4 100644 (file)
@@ -3536,13 +3536,6 @@ options_validate_cb(const void *old_options_, void *options_, char **msg)
                                    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;
index 6fa19e0fa08c288b2661176a8a39556a3d8a1495..c3a6ff09851d7c8628529af6f218fd3b8e7c6aae 100644 (file)
@@ -2934,9 +2934,9 @@ cell_queues_check_size(void)
 
       /* 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;
@@ -2944,7 +2944,7 @@ cell_queues_check_size(void)
         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 =
index bd8f888bb030699695cdfabd33c5112ecaa54369..a4dec7b54be56e32685fa36700c6de63e6f7a718 100644 (file)
@@ -155,7 +155,7 @@ cache_store_v3_as_dir(hs_cache_dir_descriptor_t *desc)
 
   /* 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
@@ -1254,6 +1254,14 @@ hs_cache_free_all(void)
   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)
index 2f78f8479a3c1d741687cba666309dd5039398d2..9cf73c1ba774c6d9c5a63c6ab14acd0c653784ef 100644 (file)
@@ -122,6 +122,7 @@ void hs_cache_client_intro_state_purge(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);