Tor  0.4.7.0-alpha-dev
Data Structures | Macros | Functions | Variables
control_events.c File Reference

Implement the event-reporting part of the controller API. More...

#include "core/or/or.h"
#include "app/config/config.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/mainloop.h"
#include "core/or/channeltls.h"
#include "core/or/circuitlist.h"
#include "core/or/circuitstats.h"
#include "core/or/command.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
#include "core/or/reasons.h"
#include "feature/control/control.h"
#include "feature/control/control_events.h"
#include "feature/control/control_fmt.h"
#include "feature/control/control_proto.h"
#include "feature/dircommon/directory.h"
#include "feature/nodelist/describe.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/control/control_connection_st.h"
#include "core/or/entry_connection_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "core/or/or_connection_st.h"
#include "core/or/or_circuit_st.h"
#include "core/or/origin_circuit_st.h"
#include "lib/evloop/compat_libevent.h"
#include "lib/encoding/confline.h"

Go to the source code of this file.

Data Structures

struct  queued_event_t
 
struct  cached_bw_event_t
 

Macros

#define CONTROL_MODULE_PRIVATE
 
#define CONTROL_EVENTS_PRIVATE
 
#define OCIRC_EVENT_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 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 N_BW_EVENTS_TO_CACHE   300
 
#define CONTROL_EVENT_STATUS_BODY(event, sev)
 

Functions

static void flush_queued_events_cb (mainloop_event_t *event, void *arg)
 
static void control_get_bytes_rw_last_sec (uint64_t *r, uint64_t *w)
 
static void send_control_event_impl (uint16_t event, const char *format, va_list ap)
 
static int control_event_status (int type, int severity, const char *format, va_list args)
 
static void send_control_event (uint16_t event, const char *format,...)
 
static int log_severity_to_event (int severity)
 
static void clear_circ_bw_fields (void)
 
void cbt_control_event_buildtimeout_set (const circuit_build_times_t *cbt, buildtimeout_set_event_t type)
 
void control_update_global_event_mask (void)
 
static int event_to_log_severity (int event)
 
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)
 
void control_initialize_event_queue (void)
 
static int * get_block_event_queue (void)
 
STATIC void queue_control_event_string (uint16_t event, char *msg)
 
static void queued_event_free_ (queued_event_t *ev)
 
static void queued_events_flush_all (int force)
 
STATIC void send_control_event_string (uint16_t event, const char *msg)
 
int control_event_circuit_status (origin_circuit_t *circ, circuit_status_event_t tp, int reason_code)
 
static int control_event_circuit_status_minor (origin_circuit_t *circ, circuit_status_minor_event_t e, int purpose, const struct timeval *tv)
 
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_circ_bandwidth_used_for_circ (origin_circuit_t *ocirc)
 
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)
 
char * get_bw_samples (void)
 
void disable_control_logging (void)
 
void enable_control_logging (void)
 
void control_logmsg_strip_newlines (char *msg)
 
void control_event_logmsg (int severity, log_domain_mask_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, uint64_t stream_id)
 
int control_event_network_liveness_update (int liveness)
 
static int control_event_networkstatus_changed_helper (smartlist_t *statuses, uint16_t event, const char *event_string)
 
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)
 
void control_event_conf_changed (const config_line_t *changes)
 
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)
 
void control_event_pt_log (const char *log)
 
void control_event_pt_status (const char *status)
 
const char * rend_auth_type_to_string (rend_auth_type_t auth_type)
 
static const char * rend_hsaddress_str_or_unknown (const char *onion_address)
 
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)
 
static void event_hs_descriptor_receive_end (const char *action, const char *onion_address, const char *desc_id, rend_auth_type_t auth_type, const char *hsdir_id_digest, const char *reason)
 
void control_event_hs_descriptor_upload_end (const char *action, const char *onion_address, const char *id_digest, const char *reason)
 
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_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_events_free_all (void)
 

Variables

static event_mask_t global_event_mask = 0
 
static int disable_log_messages = 0
 
const struct control_event_t control_event_table []
 
static uint64_t stats_prev_n_read = 0
 
static uint64_t stats_prev_n_written = 0
 
static tor_threadlocal_t block_event_queue_flag
 
static smartlist_tqueued_control_events = NULL
 
static int flush_queued_event_pending = 0
 
static tor_mutex_tqueued_control_events_lock = NULL
 
static mainloop_event_tflush_queued_events_event = NULL
 
static int next_measurement_idx = 0
 
static int n_measurements = 0
 
static struct cached_bw_event_t cached_bw_events [N_BW_EVENTS_TO_CACHE]
 

Detailed Description

Implement the event-reporting part of the controller API.

Definition in file control_events.c.

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.

Definition at line 64 of file control_events.c.

◆ 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)
static int control_event_status(int type, int severity, const char *format, va_list args)

Definition at line 1749 of file control_events.c.

◆ 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.

Definition at line 60 of file control_events.c.

◆ 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.

Definition at line 49 of file control_events.c.

Function Documentation

◆ 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.

Definition at line 1181 of file control_events.c.

Referenced by format_cell_stats().

◆ clear_circ_bw_fields()

static void clear_circ_bw_fields ( void  )
static

Helper: clear bandwidth counters of all origin circuits.

Definition at line 131 of file control_events.c.

◆ 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.

Definition at line 277 of file control_events.c.

Referenced by control_update_global_event_mask(), and options_rollback_log_transaction().

◆ 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.

Definition at line 321 of file control_events.c.

Referenced by control_per_second_events(), and control_update_global_event_mask().

◆ control_event_address_mapped()

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

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.

Definition at line 1480 of file control_events.c.

◆ 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.

Definition at line 1289 of file control_events.c.

Referenced by control_per_second_events().

◆ control_event_buildtimeout_set()

int control_event_buildtimeout_set ( buildtimeout_set_event_t  type,
const char *  args 
)

Called when we compute a new circuitbuildtimeout

Definition at line 1604 of file control_events.c.

◆ 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.

Definition at line 1032 of file control_events.c.

Referenced by control_per_second_events().

◆ control_event_circ_bandwidth_used_for_circ()

int control_event_circ_bandwidth_used_for_circ ( origin_circuit_t ocirc)

Emit a CIRC_BW event line for a specific circuit.

This function sets the values it emits to 0, and does not emit an event if there is no new data to report since the last call.

Therefore, it may be called at any frequency.

Definition at line 1057 of file control_events.c.

Referenced by control_event_circ_bandwidth_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.

Definition at line 775 of file control_events.c.

◆ 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.

Definition at line 1253 of file control_events.c.

Referenced by control_per_second_events().

◆ 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.

Definition at line 761 of file control_events.c.

◆ 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.

Definition at line 631 of file control_events.c.

◆ control_event_circuit_status_minor()

static int control_event_circuit_status_minor ( origin_circuit_t circ,
circuit_status_minor_event_t  e,
int  purpose,
const struct timeval tv 
)
static

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

Definition at line 688 of file control_events.c.

Referenced by control_event_circuit_cannibalized(), and control_event_circuit_purpose_changed().

◆ 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.

Definition at line 1794 of file control_events.c.

◆ 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.

Definition at line 1785 of file control_events.c.

Referenced by circuit_note_clock_jumped().

◆ 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.

Definition at line 1881 of file control_events.c.

◆ control_event_conf_changed()

void control_event_conf_changed ( const config_line_t changes)

Called when a configuration option changes. This is generally triggered by SETCONF requests and RELOAD/SIGHUP signals. The changes are a linked list of configuration key-values. changes can be NULL, meaning "no changes".

Definition at line 1854 of file control_events.c.

◆ 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.

Definition at line 1100 of file control_events.c.

Referenced by control_event_conn_bandwidth_used().

◆ 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.

Definition at line 1135 of file control_events.c.

Referenced by control_per_second_events().

◆ 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.

Definition at line 1448 of file control_events.c.

Referenced by routerlist_descriptors_added().

◆ 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.

Definition at line 1774 of file control_events.c.

◆ 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.

Definition at line 1765 of file control_events.c.

Referenced by circuit_note_clock_jumped(), and control_event_logmsg().

◆ 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.

Definition at line 1826 of file control_events.c.

Referenced by entry_guards_note_guard_failure(), and entry_guards_note_guard_success().

◆ 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 not trigger the control event.

Definition at line 2204 of file control_events.c.

Referenced by hs_control_desc_event_content().

◆ 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.

Definition at line 2008 of file control_events.c.

Referenced by hs_control_desc_event_created().

◆ 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.

Definition at line 1974 of file control_events.c.

Referenced by hs_control_desc_event_requested().

◆ 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.

Definition at line 2036 of file control_events.c.

Referenced by hs_control_desc_event_upload().

◆ 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.

Definition at line 2108 of file control_events.c.

◆ 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.

Definition at line 2241 of file control_events.c.

