Tor  0.4.7.0-alpha-dev
Macros | Functions | Variables
channel.c File Reference

OR/OP-to-OR channel abstraction layer. A channel's job is to transfer cells from Tor instance to Tor instance. Currently, there is only one implementation of the channel abstraction: in channeltls.c. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/mainloop.h"
#include "core/or/channel.h"
#include "core/or/channelpadding.h"
#include "core/or/channeltls.h"
#include "core/or/circuitbuild.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitmux.h"
#include "core/or/circuitstats.h"
#include "core/or/connection_or.h"
#include "core/or/dos.h"
#include "core/or/relay.h"
#include "core/or/scheduler.h"
#include "feature/client/entrynodes.h"
#include "feature/hs/hs_service.h"
#include "feature/nodelist/dirlist.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/router.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/rephist.h"
#include "lib/evloop/timers.h"
#include "lib/time/compat_time.h"
#include "core/or/cell_queue_st.h"

Go to the source code of this file.

Macros

#define CHANNEL_OBJECT_PRIVATE
 
#define CHANNEL_FILE_PRIVATE
 
#define MIN_RELAY_CONNECTIONS_TO_WARN   25
 
#define MAX_AVG_RELAY_CONNECTIONS   1.5
 
#define MAX_AVG_DIRAUTH_CONNECTIONS   4
 
#define MAX_CELLS_TO_GET_FROM_CIRCUITS_FOR_UNLIMITED   256
 

Functions

static HT_HEAD (channel_gid_map, channel_t)
 
static int channel_id_eq (const channel_t *a, const channel_t *b)
 
 HT_PROTOTYPE (channel_gid_map, channel_t, gidmap_node, channel_id_hash, channel_id_eq)
 
 HT_GENERATE2 (channel_gid_map, channel_t, gidmap_node, channel_id_hash, channel_id_eq, 0.6, tor_reallocarray_, tor_free_)
 
static HT_HEAD (channel_idmap, channel_idmap_entry_t)
 
static unsigned channel_idmap_hash (const channel_idmap_entry_t *ent)
 
static int channel_idmap_eq (const channel_idmap_entry_t *a, const channel_idmap_entry_t *b)
 
 HT_PROTOTYPE (channel_idmap, channel_idmap_entry_t, node, channel_idmap_hash, channel_idmap_eq)
 
 HT_GENERATE2 (channel_idmap, channel_idmap_entry_t, node, channel_idmap_hash, channel_idmap_eq, 0.5, tor_reallocarray_, tor_free_)
 
static void channel_remove_from_digest_map (channel_t *chan)
 
static void channel_force_xfree (channel_t *chan)
 
static void channel_free_list (smartlist_t *channels, int mark_for_close)
 
static void channel_listener_free_list (smartlist_t *channels, int mark_for_close)
 
static void channel_listener_force_xfree (channel_listener_t *chan_l)
 
int channel_state_is_valid (channel_state_t state)
 
int channel_listener_state_is_valid (channel_listener_state_t state)
 
int channel_state_can_transition (channel_state_t from, channel_state_t to)
 
int channel_listener_state_can_transition (channel_listener_state_t from, channel_listener_state_t to)
 
const char * channel_state_to_string (channel_state_t state)
 
const char * channel_listener_state_to_string (channel_listener_state_t state)
 
void channel_register (channel_t *chan)
 
void channel_unregister (channel_t *chan)
 
void channel_listener_register (channel_listener_t *chan_l)
 
void channel_listener_unregister (channel_listener_t *chan_l)
 
STATIC void channel_add_to_digest_map (channel_t *chan)
 
channel_tchannel_find_by_global_id (uint64_t global_identifier)
 
int channel_remote_identity_matches (const channel_t *chan, const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
 
channel_tchannel_find_by_remote_identity (const char *rsa_id_digest, const ed25519_public_key_t *ed_id)
 
channel_tchannel_next_with_rsa_identity (channel_t *chan)
 
void channel_check_for_duplicates (void)
 
void channel_init (channel_t *chan)
 
void channel_init_listener (channel_listener_t *chan_l)
 
void channel_free_ (channel_t *chan)
 
void channel_listener_free_ (channel_listener_t *chan_l)
 
void channel_listener_set_listener_fn (channel_listener_t *chan_l, channel_listener_fn_ptr listener)
 
channel_cell_handler_fn_ptr channel_get_cell_handler (channel_t *chan)
 
void channel_set_cell_handlers (channel_t *chan, channel_cell_handler_fn_ptr cell_handler)
 
void channel_mark_for_close (channel_t *chan)
 
void channel_listener_mark_for_close (channel_listener_t *chan_l)
 
void channel_close_from_lower_layer (channel_t *chan)
 
void channel_close_for_error (channel_t *chan)
 
void channel_closed (channel_t *chan)
 
void channel_clear_identity_digest (channel_t *chan)
 
void channel_set_identity_digest (channel_t *chan, const char *identity_digest, const ed25519_public_key_t *ed_identity)
 
void channel_clear_remote_end (channel_t *chan)
 
static int write_packed_cell (channel_t *chan, packed_cell_t *cell)
 
int channel_write_packed_cell (channel_t *chan, packed_cell_t *cell)
 
static void channel_change_state_ (channel_t *chan, channel_state_t to_state)
 
void channel_change_state (channel_t *chan, channel_state_t to_state)
 
void channel_change_state_open (channel_t *chan)
 
void channel_listener_change_state (channel_listener_t *chan_l, channel_listener_state_t to_state)
 
ssize_t channel_flush_some_cells (channel_t *chan, ssize_t num_cells)
 
int channel_more_to_flush (channel_t *chan)
 
void channel_notify_flushed (channel_t *chan)
 
void channel_listener_process_incoming (channel_listener_t *listener)
 
void channel_do_open_actions (channel_t *chan)
 
void channel_listener_queue_incoming (channel_listener_t *listener, channel_t *incoming)
 
void channel_process_cell (channel_t *chan, cell_t *cell)
 
int packed_cell_is_destroy (channel_t *chan, const packed_cell_t *packed_cell, circid_t *circid_out)
 
int channel_send_destroy (circid_t circ_id, channel_t *chan, int reason)
 
void channel_dumpstats (int severity)
 
void channel_listener_dumpstats (int severity)
 
void channel_run_cleanup (void)
 
void channel_listener_run_cleanup (void)
 
void channel_free_all (void)
 
channel_tchannel_connect (const tor_addr_t *addr, uint16_t port, const char *id_digest, const ed25519_public_key_t *ed_id)
 
int channel_is_better (channel_t *a, channel_t *b)
 
channel_tchannel_get_for_extend (const char *rsa_id_digest, const ed25519_public_key_t *ed_id, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr, bool for_origin_circ, const char **msg_out, int *launch_out)
 
const char * channel_describe_transport (channel_t *chan)
 
const char * channel_listener_describe_transport (channel_listener_t *chan_l)
 
void channel_dump_statistics (channel_t *chan, int severity)
 
void channel_listener_dump_statistics (channel_listener_t *chan_l, int severity)
 
void channel_dump_transport_statistics (channel_t *chan, int severity)
 
void channel_listener_dump_transport_statistics (channel_listener_t *chan_l, int severity)
 
const char * channel_describe_peer (channel_t *chan)
 
int channel_get_addr_if_possible (const channel_t *chan, tor_addr_t *addr_out)
 
int channel_has_queued_writes (channel_t *chan)
 
int channel_is_bad_for_new_circs (channel_t *chan)
 
void channel_mark_bad_for_new_circs (channel_t *chan)
 
int channel_is_client (const channel_t *chan)
 
void channel_mark_client (channel_t *chan)
 
void channel_clear_client (channel_t *chan)
 
int channel_is_canonical (channel_t *chan)
 
int channel_is_incoming (channel_t *chan)
 
void channel_mark_incoming (channel_t *chan)
 
int channel_is_local (channel_t *chan)
 
void channel_mark_local (channel_t *chan)
 
void channel_mark_remote (channel_t *chan)
 
int channel_is_outgoing (channel_t *chan)
 
void channel_mark_outgoing (channel_t *chan)
 
int channel_num_cells_writeable (channel_t *chan)
 
void channel_timestamp_created (channel_t *chan)
 
void channel_listener_timestamp_created (channel_listener_t *chan_l)
 
void channel_timestamp_active (channel_t *chan)
 
void channel_listener_timestamp_active (channel_listener_t *chan_l)
 
void channel_listener_timestamp_accepted (channel_listener_t *chan_l)
 
void channel_timestamp_client (channel_t *chan)
 
void channel_timestamp_recv (channel_t *chan)
 
void channel_timestamp_xmit (channel_t *chan)
 
time_t channel_when_created (channel_t *chan)
 
time_t channel_when_last_client (channel_t *chan)
 
time_t channel_when_last_xmit (channel_t *chan)
 
int channel_matches_extend_info (channel_t *chan, extend_info_t *extend_info)
 
STATIC bool channel_matches_target_addr_for_extend (channel_t *chan, const tor_addr_t *target_ipv4_addr, const tor_addr_t *target_ipv6_addr)
 
unsigned int channel_num_circuits (channel_t *chan)
 
void channel_set_circid_type (channel_t *chan, crypto_pk_t *identity_rcvd, int consider_identity)
 
static int channel_sort_by_ed25519_identity (const void **a_, const void **b_)
 
static void channel_rsa_id_group_set_badness (struct channel_list_t *lst, int force)
 
void channel_update_bad_for_new_circs (const char *digest, int force)
 

Variables

static smartlist_tall_channels = NULL
 
static smartlist_tactive_channels = NULL
 
static smartlist_tfinished_channels = NULL
 
static smartlist_tall_listeners = NULL
 
static smartlist_tactive_listeners = NULL
 
static smartlist_tfinished_listeners = NULL
 
static uint64_t n_channels_allocated = 0
 
 channel_idmap_entry_t
 

Detailed Description

OR/OP-to-OR channel abstraction layer. A channel's job is to transfer cells from Tor instance to Tor instance. Currently, there is only one implementation of the channel abstraction: in channeltls.c.

Channels are a higher-level abstraction than or_connection_t: In general, any means that two Tor relays use to exchange cells, or any means that a relay and a client use to exchange cells, is a channel.

Channels differ from pluggable transports in that they do not wrap an underlying protocol over which cells are transmitted: they are the underlying protocol.

This module defines the generic parts of the channel_t interface, and provides the machinery necessary for specialized implementations to be created. At present, there is one specialized implementation in channeltls.c, which uses connection_or.c to send cells over a TLS connection.

Every channel implementation is responsible for being able to transmit cells that are passed to it

For inbound cells, the entry point is: channel_process_cell(). It takes a cell and will pass it to the cell handler set by channel_set_cell_handlers(). Currently, this is passed back to the command subsystem which is command_process_cell().

NOTE: For now, the separation between channels and specialized channels (like channeltls) is not that well defined. So the channeltls layer calls channel_process_cell() which originally comes from the connection subsystem. This should be hopefully be fixed with #23993.

For outbound cells, the entry point is: channel_write_packed_cell(). Only packed cells are dequeued from the circuit queue by the scheduler which uses channel_flush_from_first_active_circuit() to decide which cells to flush from which circuit on the channel. They are then passed down to the channel subsystem. This calls the low layer with the function pointer .write_packed_cell().

Each specialized channel (currently only channeltls_t) MUST implement a series of function found in channel_t. See channel.h for more documentation.

Definition in file channel.c.

Function Documentation

◆ channel_add_to_digest_map()

STATIC void channel_add_to_digest_map ( channel_t chan)

Add a channel to the digest map.

This function adds a channel to the digest map and inserts it into the correct linked list if channels with that remote endpoint identity digest already exist.

Definition at line 560 of file channel.c.

◆ channel_change_state()

void channel_change_state ( channel_t chan,
channel_state_t  to_state 
)

As channel_change_state_, but change the state to any state but open.

Definition at line 1612 of file channel.c.

◆ channel_change_state_()

static void channel_change_state_ ( channel_t chan,
channel_state_t  to_state 
)
static

Change channel state.

This internal and subclass use only function is used to change channel state, performing all transition validity checks and whatever actions are appropriate to the state transition in question.

Definition at line 1519 of file channel.c.

Referenced by channel_change_state(), and channel_change_state_open().

◆ channel_change_state_open()

void channel_change_state_open ( channel_t chan)

As channel_change_state, but change the state to open.

Definition at line 1622 of file channel.c.

◆ channel_check_for_duplicates()

void channel_check_for_duplicates ( void  )

Relays run this once an hour to look over our list of channels to other relays. It prints out some statistics if there are multiple connections to many relays.

This function is similar to connection_or_set_bad_connections(), and probably could be adapted to replace it, if it was modified to actually take action on any of these connections.

Definition at line 748 of file channel.c.

◆ channel_clear_client()

void channel_clear_client ( channel_t chan)

Clear the client flag.

Mark a channel as being not from a client.

Definition at line 2919 of file channel.c.

◆ channel_clear_identity_digest()

void channel_clear_identity_digest ( channel_t chan)

Clear the identity_digest of a channel.

This function clears the identity digest of the remote endpoint for a channel; this is intended for use by the lower layer.

Definition at line 1302 of file channel.c.

◆ channel_clear_remote_end()

void channel_clear_remote_end ( channel_t chan)

Clear the remote end metadata (identity_digest) of a channel.

This function clears all the remote end info from a channel; this is intended for use by the lower layer.

Definition at line 1390 of file channel.c.

◆ channel_close_for_error()

void channel_close_for_error ( channel_t chan)

Notify that the channel is being closed due to an error condition.

This function is called by the lower layer implementing the transport when a channel must be closed due to an error condition. This does not call the channel's close method, since the lower layer already knows.

Definition at line 1244 of file channel.c.

◆ channel_close_from_lower_layer()

void channel_close_from_lower_layer ( channel_t chan)

Close a channel from the lower layer.

Notify the channel code that the channel is being closed due to a non-error condition in the lower layer. This does not call the close() method, since the lower layer already knows.

Definition at line 1216 of file channel.c.

◆ channel_closed()

void channel_closed ( channel_t chan)

Notify that the lower layer is finished closing the channel.

This function should be called by the lower layer when a channel is finished closing and it should be regarded as inactive and freed by the channel code.

Definition at line 1271 of file channel.c.

Referenced by connection_or_about_to_close().

◆ channel_connect()

channel_t* channel_connect ( const tor_addr_t addr,
uint16_t  port,
const char *  id_digest,
const ed25519_public_key_t ed_id 
)

Connect to a given addr/port/digest.

This sets up a new outgoing channel; in the future if multiple channel_t subclasses are available, this is where the selection policy should go. It may also be desirable to fold port into tor_addr_t or make a new type including a tor_addr_t and port, so we have a single abstract object encapsulating all the protocol details of how to contact an OR.

Definition at line 2319 of file channel.c.

Referenced by channel_connect_for_circuit().

◆ channel_describe_peer()

const char* channel_describe_peer ( channel_t chan)

Return text description of the remote endpoint canonical address.

This function returns a human-readable string for logging; nothing should parse it or rely on a particular format.

Subsequent calls to this function may invalidate its return value.

Definition at line 2815 of file channel.c.

◆ channel_describe_transport()

const char* channel_describe_transport ( channel_t chan)

Describe the transport subclass for a channel.

Invoke a method to get a string description of the lower-layer transport for this channel.

Definition at line 2508 of file channel.c.

Referenced by channel_dump_statistics().

◆ channel_do_open_actions()

void channel_do_open_actions ( channel_t chan)

Take actions required when a channel becomes open.

Handle actions we should do when we know a channel is open; a lot of this comes from the old connection_or_set_state_open() of connection_or.c.

Because of this mechanism, future channel_t subclasses should take care not to change a channel from CHANNEL_STATE_OPENING to CHANNEL_STATE_OPEN until there is positive confirmation that the network is operational. In particular, anything UDP-based should not make this transition until a packet is received from the other side.

Definition at line 1859 of file channel.c.

Referenced by channel_change_state_open().

◆ channel_dump_statistics()

void channel_dump_statistics ( channel_t chan,
int  severity 
)

Dump channel statistics.

Dump statistics for one channel to the log.

Definition at line 2537 of file channel.c.

◆ channel_dump_transport_statistics()

void channel_dump_transport_statistics ( channel_t chan,
int  severity 
)

Invoke transport-specific stats dump for channel.

If there is a lower-layer statistics dump method, invoke it.

Definition at line 2785 of file channel.c.

◆ channel_dumpstats()

void channel_dumpstats ( int  severity)

Dump channel statistics to the log.

This is called from dumpstats() in main.c and spams the log with statistics on channels.

Definition at line 2071 of file channel.c.

◆ channel_find_by_global_id()

channel_t* channel_find_by_global_id ( uint64_t  global_identifier)

Find channel by global ID.

This function searches for a channel by the global_identifier assigned at initialization time. This identifier is unique for the lifetime of the Tor process.

Definition at line 650 of file channel.c.

Referenced by circuitmux_set_policy().

◆ channel_find_by_remote_identity()

channel_t* channel_find_by_remote_identity ( const char *  rsa_id_digest,
const ed25519_public_key_t ed_id 
)

Find channel by RSA/Ed25519 identity of of the remote endpoint.

This function looks up a channel by the digest of its remote endpoint's RSA identity key. If ed_id is provided and nonzero, only a channel matching the ed_id will be returned.

It's possible that more than one channel to a given endpoint exists. Use channel_next_with_rsa_identity() to walk the list of channels; make sure to test for Ed25519 identity match too (as appropriate)

Definition at line 697 of file channel.c.

Referenced by channel_get_for_extend().

◆ channel_flush_some_cells()

ssize_t channel_flush_some_cells ( channel_t chan,
ssize_t  num_cells 
)

Try to flush cells of the given channel chan up to a maximum of num_cells.

This is called by the scheduler when it wants to flush cells from the channel's circuit queue(s) to the connection outbuf (not yet on the wire).

If the channel is not in state CHANNEL_STATE_OPEN, this does nothing and will return 0 meaning no cells were flushed.

If num_cells is -1, we'll try to flush up to the maximum cells allowed defined in MAX_CELLS_TO_GET_FROM_CIRCUITS_FOR_UNLIMITED.

On success, the number of flushed cells are returned and it can never be above num_cells. If 0 is returned, no cells were flushed either because the channel was not opened or we had no cells on the channel. A negative number can NOT be sent back.

This function is part of the fast path.

Definition at line 1730 of file channel.c.

◆ channel_force_xfree()

static void channel_force_xfree ( channel_t chan)
static

Free a channel and skip the state/registration asserts; this internal- use-only function should be called only from channel_free_all() when shutting down the Tor process.

Definition at line 981 of file channel.c.

◆ channel_free_()

void channel_free_ ( channel_t chan)

Free a channel; nothing outside of channel.c and subclasses should call this - it frees channels after they have closed and been unregistered.

Definition at line 902 of file channel.c.

◆ channel_free_all()

void channel_free_all ( void  )

Close all channels and free everything.

This gets called from tor_free_all() in main.c to clean up on exit. It will close all registered channels and free associated storage, then free the all_channels, active_channels, listening_channels and finished_channels lists and also channel_identity_map.

Definition at line 2246 of file channel.c.

◆ channel_free_list()

static void channel_free_list ( smartlist_t channels,
int  mark_for_close 
)
static

Free a list of channels for channel_free_all().

Definition at line 2182 of file channel.c.

◆ channel_get_addr_if_possible()

int channel_get_addr_if_possible ( const channel_t chan,
tor_addr_t addr_out 
)

Get the remote address for this channel, if possible.

Write the remote address out to a tor_addr_t if the underlying transport supports this operation, and return 1. Return 0 if the underlying transport doesn't let us do this.

Always returns the "real" address of the peer – the one we're connected to on the internet.

Definition at line 2835 of file channel.c.

Referenced by channel_do_open_actions(), and channel_dump_statistics().

◆ channel_get_cell_handler()

channel_cell_handler_fn_ptr channel_get_cell_handler ( channel_t chan)

Return the fixed-length cell handler for a channel.

This function gets the handler for incoming fixed-length cells installed on a channel.

Definition at line 1085 of file channel.c.

◆ channel_get_for_extend()

channel_t* channel_get_for_extend ( const char *  rsa_id_digest,
const ed25519_public_key_t ed_id,
const tor_addr_t target_ipv4_addr,
const tor_addr_t target_ipv6_addr,
bool  for_origin_circ,
const char **  msg_out,
int *  launch_out 
)

Get a channel to extend a circuit.

Given the desired relay identity, pick a suitable channel to extend a circuit to the target IPv4 or IPv6 address requested by the client. Search for an existing channel for the requested endpoint. Make sure the channel is usable for new circuits, and matches one of the target addresses.

Try to return the best channel. But if there is no good channel, set *msg_out to a message describing the channel's state and our next action, and set *launch_out to a boolean indicated whether the caller should try to launch a new channel with channel_connect().

If for_origin_circ is set, mark the channel as interesting for origin circuits, and therefore interesting for our bootstrapping reports.

Definition at line 2409 of file channel.c.

◆ channel_has_queued_writes()

int channel_has_queued_writes ( channel_t chan)

Return true iff the channel has any cells on the connection outbuf waiting to be sent onto the network.

Definition at line 2849 of file channel.c.

◆ channel_init()

void channel_init ( channel_t chan)

Initialize a channel.

This function should be called by subclasses to set up some per-channel variables. I.e., this is the superclass constructor. Before this, the channel should be allocated with tor_malloc_zero().

Definition at line 847 of file channel.c.

Referenced by channel_tls_common_init().

◆ channel_init_listener()

void channel_init_listener ( channel_listener_t chan_l)

Initialize a channel listener.

This function should be called by subclasses to set up some per-channel variables. I.e., this is the superclass constructor. Before this, the channel listener should be allocated with tor_malloc_zero().

Definition at line 886 of file channel.c.

◆ channel_is_bad_for_new_circs()

int channel_is_bad_for_new_circs ( channel_t chan)

Check the is_bad_for_new_circs flag.

This function returns the is_bad_for_new_circs flag of the specified channel.

Definition at line 2865 of file channel.c.

Referenced by channel_is_better(), and connection_or_is_bad_for_new_circs().

◆ channel_is_better()

int channel_is_better ( channel_t a,
channel_t b 
)

Decide which of two channels to prefer for extending a circuit.

This function is called while extending a circuit and returns true iff a is 'better' than b. The most important criterion here is that a canonical channel is always better than a non-canonical one, but the number of circuits and the age are used as tie-breakers.

This is based on the former connection_or_is_better() of connection_or.c

Definition at line 2337 of file channel.c.

◆ channel_is_canonical()

int channel_is_canonical ( channel_t chan)

Get the canonical flag for a channel.

This returns the is_canonical for a channel; this flag is determined by the lower layer and can't be set in a transport-independent way.

Definition at line 2933 of file channel.c.

Referenced by channel_is_better().

◆ channel_is_client()

int channel_is_client ( const channel_t chan)

Get the client flag.

This returns the client flag of a channel, which will be set if command_process_create_cell() in command.c thinks this is a connection from a client.

Definition at line 2893 of file channel.c.

Referenced by channel_do_open_actions(), and circuit_expire_old_circuits_serverside().

◆ channel_is_incoming()

int channel_is_incoming ( channel_t chan)

Test incoming flag.

This function gets the incoming flag; this is set when a listener spawns a channel. If this returns true the channel was remotely initiated.

Definition at line 2948 of file channel.c.

◆ channel_is_local()

int channel_is_local ( channel_t chan)

Test local flag.

This function gets the local flag; the lower layer should set this when setting up the channel if is_local_addr() is true for all of the destinations it will communicate with on behalf of this channel. It's used to decide whether to declare the network reachable when seeing incoming traffic on the channel.

Definition at line 2979 of file channel.c.

◆ channel_is_outgoing()

int channel_is_outgoing ( channel_t chan)

Test outgoing flag.

This function gets the outgoing flag; this is the inverse of the incoming bit set when a listener spawns a channel. If this returns true the channel was locally initiated.

Definition at line 3025 of file channel.c.

Referenced by channel_do_open_actions(), and channel_set_circid_type().

◆ channel_listener_change_state()

void channel_listener_change_state ( channel_listener_t chan_l,
channel_listener_state_t  to_state 
)

Change channel listener state.

This internal and subclass use only function is used to change channel listener state, performing all transition validity checks and whatever actions are appropriate to the state transition in question.

Definition at line 1639 of file channel.c.

Referenced by channel_tls_listener_close_method().

◆ channel_listener_describe_transport()

const char* channel_listener_describe_transport ( channel_listener_t chan_l)

Describe the transport subclass for a channel listener.

Invoke a method to get a string description of the lower-layer transport for this channel listener.

Definition at line 2523 of file channel.c.

Referenced by channel_listener_dump_statistics().

◆ channel_listener_dump_statistics()

void channel_listener_dump_statistics ( channel_listener_t chan_l,
int  severity 
)

Dump channel listener statistics.

Dump statistics for one channel listener to the log.

Definition at line 2719 of file channel.c.

◆ channel_listener_dump_transport_statistics()

void channel_listener_dump_transport_statistics ( channel_listener_t chan_l,
int  severity 
)

Invoke transport-specific stats dump for channel listener.

If there is a lower-layer statistics dump method, invoke it.

Definition at line 2798 of file channel.c.

Referenced by channel_listener_dump_statistics().

◆ channel_listener_dumpstats()

void channel_listener_dumpstats ( int  severity)

Dump channel listener statistics to the log.

This is called from dumpstats() in main.c and spams the log with statistics on channel listeners.

Definition at line 2102 of file channel.c.

◆ channel_listener_force_xfree()

static void channel_listener_force_xfree ( channel_listener_t chan_l)
static

Free a channel listener and skip the state/registration asserts; this internal-use-only function should be called only from channel_free_all() when shutting down the Tor process.

Definition at line 1025 of file channel.c.

◆ channel_listener_free_()

void channel_listener_free_ ( channel_listener_t chan_l)

Free a channel listener; nothing outside of channel.c and subclasses should call this - it frees channel listeners after they have closed and been unregistered.

Definition at line 954 of file channel.c.

◆ channel_listener_free_list()

static void channel_listener_free_list ( smartlist_t listeners,
int  mark_for_close 
)
static

Free a list of channel listeners for channel_free_all().

Definition at line 2213 of file channel.c.

◆ channel_listener_mark_for_close()

void channel_listener_mark_for_close ( channel_listener_t chan_l)

Mark a channel listener for closure.

This function tries to close a channel_listener_t; it will go into the CLOSING state, and eventually the lower layer should put it into the CLOSED or ERROR state. Then, channel_run_cleanup() will eventually free it.

Definition at line 1176 of file channel.c.

◆ channel_listener_process_incoming()

void channel_listener_process_incoming ( channel_listener_t listener)

Process the queue of incoming channels on a listener.

Use a listener's registered callback to process as many entries in the queue of incoming channels as possible.

Definition at line 1807 of file channel.c.

◆ channel_listener_queue_incoming()

void channel_listener_queue_incoming ( channel_listener_t listener,
channel_t incoming 
)

Queue an incoming channel on a listener.

Internal and subclass use only function to queue an incoming channel from a listener. A subclass of channel_listener_t should call this when a new incoming channel is created.

Definition at line 1925 of file channel.c.

Referenced by connection_tls_start_handshake().

◆ channel_listener_register()

void channel_listener_register ( channel_listener_t chan_l)

Register a channel listener.

This function registers a newly created channel listener in the global lists/maps of active channel listeners.

Definition at line 483 of file channel.c.

◆ channel_listener_run_cleanup()

void channel_listener_run_cleanup ( void  )

Clean up channel listeners.

This gets called periodically from run_scheduled_events() in main.c; it cleans up after closed channel listeners.

Definition at line 2159 of file channel.c.

Referenced by postloop_cleanup_cb().

◆ channel_listener_set_listener_fn()

void channel_listener_set_listener_fn ( channel_listener_t chan_l,
channel_listener_fn_ptr  listener 
)

Set the listener for a channel listener.

This function sets the handler for new incoming channels on a channel listener.

Definition at line 1062 of file channel.c.

Referenced by command_setup_listener().

◆ channel_listener_state_can_transition()

int channel_listener_state_can_transition ( channel_listener_state_t  from,
channel_listener_state_t  to 
)

Indicate whether a channel listener state transition is valid.

This function takes two channel listener states and indicates whether a transition between them is permitted (see the state definitions and transition table in or.h at the channel_listener_state_t typedef).

Definition at line 283 of file channel.c.

Referenced by channel_listener_change_state().

◆ channel_listener_state_is_valid()

int channel_listener_state_is_valid ( channel_listener_state_t  state)

Indicate whether a given channel listener state is valid.

Definition at line 210 of file channel.c.

Referenced by channel_listener_change_state().

◆ channel_listener_state_to_string()

const char* channel_listener_state_to_string ( channel_listener_state_t  state)

Return a human-readable description for a channel listener state.

Definition at line 350 of file channel.c.

Referenced by channel_listener_dump_statistics().

◆ channel_listener_timestamp_accepted()

void channel_listener_timestamp_accepted ( channel_listener_t chan_l)

Update the last accepted timestamp.

This function updates the channel listener's last accepted timestamp; it should be called whenever a new incoming channel is accepted on a listener.

Definition at line 3156 of file channel.c.

◆ channel_listener_timestamp_active()

void channel_listener_timestamp_active ( channel_listener_t chan_l)

Update the last active timestamp for a channel listener.

Definition at line 3139 of file channel.c.

◆ channel_listener_timestamp_created()

void channel_listener_timestamp_created ( channel_listener_t chan_l)

Update the created timestamp for a channel listener.

This updates the channel listener's created timestamp and should only be called from channel_init_listener().

Definition at line 3102 of file channel.c.

◆ channel_listener_unregister()

void channel_listener_unregister ( channel_listener_t chan_l)

Unregister a channel listener.

This function removes a channel listener from the global lists and maps and is used when freeing a closed/errored channel listener.

Definition at line 524 of file channel.c.

◆ channel_mark_bad_for_new_circs()

void channel_mark_bad_for_new_circs ( channel_t chan)

Mark a channel as bad for new circuits.

Set the is_bad_for_new_circs_flag on chan.

Definition at line 2878 of file channel.c.

◆ channel_mark_client()

void channel_mark_client ( channel_t chan)

Set the client flag.

Mark a channel as being from a client.

Definition at line 2906 of file channel.c.

◆ channel_mark_for_close()

void channel_mark_for_close ( channel_t chan)

Mark a channel for closure.

This function tries to close a channel_t; it will go into the CLOSING state, and eventually the lower layer should put it into the CLOSED or ERROR state. Then, channel_run_cleanup() will eventually free it.

Definition at line 1137 of file channel.c.

Referenced by channel_flush_from_first_active_circuit(), and channel_tls_listener_close_method().

◆ channel_mark_incoming()

void channel_mark_incoming ( channel_t chan)

Set the incoming flag.

This function is called when a channel arrives on a listening channel to mark it as incoming.

Definition at line 2962 of file channel.c.

◆ channel_mark_local()

void channel_mark_local ( channel_t chan)

Set the local flag.

This internal-only function should be called by the lower layer if the channel is to a local address. See channel_is_local() above or the description of the is_local bit in channel.h.

Definition at line 2994 of file channel.c.

◆ channel_mark_outgoing()

void channel_mark_outgoing ( channel_t chan)

Mark a channel as outgoing.

This function clears the incoming flag and thus marks a channel as outgoing.

Definition at line 3039 of file channel.c.

◆ channel_mark_remote()

void channel_mark_remote ( channel_t chan)

Mark a channel as remote.

This internal-only function should be called by the lower layer if the channel is not to a local address but has previously been marked local. See channel_is_local() above or the description of the is_local bit in channel.h

Definition at line 3010 of file channel.c.

◆ channel_matches_extend_info()

int channel_matches_extend_info ( channel_t chan,
extend_info_t extend_info 
)

Check if a channel matches an extend_info_t.

This function calls the lower layer and asks if this channel matches a given extend_info_t.

NOTE that this function only checks for an address/port match, and should be used only when no identity is available.

Definition at line 3270 of file channel.c.

Referenced by circuit_get_all_pending_on_channel().

◆ channel_matches_target_addr_for_extend()

STATIC bool channel_matches_target_addr_for_extend ( channel_t chan,
const tor_addr_t target_ipv4_addr,
const tor_addr_t target_ipv6_addr 
)

Check if a channel matches the given target IPv4 or IPv6 addresses. If either address matches, return true. If neither address matches, return false.

Both addresses can't be NULL.

This function calls into the lower layer and asks if this channel thinks it matches the target addresses for circuit extension purposes.

Definition at line 3290 of file channel.c.

◆ channel_more_to_flush()

int channel_more_to_flush ( channel_t chan)

Check if any cells are available.

This is used by the scheduler to know if the channel has more to flush after a scheduling round.

Definition at line 1773 of file channel.c.

◆ channel_next_with_rsa_identity()

channel_t* channel_next_with_rsa_identity ( channel_t chan)

Get next channel with digest.

This function takes a channel and finds the next channel in the list with the same digest.

Definition at line 731 of file channel.c.

Referenced by channel_get_for_extend().

◆ channel_notify_flushed()

void channel_notify_flushed ( channel_t chan)

Notify the channel we're done flushing the output in the lower layer.

Connection.c will call this when we've flushed the output; there's some dirreq-related maintenance to do.

Definition at line 1790 of file channel.c.

◆ channel_num_cells_writeable()

int channel_num_cells_writeable ( channel_t chan)

Estimate the number of writeable cells.

Ask the lower layer for an estimate of how many cells it can accept.

Definition at line 3056 of file channel.c.

◆ channel_num_circuits()

unsigned int channel_num_circuits ( channel_t chan)

Return the total number of circuits used by a channel.

Parameters
chanChannel to query
Returns
Number of circuits using this as n_chan or p_chan

Definition at line 3316 of file channel.c.

Referenced by channel_is_better(), and connection_or_get_num_circuits().

◆ channel_process_cell()

void channel_process_cell ( channel_t chan,
cell_t cell 
)

Process a cell from the given channel.

Definition at line 1976 of file channel.c.

◆ channel_register()

void channel_register ( channel_t chan)

Register a channel.

This function registers a newly created channel in the global lists/maps of active channels.

Definition at line 386 of file channel.c.

◆ channel_remote_identity_matches()

int channel_remote_identity_matches ( const channel_t chan,
const char *  rsa_id_digest,
const ed25519_public_key_t ed_id 
)

Return true iff chan matches rsa_id_digest and ed_id. as its identity keys. If either is NULL, do not check for a match.

Definition at line 667 of file channel.c.

◆ channel_remove_from_digest_map()

static void channel_remove_from_digest_map ( channel_t chan)
static

Remove a channel from the digest map.

This function removes a channel from the digest map and the linked list of channels for that digest if more than one exists.

Definition at line 597 of file channel.c.

◆ channel_rsa_id_group_set_badness()

static void channel_rsa_id_group_set_badness ( struct channel_list_t *  lst,
int  force 
)
static

Helper for channel_update_bad_for_new_circs(): Perform the channel_update_bad_for_new_circs operation on all channels in lst, all of which MUST have the same RSA ID. (They MAY have different Ed25519 IDs.)

Definition at line 3379 of file channel.c.

◆ channel_run_cleanup()

void channel_run_cleanup ( void  )

Clean up channels.

This gets called periodically from run_scheduled_events() in main.c; it cleans up after closed channels.

Definition at line 2133 of file channel.c.

Referenced by postloop_cleanup_cb().

◆ channel_send_destroy()

int channel_send_destroy ( circid_t  circ_id,
channel_t chan,
int  reason 
)

Send destroy cell on a channel.

Write a destroy cell with circ ID circ_id and reason reason onto channel chan. Don't perform range-checking on reason: we may want to propagate reasons from other cells.

Definition at line 2031 of file channel.c.

◆ channel_set_cell_handlers()

void channel_set_cell_handlers ( channel_t chan,
channel_cell_handler_fn_ptr  cell_handler 
)

Set both cell handlers for a channel.

This function sets both the fixed-length and variable length cell handlers for a channel.

Definition at line 1102 of file channel.c.

Referenced by command_setup_channel().

◆ channel_set_circid_type()

void channel_set_circid_type ( channel_t chan,
crypto_pk_t identity_rcvd,
int  consider_identity 
)

Set up circuit ID generation.

This is called when setting up a channel and replaces the old connection_or_set_circid_type().

Definition at line 3333 of file channel.c.

◆ channel_set_identity_digest()

void channel_set_identity_digest ( channel_t chan,
const char *  identity_digest,
const ed25519_public_key_t ed_identity 
)

Set the identity_digest of a channel.

This function sets the identity digest of the remote endpoint for a channel; this is intended for use by the lower layer.

Definition at line 1331 of file channel.c.

◆ channel_state_can_transition()

int channel_state_can_transition ( channel_state_t  from,
channel_state_t  to 
)

Indicate whether a channel state transition is valid.

This function takes two channel states and indicates whether a transition between them is permitted (see the state definitions and transition table in or.h at the channel_state_t typedef).

Definition at line 237 of file channel.c.

Referenced by channel_change_state_().

◆ channel_state_is_valid()

int channel_state_is_valid ( channel_state_t  state)

Indicate whether a given channel state is valid.

Definition at line 185 of file channel.c.

Referenced by channel_change_state_().

◆ channel_state_to_string()

const char* channel_state_to_string ( channel_state_t  state)

Return a human-readable description for a channel state.

Definition at line 315 of file channel.c.

Referenced by channel_dump_statistics().

◆ channel_timestamp_active()

void channel_timestamp_active ( channel_t chan)

Update the last active timestamp for a channel.

This function updates the channel's last active timestamp; it should be called by the lower layer whenever there is activity on the channel which does not lead to a cell being transmitted or received; the active timestamp is also updated from channel_timestamp_recv() and channel_timestamp_xmit(), but it should be updated for things like the v3 handshake and stuff that produce activity only visible to the lower layer.

Definition at line 3122 of file channel.c.

Referenced by connection_or_flushed_some().

◆ channel_timestamp_client()

void channel_timestamp_client ( channel_t chan)

Update client timestamp.

This function is called by relay.c to timestamp a channel that appears to be used as a client.

Definition at line 3173 of file channel.c.

◆ channel_timestamp_created()

void channel_timestamp_created ( channel_t chan)

Update the created timestamp for a channel.

This updates the channel's created timestamp and should only be called from channel_init().

Definition at line 3086 of file channel.c.

◆ channel_timestamp_recv()

void channel_timestamp_recv ( channel_t chan)

Update the recv timestamp.

This is called whenever we get an incoming cell from the lower layer. This also updates the active timestamp.

Definition at line 3189 of file channel.c.

◆ channel_timestamp_xmit()

void channel_timestamp_xmit ( channel_t chan)

Update the xmit timestamp.

This is called whenever we pass an outgoing cell to the lower layer. This also updates the active timestamp.

Definition at line 3209 of file channel.c.

◆ channel_unregister()

void channel_unregister ( channel_t chan)

Unregister a channel.

This function removes a channel from the global lists and maps and is used when freeing a closed/errored channel.

Definition at line 444 of file channel.c.

◆ channel_update_bad_for_new_circs()

void channel_update_bad_for_new_circs ( const char *  digest,
int  force 
)

Go through all the channels (or if digest is non-NULL, just the OR connections with that digest), and set the is_bad_for_new_circs flag based on the rules in connection_or_group_set_badness() (or just always set it if force is true).

Definition at line 3438 of file channel.c.

Referenced by second_elapsed_callback().

◆ channel_when_created()

time_t channel_when_created ( channel_t chan)

Query created timestamp for a channel.

Definition at line 3231 of file channel.c.

Referenced by channel_is_better().

◆ channel_when_last_client()

time_t channel_when_last_client ( channel_t chan)

Query client timestamp.

Definition at line 3242 of file channel.c.

Referenced by connection_or_client_used().

◆ channel_when_last_xmit()

time_t channel_when_last_xmit ( channel_t chan)

Query xmit timestamp.

Definition at line 3253 of file channel.c.

Referenced by circuit_expire_old_circuits_serverside().

◆ channel_write_packed_cell()

int channel_write_packed_cell ( channel_t chan,
packed_cell_t cell 
)

Write a packed cell to a channel.

Write a packed cell to a channel using the write_cell() method. This is called by the transport-independent code to deliver a packed cell to a channel for transmission.

Return 0 on success else a negative value. In both cases, the caller should not access the cell anymore, it is freed both on success and error.

Definition at line 1484 of file channel.c.

Referenced by channel_flush_from_first_active_circuit().

◆ HT_HEAD()

static HT_HEAD ( channel_gid_map  ,
channel_t   
)
static

Map from channel->global_identifier to channel. Contains the same elements as all_channels.

Definition at line 109 of file channel.c.

◆ packed_cell_is_destroy()

int packed_cell_is_destroy ( channel_t chan,
const packed_cell_t packed_cell,
circid_t circid_out 
)

If packed_cell on chan is a destroy cell, then set *circid_out to its circuit ID, and return true. Otherwise, return false.

Definition at line 2005 of file channel.c.

◆ write_packed_cell()

static int write_packed_cell ( channel_t chan,
packed_cell_t cell 
)
static

Write to a channel the given packed cell.

Two possible errors can happen. Either the channel is not opened or the lower layer (specialized channel) failed to write it. In both cases, it is the caller responsibility to free the cell.

Definition at line 1420 of file channel.c.