mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 13:53:31 +01:00
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.
This commit is contained in:
parent
121766e6b8
commit
5b3a067fe3
@ -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;
|
||||
}
|
||||
|
@ -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 */
|
||||
|
||||
|
@ -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. */
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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. */
|
||||
|
Loading…
Reference in New Issue
Block a user