◆ 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.

Definition at line 2161 of file control_events.c.

Referenced by hs_control_desc_event_uploaded().

◆ 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.

Definition at line 2178 of file control_events.c.

Referenced by hs_control_desc_event_failed().

◆ 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.

Definition at line 314 of file control_events.c.

Referenced by control_event_newconsensus(), control_event_signal(), and notify_control_networkstatus_changed().

◆ control_event_logmsg()

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

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

Definition at line 1378 of file control_events.c.

Referenced by control_adjust_event_log_severity().

◆ control_event_logmsg_pending()

void control_event_logmsg_pending ( void  )

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

Definition at line 1430 of file control_events.c.

◆ control_event_my_descriptor_changed()

int control_event_my_descriptor_changed ( void  )

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

Definition at line 1688 of file control_events.c.

◆ 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.

Definition at line 1520 of file control_events.c.

◆ 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.

Definition at line 1586 of file control_events.c.

◆ control_event_networkstatus_changed_helper()

static int control_event_networkstatus_changed_helper ( smartlist_t statuses,
uint16_t  event,
const char *  event_string 
)
static

Helper function for NS-style events. Constructs and sends an event of type event with string event_string out of the set of networkstatuses statuses. Currently it is used for NS events and NEWCONSENSUS events.

Definition at line 1550 of file control_events.c.

Referenced by control_event_networkstatus_changed(), and control_event_newconsensus().

◆ 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.

Definition at line 1670 of file control_events.c.

Referenced by mark_all_dirservers_up().

◆ 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.

Definition at line 1594 of file control_events.c.

Referenced by notify_control_networkstatus_changed().

◆ 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.

Definition at line 922 of file control_events.c.

◆ control_event_pt_log()

void control_event_pt_log ( const char *  log)

A pluggable transport called pt_name has emitted a log message found in message at severity log level.

Definition at line 1905 of file control_events.c.

◆ control_event_pt_status()

void control_event_pt_status ( const char *  status)

A pluggable transport has emitted a STATUS message found in status.

Definition at line 1915 of file control_events.c.

◆ 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.

Definition at line 1814 of file control_events.c.

◆ 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.

Definition at line 1805 of file control_events.c.

Referenced by on_hibernate_state_change().

◆ control_event_signal()

int control_event_signal ( uintptr_t  signal_num)

Called when a signal has been processed from signal_callback

Definition at line 1642 of file control_events.c.

◆ control_event_status()

static int control_event_status ( int  type,
int  severity,
const char *  format,
va_list  args 
)
static

Helper: sends a status event where type is one of EVENT_STATUS_{GENERAL,CLIENT,SERVER}, where severity is one of LOG_{NOTICE,WARN,ERR}, and where format is a printf-style format string corresponding to args.

Definition at line 1699 of file control_events.c.

◆ control_event_stream_bandwidth()

int control_event_stream_bandwidth ( edge_connection_t edge_conn)

Print out STREAM_BW event for a single conn

Definition at line 970 of file control_events.c.

◆ 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.

Definition at line 996 of file control_events.c.

Referenced by control_per_second_events().

◆ 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.

Definition at line 788 of file control_events.c.

Referenced by connection_ap_detach_retriable(), and remap_event_helper().

◆ 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

Definition at line 1894 of file control_events.c.

◆ control_get_bytes_rw_last_sec()

static void control_get_bytes_rw_last_sec ( uint64_t *  n_read,
uint64_t *  n_written 
)
static

Set n_read and n_written to the total number of bytes read and written by Tor since the last call to this function.

Call this only from the main thread.

Definition at line 346 of file control_events.c.

Referenced by control_per_second_events().

◆ control_logmsg_strip_newlines()

void control_logmsg_strip_newlines ( char *  msg)

Remove newline and carriage-return characters from msg, replacing them with spaces, and discarding any that appear at the end of the message

Definition at line 1358 of file control_events.c.

◆ 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.

Definition at line 363 of file control_events.c.

◆ 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.

Definition at line 206 of file control_events.c.

Referenced by connection_control_closed(), and connection_free_all().

◆ 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.

Definition at line 1341 of file control_events.c.

◆ 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.

Definition at line 1349 of file control_events.c.

◆ event_hs_descriptor_receive_end()

static void event_hs_descriptor_receive_end ( const char *  action,
const char *  onion_address,
const char *  desc_id,
rend_auth_type_t  auth_type,
const char *  hsdir_id_digest,
const char *  reason 
)
static

