mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 15:43:32 +01:00
hs_pow: faster hs_circuitmap lookup for rend in pow_worker_job_t
The worker job queue for hs_pow needs what's effectively a weak pointer to two circuits, but there's not a generic mechanism for this in c-tor. The previous approach of circuit_get_by_global_id() is straightforward but not efficient. These global IDs are normally only used by the control port protocol. To reduce the number of O(N) lookups we have over the whole circuit list, we can use hs_circuitmap to look up the rend circuit by its auth cookie. Signed-off-by: Micah Elizabeth Scott <beth@torproject.org>
This commit is contained in:
parent
a6138486f7
commit
50313d114f
@ -797,7 +797,7 @@ consider_sending_introduce1(origin_circuit_t *intro_circ,
|
||||
/* send it to the client-side pow cpuworker for solving. */
|
||||
intro_circ->hs_currently_solving_pow = 1;
|
||||
if (hs_pow_queue_work(intro_circ->global_identifier,
|
||||
rend_circ->global_identifier,
|
||||
rend_circ->hs_ident->rendezvous_cookie,
|
||||
&pow_inputs) != 0) {
|
||||
log_warn(LD_REND, "Failed to enqueue PoW request");
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include "ext/equix/include/equix.h"
|
||||
#include "feature/hs/hs_cache.h"
|
||||
#include "feature/hs/hs_descriptor.h"
|
||||
#include "feature/hs/hs_circuitmap.h"
|
||||
#include "feature/hs/hs_client.h"
|
||||
#include "feature/hs/hs_pow.h"
|
||||
#include "lib/crypt_ops/crypto_rand.h"
|
||||
@ -356,7 +357,7 @@ typedef struct pow_worker_job_t {
|
||||
|
||||
/** State: we'll look these up to figure out how to proceed after. */
|
||||
uint32_t intro_circ_identifier;
|
||||
uint32_t rend_circ_identifier;
|
||||
uint8_t rend_circ_cookie[HS_REND_COOKIE_LEN];
|
||||
|
||||
/** Output: The worker thread will malloc and write its answer here,
|
||||
* or set it to NULL if it produced no useful answer. */
|
||||
@ -411,11 +412,17 @@ pow_worker_replyfn(void *work_)
|
||||
|
||||
pow_worker_job_t *job = work_;
|
||||
|
||||
// look up the circuits that we're going to use this pow in
|
||||
/* Look up the circuits that we're going to use this pow in.
|
||||
* There's room for improvement here. We already had a fast mapping to
|
||||
* rend circuits from some kind of identifier that we can keep in a
|
||||
* pow_worker_job_t, but we don't have that index for intro circs at this
|
||||
* time. If the linear search in circuit_get_by_global_id() is ever a
|
||||
* noticeable bottleneck we should add another map.
|
||||
*/
|
||||
origin_circuit_t *intro_circ =
|
||||
circuit_get_by_global_id(job->intro_circ_identifier);
|
||||
origin_circuit_t *rend_circ =
|
||||
circuit_get_by_global_id(job->rend_circ_identifier);
|
||||
hs_circuitmap_get_established_rend_circ_client_side(job->rend_circ_cookie);
|
||||
|
||||
/* try to re-create desc and ip */
|
||||
const ed25519_public_key_t *service_identity_pk = NULL;
|
||||
@ -466,14 +473,17 @@ pow_worker_replyfn(void *work_)
|
||||
*/
|
||||
int
|
||||
hs_pow_queue_work(uint32_t intro_circ_identifier,
|
||||
uint32_t rend_circ_identifier,
|
||||
const uint8_t *rend_circ_cookie,
|
||||
const hs_pow_solver_inputs_t *pow_inputs)
|
||||
{
|
||||
tor_assert(in_main_thread());
|
||||
tor_assert(rend_circ_cookie);
|
||||
tor_assert(pow_inputs);
|
||||
|
||||
pow_worker_job_t *job = tor_malloc_zero(sizeof(*job));
|
||||
job->intro_circ_identifier = intro_circ_identifier;
|
||||
job->rend_circ_identifier = rend_circ_identifier;
|
||||
memcpy(&job->rend_circ_cookie, rend_circ_cookie,
|
||||
sizeof job->rend_circ_cookie);
|
||||
memcpy(&job->pow_inputs, pow_inputs, sizeof job->pow_inputs);
|
||||
|
||||
workqueue_entry_t *work;
|
||||
|
@ -145,7 +145,7 @@ void hs_pow_remove_seed_from_cache(const uint8_t *seed_head);
|
||||
void hs_pow_free_service_state(hs_pow_service_state_t *state);
|
||||
|
||||
int hs_pow_queue_work(uint32_t intro_circ_identifier,
|
||||
uint32_t rend_circ_identifier,
|
||||
const uint8_t *rend_circ_cookie,
|
||||
const hs_pow_solver_inputs_t *pow_inputs);
|
||||
|
||||
#else /* !defined(HAVE_MODULE_POW) */
|
||||
@ -183,11 +183,11 @@ hs_pow_free_service_state(hs_pow_service_state_t *state)
|
||||
|
||||
static inline int
|
||||
hs_pow_queue_work(uint32_t intro_circ_identifier,
|
||||
uint32_t rend_circ_identifier,
|
||||
const uint8_t *rend_circ_cookie,
|
||||
const hs_pow_solver_inputs_t *pow_inputs)
|
||||
{
|
||||
(void)intro_circ_identifier;
|
||||
(void)rend_circ_identifier;
|
||||
(void)rend_circ_cookie;
|
||||
(void)pow_inputs;
|
||||
return -1;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user