38 #include "core/or/or_circuit_st.h"
45 uint16_t handshake_type;
51 #define ONIONQUEUE_WAIT_CUTOFF 5
54 typedef struct onion_queue_head_t onion_queue_head_t;
58 static onion_queue_head_t
ol_list[MAX_ONION_HANDSHAKE_TYPE+1] =
59 { TOR_TAILQ_HEAD_INITIALIZER(
ol_list[0]),
60 TOR_TAILQ_HEAD_INITIALIZER(
ol_list[1]),
61 TOR_TAILQ_HEAD_INITIALIZER(
ol_list[2]),
84 uint64_t tap_usec, ntor_usec;
85 uint64_t ntor_during_tap_usec, tap_during_ntor_usec;
97 ONION_HANDSHAKE_TYPE_TAP) / num_cpus;
102 ONION_HANDSHAKE_TYPE_NTOR) / num_cpus;
109 ONION_HANDSHAKE_TYPE_TAP) / num_cpus;
116 ONION_HANDSHAKE_TYPE_NTOR) / num_cpus;
120 if (type == ONION_HANDSHAKE_TYPE_NTOR &&
121 (ntor_usec + tap_during_ntor_usec) / 1000 >
122 (uint64_t)options->MaxOnionQueueDelay)
125 if (type == ONION_HANDSHAKE_TYPE_TAP &&
126 (tap_usec + ntor_during_tap_usec) / 1000 >
127 (uint64_t)options->MaxOnionQueueDelay)
132 if (type == ONION_HANDSHAKE_TYPE_TAP &&
133 tap_usec / 1000 > (uint64_t)options->MaxOnionQueueDelay * 2 / 3)
146 time_t now = time(NULL);
151 log_warn(
LD_BUG,
"Handshake %d out of range! Dropping.",
160 tmp->onionskin = onionskin;
161 tmp->when_added = now;
164 #define WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL (60)
166 RATELIM_INIT(WARN_TOO_MANY_CIRC_CREATIONS_INTERVAL);
174 "Your computer is too slow to handle this many circuit "
175 "creation requests! Please consider using the "
176 "MaxAdvertisedBandwidth config option or choosing a more "
177 "restricted exit policy.%s",
187 log_info(
LD_OR,
"New create (%s). Queues now ntor=%d and tap=%d.",
188 onionskin->
handshake_type == ONION_HANDSHAKE_TYPE_NTOR ?
"ntor" :
"tap",
205 "Circuit create request is too old; canceling due to overload.");
207 circuit_mark_for_close(
TO_CIRCUIT(circ), END_CIRC_REASON_RESOURCELIMIT);
219 #define DEFAULT_NUM_NTORS_PER_TAP 10
220 #define MIN_NUM_NTORS_PER_TAP 1
221 #define MAX_NUM_NTORS_PER_TAP 100000
224 DEFAULT_NUM_NTORS_PER_TAP,
225 MIN_NUM_NTORS_PER_TAP,
226 MAX_NUM_NTORS_PER_TAP);
238 static int recently_chosen_ntors = 0;
241 return ONION_HANDSHAKE_TYPE_TAP;
255 ++recently_chosen_ntors;
257 return ONION_HANDSHAKE_TYPE_NTOR;
263 return ONION_HANDSHAKE_TYPE_NTOR;
267 recently_chosen_ntors = 0;
268 return ONION_HANDSHAKE_TYPE_TAP;
285 tor_assert(head->handshake_type <= MAX_ONION_HANDSHAKE_TYPE);
292 log_info(
LD_OR,
"Processing create (%s). Queues now ntor=%d and tap=%d.",
293 head->handshake_type == ONION_HANDSHAKE_TYPE_NTOR ?
"ntor" :
"tap",
297 *onionskin_out = head->onionskin;
298 head->onionskin = NULL;
335 if (victim->handshake_type > MAX_ONION_HANDSHAKE_TYPE) {
338 log_warn(
LD_BUG,
"Handshake %d out of range! Dropping.",
339 victim->handshake_type);
345 TOR_TAILQ_REMOVE(&
ol_list[victim->handshake_type], victim, next);
348 victim->circ->onionqueue_entry = NULL;
350 if (victim->onionskin)
363 for (i=0; i<=MAX_ONION_HANDSHAKE_TYPE; i++) {
364 for (victim = TOR_TAILQ_FIRST(&
ol_list[i]); victim; victim = next) {
365 next = TOR_TAILQ_NEXT(victim,next);
Header file for circuitlist.c.
int get_num_cpus(const or_options_t *options)
const or_options_t * get_options(void)
Header file for config.c.
void cpuworker_cancel_circ_handshake(or_circuit_t *circ)
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)
#define ONIONQUEUE_WAIT_CUTOFF
int onion_pending_add(or_circuit_t *circ, create_cell_t *onionskin)
int onion_num_pending(uint16_t handshake_type)
or_circuit_t * onion_next_task(create_cell_t **onionskin_out)
static int have_room_for_onionskin(uint16_t type)
void onion_pending_remove(or_circuit_t *circ)
static int ol_entries[MAX_ONION_HANDSHAKE_TYPE+1]
static int num_ntors_per_tap(void)
static void onion_queue_entry_remove(onion_queue_t *victim)
static onion_queue_head_t ol_list[MAX_ONION_HANDSHAKE_TYPE+1]
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)
void rep_hist_note_overload(overload_type_t overload)
Header file for rephist.c.
struct onion_queue_t * onionqueue_entry