Data Structures | Macros | Typedefs | Functions | Variables
onion_queue.c File Reference

Functions to queue create cells for processing. More...

#include "core/or/or.h"
#include "feature/relay/onion_queue.h"
#include "app/config/config.h"
#include "core/mainloop/cpuworker.h"
#include "core/or/circuitlist.h"
#include "core/or/onion.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/stats/rephist.h"
#include "core/or/or_circuit_st.h"
#include "core/or/channel.h"

Go to the source code of this file.

Data Structures

struct  onion_queue_t


#define NUM_NTORS_PER_TAP_MAX   100000


typedef struct onion_queue_head_t onion_queue_head_t


 TOR_TAILQ_HEAD (onion_queue_head_t, onion_queue_t)
static void onion_queue_entry_remove (onion_queue_t *victim)
static int32_t get_num_ntors_per_tap (void)
static time_t get_onion_queue_wait_cutoff (void)
static uint32_t get_onion_queue_max_delay (const or_options_t *options)
static uint16_t onionskin_type_to_queue (uint16_t type)
static int have_room_for_onionskin (uint16_t type)
int onion_pending_add (or_circuit_t *circ, create_cell_t *onionskin)
static uint16_t decide_next_handshake_type (void)
or_circuit_tonion_next_task (create_cell_t **onionskin_out)
int onion_num_pending (uint16_t handshake_type)
void onion_pending_remove (or_circuit_t *circ)
void clear_pending_onions (void)
void onion_consensus_has_changed (const networkstatus_t *ns)


static onion_queue_head_t ol_list [MAX_QUEUE_IDX+1]
static int ol_entries [MAX_QUEUE_IDX+1]
static int32_t ns_num_ntors_per_tap = NUM_NTORS_PER_TAP_DEFAULT
static time_t ns_onion_queue_wait_cutoff = ONION_QUEUE_WAIT_CUTOFF_DEFAULT
static uint32_t ns_onion_queue_max_delay = ONION_QUEUE_MAX_DELAY_DEFAULT

Detailed Description

Functions to queue create cells for processing.

Relays invoke these functions when they receive a CREATE or EXTEND cell in command.c or relay.c, in order to queue the pending request. They also invoke them from cpuworker.c, which handles dispatching onionskin requests to different worker threads.

This module also handles:

Definition in file onion_queue.c.

Macro Definition Documentation



We have 3 queues: tap, fast, and ntor. (ntorv3 goes into ntor queue).

Definition at line 71 of file onion_queue.c.



Definition at line 53 of file onion_queue.c.


#define NUM_NTORS_PER_TAP_MAX   100000

Definition at line 55 of file onion_queue.c.



Definition at line 54 of file onion_queue.c.



Definition at line 49 of file onion_queue.c.



Definition at line 51 of file onion_queue.c.



Definition at line 50 of file onion_queue.c.



Onion queue default, max and min.

Definition at line 44 of file onion_queue.c.



Definition at line 46 of file onion_queue.c.



Definition at line 45 of file onion_queue.c.

Typedef Documentation

◆ onion_queue_head_t

typedef struct onion_queue_head_t onion_queue_head_t

Definition at line 68 of file onion_queue.c.

Function Documentation

◆ clear_pending_onions()

void clear_pending_onions ( void  )

Remove all circuits from the pending list. Called from tor_free_all.

Definition at line 417 of file onion_queue.c.

◆ decide_next_handshake_type()

static uint16_t decide_next_handshake_type ( void  )

Choose which onion queue we'll pull from next. If one is empty choose the other; if they both have elements, load balance across them but favoring NTOR.

Definition at line 293 of file onion_queue.c.

Referenced by onion_next_task().

◆ get_num_ntors_per_tap()

static int32_t get_num_ntors_per_tap ( void  )

Return the number of ntors per tap from the cached parameter.

Definition at line 93 of file onion_queue.c.

