tor  0.4.0.0-alpha-dev
Macros | Functions | Variables
command.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "core/crypto/onion_crypto.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/cpuworker.h"
#include "core/or/channel.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/command.h"
#include "core/or/connection_or.h"
#include "core/or/dos.h"
#include "core/or/onion.h"
#include "core/or/relay.h"
#include "feature/control/control.h"
#include "feature/hibernate/hibernate.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/routermode.h"
#include "feature/stats/rephist.h"
#include "lib/crypt_ops/crypto_util.h"
#include "core/or/cell_st.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"
#include "core/or/var_cell_st.h"

Go to the source code of this file.

Macros

#define PROCESS_CELL(tp, cl, cn)   command_process_ ## tp ## _cell(cl, cn)
 

Functions

static void command_handle_incoming_channel (channel_listener_t *listener, channel_t *chan)
 
static void command_process_create_cell (cell_t *cell, channel_t *chan)
 
static void command_process_created_cell (cell_t *cell, channel_t *chan)
 
static void command_process_relay_cell (cell_t *cell, channel_t *chan)
 
static void command_process_destroy_cell (cell_t *cell, channel_t *chan)
 
const char * cell_command_to_string (uint8_t command)
 
void command_process_cell (channel_t *chan, cell_t *cell)
 
void command_process_var_cell (channel_t *chan, var_cell_t *var_cell)
 
void command_setup_channel (channel_t *chan)
 
void command_setup_listener (channel_listener_t *listener)
 

Variables

uint64_t stats_n_create_cells_processed = 0
 
uint64_t stats_n_created_cells_processed = 0
 
uint64_t stats_n_relay_cells_processed = 0
 
uint64_t stats_n_destroy_cells_processed = 0
 

Detailed Description

Functions for processing incoming cells.

When we receive a cell from a client or a relay, it arrives on some channel, and tells us what to do with it. In this module, we dispatch based on the cell type using the functions command_process_cell() and command_process_var_cell(), and deal with the cell accordingly. (These handlers are installed on a channel with the command_setup_channel() function.)

Channels have a chance to handle some cell types on their own before they are ever passed here — typically, they do this for cells that are specific to a given channel type. For example, in channeltls.c, the cells for the initial connection handshake are handled before we get here. (Of course, the fact that there is only one channel type for now means that we may have gotten the factoring wrong here.)

Handling other cell types is mainly farmed off to other modules, after initial sanity-checking. CREATE* cells are handled ultimately in onion.c, CREATED* cells trigger circuit creation in circuitbuild.c, DESTROY cells are handled here (since they're simple), and RELAY cells, in all their complexity, are passed off to relay.c.

Definition in file command.c.

Function Documentation

◆ cell_command_to_string()

const char* cell_command_to_string ( uint8_t  command)

Convert the cell command into a lower-case, human-readable string.

Definition at line 88 of file command.c.

◆ command_handle_incoming_channel()

static void command_handle_incoming_channel ( channel_listener_t listener,
channel_t chan 
)
static

Callback to handle a new channel; call command_setup_channel() to give it the right cell handlers.

Definition at line 670 of file command.c.

References command_setup_channel(), and tor_assert().

◆ command_process_cell()

void command_process_cell ( channel_t chan,
cell_t cell 
)

Process a cell that was just received on chan. Keep internal statistics about how many of each cell we've processed so far this second, and the total number of microseconds it took to process each type of cell.

Definition at line 148 of file command.c.

References current_second.

Referenced by command_setup_channel().

◆ command_process_create_cell()

static void command_process_create_cell ( cell_t cell,
channel_t chan 
)
static

Process a 'create' cell that just arrived from chan. Make a new circuit with the p_circ_id specified in cell. Put the circuit in state onionskin_pending, and pass the onionskin to the cpuworker. Circ will get picked up again when the cpuworker finishes decrypting it.

Definition at line 243 of file command.c.

References tor_assert().

◆ command_process_created_cell()

static void command_process_created_cell ( cell_t cell,
channel_t chan 
)
static

Process a 'created' cell that just arrived from chan. Find the circuit that it's intended for. If we're not the origin of the circuit, package the 'created' cell in an 'extended' relay cell and pass it back. If we are the origin of the circuit, send it to circuit_finish_handshake() to finish processing keys, and then call circuit_send_next_onion_skin() to extend to the next hop in the circuit if necessary.

Definition at line 410 of file command.c.

References cell_t::circ_id, and circuit_get_by_circid_channel().

◆ command_process_destroy_cell()

static void command_process_destroy_cell ( cell_t cell,
channel_t chan 
)
static

Process a 'destroy' cell that just arrived from chan. Find the circ that it refers to (if any).

If the circ is in state onionskin_pending, then call onion_pending_remove() to remove it from the pending onion list (note that if it's already being processed by the cpuworker, it won't be in the list anymore; but when the cpuworker returns it, the circuit will be gone, and the cpuworker response will be dropped).

Then mark the circuit for close (which marks all edges for close, and passes the destroy cell onward if necessary).

Definition at line 628 of file command.c.

References cell_t::circ_id, and circuit_get_by_circid_channel().

◆ command_process_relay_cell()

static void command_process_relay_cell ( cell_t cell,
channel_t chan 
)
static

Process a 'relay' or 'relay_early' cell that just arrived from conn. Make sure it came in with a recognized circ_id. Pass it on to circuit_receive_relay_cell() for actual processing.

Definition at line 480 of file command.c.

References cell_t::circ_id, and circuit_get_by_circid_channel().

◆ command_process_var_cell()

void command_process_var_cell ( channel_t chan,
var_cell_t var_cell 
)

Process an incoming var_cell from a channel; in the current protocol all the var_cells are handshake-related and handled below the channel layer, so this just logs a warning and drops the cell.

Definition at line 226 of file command.c.

References tor_assert().

Referenced by command_setup_channel().

◆ command_setup_channel()

void command_setup_channel ( channel_t chan)

Given a channel, install the right handlers to process incoming cells on it.

Definition at line 683 of file command.c.

References channel_set_cell_handlers(), command_process_cell(), command_process_var_cell(), and tor_assert().

Referenced by channel_connect_for_circuit(), and command_handle_incoming_channel().

◆ command_setup_listener()

void command_setup_listener ( channel_listener_t listener)

Given a listener, install the right handler to process incoming channels on it.

Definition at line 697 of file command.c.

References tor_assert().

Referenced by MOCK_IMPL().

Variable Documentation

◆ stats_n_create_cells_processed

uint64_t stats_n_create_cells_processed = 0

How many CELL_CREATE cells have we received, ever?

Definition at line 67 of file command.c.

◆ stats_n_created_cells_processed

uint64_t stats_n_created_cells_processed = 0

How many CELL_CREATED cells have we received, ever?

Definition at line 69 of file command.c.

◆ stats_n_destroy_cells_processed

uint64_t stats_n_destroy_cells_processed = 0

How many CELL_DESTROY cells have we received, ever?

Definition at line 73 of file command.c.

◆ stats_n_relay_cells_processed

uint64_t stats_n_relay_cells_processed = 0

How many CELL_RELAY cells have we received, ever?

Definition at line 71 of file command.c.