tor  master
Data Structures | Macros | Typedefs | Functions
control.c File Reference

Implementation for Tor's control-socket interface. More...

#include "or.h"
#include "addressmap.h"
#include "bridges.h"
#include "buffers.h"
#include "channel.h"
#include "channeltls.h"
#include "circuitbuild.h"
#include "circuitlist.h"
#include "circuitstats.h"
#include "circuituse.h"
#include "command.h"
#include "compat_libevent.h"
#include "config.h"
#include "confparse.h"
#include "connection.h"
#include "connection_edge.h"
#include "connection_or.h"
#include "control.h"
#include "crypto_rand.h"
#include "crypto_util.h"
#include "directory.h"
#include "dirserv.h"
#include "dnsserv.h"
#include "entrynodes.h"
#include "geoip.h"
#include "hibernate.h"
#include "hs_cache.h"
#include "hs_common.h"
#include "hs_control.h"
#include "main.h"
#include "microdesc.h"
#include "networkstatus.h"
#include "nodelist.h"
#include "policies.h"
#include "proto_control0.h"
#include "proto_http.h"
#include "reasons.h"
#include "rendclient.h"
#include "rendcommon.h"
#include "rendservice.h"
#include "rephist.h"
#include "router.h"
#include "routerlist.h"
#include "routerparse.h"
#include "shared_random_client.h"
#include <pwd.h>
#include <sys/resource.h>
#include "crypto_s2k.h"
#include "procmon.h"
Include dependency graph for control.c:

Data Structures

struct  queued_event_s
 
struct  control_event_t
 
struct  signal_t
 
struct  getinfo_item_t
 
struct  cached_bw_event_s
 

Macros

#define CONTROL_PRIVATE
 
#define STATE_IS_OPEN(s)   ((s) == CONTROL_CONN_STATE_OPEN)
 
#define EVENT_IS_INTERESTING(e)   (!! (global_event_mask & EVENT_MASK_(e)))
 
#define ANY_EVENT_IS_INTERESTING(e)   (!! (global_event_mask & (e)))
 
#define AUTHENTICATION_COOKIE_LEN   32
 
#define SAFECOOKIE_SERVER_TO_CONTROLLER_CONSTANT   "Tor safe cookie authentication server-to-controller hash"
 
#define SAFECOOKIE_CONTROLLER_TO_SERVER_CONSTANT   "Tor safe cookie authentication controller-to-server hash"
 
#define SAFECOOKIE_SERVER_NONCE_LEN   DIGEST256_LEN
 
#define BOOTSTRAP_MSG_LEN   1024
 
#define NEWLY_ENABLED(ev)   (! (old_mask & (ev)) && (new_mask & (ev)))
 
#define queued_event_free(ev)   FREE_AND_NULL(queued_event_t, queued_event_free_, (ev))
 
#define ITEM(name, fn, desc)   { name, getinfo_helper_##fn, desc, 0 }
 
#define PREFIX(name, fn, desc)   { name, getinfo_helper_##fn, desc, 1 }
 
#define DOC(name, desc)   { name, NULL, desc, 0 }
 
#define MAX_COMMAND_LINE_LENGTH   (1024*1024)
 
#define N_BW_EVENTS_TO_CACHE   300
 
#define CONTROL_EVENT_STATUS_BODY(event, sev)
 
#define BOOTSTRAP_PROBLEM_THRESHOLD   10
 
#define BOOTSTRAP_PCT_INCREMENT   5
 

Typedefs

typedef uint64_t event_mask_t
 
typedef struct queued_event_s queued_event_t
 
typedef int(* getinfo_helper_t) (control_connection_t *, const char *q, char **a, const char **error_out)
 
typedef struct getinfo_item_t getinfo_item_t
 

Functions

void control_update_global_event_mask (void)
 
void control_adjust_event_log_severity (void)
 
int control_event_is_interesting (int event)
 
int control_any_per_second_event_enabled (void)
 
void control_per_second_events (void)
 
STATIC size_t write_escaped_data (const char *data, size_t len, char **out)
 
STATIC size_t read_escaped_data (const char *data, size_t len, char **out)
 
int control_connection_add_local_fd (tor_socket_t sock, unsigned flags)
 
void control_ports_write_to_file (void)
 
void control_initialize_event_queue (void)
 
 MOCK_IMPL (STATIC void, queue_control_event_string,(uint16_t event, char *msg))
 
 MOCK_IMPL (STATIC void, send_control_event_string,(uint16_t event, const char *msg))
 
smartlist_tdecode_hashed_passwords (config_line_t *passwords)
 
