tor  0.4.1.0-alpha-dev
Macros | Functions | Variables
mainloop.c File Reference
#include "core/or/or.h"
#include "app/config/config.h"
#include "app/config/statefile.h"
#include "app/main/ntmain.h"
#include "core/mainloop/connection.h"
#include "core/mainloop/cpuworker.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/mainloop/periodic.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/circuituse.h"
#include "core/or/connection_edge.h"
#include "core/or/connection_or.h"
#include "core/or/dos.h"
#include "core/or/status.h"
#include "feature/client/addressmap.h"
#include "feature/client/bridges.h"
#include "feature/client/dnsserv.h"
#include "feature/client/entrynodes.h"
#include "feature/client/transports.h"
#include "feature/control/control.h"
#include "feature/dirauth/authmode.h"
#include "feature/dirauth/reachability.h"
#include "feature/dircache/consdiffmgr.h"
#include "feature/dircache/dirserv.h"
#include "feature/dircommon/directory.h"
#include "feature/hibernate/hibernate.h"
#include "feature/hs/hs_cache.h"
#include "feature/hs/hs_client.h"
#include "feature/hs/hs_service.h"
#include "feature/nodelist/microdesc.h"
#include "feature/nodelist/networkstatus.h"
#include "feature/nodelist/nodelist.h"
#include "feature/nodelist/routerlist.h"
#include "feature/relay/dns.h"
#include "feature/relay/routerkeys.h"
#include "feature/relay/routermode.h"
#include "feature/relay/selftest.h"
#include "feature/rend/rendcache.h"
#include "feature/rend/rendservice.h"
#include "feature/stats/geoip_stats.h"
#include "feature/stats/predict_ports.h"
#include "feature/stats/rephist.h"
#include "lib/buf/buffers.h"
#include "lib/crypt_ops/crypto_rand.h"
#include "lib/err/backtrace.h"
#include "lib/tls/buffers_tls.h"
#include "lib/net/buffers_net.h"
#include "lib/evloop/compat_libevent.h"
#include <event2/event.h>
#include "feature/dirauth/dirvote.h"
#include "core/or/cell_st.h"
#include "core/or/entry_connection_st.h"
#include "feature/nodelist/networkstatus_st.h"
#include "core/or/or_connection_st.h"
#include "app/config/or_state_st.h"
#include "feature/nodelist/routerinfo_st.h"
#include "core/or/socks_request_st.h"

Go to the source code of this file.

Macros

#define MAINLOOP_PRIVATE
 
#define MAX_SIGNEWNYM_RATE   10
 
#define GREEDY_DESCRIPTOR_RETRY_INTERVAL   (10)
 
#define LAZY_DESCRIPTOR_RETRY_INTERVAL   (60)
 
#define CALLBACK(name)   static int name ## _callback(time_t, const or_options_t *)
 
#define CALLBACK(name, r, f)   PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f)
 
#define FL(name)   (PERIODIC_EVENT_FLAG_ ## name)
 
#define NAMED_CALLBACK(name)   STMT_BEGIN name ## _event = find_periodic_event( #name ); STMT_END
 
#define LONGEST_TIMER_PERIOD   (30 * 86400)
 
#define ENTROPY_INTERVAL   (60*60)
 
#define CHECK_PARTICIPATION_INTERVAL   (5*60)
 
#define SAVE_STABILITY_INTERVAL   (30*60)
 
#define CHECK_V3_CERTIFICATE_INTERVAL   (5*60)
 
#define CHECK_EXPIRED_NS_INTERVAL   (2*60)
 
#define CHECK_WRITE_STATS_INTERVAL   (60*60)
 
#define CHANNEL_CHECK_INTERVAL   (60*60)
 
#define CLEAN_CACHES_INTERVAL   (30*60)
 
#define RETRY_DNS_INTERVAL   (10*60)
 
#define ROUTERLIST_PRUNING_INTERVAL   (60*60)
 
#define CHECK_DESCRIPTOR_INTERVAL   (60)
 
#define BANDWIDTH_RECHECK_INTERVAL   (12*60*60)
 
#define BRIDGE_STATUSFILE_INTERVAL   (30*60)
 
#define CDM_CLEAN_CALLBACK_INTERVAL   600
 
#define NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE   20
 
#define NUM_JUMPED_SECONDS_BEFORE_WARN   100
 
#define NUM_IDLE_SECONDS_BEFORE_WARN   3600
 
#define UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST   (6*60*60)
 

Functions

static int conn_close_if_marked (int i)
 
static void connection_start_reading_from_linked_conn (connection_t *conn)
 
static int connection_should_read_from_linked_conn (connection_t *conn)
 
static void conn_read_callback (evutil_socket_t fd, short event, void *_conn)
 
static void conn_write_callback (evutil_socket_t fd, short event, void *_conn)
 
static void shutdown_did_not_work_callback (evutil_socket_t fd, short event, void *arg) ATTR_NORETURN
 
int have_completed_a_circuit (void)
 
void note_that_we_completed_a_circuit (void)
 
void note_that_we_maybe_cant_complete_circuits (void)
 
int connection_add_impl (connection_t *conn, int is_connecting)
 
void connection_unregister_events (connection_t *conn)
 
int connection_remove (connection_t *conn)
 
static void connection_unlink (connection_t *conn)
 
static void schedule_active_linked_connections_cb (mainloop_event_t *event, void *arg)
 
void tor_init_connection_lists (void)
 
void add_connection_to_closeable_list (connection_t *conn)
 
int connection_is_on_closeable_list (connection_t *conn)
 
int connection_in_array (connection_t *conn)
 
 MOCK_IMPL (smartlist_t *, get_connection_array,(void))
 
 MOCK_IMPL (uint64_t, get_bytes_read,(void))
 
 MOCK_IMPL (uint64_t, get_bytes_written,(void))
 
void stats_increment_bytes_read_and_written (uint64_t r, uint64_t w)
 
void connection_watch_events (connection_t *conn, watchable_events_t events)
 
int connection_is_reading (connection_t *conn)
 
void reset_main_loop_counters (void)
 
static void increment_main_loop_success_count (void)
 
uint64_t get_main_loop_success_count (void)
 
static void increment_main_loop_error_count (void)
 
uint64_t get_main_loop_error_count (void)
 
static void increment_main_loop_idle_count (void)
 
uint64_t get_main_loop_idle_count (void)
 
static int connection_check_event (connection_t *conn, struct event *ev)
 
 MOCK_IMPL (void, connection_stop_reading,(connection_t *conn))
 
 MOCK_IMPL (void, connection_start_reading,(connection_t *conn))
 
int connection_is_writing (connection_t *conn)
 
 MOCK_IMPL (void, connection_stop_writing,(connection_t *conn))
 
 MOCK_IMPL (void, connection_start_writing,(connection_t *conn))
 
void tor_shutdown_event_loop_and_exit (int exitcode)
 
