aboutsummaryrefslogtreecommitdiff
path: root/src/feature/hs/hs_circuit.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2022-06-30 09:53:41 -0400
committerMicah Elizabeth Scott <beth@torproject.org>2023-05-10 07:37:11 -0700
commitbc9fe5a6f851a0749c141d3f1d4673ac12e3ca39 (patch)
treebb2df95234f7cd706557694e25cfd41b6314b23b /src/feature/hs/hs_circuit.c
parentc2f6b057b88ea3ee4d3a4a86ec198775d50c6d4c (diff)
downloadtor-bc9fe5a6f851a0749c141d3f1d4673ac12e3ca39.tar.gz
tor-bc9fe5a6f851a0749c141d3f1d4673ac12e3ca39.zip
hs: Handle multiple rend request per mainloop run
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/feature/hs/hs_circuit.c')
-rw-r--r--src/feature/hs/hs_circuit.c51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/feature/hs/hs_circuit.c b/src/feature/hs/hs_circuit.c
index cbb3e0bfdd..3d9892e482 100644
--- a/src/feature/hs/hs_circuit.c
+++ b/src/feature/hs/hs_circuit.c
@@ -617,32 +617,47 @@ compare_rend_request_by_effort_(const void *_a, const void *_b)
}
}
+/** How many rendezvous request we handle per mainloop event. Per prop327,
+ * handling an INTRODUCE2 cell takes on average 5.56msec on an average CPU and
+ * so it means that launching this max amount of circuits is well below 0.08
+ * seconds which we believe is negligable on the whole mainloop. */
+#define MAX_REND_REQUEST_PER_MAINLOOP 16
+
static void
handle_rend_pqueue_cb(mainloop_event_t *ev, void *arg)
{
- (void) ev; /* Not using the returned event, make compiler happy. */
+ int count = 0;
hs_service_t *service = arg;
hs_pow_service_state_t *pow_state = service->state.pow_state;
- /* Pop next request by effort. */
- pending_rend_t *req =
- smartlist_pqueue_pop(pow_state->rend_request_pqueue,
- compare_rend_request_by_effort_,
- offsetof(pending_rend_t, idx));
-
- log_info(LD_REND, "Dequeued pending rendezvous request with effort: %u. "
- "Remaining requests: %u",
- req->rdv_data.pow_effort,
- smartlist_len(pow_state->rend_request_pqueue));
+ (void) ev; /* Not using the returned event, make compiler happy. */
- /* Launch the rendezvous circuit. */
- launch_rendezvous_point_circuit(service, &req->ip_auth_pubkey,
- &req->ip_enc_key_kp, &req->rdv_data);
+ /* Process rendezvous request until the maximum per mainloop run. */
+ while (smartlist_len(pow_state->rend_request_pqueue) > 0) {
+ if (++count == MAX_REND_REQUEST_PER_MAINLOOP) {
+ break;
+ }
- /* Clean memory. */
- link_specifier_smartlist_free(req->rdv_data.link_specifiers);
- memwipe(req, 0, sizeof(pending_rend_t));
- tor_free(req);
+ /* Pop next request by effort. */
+ pending_rend_t *req =
+ smartlist_pqueue_pop(pow_state->rend_request_pqueue,
+ compare_rend_request_by_effort_,
+ offsetof(pending_rend_t, idx));
+
+ log_info(LD_REND, "Dequeued pending rendezvous request with effort: %u. "
+ "Remaining requests: %u",
+ req->rdv_data.pow_effort,
+ smartlist_len(pow_state->rend_request_pqueue));
+
+ /* Launch the rendezvous circuit. */
+ launch_rendezvous_point_circuit(service, &req->ip_auth_pubkey,
+ &req->ip_enc_key_kp, &req->rdv_data);
+
+ /* Clean memory. */
+ link_specifier_smartlist_free(req->rdv_data.link_specifiers);
+ memwipe(req, 0, sizeof(pending_rend_t));
+ tor_free(req);
+ }
/* If there are still some pending rendezvous circuits in the pqueue then
* reschedule the event in order to continue handling them. */