[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor] 29/77: Replace the constant bottom-half rate with handled count.



This is an automated email from the git hooks/post-receive script.

dgoulet pushed a commit to branch main
in repository tor.

commit 5b3a067fe37bce66f2f3cc4e8972ce428535e175
Author: Mike Perry <mikeperry-git@xxxxxxxxxxxxxx>
AuthorDate: Wed Jul 13 20:50:38 2022 +0000

    Replace the constant bottom-half rate with handled count.
    
    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 |  2 ++
 src/feature/hs/hs_config.h  |  1 -
 src/feature/hs/hs_pow.h     |  4 ++--
 src/feature/hs/hs_service.c | 14 +++++---------
 src/feature/hs/hs_service.h |  1 -
 5 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c
index 948dab6933..acb33bbf88 100644
--- a/src/feature/hs/hs_circuit.c
+++ b/src/feature/hs/hs_circuit.c
@@ -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;
     }
diff --git a/src/feature/hs/hs_config.h b/src/feature/hs/hs_config.h
index 15af172674..119a91565b 100644
--- a/src/feature/hs/hs_config.h
+++ b/src/feature/hs/hs_config.h
@@ -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 */
 
diff --git a/src/feature/hs/hs_pow.h b/src/feature/hs/hs_pow.h
index ee7b3c45d8..019fea400e 100644
--- a/src/feature/hs/hs_pow.h
+++ b/src/feature/hs/hs_pow.h
@@ -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. */
diff --git a/src/feature/hs/hs_service.c b/src/feature/hs/hs_service.c
index 65f6dce2c6..045022f182 100644
--- a/src/feature/hs/hs_service.c
+++ b/src/feature/hs/hs_service.c
@@ -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;
 }
 
diff --git a/src/feature/hs/hs_service.h b/src/feature/hs/hs_service.h
index 817fa67718..465d9fba80 100644
--- a/src/feature/hs/hs_service.h
+++ b/src/feature/hs/hs_service.h
@@ -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. */

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits