]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Replace the constant bottom-half rate with handled count.
authorMike Perry <mikeperry-git@torproject.org>
Wed, 13 Jul 2022 20:50:38 +0000 (20:50 +0000)
committerMicah Elizabeth Scott <beth@torproject.org>
Wed, 10 May 2023 14:37:11 +0000 (07:37 -0700)
This allows us to more accurately estimate effort, based on real bottom-half
throughput over the duration of a descriptor update.

src/feature/hs/hs_circuit.c
src/feature/hs/hs_config.h
src/feature/hs/hs_pow.h
src/feature/hs/hs_service.c
src/feature/hs/hs_service.h

index 948dab6933bdcca15ebc1f95f5cbf4aca9664db5..acb33bbf8815b81614e1699172ccf60dfeae1c36 100644 (file)
@@ -803,7 +803,9 @@ handle_rend_pqueue_cb(mainloop_event_t *ev, void *arg)
                                     &req->ip_enc_key_kp, &req->rdv_data, now);
     free_pending_rend(req);
 
+    ++pow_state->rend_handled;
     ++in_flight;
+
     if (++count == MAX_REND_REQUEST_PER_MAINLOOP) {
       break;
     }
index 15af1726742bc5c2081e64f5a68b0c3c398b4c76..119a91565b24a0041e053c8cfef9a9305b30abb4 100644 (file)
@@ -28,7 +28,6 @@
 /* Default values for the HS anti-DoS PoW defenses. */
 #define HS_CONFIG_V3_POW_DEFENSES_DEFAULT 0
 #define HS_CONFIG_V3_POW_DEFENSES_MIN_EFFORT_DEFAULT 20
-#define HS_CONFIG_V3_POW_DEFENSES_SVC_BOTTOM_CAPACITY_DEFAULT 100
 
 /* API */
 
index ee7b3c45d856b792a3362aba2aae2bea95483e80..019fea400e27b0c52c98aaff941f4ef98e9dd75c 100644 (file)
@@ -90,8 +90,8 @@ typedef struct hs_pow_service_state_t {
   /* The following values are used when calculating and updating the suggested
    * effort every HS_UPDATE_PERIOD seconds. */
 
-  /* Number of intro requests the service can handle per second. */
-  uint32_t svc_bottom_capacity;
+  /* Number of intro requests the service handled since last update. */
+  uint32_t rend_handled;
   /* The next time at which to update the suggested effort. */
   time_t next_effort_update;
   /* Sum of effort of all valid requests received since the last update. */
index 65f6dce2c65e5312d45a30b717accce39fdc21ce..045022f182e01a6d3e92ae0f3ca0a0ff86da86e6 100644 (file)
@@ -265,8 +265,6 @@ set_service_default_config(hs_service_config_t *c,
   /* PoW default options. */
   c->has_dos_defense_enabled = HS_CONFIG_V3_POW_DEFENSES_DEFAULT;
   c->pow_min_effort = HS_CONFIG_V3_POW_DEFENSES_MIN_EFFORT_DEFAULT;
-  c->pow_svc_bottom_capacity =
-    HS_CONFIG_V3_POW_DEFENSES_SVC_BOTTOM_CAPACITY_DEFAULT;
 }
 
 /** Initialize PoW defenses */
@@ -286,7 +284,7 @@ initialize_pow_defenses(hs_service_t *service)
   /* We recalculate and update the suggested effort every HS_UPDATE_PERIOD
    * seconds. */
   pow_state->suggested_effort = HS_POW_SUGGESTED_EFFORT_DEFAULT;
-  pow_state->svc_bottom_capacity = service->config.pow_svc_bottom_capacity;
+  pow_state->rend_handled = 0;
   pow_state->total_effort = 0;
   pow_state->next_effort_update = (time(NULL) + HS_UPDATE_PERIOD);
 
@@ -2677,15 +2675,12 @@ rotate_pow_seeds(hs_service_t *service, time_t now)
 static void
 update_suggested_effort(hs_service_t *service, time_t now)
 {
-  uint64_t denom;
-
   /* Make life easier */
   hs_pow_service_state_t *pow_state = service->state.pow_state;
 
   /* Calculate the new suggested effort. */
-  /* TODO Check for overflow in denominator? */
-  denom = (pow_state->svc_bottom_capacity * HS_UPDATE_PERIOD);
-  pow_state->suggested_effort = (pow_state->total_effort / denom);
+  /* TODO Check for overflow? */
+  pow_state->suggested_effort = (uint32_t)(pow_state->total_effort / pow_state->rend_handled);
 
   log_debug(LD_REND, "Recalculated suggested effort: %u",
             pow_state->suggested_effort);
@@ -2695,8 +2690,9 @@ update_suggested_effort(hs_service_t *service, time_t now)
     pow_state->suggested_effort = pow_state->min_effort;
   }
 
-  /* Reset the total effort sum for this update period. */
+  /* Reset the total effort sum and number of rends for this update period. */
   pow_state->total_effort = 0;
+  pow_state->rend_handled = 0;
   pow_state->next_effort_update = now + HS_UPDATE_PERIOD;
 }
 
index 817fa677187bab7db94d5bde9e8e370ac92a76fe..465d9fba80ef812e808a0abc49f7643bd643ef96 100644 (file)
@@ -265,7 +265,6 @@ typedef struct hs_service_config_t {
   /** True iff PoW anti-DoS defenses are enabled. */
   unsigned int has_pow_defenses_enabled : 1;
   uint32_t pow_min_effort;
-  uint32_t pow_svc_bottom_capacity;
 
   /** If set, contains the Onion Balance master ed25519 public key (taken from
    * an .onion addresses) that this tor instance serves as backend. */