STATIC int getinfo_helper_current_time (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_dir (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC void getinfo_helper_downloads_networkstatus (const char *flavor, download_status_t **dl_to_emit, const char **errmsg)
 
STATIC void getinfo_helper_downloads_cert (const char *fp_sk_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC void getinfo_helper_downloads_desc (const char *desc_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC void getinfo_helper_downloads_bridge (const char *bridge_req, download_status_t **dl_to_emit, smartlist_t **digest_list, const char **errmsg)
 
STATIC int getinfo_helper_downloads (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int getinfo_helper_onions (control_connection_t *control_conn, const char *question, char **answer, const char **errmsg)
 
STATIC int add_onion_helper_keyarg (const char *arg, int discard_pk, const char **key_new_alg_out, char **key_new_blob_out, add_onion_secret_key_t *decoded_key, int *hs_version, char **err_msg_out)
 
STATIC rend_authorized_client_tadd_onion_helper_clientauth (const char *arg, int *created, char **err_msg)
 
int connection_control_finished_flushing (control_connection_t *conn)
 
int connection_control_reached_eof (control_connection_t *conn)
 
void connection_control_closed (control_connection_t *conn)
 
int connection_control_process_inbuf (control_connection_t *conn)
 
int control_event_circuit_status (origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
 
int control_event_circuit_purpose_changed (origin_circuit_t *circ, int old_purpose)
 
int control_event_circuit_cannibalized (origin_circuit_t *circ, int old_purpose, const struct timeval *old_tv_created)
 
int control_event_stream_status (entry_connection_t *conn, stream_status_event_t tp, int reason_code)
 
int control_event_or_conn_status (or_connection_t *conn, or_conn_status_event_t tp, int reason)
 
int control_event_stream_bandwidth (edge_connection_t *edge_conn)
 
int control_event_stream_bandwidth_used (void)
 
int control_event_circ_bandwidth_used (void)
 
int control_event_conn_bandwidth (connection_t *conn)
 
int control_event_conn_bandwidth_used (void)
 
void sum_up_cell_stats_by_command (circuit_t *circ, cell_stats_t *cell_stats)
 
void append_cell_stats_by_command (smartlist_t *event_parts, const char *key, const uint64_t *include_if_non_zero, const uint64_t *number_to_include)
 
void format_cell_stats (char **event_string, circuit_t *circ, cell_stats_t *cell_stats)
 
int control_event_circuit_cell_stats (void)
 
int control_event_bandwidth_used (uint32_t n_read, uint32_t n_written)
 
STATIC char * get_bw_samples (void)
 
void disable_control_logging (void)
 
void enable_control_logging (void)
 
void control_event_logmsg (int severity, uint32_t domain, const char *msg)
 
void control_event_logmsg_pending (void)
 
int control_event_descriptors_changed (smartlist_t *routers)
 
int control_event_address_mapped (const char *from, const char *to, time_t expires, const char *error, const int cached)
 
int control_event_network_liveness_update (int liveness)
 
int control_event_networkstatus_changed (smartlist_t *statuses)
 
int control_event_newconsensus (const networkstatus_t *consensus)
 
int control_event_buildtimeout_set (buildtimeout_set_event_t type, const char *args)
 
int control_event_signal (uintptr_t signal_num)
 
int control_event_networkstatus_changed_single (const routerstatus_t *rs)
 
int control_event_my_descriptor_changed (void)
 
int control_event_general_status (int severity, const char *format,...)
 
int control_event_general_error (const char *format,...)
 
int control_event_client_status (int severity, const char *format,...)
 
int control_event_client_error (const char *format,...)
 
int control_event_server_status (int severity, const char *format,...)
 
int control_event_server_error (const char *format,...)
 
int control_event_guard (const char *nickname, const char *digest, const char *status)
 
int control_event_conf_changed (const smartlist_t *elements)
 
char * get_controller_cookie_file_name (void)
 
int init_control_cookie_authentication (int enabled)
 
void monitor_owning_controller_process (const char *process_spec)
 
int control_event_bootstrap (bootstrap_status_t status, int progress)
 
void control_event_bootstrap_problem (const char *warn, const char *reason, const connection_t *conn, int dowarn)
 
 MOCK_IMPL (void, control_event_bootstrap_prob_or,(const char *warn, int reason, or_connection_t *or_conn))
 
void control_event_clients_seen (const char *controller_str)
 
void control_event_transport_launched (const char *mode, const char *transport_name, tor_addr_t *addr, uint16_t port)
 
const char * rend_auth_type_to_string (rend_auth_type_t auth_type)
 
 MOCK_IMPL (const char *, node_describe_longname_by_id,(const char *id_digest))
 
void control_event_hs_descriptor_requested (const char *onion_address, rend_auth_type_t auth_type, const char *id_digest, const char *desc_id, const char *hsdir_index)
 
void control_event_hs_descriptor_created (const char *onion_address, const char *desc_id, int replica)
 
void control_event_hs_descriptor_upload (const char *onion_address, const char *id_digest, const char *desc_id, const char *hsdir_index)
 
void control_event_hs_descriptor_upload_end (const char *action, const char *onion_address, const char *id_digest, const char *reason)
 
void control_event_hsv2_descriptor_received (const char *onion_address, const rend_data_t *rend_data, const char *hsdir_id_digest)
 
void control_event_hsv3_descriptor_received (const char *onion_address, const char *desc_id, const char *hsdir_id_digest)
 
void control_event_hs_descriptor_uploaded (const char *id_digest, const char *onion_address)
 
void control_event_hsv2_descriptor_failed (const rend_data_t *rend_data, const char *hsdir_id_digest, const char *reason)
 
void control_event_hsv3_descriptor_failed (const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *reason)
 
void control_event_hs_descriptor_content (const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *content)
 
void control_event_hs_descriptor_upload_failed (const char *id_digest, const char *onion_address, const char *reason)
 
void control_free_all (void)
 

Detailed Description

Implementation for Tor's control-socket interface.

A "controller" is an external program that monitors and controls a Tor instance via a text-based protocol. It connects to Tor via a connection to a local socket.

The protocol is line-driven. The controller sends commands terminated by a CRLF. Tor sends lines that are either replies to what the controller has said, or events that Tor sends to the controller asynchronously based on occurrences in the Tor network model.

See the control-spec.txt file in the torspec.git repository for full details on protocol.

This module generally has two kinds of entry points: those based on having received a command on a controller socket, which are handled in connection_control_process_inbuf(), and dispatched to individual functions with names like control_handle_COMMANDNAME(); and those based on events that occur elsewhere in Tor, which are handled by functions with names like control_event_EVENTTYPE().

Controller events are not sent immediately; rather, they are inserted into the queued_control_events array, and flushed later from flush_queued_events_cb(). Doing this simplifies our callgraph greatly, by limiting the number of places in Tor that can call back into the network stack.

Macro Definition Documentation

◆ ANY_EVENT_IS_INTERESTING

#define ANY_EVENT_IS_INTERESTING (   e)    (!! (global_event_mask & (e)))

Macro: true if any event from the bitfield 'e' is interesting.

◆ AUTHENTICATION_COOKIE_LEN

#define AUTHENTICATION_COOKIE_LEN   32

If we're using cookie-type authentication, how long should our cookies be?

◆ BOOTSTRAP_MSG_LEN

#define BOOTSTRAP_MSG_LEN   1024

A sufficiently large size to record the last bootstrap phase string.

◆ BOOTSTRAP_PCT_INCREMENT

#define BOOTSTRAP_PCT_INCREMENT   5

When our bootstrapping progress level changes, but our bootstrapping status has not advanced, we only log at NOTICE when we have made at least this much progress.

◆ BOOTSTRAP_PROBLEM_THRESHOLD

#define BOOTSTRAP_PROBLEM_THRESHOLD   10

We only tell the controller once we've hit a threshold of problems for the current phase.

◆ CONTROL_EVENT_STATUS_BODY

#define CONTROL_EVENT_STATUS_BODY (   event,
  sev 
)
Value:
int r; \
do { \
va_list ap; \
if (!EVENT_IS_INTERESTING(event)) \
return 0; \
\
va_start(ap, format); \
r = control_event_status((event), (sev), format, ap); \
va_end(ap); \
} while (0)
#define EVENT_IS_INTERESTING(e)
Definition: control.c:113

◆ EVENT_IS_INTERESTING

#define EVENT_IS_INTERESTING (   e)    (!! (global_event_mask & EVENT_MASK_(e)))

Macro: true if any control connection is interested in events of type e.

◆ MAX_COMMAND_LINE_LENGTH

#define MAX_COMMAND_LINE_LENGTH   (1024*1024)

Do not accept any control command of more than 1MB in length. Anything that needs to be anywhere near this long probably means that one of our interfaces is broken.

◆ STATE_IS_OPEN

#define STATE_IS_OPEN (   s)    ((s) == CONTROL_CONN_STATE_OPEN)

Yield true iff s is the state of a control_connection_t that has finished authentication and is accepting commands.

Typedef Documentation

◆ event_mask_t

typedef uint64_t event_mask_t

Bitfield: The bit 1<<e is set if any open control connection is interested in events of type e. We use this so that we can decide to skip generating event messages that nobody has interest in without having to walk over the global connection list to find out.

◆ getinfo_helper_t

typedef int(* getinfo_helper_t) (control_connection_t *, const char *q, char **a, const char **error_out)

Callback function for GETINFO: on a given control connection, try to answer the question q and store the newly-allocated answer in *a. If an internal error occurs, return -1 and optionally set *error_out to point to an error message to be delivered to the controller. On success, or if the key is not recognized, return 0. Do not set a if the key is not recognized but you may set error_out to improve the error message.

◆ getinfo_item_t

A single item for the GETINFO question-to-answer-function table.

◆ queued_event_t

Represents an event that's queued to be sent to one or more controllers.

Function Documentation

◆ add_onion_helper_clientauth()

STATIC rend_authorized_client_t* add_onion_helper_clientauth ( const char *  arg,
int *  created,
char **  err_msg 
)

Helper function to handle parsing a ClientAuth argument to the ADD_ONION command. Return a new rend_authorized_client_t, or NULL and an optional control protocol error message on failure. The caller is responsible for freeing the returned auth_client and err_msg.

If 'created' is specified, it will be set to 1 when a new cookie has been generated.

◆ add_onion_helper_keyarg()

STATIC int add_onion_helper_keyarg ( const char *  arg,
int  discard_pk,
const char **  key_new_alg_out,
char **  key_new_blob_out,
add_onion_secret_key_t *  decoded_key,
int *  hs_version,
char **  err_msg_out 
)

Helper function to handle parsing the KeyType:KeyBlob argument to the ADD_ONION command. Return a new crypto_pk_t and if a new key was generated and the private key not discarded, the algorithm and serialized private key, or NULL and an optional control protocol error message on failure. The caller is responsible for freeing the returned key_new_blob and err_msg.

Note: The error messages returned are deliberately vague to avoid echoing key material.

Here is the call graph for this function:

◆ append_cell_stats_by_command()

void append_cell_stats_by_command ( smartlist_t event_parts,
const char *  key,
const uint64_t *  include_if_non_zero,
const uint64_t *  number_to_include 
)

Helper: append a cell statistics string to event_parts, prefixed with key=. Statistics consist of comma-separated key:value pairs with lower-case command strings as keys and cell numbers or total waiting times as values. A key:value pair is included if the entry in include_if_non_zero is not zero, but with the (possibly zero) entry from number_to_include. Both arrays are expected to have a length of CELL_COMMAND_MAX_ + 1. If no entry in include_if_non_zero is positive, no string will be added to event_parts.

◆ connection_control_closed()

void connection_control_closed ( control_connection_t conn)

Called when conn is being freed.

Here is the call graph for this function:

◆ connection_control_finished_flushing()

int connection_control_finished_flushing ( control_connection_t conn)

Called when conn has no more bytes left on its outbuf.

◆ connection_control_process_inbuf()

int connection_control_process_inbuf ( control_connection_t conn)

Called when data has arrived on a v1 control connection: Try to fetch commands from conn->inbuf, and execute them.

◆ connection_control_reached_eof()

int connection_control_reached_eof ( control_connection_t conn)

Called when conn has gotten its socket closed.

◆ control_adjust_event_log_severity()

void control_adjust_event_log_severity ( void  )

Adjust the log severities that result in control_event_logmsg being called to match the severity of log messages that any controllers are interested in.

Here is the call graph for this function:

◆ control_any_per_second_event_enabled()

int control_any_per_second_event_enabled ( void  )

Return true if any event that needs to fire once a second is enabled.

Here is the caller graph for this function:

◆ control_connection_add_local_fd()

int control_connection_add_local_fd ( tor_socket_t  sock,
unsigned  flags 
)

Create and add a new controller connection on sock. If CC_LOCAL_FD_IS_OWNER is set in flags, this Tor process should exit when the connection closes. If CC_LOCAL_FD_IS_AUTHENTICATED is set, then the connection does not need to authenticate.

◆ control_event_address_mapped()

int control_event_address_mapped ( const char *  from,
const char *  to,
time_t  expires,
const char *  error,
const int  cached 
)

Called when an address mapping on from from changes to to. expires values less than 3 are special; see connection_edge.c. If error is non-NULL, it is an error code describing the failure mode of the mapping.

◆ control_event_bandwidth_used()

int control_event_bandwidth_used ( uint32_t  n_read,
uint32_t  n_written 
)

A second or more has elapsed: tell any interested control connections how much bandwidth we used.

◆ control_event_bootstrap()

int control_event_bootstrap ( bootstrap_status_t  status,
int  progress 
)

Called when Tor has made progress at bootstrapping its directory information and initial circuits.

status is the new status, that is, what task we will be doing next. progress is zero if we just started this task, else it represents progress on the task.

Return true if we logged a message at level NOTICE, and false otherwise.

◆ control_event_bootstrap_problem()

void control_event_bootstrap_problem ( const char *  warn,
const char *  reason,
const connection_t conn,
int  dowarn 
)

Called when Tor has failed to make bootstrapping progress in a way that indicates a problem. warn gives a human-readable hint as to why, and reason provides a controller-facing short tag. conn is the connection that caused this problem and can be NULL if a connection cannot be easily identified.

◆ control_event_buildtimeout_set()

int control_event_buildtimeout_set ( buildtimeout_set_event_t  type,
const char *  args 
)

Called when we compute a new circuitbuildtimeout

◆ control_event_circ_bandwidth_used()

int control_event_circ_bandwidth_used ( void  )

A second or more has elapsed: tell any interested control connections how much bandwidth origin circuits have used.

◆ control_event_circuit_cannibalized()

int control_event_circuit_cannibalized ( origin_circuit_t circ,
int  old_purpose,
const struct timeval old_tv_created 
)

circ has changed its purpose from old_purpose, and its created-time from old_tv_created: tell any interested controllers.

◆ control_event_circuit_cell_stats()

int control_event_circuit_cell_stats ( void  )

A second or more has elapsed: tell any interested control connection how many cells have been processed for a given circuit.

◆ control_event_circuit_purpose_changed()

int control_event_circuit_purpose_changed ( origin_circuit_t circ,
int  old_purpose 
)

circ has changed its purpose from old_purpose: tell any interested controllers.

◆ control_event_circuit_status()

int control_event_circuit_status ( origin_circuit_t circ,
circuit_status_event_t  tp,
int  reason_code 
)

Something major has happened to circuit circ: tell any interested control connections.

Here is the caller graph for this function:

◆ control_event_client_error()

int control_event_client_error ( const char *  format,
  ... 
)

Format and send an EVENT_STATUS_CLIENT LOG_ERR event, and flush it to the controller(s) immediately.

◆ control_event_client_status()

int control_event_client_status ( int  severity,
const char *  format,
  ... 
)

Format and send an EVENT_STATUS_CLIENT event whose main text is obtained by formatting the arguments using the printf-style format.

Here is the caller graph for this function:

◆ control_event_clients_seen()

void control_event_clients_seen ( const char *  controller_str)

We just generated a new summary of which countries we've seen clients from recently. Send a copy to the controller in case it wants to display it for the user.

◆ control_event_conf_changed()

int control_event_conf_changed ( const smartlist_t elements)

Called when a configuration option changes. This is generally triggered by SETCONF requests and RELOAD/SIGHUP signals. The elements is a smartlist_t containing (key, value, ...) pairs in sequence. value can be NULL.

Here is the call graph for this function:

◆ control_event_conn_bandwidth()

int control_event_conn_bandwidth ( connection_t conn)

Print out CONN_BW event for a single OR/DIR/EXIT conn and reset bandwidth counters.

Here is the caller graph for this function:

◆ control_event_conn_bandwidth_used()

int control_event_conn_bandwidth_used ( void  )

A second or more has elapsed: tell any interested control connections how much bandwidth connections have used.

Here is the call graph for this function:

◆ control_event_descriptors_changed()

int control_event_descriptors_changed ( smartlist_t routers)

Called whenever we receive new router descriptors: tell any interested control connections. routers is a list of routerinfo_t's.

Here is the caller graph for this function:

◆ control_event_general_error()

int control_event_general_error ( const char *  format,
  ... 
)

Format and send an EVENT_STATUS_GENERAL LOG_ERR event, and flush it to the controller(s) immediately.

◆ control_event_general_status()

int control_event_general_status ( int  severity,
const char *  format,
  ... 
)

Format and send an EVENT_STATUS_GENERAL event whose main text is obtained by formatting the arguments using the printf-style format.

Here is the caller graph for this function:

◆ control_event_guard()

int control_event_guard ( const char *  nickname,
const char *  digest,
const char *  status 
)

Called when the status of an entry guard with the given nickname and identity digest has changed to status: tells any controllers that care.

Here is the call graph for this function:

◆ control_event_hs_descriptor_content()

void control_event_hs_descriptor_content ( const char *  onion_address,
const char *  desc_id,
const char *  hsdir_id_digest,
const char *  content 
)

Send HS_DESC_CONTENT event after completion of a successful fetch from hs directory. If hsdir_id_digest is NULL, it is replaced by "UNKNOWN". If content is NULL, it is replaced by an empty string. The onion_address or desc_id set to NULL will no trigger the control event.

◆ control_event_hs_descriptor_created()

void control_event_hs_descriptor_created ( const char *  onion_address,
const char *  desc_id,
int  replica 
)

send HS_DESC CREATED event when a local service generates a descriptor.

onion_address is service address. desc_id is the descriptor ID. replica is the the descriptor replica number. If it is negative, it is ignored.

◆ control_event_hs_descriptor_requested()

void control_event_hs_descriptor_requested ( const char *  onion_address,
rend_auth_type_t  auth_type,
const char *  id_digest,
const char *  desc_id,
const char *  hsdir_index 
)

send HS_DESC requested event.

rend_query is used to fetch requested onion address and auth type. hs_dir is the description of contacting hs directory. desc_id_base32 is the ID of requested hs descriptor. hsdir_index is the HSDir fetch index value for v3, an hex string.

◆ control_event_hs_descriptor_upload()

void control_event_hs_descriptor_upload ( const char *  onion_address,
const char *  id_digest,
const char *  desc_id,
const char *  hsdir_index 
)

send HS_DESC upload event.

onion_address is service address. hs_dir is the description of contacting hs directory. desc_id is the ID of requested hs descriptor.

◆ control_event_hs_descriptor_upload_end()

void control_event_hs_descriptor_upload_end ( const char *  action,
const char *  onion_address,
const char *  id_digest,
const char *  reason 
)

send HS_DESC event after got response from hs directory.

NOTE: this is an internal function used by following functions: control_event_hs_descriptor_uploaded control_event_hs_descriptor_upload_failed

So do not call this function directly.

◆ control_event_hs_descriptor_upload_failed()

void control_event_hs_descriptor_upload_failed ( const char *  id_digest,
const char *  onion_address,
const char *  reason 
)

Send HS_DESC event to inform controller upload of hidden service descriptor identified by id_digest failed. If reason is not NULL, add it to REASON= field.

◆ control_event_hs_descriptor_uploaded()

void control_event_hs_descriptor_uploaded ( const char *  id_digest,
const char *  onion_address 
)

send HS_DESC UPLOADED event

called when we successfully uploaded a hidden service descriptor.

◆ control_event_hsv2_descriptor_failed()

void control_event_hsv2_descriptor_failed ( const rend_data_t rend_data,
const char *  hsdir_id_digest,
const char *  reason 
)

Send HS_DESC event to inform controller that query rend_data failed to retrieve hidden service descriptor from directory identified by id_digest. If NULL, "UNKNOWN" is used. If reason is not NULL, add it to REASON= field.

◆ control_event_hsv2_descriptor_received()

void control_event_hsv2_descriptor_received ( const char *  onion_address,
const rend_data_t rend_data,
const char *  hsdir_id_digest 
)

send HS_DESC RECEIVED event

called when we successfully received a hidden service descriptor.

◆ control_event_hsv3_descriptor_failed()

void control_event_hsv3_descriptor_failed ( const char *  onion_address,
const char *  desc_id,
const char *  hsdir_id_digest,
const char *  reason 
)

Send HS_DESC event to inform controller that the query to onion_address failed to retrieve hidden service descriptor desc_id from directory identified by hsdir_id_digest. If NULL, "UNKNOWN" is used. If reason is not NULL, add it to REASON= field.

◆ control_event_is_interesting()

int control_event_is_interesting ( int  event)

Return true iff the event with code c is being sent to any current control connection. This is useful if the amount of work needed to prepare to call the appropriate control_event_...() function is high.

Here is the caller graph for this function:

◆ control_event_logmsg()

void control_event_logmsg ( int  severity,
uint32_t  domain,
const char *  msg 
)

We got a log message: tell any interested control connections.

Here is the call graph for this function:

◆ control_event_logmsg_pending()

void control_event_logmsg_pending ( void  )

Logging callback: called when there is a queued pending log callback.

Here is the call graph for this function:

◆ control_event_my_descriptor_changed()

int control_event_my_descriptor_changed ( void  )

Our own router descriptor has changed; tell any controllers that care.

◆ control_event_network_liveness_update()

int control_event_network_liveness_update ( int  liveness)

The network liveness has changed; this is called from circuitstats.c whenever we receive a cell, or when timeout expires and we assume the network is down.

◆ control_event_networkstatus_changed()

int control_event_networkstatus_changed ( smartlist_t statuses)

Called when the routerstatus_ts statuses have changed: sends an NS event to any controller that cares.

◆ control_event_networkstatus_changed_single()

int control_event_networkstatus_changed_single ( const routerstatus_t rs)

Called when a single local_routerstatus_t has changed: Sends an NS event to any controller that cares.

◆ control_event_newconsensus()

int control_event_newconsensus ( const networkstatus_t consensus)

Called when we get a new consensus networkstatus. Sends a NEWCONSENSUS event consisting of an NS-style line for each relay in the consensus.

Here is the call graph for this function:

◆ control_event_or_conn_status()

int control_event_or_conn_status ( or_connection_t conn,
or_conn_status_event_t  tp,
int  reason 
)

Called when the status of an OR connection conn changes: tell any interested control connections. tp is the new status for the connection. If conn has just closed or failed, then reason may be the reason why.

Here is the caller graph for this function:

◆ control_event_server_error()

int control_event_server_error ( const char *  format,
  ... 
)

Format and send an EVENT_STATUS_SERVER LOG_ERR event, and flush it to the controller(s) immediately.

◆ control_event_server_status()

int control_event_server_status ( int  severity,
const char *  format,
  ... 
)

Format and send an EVENT_STATUS_SERVER event whose main text is obtained by formatting the arguments using the printf-style format.

◆ control_event_signal()

int control_event_signal ( uintptr_t  signal_num)

Called when a signal has been processed from signal_callback

Here is the call graph for this function:

◆ control_event_stream_bandwidth()

int control_event_stream_bandwidth ( edge_connection_t edge_conn)

Print out STREAM_BW event for a single conn

◆ control_event_stream_bandwidth_used()

int control_event_stream_bandwidth_used ( void  )

A second or more has elapsed: tell any interested control connections how much bandwidth streams have used.

◆ control_event_stream_status()

int control_event_stream_status ( entry_connection_t conn,
stream_status_event_t  tp,
int  reason_code 
)

Something has happened to the stream associated with AP connection conn: tell any interested control connections.

Here is the caller graph for this function:

◆ control_event_transport_launched()

void control_event_transport_launched ( const char *  mode,
const char *  transport_name,
tor_addr_t addr,
uint16_t  port 
)

A new pluggable transport called transport_name was launched on addr:port. mode is either "server" or "client" depending on the mode of the pluggable transport. "650" SP "TRANSPORT_LAUNCHED" SP Mode SP Name SP Address SP Port

◆ control_free_all()

void control_free_all ( void  )

Free any leftover allocated memory of the control.c subsystem.

◆ control_per_second_events()

void control_per_second_events ( void  )

Run all the controller events (if any) that are scheduled to trigger once per second.

Here is the call graph for this function:

◆ control_ports_write_to_file()

void control_ports_write_to_file ( void  )

Write all of the open control ports to ControlPortWriteToFile

Here is the call graph for this function:

◆ control_update_global_event_mask()

void control_update_global_event_mask ( void  )

Set global_event_mask* to the bitwise OR of each live control connection's event_mask field.

Here is the caller graph for this function:

◆ decode_hashed_passwords()

smartlist_t* decode_hashed_passwords ( config_line_t passwords)

Decode the hashed, base64'd passwords stored in passwords. Return a smartlist of acceptable passwords (unterminated strings of length S2K_RFC2440_SPECIFIER_LEN+DIGEST_LEN) on success, or NULL on failure.

Here is the call graph for this function:

◆ disable_control_logging()

void disable_control_logging ( void  )

Called when we are sending a log message to the controllers: suspend sending further log messages to the controllers until we're done. Used by CONN_LOG_PROTECT.

◆ enable_control_logging()

void enable_control_logging ( void  )

We're done sending a log message to the controllers: re-enable controller logging. Used by CONN_LOG_PROTECT.

◆ format_cell_stats()

void format_cell_stats ( char **  event_string,
circuit_t circ,
cell_stats_t *  cell_stats 
)

Helper: format cell_stats for circ for inclusion in a CELL_STATS event and write result string to event_string.

◆ get_controller_cookie_file_name()

char* get_controller_cookie_file_name ( void  )

Helper: Return a newly allocated string containing a path to the file where we store our authentication cookie.

Here is the caller graph for this function:

◆ getinfo_helper_current_time()

STATIC int getinfo_helper_current_time ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: answers requests for information about the current time in both local and UTF forms.

◆ getinfo_helper_dir()

STATIC int getinfo_helper_dir ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows the answers for questions about directory information.

Here is the call graph for this function:

◆ getinfo_helper_downloads()

STATIC int getinfo_helper_downloads ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows the answers for questions about download status information.

Here is the call graph for this function:

◆ getinfo_helper_downloads_bridge()

STATIC void getinfo_helper_downloads_bridge ( const char *  bridge_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the bridge download cases for getinfo_helper_downloads()

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getinfo_helper_downloads_cert()

STATIC void getinfo_helper_downloads_cert ( const char *  fp_sk_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the cert download cases for getinfo_helper_downloads()

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getinfo_helper_downloads_desc()

STATIC void getinfo_helper_downloads_desc ( const char *  desc_req,
download_status_t **  dl_to_emit,
smartlist_t **  digest_list,
const char **  errmsg 
)

Handle the routerdesc download cases for getinfo_helper_downloads()

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getinfo_helper_downloads_networkstatus()

STATIC void getinfo_helper_downloads_networkstatus ( const char *  flavor,
download_status_t **  dl_to_emit,
const char **  errmsg 
)

Handle the consensus download cases for getinfo_helper_downloads()

Here is the caller graph for this function:

◆ getinfo_helper_onions()

STATIC int getinfo_helper_onions ( control_connection_t control_conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Implementation helper for GETINFO: knows how to enumerate hidden services created via the control port.

◆ MOCK_IMPL() [1/4]

MOCK_IMPL ( STATIC  void,
queue_control_event_string  ,
(uint16_t event, char *msg)   
)

Helper: inserts an event on the list of events queued to be sent to one or more controllers, and schedules the events to be flushed if needed.

This function takes ownership of msg, and may free it.

We queue these events rather than send them immediately in order to break the dependency in our callgraph from code that generates events for the controller, and the network layer at large. Otherwise, nearly every interesting part of Tor would potentially call every other interesting part of Tor.

◆ MOCK_IMPL() [2/4]

MOCK_IMPL ( STATIC  void,
send_control_event_string  ,
(uint16_t event, const char *msg)   
)

Send an event to all v1 controllers that are listening for code event. The event's body is given by msg.

The EXTENDED_FORMAT and NONEXTENDED_FORMAT flags behave similarly with respect to the EXTENDED_EVENTS feature.

◆ MOCK_IMPL() [3/4]

MOCK_IMPL ( void  ,
control_event_bootstrap_prob_or  ,
(const char *warn, int reason, or_connection_t *or_conn)   
)

Called when Tor has failed to make bootstrapping progress in a way that indicates a problem. warn gives a hint as to why, and reason provides an "or_conn_end_reason" tag. or_conn is the connection that caused this problem.

◆ MOCK_IMPL() [4/4]

MOCK_IMPL ( const char *  ,
node_describe_longname_by_id  ,
(const char *id_digest)   
)

Return a longname the node whose identity is id_digest. If node_get_by_id() returns NULL, base 16 encoding of id_digest is returned instead.

This function is not thread-safe. Each call to this function invalidates previous values returned by this function.

Here is the call graph for this function:

◆ monitor_owning_controller_process()

void monitor_owning_controller_process ( const char *  process_spec)

Set process_spec as Tor's owning controller process. Exit on failure.

◆ read_escaped_data()

STATIC size_t read_escaped_data ( const char *  data,
size_t  len,
char **  out 
)

Given a len-character string in data, made of lines terminated by CRLF, allocate a new string in *out, and copy the contents of data into *out, removing any period that appears at the start of a line, and replacing all CRLF sequences with LF. Return the number of bytes in *out.

◆ rend_auth_type_to_string()

const char* rend_auth_type_to_string ( rend_auth_type_t  auth_type)

Convert rendezvous auth type to string for HS_DESC control events

◆ sum_up_cell_stats_by_command()

void sum_up_cell_stats_by_command ( circuit_t circ,
cell_stats_t *  cell_stats 
)

Helper: iterate over cell statistics of circ and sum up added cells, removed cells, and waiting times by cell command and direction. Store results in cell_stats. Free cell statistics of the circuit afterwards.

◆ write_escaped_data()

STATIC size_t write_escaped_data ( const char *  data,
size_t  len,
char **  out 
)

Given a len-character string in data, made of lines terminated by CRLF, allocate a new string in *out, and copy the contents of data into *out, adding a period before any period that appears at the start of a line, and adding a period-CRLF line at the end. Replace all LF characters sequences with CRLF. Return the number of bytes in *out.