send HS_DESC event after got response from hs directory.

NOTE: this is an internal function used by following functions: control_event_hsv3_descriptor_failed

So do not call this function directly.

Definition at line 2068 of file control_events.c.

◆ event_to_log_severity()

static int event_to_log_severity ( int  event)
inlinestatic

Given a control event code for a message event, return the corresponding log severity.

Definition at line 261 of file control_events.c.

Referenced by control_adjust_event_log_severity().

◆ flush_queued_events_cb()

static void flush_queued_events_cb ( mainloop_event_t event,
void *  arg 
)
static

Libevent callback: Flushes pending events to controllers that are interested in them.

Definition at line 575 of file control_events.c.

◆ 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.

Definition at line 1206 of file control_events.c.

◆ log_severity_to_event()

static int log_severity_to_event ( int  severity)
inlinestatic

Given a log severity, return the corresponding control event code.

Definition at line 117 of file control_events.c.

Referenced by control_event_logmsg().

◆ queue_control_event_string()

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.

Definition at line 448 of file control_events.c.

Referenced by send_control_event_string().

◆ queued_event_free_()

static void queued_event_free_ ( queued_event_t ev)
static

Release all storage held by ev.

Definition at line 499 of file control_events.c.

◆ queued_events_flush_all()

static void queued_events_flush_all ( int  force)
static

Send every queued event to every controller that's interested in it, and remove the events from the queue. If force is true, then make all controllers send their data out immediately, since we may be about to shut down.

Definition at line 513 of file control_events.c.

Referenced by flush_queued_events_cb().

◆ 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

Definition at line 1925 of file control_events.c.

◆ rend_hsaddress_str_or_unknown()

static const char* rend_hsaddress_str_or_unknown ( const char *  onion_address)
static

Return either the onion address if the given pointer is a non empty string else the unknown string.

Definition at line 1946 of file control_events.c.

◆ send_control_event()

static void send_control_event ( uint16_t  event,
const char *  format,
  ... 
)
static

Send an event to all v1 controllers that are listening for code event. The event's body is created by the printf-style format in format, and other arguments as provided.

Definition at line 619 of file control_events.c.

Referenced by control_event_clients_seen(), control_event_conf_changed(), control_event_conn_bandwidth(), control_event_my_descriptor_changed(), control_event_pt_log(), and control_event_transport_launched().

◆ send_control_event_impl()

static void send_control_event_impl ( uint16_t  event,
const char *  format,
va_list  ap 
)
static

Helper for send_control_event and control_event_status: Send an event to all v1 controllers that are listening for code event. The event's body is created by the printf-style format in format, and other arguments as provided.

Definition at line 600 of file control_events.c.

Referenced by send_control_event().

◆ send_control_event_string()

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.

Definition at line 589 of file control_events.c.

◆ 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.

Definition at line 1150 of file control_events.c.

Variable Documentation

◆ block_event_queue_flag

tor_threadlocal_t block_event_queue_flag
static

Pointer to int. If this is greater than 0, we don't allow new events to be queued.

Definition at line 387 of file control_events.c.

◆ control_event_table

const struct control_event_t control_event_table[]

Table mapping event values to their names. Used to implement SETEVENTS and GETINFO events/names, and to keep they in sync.

Definition at line 74 of file control_events.c.

◆ disable_log_messages

int disable_log_messages = 0
static

True iff we have disabled log messages from being sent to the controller

Definition at line 56 of file control_events.c.

Referenced by control_event_logmsg(), disable_control_logging(), and enable_control_logging().

◆ flush_queued_event_pending

int flush_queued_event_pending = 0
static

True if the flush_queued_events_event is pending.

Definition at line 394 of file control_events.c.

◆ flush_queued_events_event

mainloop_event_t* flush_queued_events_event = NULL
static

An event that should fire in order to flush the contents of queued_control_events.

Definition at line 401 of file control_events.c.

Referenced by control_event_logmsg_pending().

◆ global_event_mask

event_mask_t global_event_mask = 0
static

An event mask of all the events that any controller is interested in receiving.

Definition at line 53 of file control_events.c.

Referenced by control_update_global_event_mask().

◆ queued_control_events

smartlist_t* queued_control_events = NULL
static

Holds a smartlist of queued_event_t objects that may need to be sent to one or more controllers

Definition at line 391 of file control_events.c.

◆ queued_control_events_lock

tor_mutex_t* queued_control_events_lock = NULL
static

Lock to protect the above fields.

Definition at line 397 of file control_events.c.