int tor_event_loop_shutdown_is_pending (void)
 
void connection_stop_reading_from_linked_conn (connection_t *conn)
 
STATIC void close_closeable_connections (void)
 
 MOCK_IMPL (int, connection_count_moribund,(void))
 
static void directory_all_unreachable_cb (mainloop_event_t *event, void *arg)
 
void directory_all_unreachable (time_t now)
 
void directory_info_has_arrived (time_t now, int from_cache, int suppress_logs)
 
static void run_connection_housekeeping (int i, time_t now)
 
static void signewnym_impl (time_t now)
 
static void handle_deferred_signewnym_cb (mainloop_event_t *event, void *arg)
 
void do_signewnym (time_t now)
 
unsigned get_signewnym_epoch (void)
 
 CALLBACK (add_entropy)
 
 CALLBACK (check_authority_cert)
 
 CALLBACK (check_canonical_channels)
 
 CALLBACK (check_descriptor)
 
 CALLBACK (check_dns_honesty)
 
 CALLBACK (check_ed_keys)
 
 CALLBACK (check_expired_networkstatus)
 
 CALLBACK (check_for_reachability_bw)
 
 CALLBACK (check_onion_keys_expiry_time)
 
 CALLBACK (clean_caches)
 
 CALLBACK (clean_consdiffmgr)
 
 CALLBACK (dirvote)
 
 CALLBACK (downrate_stability)
 
 CALLBACK (expire_old_ciruits_serverside)
 
 CALLBACK (fetch_networkstatus)
 
 CALLBACK (heartbeat)
 
 CALLBACK (hs_service)
 
 CALLBACK (launch_descriptor_fetches)
 
 CALLBACK (launch_reachability_tests)
 
 CALLBACK (prune_old_routers)
 
 CALLBACK (reachability_warnings)
 
 CALLBACK (record_bridge_stats)
 
 CALLBACK (rend_cache_failure_clean)
 
 CALLBACK (reset_padding_counts)
 
 CALLBACK (retry_dns)
 
 CALLBACK (retry_listeners)
 
 CALLBACK (rotate_onion_key)
 
 CALLBACK (rotate_x509_certificate)
 
 CALLBACK (save_stability)
 
 CALLBACK (save_state)
 
 CALLBACK (write_bridge_ns)
 
 CALLBACK (write_stats_file)
 
 CALLBACK (control_per_second_events)
 
 CALLBACK (second_elapsed)
 
void reset_all_main_loop_timers (void)
 
static periodic_event_item_tfind_periodic_event (const char *name)
 
STATIC int get_my_roles (const or_options_t *options)
 
static void initialize_periodic_events_cb (evutil_socket_t fd, short events, void *data)
 
STATIC void initialize_periodic_events (void)
 
STATIC void teardown_periodic_events (void)
 
static void rescan_periodic_events_cb (mainloop_event_t *event, void *arg)
 
 MOCK_IMPL (void, schedule_rescan_periodic_events,(void))
 
void rescan_periodic_events (const or_options_t *options)
 
void periodic_events_on_new_options (const or_options_t *options)
 
void reschedule_descriptor_update_check (void)
 
void reschedule_directory_downloads (void)
 
static void postloop_cleanup_cb (mainloop_event_t *ev, void *arg)
 
void mainloop_schedule_postloop_cleanup (void)
 
static void scheduled_shutdown_cb (mainloop_event_t *ev, void *arg)
 
void mainloop_schedule_shutdown (int delay_sec)
 
static int safe_timer_diff (time_t now, time_t next)
 
static int second_elapsed_callback (time_t now, const or_options_t *options)
 
static int rotate_onion_key_callback (time_t now, const or_options_t *options)
 
static int check_onion_keys_expiry_time_callback (time_t now, const or_options_t *options)
 
static int check_ed_keys_callback (time_t now, const or_options_t *options)
 
static int launch_descriptor_fetches_callback (time_t now, const or_options_t *options)
 
static int rotate_x509_certificate_callback (time_t now, const or_options_t *options)
 
static int add_entropy_callback (time_t now, const or_options_t *options)
 
STATIC int check_network_participation_callback (time_t now, const or_options_t *options)
 
static int launch_reachability_tests_callback (time_t now, const or_options_t *options)
 
static int downrate_stability_callback (time_t now, const or_options_t *options)
 
static int save_stability_callback (time_t now, const or_options_t *options)
 
static int check_authority_cert_callback (time_t now, const or_options_t *options)
 
static int dirvote_callback (time_t now, const or_options_t *options)
 
void reschedule_dirvote (const or_options_t *options)
 
static int check_expired_networkstatus_callback (time_t now, const or_options_t *options)
 
static int save_state_callback (time_t now, const or_options_t *options)
 
void reschedule_or_state_save (void)
 
static int write_stats_file_callback (time_t now, const or_options_t *options)
 
static int check_canonical_channels_callback (time_t now, const or_options_t *options)
 
static int reset_padding_counts_callback (time_t now, const or_options_t *options)
 
static int record_bridge_stats_callback (time_t now, const or_options_t *options)
 
static int clean_caches_callback (time_t now, const or_options_t *options)
 
static int rend_cache_failure_clean_callback (time_t now, const or_options_t *options)
 
static int retry_dns_callback (time_t now, const or_options_t *options)
 
static int prune_old_routers_callback (time_t now, const or_options_t *options)
 
static int check_descriptor_callback (time_t now, const or_options_t *options)
 
static int check_for_reachability_bw_callback (time_t now, const or_options_t *options)
 
static int fetch_networkstatus_callback (time_t now, const or_options_t *options)
 
static int retry_listeners_callback (time_t now, const or_options_t *options)
 
static int expire_old_ciruits_serverside_callback (time_t now, const or_options_t *options)
 
static int reachability_warnings_callback (time_t now, const or_options_t *options)
 
static int check_dns_honesty_callback (time_t now, const or_options_t *options)
 
static int write_bridge_ns_callback (time_t now, const or_options_t *options)
 
static int heartbeat_callback (time_t now, const or_options_t *options)
 
static int clean_consdiffmgr_callback (time_t now, const or_options_t *options)
 
static int hs_service_callback (time_t now, const or_options_t *options)
 
static int control_per_second_events_callback (time_t now, const or_options_t *options)
 
void update_current_time (time_t now)
 
void ip_address_changed (int at_interface)
 
void dns_servers_relaunch_checks (void)
 
void initialize_mainloop_events (void)
 
int do_main_loop (void)
 
static int run_main_loop_once (void)
 
STATIC int run_main_loop_until_done (void)
 
 MOCK_IMPL (long, get_uptime,(void))
 
 MOCK_IMPL (void, reset_uptime,(void))
 
void tor_mainloop_free_all (void)
 

Variables

token_bucket_rw_t global_bucket
 
token_bucket_rw_t global_relayed_bucket
 
static uint64_t stats_n_bytes_read = 0
 
