37 #include "core/or/or_circuit_st.h"
44 uint16_t handshake_type;
50 #define ONIONQUEUE_WAIT_CUTOFF 5
53 typedef struct onion_queue_head_t onion_queue_head_t;
57 static onion_queue_head_t
ol_list[MAX_ONION_HANDSHAKE_TYPE+1] =
58 { TOR_TAILQ_HEAD_INITIALIZER(
ol_list[0]),
59 TOR_TAILQ_HEAD_INITIALIZER(
ol_list[1]),
60 TOR_TAILQ_HEAD_INITIALIZER(
ol_list[2]),
83 uint64_t tap_usec, ntor_usec;
84 uint64_t ntor_during_tap_usec, tap_during_ntor_usec;
96 ONION_HANDSHAKE_TYPE_TAP) / num_cpus;
101 ONION_HANDSHAKE_TYPE_NTOR) / num_cpus;
108 ONION_HANDSHAKE_TYPE_TAP) / num_cpus;
115 ONION_HANDSHAKE_TYPE_NTOR) / num_cpus;
119 if (type == ONION_HANDSHAKE_TYPE_NTOR &&
120 (ntor_usec + tap_during_ntor_usec) / 1000 >
121 (uint64_t)options->MaxOnionQueueDelay)
124 if (type == ONION_HANDSHAKE_TYPE_TAP &&
125 (tap_usec + ntor_during_tap_usec) / 1000 >
126 (uint64_t)options->MaxOnionQueueDelay)
131 if (type == ONION_HANDSHAKE_TYPE_TAP &&
132 tap_usec / 1000 > (uint64_t)options->MaxOnionQueueDelay * 2 / 3)
145 time_t now = time(NULL);
150 log_warn(
LD_BUG,
"Handshake %d out of range! Dropping.",
159 tmp->onionskin = onionskin;
160 tmp->when_added = now;
163 #define WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL (60)
165 RATELIM_INIT(WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL);
170 "Your computer is too slow to handle this many circuit "
171 "creation requests! Please consider using the "
172 "MaxAdvertisedBandwidth config option or choosing a more "
173 "restricted exit policy.%s",m);
181 log_info(
LD_OR,
"New create (%s). Queues now ntor=%d and tap=%d.",
182 onionskin->
handshake_type == ONION_HANDSHAKE_TYPE_NTOR ?
"ntor" :
"tap",
199 "Circuit create request is too old; canceling due to overload.");
201 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_RESOURCELIMIT);
213 #define DEFAULT_NUM_NTORS_PER_TAP 10
214 #define MIN_NUM_NTORS_PER_TAP 1
215 #define MAX_NUM_NTORS_PER_TAP 100000
218 DEFAULT_NUM_NTORS_PER_TAP,
219 MIN_NUM_NTORS_PER_TAP,
220 MAX_NUM_NTORS_PER_TAP);
232 static int recently_chosen_ntors = 0;
235 return ONION_HANDSHAKE_TYPE_TAP;
249 ++recently_chosen_ntors;
251 return ONION_HANDSHAKE_TYPE_NTOR;
257 return ONION_HANDSHAKE_TYPE_NTOR;
261 recently_chosen_ntors = 0;
262 return ONION_HANDSHAKE_TYPE_TAP;
279 tor_assert(head->handshake_type <= MAX_ONION_HANDSHAKE_TYPE);
286 log_info(
LD_OR,
"Processing create (%s). Queues now ntor=%d and tap=%d.",
287 head->handshake_type == ONION_HANDSHAKE_TYPE_NTOR ?
"ntor" :
"tap",
291 *onionskin_out = head->onionskin;
292 head->onionskin = NULL;
329 if (victim->handshake_type > MAX_ONION_HANDSHAKE_TYPE) {
332 log_warn(
LD_BUG,
"Handshake %d out of range! Dropping.",
333 victim->handshake_type);
339 TOR_TAILQ_REMOVE(&
ol_list[victim->handshake_type], victim, next);
342 victim->circ->onionqueue_entry = NULL;
344 if (victim->onionskin)
357 for (i=0; i<=MAX_ONION_HANDSHAKE_TYPE; i++) {
358 for (victim = TOR_TAILQ_FIRST(&
ol_list[i]); victim; victim = next) {
359 next = TOR_TAILQ_NEXT(victim,next);