38#include "core/or/or_circuit_st.h"
44#define ONION_QUEUE_WAIT_CUTOFF_DEFAULT 5
45#define ONION_QUEUE_WAIT_CUTOFF_MIN 0
46#define ONION_QUEUE_WAIT_CUTOFF_MAX INT32_MAX
49#define ONION_QUEUE_MAX_DELAY_DEFAULT 1750
50#define ONION_QUEUE_MAX_DELAY_MIN 1
51#define ONION_QUEUE_MAX_DELAY_MAX INT32_MAX
64typedef struct onion_queue_head_t onion_queue_head_t;
67#define MAX_QUEUE_IDX ONION_HANDSHAKE_TYPE_NTOR
72{ TOR_TAILQ_HEAD_INITIALIZER(
ol_list[0]),
73 TOR_TAILQ_HEAD_INITIALIZER(
ol_list[1]),
74 TOR_TAILQ_HEAD_INITIALIZER(
ol_list[2]),
84static uint32_t ns_onion_queue_max_delay = ONION_QUEUE_MAX_DELAY_DEFAULT;
98 if (options && options->MaxOnionQueueDelay > 0) {
99 return options->MaxOnionQueueDelay;
101 return ns_onion_queue_max_delay;
108static inline uint16_t
111 if (type == ONION_HANDSHAKE_TYPE_NTOR_V3) {
112 return ONION_HANDSHAKE_TYPE_NTOR;
136 uint64_t max_onion_queue_delay;
140 if (type == ONION_HANDSHAKE_TYPE_TAP) {
162 ONION_HANDSHAKE_TYPE_NTOR) / num_cpus;
166 if (type == ONION_HANDSHAKE_TYPE_NTOR &&
167 (ntor_usec / 1000) > max_onion_queue_delay)
180 time_t now = time(NULL);
181 uint16_t queue_idx = 0;
186 log_warn(
LD_BUG,
"Handshake %d out of range! Dropping.",
196 tmp->queue_idx = queue_idx;
197 tmp->onionskin = onionskin;
198 tmp->when_added = now;
201#define WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL (60)
203 RATELIM_INIT(WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL);
209 if (queue_idx == ONION_HANDSHAKE_TYPE_NTOR) {
213 "Your computer is too slow to handle this many circuit "
214 "creation requests! Please consider using the "
215 "MaxAdvertisedBandwidth config option or choosing a more "
216 "restricted exit policy.%s",
226 log_info(
LD_OR,
"New create (%s). Queues now ntor=%d and tap=%d.",
227 queue_idx == ONION_HANDSHAKE_TYPE_NTOR ?
"ntor" :
"tap",
232 TOR_TAILQ_INSERT_TAIL(&
ol_list[queue_idx], tmp, next);
244 "Circuit create request is too old; canceling due to overload.");
246 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_RESOURCELIMIT);
258 return ONION_HANDSHAKE_TYPE_NTOR;
282 log_info(
LD_OR,
"Processing create (%s). Queues now ntor=%d and tap=%d.",
283 head->queue_idx == ONION_HANDSHAKE_TYPE_NTOR ?
"ntor" :
"tap",
287 *onionskin_out = head->onionskin;
288 head->onionskin = NULL;
328 log_warn(
LD_BUG,
"Handshake %d out of range! Dropping.",
335 TOR_TAILQ_REMOVE(&
ol_list[victim->queue_idx], victim, next);
338 victim->circ->onionqueue_entry = NULL;
340 if (victim->onionskin)
354 for (victim = TOR_TAILQ_FIRST(&
ol_list[i]); victim; victim = next) {
355 next = TOR_TAILQ_NEXT(victim,next);
369 ns_onion_queue_max_delay =
371 ONION_QUEUE_MAX_DELAY_DEFAULT,
372 ONION_QUEUE_MAX_DELAY_MIN,
373 ONION_QUEUE_MAX_DELAY_MAX);
378 ONION_QUEUE_WAIT_CUTOFF_MIN,
379 ONION_QUEUE_WAIT_CUTOFF_MAX);
int channel_is_client(const channel_t *chan)
Header file for channel.c.
Header file for circuitlist.c.
const or_options_t * get_options(void)
Header file for config.c.
void cpuworker_cancel_circ_handshake(or_circuit_t *circ)
unsigned int cpuworker_get_n_threads(void)
uint64_t estimated_usec_for_onionskins(uint32_t n_requests, uint16_t onionskin_type)
Header file for cpuworker.c.
int32_t networkstatus_get_param(const networkstatus_t *ns, const char *param_name, int32_t default_val, int32_t min_val, int32_t max_val)
Header file for networkstatus.c.
void clear_pending_onions(void)
static int ol_entries[MAX_QUEUE_IDX+1]
static time_t ns_onion_queue_wait_cutoff
static time_t get_onion_queue_wait_cutoff(void)
static uint32_t get_onion_queue_max_delay(const or_options_t *options)
#define ONION_QUEUE_WAIT_CUTOFF_DEFAULT
void onion_consensus_has_changed(const networkstatus_t *ns)
static onion_queue_head_t ol_list[MAX_QUEUE_IDX+1]
int onion_pending_add(or_circuit_t *circ, create_cell_t *onionskin)
int onion_num_pending(uint16_t handshake_type)
static int have_room_for_onionskin(uint16_t type)
void onion_pending_remove(or_circuit_t *circ)
or_circuit_t * onion_next_task(create_cell_t **onionskin_out)
static void onion_queue_entry_remove(onion_queue_t *victim)
static uint16_t onionskin_type_to_queue(uint16_t type)
static uint16_t decide_next_handshake_type(void)
Header file for onion_queue.c.
Master header file for Tor-specific functionality.
char * rate_limit_log(ratelim_t *lim, time_t now)
void rep_hist_note_circuit_handshake_dropped(uint16_t type)
Header file for rephist.c.
struct onion_queue_t * onionqueue_entry