static uint64_t stats_n_bytes_written = 0
 
time_t time_of_process_start = 0
 
static long stats_n_seconds_working = 0
 
static uint64_t stats_n_main_loop_successes = 0
 
static uint64_t stats_n_main_loop_errors = 0
 
static uint64_t stats_n_main_loop_idle = 0
 
static time_t time_of_last_signewnym = 0
 
static int signewnym_is_pending = 0
 
static mainloop_event_thandle_deferred_signewnym_ev = NULL
 
static unsigned newnym_epoch = 0
 
STATIC smartlist_tconnection_array = NULL
 
static smartlist_tcloseable_connection_lst = NULL
 
static smartlist_tactive_linked_connection_lst = NULL
 
static int called_loop_once = 0
 
static int main_loop_should_exit = 0
 
static int main_loop_exit_value = 0
 
static int can_complete_circuits = 0
 
static mainloop_event_tschedule_active_linked_connections_event = NULL
 
static struct event * shutdown_did_not_work_event = NULL
 
static mainloop_event_tdirectory_all_unreachable_cb_event = NULL
 
static int periodic_events_initialized = 0
 
STATIC periodic_event_item_t periodic_events []
 
static periodic_event_item_tcheck_descriptor_event =NULL
 
static periodic_event_item_tdirvote_event =NULL
 
static periodic_event_item_tfetch_networkstatus_event =NULL
 
static periodic_event_item_tlaunch_descriptor_fetches_event =NULL
 
static periodic_event_item_tcheck_dns_honesty_event =NULL
 
static periodic_event_item_tsave_state_event =NULL
 
static periodic_event_item_tprune_old_routers_event =NULL
 
static struct event * initialize_periodic_events_event = NULL
 
static mainloop_event_trescan_periodic_events_ev = NULL
 
static mainloop_event_tpostloop_cleanup_ev =NULL
 
static mainloop_event_tscheduled_shutdown_ev =NULL
 
static int should_init_bridge_stats = 1
 
static int dns_honesty_first_time = 1
 
static int heartbeat_callback_first_time = 1
 
static time_t current_second = 0
 
static monotime_coarse_t current_second_last_changed
 
static ratelim_t libevent_error_ratelim = RATELIM_INIT(10)
 

Detailed Description

Toplevel module. Handles signals, multiplexes between connections, implements main loop, and drives scheduled events.

For the main loop itself; see run_main_loop_once(). It invokes the rest of Tor mostly through Libevent callbacks. Libevent callbacks can happen when a timer elapses, a signal is received, a socket is ready to read or write, or an event is manually activated.

Most events in Tor are driven from these callbacks:

Other events are used for specific purposes, or for building more complex control structures. If you search for usage of tor_libevent_new(), you will find all the events that we construct in Tor.

Tor has numerous housekeeping operations that need to happen regularly. They are handled in different ways:

Definition in file mainloop.c.

Macro Definition Documentation

◆ GREEDY_DESCRIPTOR_RETRY_INTERVAL

#define GREEDY_DESCRIPTOR_RETRY_INTERVAL   (10)

How often do we check for router descriptors that we should download when we have too little directory info?

Definition at line 197 of file mainloop.c.

Referenced by launch_descriptor_fetches_callback().

◆ LAZY_DESCRIPTOR_RETRY_INTERVAL

#define LAZY_DESCRIPTOR_RETRY_INTERVAL   (60)

How often do we check for router descriptors that we should download when we have enough directory info?

Definition at line 200 of file mainloop.c.

Referenced by launch_descriptor_fetches_callback().

◆ MAX_SIGNEWNYM_RATE

#define MAX_SIGNEWNYM_RATE   10

How often will we honor SIGNEWNYM requests?

Definition at line 156 of file mainloop.c.

Referenced by do_signewnym().

Function Documentation

◆ add_connection_to_closeable_list()

void add_connection_to_closeable_list ( connection_t conn)

◆ add_entropy_callback()

static int add_entropy_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: once an hour, grab some more entropy from the kernel and feed it to our CSPRNG.

How often do we add more entropy to OpenSSL's RNG pool?

Definition at line 1999 of file mainloop.c.

References crypto_seed_rng().

◆ check_authority_cert_callback()

static int check_authority_cert_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: if we're an authority, check on our authority certificate (the one that authenticates our authority signing key).

Definition at line 2114 of file mainloop.c.

References v3_authority_check_key_expiry().

◆ check_descriptor_callback()