◆ get_onion_queue_max_delay()

static uint32_t get_onion_queue_max_delay ( const or_options_t options)

Return the max onion queue delay value either from the torrc options (if the user explicitly set it) else from the cached parameter.

Definition at line 108 of file onion_queue.c.

◆ get_onion_queue_wait_cutoff()

static time_t get_onion_queue_wait_cutoff ( void  )

Return the onion queue wait cutoff value from the cached parameter.

Definition at line 100 of file onion_queue.c.

◆ have_room_for_onionskin()

static int have_room_for_onionskin ( uint16_t  type)

Return true iff we have room to queue another onionskin of type type.

Definition at line 144 of file onion_queue.c.

◆ onion_consensus_has_changed()

void onion_consensus_has_changed ( const networkstatus_t ns)

Consensus has changed, update the cached parameters.

Definition at line 433 of file onion_queue.c.

◆ onion_next_task()

or_circuit_t * onion_next_task ( create_cell_t **  onionskin_out)

Remove the highest priority item from ol_list[] and return it, or return NULL if the lists are empty.

Definition at line 333 of file onion_queue.c.

◆ onion_num_pending()

int onion_num_pending ( uint16_t  handshake_type)

Return the number of handshake_type-style create requests pending.

Definition at line 365 of file onion_queue.c.

◆ onion_pending_add()

int onion_pending_add ( or_circuit_t circ,
create_cell_t onionskin 

Add circ to the end of ol_list and return 0, except if ol_list is too long, in which case do nothing and return -1.

Definition at line 214 of file onion_queue.c.

◆ onion_pending_remove()

void onion_pending_remove ( or_circuit_t circ)

Go through ol_list, find the onion_queue_t element which points to circ, remove and free that element. Leave circ itself alone.

Definition at line 374 of file onion_queue.c.

Referenced by circuit_about_to_free().

◆ onion_queue_entry_remove()

static void onion_queue_entry_remove ( onion_queue_t victim)

Remove a queue entry victim from the queue, unlinking it from its circuit and freeing it and any structures it owns.

Definition at line 391 of file onion_queue.c.

Referenced by clear_pending_onions(), and onion_pending_remove().

◆ onionskin_type_to_queue()

static uint16_t onionskin_type_to_queue ( uint16_t  type)

We combine ntorv3 and ntor into the same queue, so we must use this function to convert the cell type to a queue index.

Definition at line 121 of file onion_queue.c.

Referenced by onion_num_pending().

Variable Documentation

◆ ns_num_ntors_per_tap

int32_t ns_num_ntors_per_tap = NUM_NTORS_PER_TAP_DEFAULT

Consensus parameters.

Definition at line 87 of file onion_queue.c.

Referenced by get_num_ntors_per_tap().

◆ ns_onion_queue_max_delay

uint32_t ns_onion_queue_max_delay = ONION_QUEUE_MAX_DELAY_DEFAULT

Definition at line 89 of file onion_queue.c.

◆ ns_onion_queue_wait_cutoff

time_t ns_onion_queue_wait_cutoff = ONION_QUEUE_WAIT_CUTOFF_DEFAULT

Definition at line 88 of file onion_queue.c.

◆ ol_entries

int ol_entries[MAX_QUEUE_IDX+1]

Number of entries of each type currently in each element of ol_list[].

Definition at line 82 of file onion_queue.c.

Referenced by clear_pending_onions(), decide_next_handshake_type(), onion_next_task(), and onion_num_pending().

◆ ol_list

onion_queue_head_t ol_list[MAX_QUEUE_IDX+1]
Initial value:
static onion_queue_head_t ol_list[MAX_QUEUE_IDX+1]
Definition: onion_queue.c:75

Array of queues of circuits waiting for CPU workers. An element is NULL if that queue is empty.

Definition at line 75 of file onion_queue.c.

Referenced by clear_pending_onions(), and onion_next_task().