static int check_descriptor_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: consider rebuilding or and re-uploading our descriptor (if we've passed our internal checks).

How often do we check whether part of our router info has changed in a way that would require an upload? That includes checking whether our IP address has changed.

Definition at line 2378 of file mainloop.c.

References check_descriptor_bandwidth_changed(), check_descriptor_ipaddress_changed(), consider_publishable_server(), and mark_my_descriptor_dirty_if_too_old().

◆ check_dns_honesty_callback()

static int check_dns_honesty_callback ( time_t  now,
const or_options_t options 
)
static

Periodic event: if we're an exit, see if our DNS server is telling us obvious lies.

Definition at line 2549 of file mainloop.c.

◆ check_expired_networkstatus_callback()

static int check_expired_networkstatus_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: If our consensus is too old, recalculate whether we can actually use it.

Definition at line 2164 of file mainloop.c.

References networkstatus_consensus_reasonably_live(), and router_dir_info_changed().

◆ check_for_reachability_bw_callback()

static int check_for_reachability_bw_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: check whether we're reachable (as a relay), and whether our bandwidth has changed enough that we need to publish a new descriptor.

Definition at line 2405 of file mainloop.c.

References any_predicted_circuits(), routerinfo_t::bandwidthcapacity, routerinfo_t::bandwidthrate, have_completed_a_circuit(), reset_bandwidth_test(), router_do_reachability_checks(), and TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT.

◆ check_network_participation_callback()

STATIC int check_network_participation_callback ( time_t  now,
const or_options_t options 
)

Periodic callback: if there has been no network usage in a while, enter a dormant state.

How often do we check whether we have had network activity?

Definition at line 2017 of file mainloop.c.

References CONN_TYPE_AP, or_options_t::DormantClientTimeout, or_options_t::DormantTimeoutDisabledByIdleStreams, and rend_num_services().

◆ clean_caches_callback()

static int clean_caches_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: Clean in-memory caches every once in a while

Definition at line 2313 of file mainloop.c.

References rend_cache_clean(), rep_history_clean(), and or_options_t::RephistTrackTime.

◆ close_closeable_connections()

STATIC void close_closeable_connections ( void  )

Close all connections that have been scheduled to get closed.

Definition at line 836 of file mainloop.c.

Referenced by postloop_cleanup_cb().

◆ conn_close_if_marked()

static int conn_close_if_marked ( int  i)
static

If the connection at connection_array[i] is marked for close, then:

  • If it has data that it wants to flush, try to flush it.
  • If it still has data to flush, and conn->hold_open_until_flushed is true, then leave the connection open and return.
  • Otherwise, remove the connection from connection_array and from all other lists, close it, and free it. Returns 1 if the connection was closed, 0 otherwise.

Definition at line 946 of file mainloop.c.

◆ conn_read_callback()

static void conn_read_callback ( evutil_socket_t  fd,
short  event,
void *  _conn 
)
static

Libevent callback: this gets invoked when (connection_t*)conn has some data to read.

Definition at line 870 of file mainloop.c.

◆ conn_write_callback()

static void conn_write_callback ( evutil_socket_t  fd,
short  events,
void *  _conn 
)
static

Libevent callback: this gets invoked when (connection_t*)conn has some data to write.

Definition at line 902 of file mainloop.c.

References LD_NET, LOG_DEBUG, LOG_FN_CONN, and connection_t::s.

◆ connection_add_impl()

int connection_add_impl ( connection_t conn,
int  is_connecting 
)

Add conn to the array of connections that we can poll on. The connection's socket must be set; the connection starts out non-reading and non-writing.

Definition at line 247 of file mainloop.c.

References connection_t::conn_array_index, CONN_TYPE_AP, connection_t::linked, connection_t::s, SOCKET_OK, TO_EDGE_CONN(), tor_assert(), and connection_t::type.

◆ connection_check_event()

static int connection_check_event ( connection_t conn,
struct event *  ev 
)
static

Check whether conn is correct in having (or not having) a read/write event (passed in ev). On success, return 0. On failure, log a warning and return -1.

Definition at line 574 of file mainloop.c.

References CONN_TYPE_AP, TO_EDGE_CONN(), and connection_t::type.

Referenced by MOCK_IMPL().

◆ connection_in_array()

int connection_in_array ( connection_t conn)

Return true iff conn is in the current poll array.

Definition at line 445 of file mainloop.c.

References connection_array, and smartlist_contains().

Referenced by assert_all_pending_dns_resolves_ok(), and MOCK_IMPL().

◆ connection_is_on_closeable_list()

int connection_is_on_closeable_list ( connection_t conn)

Return 1 if conn is on the closeable list, else return 0.

Definition at line 438 of file mainloop.c.

References closeable_connection_lst, and smartlist_contains().

Referenced by MOCK_IMPL().

◆ connection_is_reading()

int connection_is_reading ( connection_t conn)

Return true iff conn is listening for read events.

Definition at line 511 of file mainloop.c.

References connection_t::read_event, connection_t::reading_from_linked_conn, and tor_assert().

Referenced by set_streams_blocked_on_circ().

◆ connection_is_writing()

int connection_is_writing ( connection_t conn)

Return true iff conn is listening for write events.

Definition at line 657 of file mainloop.c.

References tor_assert(), connection_t::write_event, and connection_t::writing_to_linked_conn.

◆ connection_remove()

int connection_remove ( connection_t conn)

Remove the connection from the global list, and remove the corresponding poll entry. Calling this function will shift the last connection (if any) into the position occupied by conn.

Definition at line 300 of file mainloop.c.

References tor_assert().

Referenced by connection_unlink().

◆ connection_should_read_from_linked_conn()

static int connection_should_read_from_linked_conn ( connection_t conn)
static

Return true iff conn is linked conn, and reading from the conn linked to it would be good and feasible. (Reading is "feasible" if the other conn exists and has data in its outbuf, and is "good" if we have our reading_from_linked_conn flag set and the other conn has its writing_to_linked_conn flag set.)

Definition at line 718 of file mainloop.c.

References connection_t::linked, connection_t::linked_conn, connection_t::outbuf, connection_t::reading_from_linked_conn, and connection_t::writing_to_linked_conn.

Referenced by MOCK_IMPL().

◆ connection_start_reading_from_linked_conn()

static void connection_start_reading_from_linked_conn ( connection_t conn)
static

Helper: Tell the main loop to begin reading bytes into conn from its linked connection, if it is not doing so already. Called by connection_start_reading and connection_start_writing as appropriate.

Definition at line 800 of file mainloop.c.

References active_linked_connection_lst, connection_t::active_on_link, connection_t::linked, mainloop_event_activate(), schedule_active_linked_connections_event, smartlist_add(), smartlist_contains(), and tor_assert().

Referenced by MOCK_IMPL().

◆ connection_stop_reading_from_linked_conn()

void connection_stop_reading_from_linked_conn ( connection_t conn)

Tell the main loop to stop reading bytes into conn from its linked connection, if is currently doing so. Called by connection_stop_reading, connection_stop_writing, and connection_read.

Definition at line 818 of file mainloop.c.

References active_linked_connection_lst, connection_t::active_on_link, connection_t::linked, smartlist_contains(), smartlist_remove(), and tor_assert().

Referenced by MOCK_IMPL().

◆ connection_unlink()

static void connection_unlink ( connection_t conn)
static

If conn is an edge conn, remove it from the list of conn's on this circuit. If it's not on an edge, flush and send destroys for all circuits on this conn.

Remove it from connection_array (if applicable) and from closeable_connection_list.

Then free it.

Definition at line 343 of file mainloop.c.

References active_linked_connection_lst, assert_connection_edge_not_dns_pending(), closeable_connection_lst, connection_t::conn_array_index, CONN_TYPE_EXIT, CONN_TYPE_OR, connection_about_to_close_connection(), connection_or_clear_identity(), connection_remove(), connection_t::linked_conn, connection_t::marked_for_close, connection_t::reading_from_linked_conn, smartlist_remove(), TO_EDGE_CONN(), TO_OR_CONN(), tor_digest_is_zero(), and connection_t::type.

◆ connection_unregister_events()

void connection_unregister_events ( connection_t conn)

Tell libevent that we don't care about conn any more.

Definition at line 278 of file mainloop.c.

References connection_t::read_event.

◆ connection_watch_events()

void connection_watch_events ( connection_t conn,
watchable_events_t  events 
)

Set the event mask on conn to events. (The event mask is a bitmask whose bits are READ_EVENT and WRITE_EVENT)

Definition at line 496 of file mainloop.c.

References READ_EVENT, and WRITE_EVENT.

◆ directory_all_unreachable()

void directory_all_unreachable ( time_t  now)

We've just tried every dirserver we know about, and none of them were reachable. Assume the network is down. Change state so next time an application connection arrives we'll delay it and try another directory fetch. Kill off all the circuit_wait streams that are waiting now, since they will all timeout anyway.

Definition at line 1091 of file mainloop.c.

◆ directory_all_unreachable_cb()

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

Implementation for directory_all_unreachable. This is done in a callback, since otherwise it would complicate Tor's control-flow graph beyond all reason.

Definition at line 1061 of file mainloop.c.

References AP_CONN_STATE_CIRCUIT_WAIT, CONN_TYPE_AP, and connection_get_by_type_state().

◆ directory_info_has_arrived()

void directory_info_has_arrived ( time_t  now,
int  from_cache,
int  suppress_logs 
)

◆ dirvote_callback()

static int dirvote_callback ( time_t  now,
const or_options_t options 
)
static

Scheduled callback: Run directory-authority voting functionality.

The schedule is a bit complicated here, so dirvote_act() manages the schedule itself.

Definition at line 2132 of file mainloop.c.

◆ dns_servers_relaunch_checks()

void dns_servers_relaunch_checks ( void  )

Forget what we've learned about the correctness of our DNS servers, and start learning again.

Definition at line 2796 of file mainloop.c.

References dns_reset_correctness_checks(), periodic_events_initialized, and tor_assert().

◆ do_main_loop()

int do_main_loop ( void  )

◆ do_signewnym()

void do_signewnym ( time_t  now)

Either perform a signewnym or schedule one, depending on rate limiting.

Definition at line 1310 of file mainloop.c.

References handle_deferred_signewnym_cb(), handle_deferred_signewnym_ev, mainloop_event_postloop_new(), mainloop_event_schedule(), MAX_SIGNEWNYM_RATE, signewnym_is_pending, and time_of_last_signewnym.

◆ downrate_stability_callback()

static int downrate_stability_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: if we're an authority, discount the stability information (and other rephist information) that's older.

Definition at line 2083 of file mainloop.c.

References rep_hist_downrate_old_runs(), and safe_timer_diff().

◆ expire_old_ciruits_serverside_callback()

static int expire_old_ciruits_serverside_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: as a server, see if we have any old unused circuits that should be expired

Definition at line 2486 of file mainloop.c.

References circuit_expire_old_circuits_serverside().

◆ fetch_networkstatus_callback()

static int fetch_networkstatus_callback ( time_t  now,
const or_options_t options 
)
static

Periodic event: once a minute, (or every second if TestingTorNetwork, or during client bootstrap), check whether we want to download any networkstatus documents.

Definition at line 2445 of file mainloop.c.

References directory_fetches_from_authorities(), should_delay_dir_fetches(), or_options_t::TestingTorNetwork, and update_networkstatus_downloads().

◆ find_periodic_event()

static periodic_event_item_t* find_periodic_event ( const char *  name)
static

Return the member of periodic_events[] whose name is name. Return NULL if no such event is found.

Definition at line 1497 of file mainloop.c.

◆ get_main_loop_error_count()

uint64_t get_main_loop_error_count ( void  )

Get the main loop error counter.

Definition at line 551 of file mainloop.c.

References stats_n_main_loop_errors.

◆ get_main_loop_idle_count()

uint64_t get_main_loop_idle_count ( void  )

Get the main loop idle counter.

Definition at line 565 of file mainloop.c.

References stats_n_main_loop_idle.

◆ get_main_loop_success_count()

uint64_t get_main_loop_success_count ( void  )

Get the main loop success counter.

Definition at line 537 of file mainloop.c.

References stats_n_main_loop_successes.

◆ get_my_roles()

STATIC int get_my_roles ( const or_options_t options)

Return a bitmask of the roles this tor instance is configured for using the given options.

Definition at line 1510 of file mainloop.c.

References or_options_t::BridgeRelay, and tor_assert().

Referenced by rescan_periodic_events().

◆ get_signewnym_epoch()

unsigned get_signewnym_epoch ( void  )

Return the number of times that signewnym has been called.

Definition at line 1334 of file mainloop.c.

References newnym_epoch.

◆ handle_deferred_signewnym_cb()

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

Callback: run a deferred signewnym.

Definition at line 1300 of file mainloop.c.

Referenced by do_signewnym().

◆ have_completed_a_circuit()

int have_completed_a_circuit ( void  )

Return 1 if we have successfully built a circuit, and nothing has changed to make us think that maybe we can't.

Definition at line 221 of file mainloop.c.

References can_complete_circuits.

Referenced by check_for_reachability_bw_callback(), directory_info_has_arrived(), and reachability_warnings_callback().

◆ heartbeat_callback()

static int heartbeat_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: write the heartbeat message in the logs.

If writing the heartbeat message to the logs fails for some reason, retry again after MIN_HEARTBEAT_PERIOD seconds.

Definition at line 2594 of file mainloop.c.

References or_options_t::HeartbeatPeriod.

◆ increment_main_loop_error_count()

static void increment_main_loop_error_count ( void  )
static

Increment the main loop error counter.

Definition at line 544 of file mainloop.c.

References stats_n_main_loop_errors.

◆ increment_main_loop_idle_count()

static void increment_main_loop_idle_count ( void  )
static

Increment the main loop idle counter.

Definition at line 558 of file mainloop.c.

References stats_n_main_loop_idle.

◆ increment_main_loop_success_count()

static void increment_main_loop_success_count ( void  )
static

Increment the main loop success counter.

Definition at line 530 of file mainloop.c.

References stats_n_main_loop_successes.

◆ initialize_mainloop_events()

void initialize_mainloop_events ( void  )

◆ initialize_periodic_events()

STATIC void initialize_periodic_events ( void  )

Set up all the members of periodic_events[], and configure them all to be launched from a callback.

Definition at line 1570 of file mainloop.c.

References periodic_events_initialized.

Referenced by do_main_loop(), and initialize_mainloop_events().

◆ initialize_periodic_events_cb()

static void initialize_periodic_events_cb ( evutil_socket_t  fd,
short  events,
void *  data 
)
static

Helper, run one second after setup: Initializes all members of periodic_events and starts them running.

(We do this one second after setup for backward-compatibility reasons; it might not actually be necessary.)

Definition at line 1556 of file mainloop.c.

◆ ip_address_changed()

void ip_address_changed ( int  at_interface)

Called when our IP address seems to have changed. at_interface should be true if we detected a change in our interface, and false if we detected a change in our published address.

Definition at line 2762 of file mainloop.c.

References or_options_t::ExitPolicyRejectLocalInterfaces, and or_options_t::ExitRelay.

◆ launch_descriptor_fetches_callback()

static int launch_descriptor_fetches_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: Every {LAZY,GREEDY}_DESCRIPTOR_RETRY_INTERVAL, see about fetching descriptors, microdescriptors, and extrainfo documents.

Definition at line 1947 of file mainloop.c.

References GREEDY_DESCRIPTOR_RETRY_INTERVAL, LAZY_DESCRIPTOR_RETRY_INTERVAL, should_delay_dir_fetches(), update_all_descriptor_downloads(), and update_extrainfo_downloads().

◆ launch_reachability_tests_callback()

static int launch_reachability_tests_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: if we're an authority, make sure we test the routers on the network for reachability.

Definition at line 2068 of file mainloop.c.

References authdir_mode_tests_reachability(), dirserv_test_reachability(), and REACHABILITY_TEST_INTERVAL.

◆ mainloop_schedule_postloop_cleanup()

void mainloop_schedule_postloop_cleanup ( void  )

Schedule a post-loop event to clean up marked channels, connections, and circuits.

Definition at line 1738 of file mainloop.c.

Referenced by add_connection_to_closeable_list().

◆ mainloop_schedule_shutdown()

void mainloop_schedule_shutdown ( int  delay_sec)

Schedule the mainloop to exit after delay_sec seconds.

Definition at line 1763 of file mainloop.c.

References mainloop_event_new(), mainloop_event_schedule(), scheduled_shutdown_cb(), and scheduled_shutdown_ev.

◆ MOCK_IMPL() [1/11]

MOCK_IMPL ( smartlist_t ,
get_connection_array  ,
(void)   
)

Set *array to an array of all connections. *array must not be modified.

Definition at line 453 of file mainloop.c.

References connection_array.

◆ MOCK_IMPL() [2/11]

MOCK_IMPL ( uint64_t  ,
get_bytes_read  ,
(void)   
)

Return the amount of network traffic read, in bytes, over the life of this process.

Definition at line 465 of file mainloop.c.

References stats_n_bytes_read.

◆ MOCK_IMPL() [3/11]

MOCK_IMPL ( uint64_t  ,
get_bytes_written  ,
(void)   
)

Return the amount of network traffic read, in bytes, over the life of this process.

Definition at line 475 of file mainloop.c.

References stats_n_bytes_written.

◆ MOCK_IMPL() [4/11]

MOCK_IMPL ( void  ,
connection_stop_reading  ,
(connection_t *conn)   
)

Tell the main loop to stop notifying conn of any read events.

Definition at line 611 of file mainloop.c.

References connection_check_event(), connection_stop_reading_from_linked_conn(), connection_t::linked, connection_t::read_event, connection_t::reading_from_linked_conn, and tor_assert().

◆ MOCK_IMPL() [5/11]

MOCK_IMPL ( void  ,
connection_start_reading  ,
(connection_t *conn)   
)

◆ MOCK_IMPL() [6/11]

MOCK_IMPL ( void  ,
connection_stop_writing  ,
(connection_t *conn)   
)

◆ MOCK_IMPL() [7/11]

MOCK_IMPL ( void  ,
connection_start_writing  ,
(connection_t *conn)   
)

◆ MOCK_IMPL() [8/11]

MOCK_IMPL ( int  ,
connection_count_moribund  ,
(void)   
)

Count moribund connections for the OOS handler

Definition at line 851 of file mainloop.c.

References closeable_connection_lst, connection_is_moribund(), SMARTLIST_FOREACH_BEGIN, and SOCKET_OK.

◆ MOCK_IMPL() [9/11]

MOCK_IMPL ( void  ,
schedule_rescan_periodic_events  ,
(void)   
)

Schedule an event that will rescan which periodic events should run.

Definition at line 1625 of file mainloop.c.

◆ MOCK_IMPL() [10/11]

MOCK_IMPL ( long  ,
get_uptime  ,
(void)   
)

Returns Tor's uptime.

Definition at line 2998 of file mainloop.c.

References stats_n_seconds_working.

◆ MOCK_IMPL() [11/11]

MOCK_IMPL ( void  ,
reset_uptime  ,
(void)   
)

Reset Tor's uptime.

Definition at line 3005 of file mainloop.c.

References stats_n_seconds_working.

◆ note_that_we_completed_a_circuit()

void note_that_we_completed_a_circuit ( void  )

Note that we have successfully built a circuit, so that reachability testing and introduction points and so on may be attempted.

Definition at line 229 of file mainloop.c.

References can_complete_circuits.

◆ note_that_we_maybe_cant_complete_circuits()

void note_that_we_maybe_cant_complete_circuits ( void  )

Note that something has happened (like a clock jump, or DisableNetwork) to make us think that maybe we can't complete circuits.

Definition at line 237 of file mainloop.c.

References can_complete_circuits.

Referenced by circuit_note_clock_jumped().

◆ postloop_cleanup_cb()

static void postloop_cleanup_cb ( mainloop_event_t ev,
void *  arg 
)
static

Mainloop callback: clean up circuits, channels, and connections that are pending close.

Definition at line 1722 of file mainloop.c.

References channel_listener_run_cleanup(), channel_run_cleanup(), circuit_close_all_marked(), and close_closeable_connections().

Referenced by initialize_mainloop_events().

◆ prune_old_routers_callback()

static int prune_old_routers_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: prune routerlist of old information about Tor network.

Definition at line 2358 of file mainloop.c.

◆ reachability_warnings_callback()

static int reachability_warnings_callback ( time_t  now,
const or_options_t options 
)
static

Callback: Send warnings if Tor doesn't find its ports reachable.

Definition at line 2498 of file mainloop.c.

References routerinfo_t::addr, check_whether_orport_reachable(), have_completed_a_circuit(), TIMEOUT_UNTIL_UNREACHABILITY_COMPLAINT, and tor_dup_ip().

◆ record_bridge_stats_callback()

static int record_bridge_stats_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: Write bridge statistics to disk if appropriate.

Definition at line 2285 of file mainloop.c.

References should_record_bridge_info().

◆ rend_cache_failure_clean_callback()

static int rend_cache_failure_clean_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: Clean the cache of failed hidden service lookups frequently.

Definition at line 2330 of file mainloop.c.

References rend_cache_failure_clean().

◆ rescan_periodic_events()

void rescan_periodic_events ( const or_options_t options)

Do a pass at all our periodic events, disable those we don't need anymore and enable those we need now using the given options.

Definition at line 1638 of file mainloop.c.

References get_my_roles(), periodic_events_initialized, and tor_assert().

Referenced by on_hibernate_state_change(), and rescan_periodic_events_cb().

◆ rescan_periodic_events_cb()

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

Callback: rescan the periodic event list.

Definition at line 1615 of file mainloop.c.

References rescan_periodic_events().

◆ reschedule_descriptor_update_check()

void reschedule_descriptor_update_check ( void  )

Update our schedule so that we'll check whether we need to update our descriptor immediately, rather than after up to CHECK_DESCRIPTOR_INTERVAL seconds.

Definition at line 1698 of file mainloop.c.

◆ reschedule_directory_downloads()

void reschedule_directory_downloads ( void  )

Update our schedule so that we'll check whether we need to fetch directory info immediately.

Definition at line 1710 of file mainloop.c.

References tor_assert().

◆ reschedule_dirvote()

void reschedule_dirvote ( const or_options_t options)

Reschedule the directory-authority voting event. Run this whenever the schedule has changed.

Definition at line 2152 of file mainloop.c.

References periodic_events_initialized.

◆ reschedule_or_state_save()

void reschedule_or_state_save ( void  )

Reschedule the event for saving the state file.

Run this when the state becomes dirty.

Definition at line 2198 of file mainloop.c.

Referenced by or_state_mark_dirty().

◆ reset_all_main_loop_timers()

void reset_all_main_loop_timers ( void  )

Reset all the periodic events so we'll do all our actions again as if we just started up. Useful if our clock just moved back a long time from the future, so we don't wait until that future arrives again before acting.

Definition at line 1485 of file mainloop.c.

Referenced by circuit_note_clock_jumped().

◆ reset_main_loop_counters()

void reset_main_loop_counters ( void  )

Reset our main loop counters.

Definition at line 521 of file mainloop.c.

References stats_n_main_loop_errors, stats_n_main_loop_idle, and stats_n_main_loop_successes.

◆ retry_dns_callback()

static int retry_dns_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: If we're a server and initializing dns failed, retry.

Definition at line 2345 of file mainloop.c.

References dns_init(), and has_dns_init_failed().

◆ retry_listeners_callback()

static int retry_listeners_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: Every 60 seconds, we relaunch listeners if any died.

Definition at line 2471 of file mainloop.c.

References retry_all_listeners().

◆ rotate_x509_certificate_callback()

static int rotate_x509_certificate_callback ( time_t  now,
const or_options_t options 
)
static

Periodic event: Rotate our X.509 certificates and TLS keys once every MAX_SSL_KEY_LIFETIME_INTERNAL.

Definition at line 1965 of file mainloop.c.

References MAX_SSL_KEY_LIFETIME_INTERNAL.

◆ run_connection_housekeeping()

static void run_connection_housekeeping ( int  i,
time_t  now 
)
static

Perform regular maintenance tasks for a single connection. This function gets run once per second per connection by run_scheduled_events.

Definition at line 1150 of file mainloop.c.

◆ run_main_loop_once()

static int run_main_loop_once ( void  )
static

Run the main loop a single time. Return 0 for "exit"; -1 for "exit with error", and 1 for "run this again."

Definition at line 2892 of file mainloop.c.

Referenced by run_main_loop_until_done().

◆ run_main_loop_until_done()

STATIC int run_main_loop_until_done ( void  )

Run the run_main_loop_once() function until it declares itself done, and return its final return value.

Shadow won't invoke this function, so don't fill it up with things.

Definition at line 2980 of file mainloop.c.

References main_loop_exit_value, main_loop_should_exit, and run_main_loop_once().

◆ safe_timer_diff()

static int safe_timer_diff ( time_t  now,
time_t  next 
)
inlinestatic

Helper: Return the number of seconds between now and next, clipped to the range [1 second, LONGEST_TIMER_PERIOD].

Definition at line 1776 of file mainloop.c.

References tor_assert().

Referenced by downrate_stability_callback().

◆ save_stability_callback()

static int save_stability_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: if we're an authority, record our measured stability information from rephist in an mtbf file.

Definition at line 2098 of file mainloop.c.

References authdir_mode_tests_reachability(), and rep_hist_record_mtbf_data().

◆ save_state_callback()

static int save_state_callback ( time_t  now,
const or_options_t options 
)
static

Scheduled callback: Save the state file to disk if appropriate.

Definition at line 2183 of file mainloop.c.

References or_state_save().

◆ schedule_active_linked_connections_cb()

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

Callback: used to activate read events for all linked connections, so libevent knows to call their read callbacks. This callback run as a postloop event, so that the events it activates don't happen until Libevent has a chance to check for other events.

Definition at line 390 of file mainloop.c.

References active_linked_connection_lst, and SMARTLIST_FOREACH.

Referenced by initialize_mainloop_events().

◆ scheduled_shutdown_cb()

static void scheduled_shutdown_cb ( mainloop_event_t ev,
void *  arg 
)
static

Callback: run a scheduled shutdown

Definition at line 1753 of file mainloop.c.

Referenced by mainloop_schedule_shutdown().

◆ second_elapsed_callback()

static int second_elapsed_callback ( time_t  now,
const or_options_t options 
)
static

◆ shutdown_did_not_work_callback()

static void shutdown_did_not_work_callback ( evutil_socket_t  fd,
short  event,
void *  arg 
)
static

Failsafe measure that should never actually be necessary: If tor_shutdown_event_loop_and_exit() somehow doesn't successfully exit the event loop, then this callback will kill Tor with an assertion failure seconds later

Definition at line 738 of file mainloop.c.

◆ signewnym_impl()

static void signewnym_impl ( time_t  now)
static

Honor a NEWNYM request: make future requests unlinkable to past requests.

Definition at line 1278 of file mainloop.c.

References proxy_mode().

◆ stats_increment_bytes_read_and_written()

void stats_increment_bytes_read_and_written ( uint64_t  r,
uint64_t  w 
)

Increment the amount of network traffic read and written, over the life of this process.

Definition at line 486 of file mainloop.c.

References stats_n_bytes_read, and stats_n_bytes_written.

Referenced by record_num_bytes_transferred_impl().

◆ tor_event_loop_shutdown_is_pending()

int tor_event_loop_shutdown_is_pending ( void  )

Return true iff tor_shutdown_event_loop_and_exit() has been called.

Definition at line 791 of file mainloop.c.

References main_loop_should_exit.

Referenced by set_options().

◆ tor_init_connection_lists()

void tor_init_connection_lists ( void  )

Initialize the global connection list, closeable connection list, and active connection list.

Definition at line 415 of file mainloop.c.

References active_linked_connection_lst, closeable_connection_lst, and connection_array.

Referenced by tor_init().

◆ tor_shutdown_event_loop_and_exit()

void tor_shutdown_event_loop_and_exit ( int  exitcode)

After finishing the current callback (if any), shut down the main loop, clean up the process, and exit with exitcode.

Definition at line 767 of file mainloop.c.

References main_loop_exit_value, main_loop_should_exit, and shutdown_did_not_work_event.

◆ update_current_time()

void update_current_time ( time_t  now)

Set the current time to "now", which should be the value returned by time(). Check for clock jumps and track the total number of seconds we have been running.

How much clock jumping means that we should adjust our idea of when to go dormant?

How much clock jumping do we tolerate?
How much idleness do we tolerate?

Definition at line 2677 of file mainloop.c.

Referenced by periodic_event_dispatch(), and signal_callback().

◆ write_bridge_ns_callback()

static int write_bridge_ns_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: if we're the bridge authority, write a networkstatus file to disk.

Definition at line 2574 of file mainloop.c.

References or_options_t::BridgeAuthoritativeDir, and networkstatus_dump_bridge_status_to_file().

◆ write_stats_file_callback()

static int write_stats_file_callback ( time_t  now,
const or_options_t options 
)
static

Periodic callback: Write statistics to disk if appropriate.

Definition at line 2211 of file mainloop.c.

Variable Documentation

◆ active_linked_connection_lst

smartlist_t* active_linked_connection_lst = NULL
static

List of linked connections that are currently reading data into their inbuf from their partner's outbuf.

Definition at line 173 of file mainloop.c.

Referenced by connection_start_reading_from_linked_conn(), connection_stop_reading_from_linked_conn(), connection_unlink(), schedule_active_linked_connections_cb(), and tor_init_connection_lists().

◆ called_loop_once

int called_loop_once = 0
static

Flag: Set to true iff we entered the current libevent main loop via loop_once. If so, there's no need to trigger a loopexit in order to handle linked connections.

Definition at line 177 of file mainloop.c.

◆ can_complete_circuits

int can_complete_circuits = 0
static

We set this to 1 when we've opened a circuit, so we can print a log entry to inform the user that Tor is working. We set it to 0 when we think the fact that we once opened a circuit doesn't mean we can do so any longer (a big time jump happened, when we notice our directory is heinously out-of-date, etc.

Definition at line 193 of file mainloop.c.

Referenced by have_completed_a_circuit(), note_that_we_completed_a_circuit(), and note_that_we_maybe_cant_complete_circuits().

◆ closeable_connection_lst

smartlist_t* closeable_connection_lst = NULL
static

List of connections that have been marked for close and need to be freed and removed from connection_array.

Definition at line 170 of file mainloop.c.

Referenced by add_connection_to_closeable_list(), connection_is_on_closeable_list(), connection_unlink(), MOCK_IMPL(), and tor_init_connection_lists().

◆ connection_array

STATIC smartlist_t* connection_array = NULL

Smartlist of all open connections.

Definition at line 167 of file mainloop.c.

Referenced by circuits_handle_oom(), connection_in_array(), MOCK_IMPL(), rend_client_cancel_descriptor_fetches(), and tor_init_connection_lists().

◆ current_second

time_t current_second = 0
static

Last time that update_current_time was called.

Definition at line 2667 of file mainloop.c.

Referenced by channel_tls_handle_var_cell(), and command_process_cell().

◆ current_second_last_changed

monotime_coarse_t current_second_last_changed
static

Last time that update_current_time updated current_second.

Definition at line 2669 of file mainloop.c.

◆ handle_deferred_signewnym_ev

mainloop_event_t* handle_deferred_signewnym_ev = NULL
static

Mainloop event for the deferred signewnym call.

Definition at line 162 of file mainloop.c.

Referenced by do_signewnym().

◆ initialize_periodic_events_event

struct event* initialize_periodic_events_event = NULL
static

Event to run initialize_periodic_events_cb

Definition at line 1548 of file mainloop.c.

◆ libevent_error_ratelim

ratelim_t libevent_error_ratelim = RATELIM_INIT(10)
static

Rate-limiter for EINVAL-type libevent warnings.

Definition at line 2884 of file mainloop.c.

◆ main_loop_exit_value

int main_loop_exit_value = 0
static

The return value that the main loop should yield when it exits, if main_loop_should_exit is true.

Definition at line 185 of file mainloop.c.

Referenced by run_main_loop_until_done(), and tor_shutdown_event_loop_and_exit().

◆ main_loop_should_exit

int main_loop_should_exit = 0
static

Flag: if true, it's time to shut down, so the main loop should exit as soon as possible.

Definition at line 181 of file mainloop.c.

Referenced by run_main_loop_until_done(), tor_event_loop_shutdown_is_pending(), and tor_shutdown_event_loop_and_exit().

◆ newnym_epoch

unsigned newnym_epoch = 0
static

How many times have we called newnym?

Definition at line 164 of file mainloop.c.

Referenced by get_signewnym_epoch().

◆ periodic_events_initialized

int periodic_events_initialized = 0
static

True iff we have initialized all the members of periodic_events. Used to prevent double-initialization.

Definition at line 1341 of file mainloop.c.

Referenced by dns_servers_relaunch_checks(), initialize_periodic_events(), rescan_periodic_events(), and reschedule_dirvote().

◆ postloop_cleanup_ev

mainloop_event_t* postloop_cleanup_ev =NULL
static

Event to run postloop_cleanup_cb

Definition at line 1733 of file mainloop.c.

Referenced by initialize_mainloop_events().

◆ schedule_active_linked_connections_event

mainloop_event_t* schedule_active_linked_connections_event = NULL
static

Event that invokes schedule_active_linked_connections_cb.

Definition at line 381 of file mainloop.c.

Referenced by connection_start_reading_from_linked_conn(), and initialize_mainloop_events().

◆ scheduled_shutdown_ev

mainloop_event_t* scheduled_shutdown_ev =NULL
static

Event to run 'scheduled_shutdown_cb'

Definition at line 1749 of file mainloop.c.

Referenced by mainloop_schedule_shutdown().

◆ shutdown_did_not_work_event

struct event* shutdown_did_not_work_event = NULL
static

Event to run 'shutdown did not work callback'.

Definition at line 730 of file mainloop.c.

Referenced by tor_shutdown_event_loop_and_exit().

◆ signewnym_is_pending

int signewnym_is_pending = 0
static

Is there a signewnym request we're currently waiting to handle?

Definition at line 160 of file mainloop.c.

Referenced by do_signewnym().

◆ stats_n_bytes_read

uint64_t stats_n_bytes_read = 0
static

How many bytes have we read since we started the process?

Definition at line 141 of file mainloop.c.

Referenced by control_get_bytes_rw_last_sec(), MOCK_IMPL(), and stats_increment_bytes_read_and_written().

◆ stats_n_bytes_written

uint64_t stats_n_bytes_written = 0
static

How many bytes have we written since we started the process?

Definition at line 143 of file mainloop.c.

Referenced by control_get_bytes_rw_last_sec(), MOCK_IMPL(), and stats_increment_bytes_read_and_written().

◆ stats_n_main_loop_errors

uint64_t stats_n_main_loop_errors = 0
static

How many times have we received an error from the main loop?

Definition at line 151 of file mainloop.c.

Referenced by get_main_loop_error_count(), increment_main_loop_error_count(), and reset_main_loop_counters().

◆ stats_n_main_loop_idle

uint64_t stats_n_main_loop_idle = 0
static

How many times have we returned from the main loop with no events.

Definition at line 153 of file mainloop.c.

Referenced by get_main_loop_idle_count(), increment_main_loop_idle_count(), and reset_main_loop_counters().

◆ stats_n_main_loop_successes

uint64_t stats_n_main_loop_successes = 0
static

How many times have we returned from the main loop successfully?

Definition at line 149 of file mainloop.c.

Referenced by get_main_loop_success_count(), increment_main_loop_success_count(), and reset_main_loop_counters().

◆ stats_n_seconds_working

long stats_n_seconds_working = 0
static

How many seconds have we been running?

Definition at line 147 of file mainloop.c.

Referenced by MOCK_IMPL().

◆ time_of_last_signewnym

time_t time_of_last_signewnym = 0
static

When did we last process a SIGNEWNYM request?

Definition at line 158 of file mainloop.c.

Referenced by do_signewnym().

◆ time_of_process_start

time_t time_of_process_start = 0

What time did this process start up?

Definition at line 145 of file mainloop.c.

Referenced by tor_init().