49#define MAINLOOP_PRIVATE
61#include "core/or/channelpadding.h"
68#include "core/or/dos.h"
106#include <event2/event.h>
121# if defined(__COVERITY__) && !defined(__INCLUDE_LEVEL__)
125# define __INCLUDE_LEVEL__ 2
127#include <systemd/sd-daemon.h>
153#define MAX_SIGNEWNYM_RATE 10
194#define GREEDY_DESCRIPTOR_RETRY_INTERVAL (10)
197#define LAZY_DESCRIPTOR_RETRY_INTERVAL (60)
205 void *arg) ATTR_NORETURN;
256 (void) is_connecting;
266 log_debug(
LD_NET,
"new conn type %s, socket %d, address %s, n_conns %d.",
296 log_debug(
LD_NET,
"removing socket %d (type %s), n_conns now %d",
301 log_info(
LD_NET,
"Closing SOCKS Unix socket connection");
366 connection_free(conn);
387 event_active(conn->read_event, EV_READ, 1));
581 log_warn(
LD_BUG,
"Event missing on connection %p [%s;%s]. "
582 "socket=%d. linked=%d. "
583 "is_dns_request=%d. Marked_for_close=%s:%d",
587 (
int)conn->
s, (
int)conn->
linked,
614 log_warn(
LD_NET,
"Error from libevent setting read event state for %d "
617 tor_socket_strerror(tor_socket_errno(conn->
s)));
640 "Request to start reading on an edgeconn blocked with XOFF");
644 log_warn(
LD_NET,
"Error from libevent setting read event state for %d "
647 tor_socket_strerror(tor_socket_errno(conn->
s)));
687 log_warn(
LD_NET,
"Error from libevent setting write event state for %d "
690 tor_socket_strerror(tor_socket_errno(conn->
s)));
711 log_warn(
LD_NET,
"Error from libevent setting write event state for %d "
714 tor_socket_strerror(tor_socket_errno(conn->
s)));
750 tor_assert_unreached();
754#ifdef ENABLE_RESTART_DEBUGGING
755static struct event *tor_shutdown_event_loop_for_restart_event = NULL;
757tor_shutdown_event_loop_for_restart_cb(
758 evutil_socket_t fd,
short event,
void *arg)
763 tor_event_free(tor_shutdown_event_loop_for_restart_event);
788 struct timeval ten_seconds = { 10, 0 };
872 } SMARTLIST_FOREACH_END(conn);
886 log_debug(
LD_NET,
"socket %d wants to read.",(
int)conn->
s);
900 if (connection_handle_read(conn) < 0) {
903 log_warn(
LD_BUG,
"Unhandled error on read for %s connection "
910 connection_mark_for_close(conn);
933 if (connection_handle_write(conn, 0) < 0) {
937 "unhandled error on write for %s connection (fd %d); removing",
944 edge_conn->
end_reason = END_STREAM_REASON_INTERNAL;
948 connection_mark_for_close(conn);
978 log_debug(
LD_NET,
"Cleaning up connection (fd "TOR_SOCKET_T_FORMAT
").",
994 "Conn (addr %s, fd %d, type %s, state %d) marked, but wants "
995 "to flush %"TOR_PRIuSZ
" bytes. (Marked at %s:%d)",
998 connection_get_outbuf_len(conn),
1007 log_debug(
LD_GENERAL,
"Flushed last %d bytes from a linked conn; "
1008 "%d left; wants-to-flush==%d", retval,
1009 (
int)connection_get_outbuf_len(conn),
1011 }
else if (connection_speaks_cells(conn)) {
1024 "Holding conn (fd %d) open for more flushing.",
1028 }
else if (sz == 0) {
1055 "bytes to address %s. If this happens a lot, either "
1056 "something is wrong with your network connection, or "
1057 "something is wrong with theirs. "
1058 "(fd %d, type %s, state %d, marked at %s:%d).",
1059 (
int)connection_get_outbuf_len(conn),
1087 "Is your network connection down? "
1088 "Failing connection to '%s:%d'.",
1091 connection_mark_unattached_ap(entry_conn,
1112 if (!directory_all_unreachable_cb_event) {
1113 directory_all_unreachable_cb_event =
1115 tor_assert(directory_all_unreachable_cb_event);
1132 if (invalidate_circs) {
1138 int quiet = suppress_logs || from_cache ||
1141 "I learned some more directory information, but not enough to "
1172 int have_any_circuits;
1173 int past_keepalive =
1176 if (conn->
outbuf && !connection_get_outbuf_len(conn) &&
1194 log_info(
LD_DIR,
"Expiring wedged directory conn (fd %d, purpose %d)",
1199 connection_get_inbuf_len(conn) >= 1024) {
1200 log_info(
LD_DIR,
"Trying to extract information from wedged server desc "
1204 connection_mark_for_close(conn);
1209 if (!connection_speaks_cells(conn))
1218 chan = TLS_CHAN_TO_BASE(or_conn->
chan);
1222 have_any_circuits = 1;
1225 have_any_circuits = 0;
1229 ! have_any_circuits) {
1233 "Expiring non-used OR connection to fd %d (%s:%d) [Too old].",
1237 END_OR_CONN_REASON_TIMEOUT,
1238 "Tor gave up on the connection");
1241 if (past_keepalive) {
1243 log_info(
LD_OR,
"Expiring non-open OR connection to fd %d (%s:%d).",
1248 ! have_any_circuits &&
1249 !connection_get_outbuf_len(conn)) {
1252 log_info(
LD_OR,
"Expiring non-used OR connection to fd %d (%s:%d) "
1253 "[Hibernating or exiting].",
1256 }
else if (!have_any_circuits &&
1259 log_info(
LD_OR,
"Expiring non-used OR connection %"PRIu64
" to fd %d "
1260 "(%s:%d) [no circuits for %d; timeout %d; %scanonical].",
1272 "Expiring stuck OR connection to fd %d (%s:%d). (%d bytes to "
1273 "flush; %d seconds since last write)",
1275 conn->
port, (
int)connection_get_outbuf_len(conn),
1278 }
else if (past_keepalive && !connection_get_outbuf_len(conn)) {
1282 memset(&cell,0,
sizeof(
cell_t));
1297 log_info(
LD_CONTROL,
"Ignoring SIGNAL NEWNYM because client functionality "
1320 log_info(
LD_CONTROL,
"Honoring delayed NEWNYM request");
1329 const time_t delay_sec =
1337 const struct timeval delay_tv = { delay_sec, 0 };
1341 "Rate limiting NEWNYM request: delaying by %d second(s)",
1362#define CALLBACK(name) \
1363 static int name ## _callback(time_t, const or_options_t *)
1365CALLBACK(add_entropy);
1366CALLBACK(check_expired_networkstatus);
1367CALLBACK(clean_caches);
1368CALLBACK(clean_consdiffmgr);
1369CALLBACK(fetch_networkstatus);
1371CALLBACK(hs_service);
1372CALLBACK(launch_descriptor_fetches);
1373CALLBACK(prune_old_routers);
1374CALLBACK(record_bridge_stats);
1375CALLBACK(rend_cache_failure_clean);
1376CALLBACK(reset_padding_counts);
1377CALLBACK(retry_listeners);
1378CALLBACK(rotate_x509_certificate);
1379CALLBACK(save_state);
1380CALLBACK(write_stats_file);
1382CALLBACK(second_elapsed);
1383CALLBACK(manage_vglite);
1388#define CALLBACK(name, r, f) \
1389 PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f)
1390#define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
1397 CALLBACK(add_entropy, ALL, 0),
1398 CALLBACK(heartbeat, ALL, 0),
1399 CALLBACK(reset_padding_counts, ALL, 0),
1403 CALLBACK(second_elapsed, NET_PARTICIPANT,
1404 FL(RUN_ON_DISABLE)),
1407 CALLBACK(manage_vglite, NET_PARTICIPANT, FL(NEED_NET)),
1411 CALLBACK(retry_listeners, NET_PARTICIPANT, FL(NEED_NET)),
1414 CALLBACK(check_expired_networkstatus, NET_PARTICIPANT, 0),
1415 CALLBACK(fetch_networkstatus, NET_PARTICIPANT, 0),
1416 CALLBACK(launch_descriptor_fetches, NET_PARTICIPANT, FL(NEED_NET)),
1417 CALLBACK(rotate_x509_certificate, NET_PARTICIPANT, 0),
1418 CALLBACK(check_network_participation, NET_PARTICIPANT, 0),
1422 CALLBACK(clean_caches, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1423 CALLBACK(save_state, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1424 CALLBACK(write_stats_file, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1425 CALLBACK(prune_old_routers, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1428 CALLBACK(hs_service, HS_SERVICE, FL(NEED_NET)),
1431 CALLBACK(record_bridge_stats, BRIDGE, 0),
1435 CALLBACK(rend_cache_failure_clean, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1438 CALLBACK(clean_consdiffmgr, DIRSERVER, 0),
1443 END_OF_PERIODIC_EVENTS
1478 int roles = PERIODIC_EVENT_ROLE_ALL;
1481 int is_dirauth = authdir_mode_v3(options);
1491 options->ControlPort_set ||
1495 is_relay || is_hidden_service;
1497 if (is_bridge) roles |= PERIODIC_EVENT_ROLE_BRIDGE;
1498 if (is_client) roles |= PERIODIC_EVENT_ROLE_CLIENT;
1499 if (is_relay) roles |= PERIODIC_EVENT_ROLE_RELAY;
1500 if (is_dirauth) roles |= PERIODIC_EVENT_ROLE_DIRAUTH;
1501 if (is_bridgeauth) roles |= PERIODIC_EVENT_ROLE_BRIDGEAUTH;
1502 if (is_hidden_service) roles |= PERIODIC_EVENT_ROLE_HS_SERVICE;
1503 if (is_dirserver) roles |= PERIODIC_EVENT_ROLE_DIRSERVER;
1504 if (is_net_participant) roles |= PERIODIC_EVENT_ROLE_NET_PARTICIPANT;
1505 if (sending_control_events) roles |= PERIODIC_EVENT_ROLE_CONTROLEV;
1540 for (
int i = 0; mainloop_periodic_events[i].
name; ++i) {
1547#define NAMED_CALLBACK(name) \
1548 STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END
1551 NAMED_CALLBACK(prune_old_routers);
1552 NAMED_CALLBACK(fetch_networkstatus);
1553 NAMED_CALLBACK(launch_descriptor_fetches);
1554 NAMED_CALLBACK(check_dns_honesty);
1555 NAMED_CALLBACK(save_state);
1559teardown_periodic_events(
void)
1562 fetch_networkstatus_event = NULL;
1563 launch_descriptor_fetches_event = NULL;
1564 check_dns_honesty_event = NULL;
1565 save_state_event = NULL;
1566 prune_old_routers_event = NULL;
1587 if (!rescan_periodic_events_ev) {
1588 rescan_periodic_events_ev =
1607periodic_events_on_new_options(
const or_options_t *options)
1664 log_notice(
LD_GENERAL,
"Clean shutdown finished. Exiting.");
1672 const struct timeval delay_tv = { delay_sec, 0 };
1687#define VANGUARDS_LITE_INTERVAL (15*60)
1691 return VANGUARDS_LITE_INTERVAL;
1778 return PERIODIC_EVENT_NO_UPDATE;
1795 static int first = 1;
1805 log_info(
LD_GENERAL,
"Rotating tls context.");
1807 log_err(
LD_BUG,
"Error reinitializing TLS context");
1808 tor_assert_unreached();
1811 log_err(
LD_OR,
"Unable to update Ed25519->TLS link certificate for "
1812 "new TLS context.");
1813 tor_assert_unreached();
1833 log_warn(
LD_GENERAL,
"Tried to re-seed RNG, but failed. We already "
1834 "seeded once, though, so we won't exit here.");
1838#define ENTROPY_INTERVAL (60*60)
1839 return ENTROPY_INTERVAL;
1849 goto found_activity;
1855 goto found_activity;
1862 goto found_activity;
1870 goto found_activity;
1876#define CHECK_PARTICIPATION_INTERVAL (5*60)
1880 time_t time_since_last_activity = 0;
1884 log_notice(
LD_GENERAL,
"No user activity in a long time: becoming"
1890 return CHECK_PARTICIPATION_INTERVAL;
1894 return CHECK_PARTICIPATION_INTERVAL;
1913#define CHECK_EXPIRED_NS_INTERVAL (2*60)
1914 return CHECK_EXPIRED_NS_INTERVAL;
1926 if (next_write == TIME_MAX) {
1938 if (save_state_event == NULL) {
1953#define CHECK_WRITE_STATS_INTERVAL (60*60)
1954 time_t next_time_to_write_stats_files = now + CHECK_WRITE_STATS_INTERVAL;
1958 if (next_write && next_write < next_time_to_write_stats_files)
1959 next_time_to_write_stats_files = next_write;
1963 if (next_write && next_write < next_time_to_write_stats_files)
1964 next_time_to_write_stats_files = next_write;
1968 if (next_write && next_write < next_time_to_write_stats_files)
1969 next_time_to_write_stats_files = next_write;
1973 if (next_write && next_write < next_time_to_write_stats_files)
1974 next_time_to_write_stats_files = next_write;
1977 if (next_write && next_write < next_time_to_write_stats_files)
1978 next_time_to_write_stats_files = next_write;
1982 if (next_write && next_write < next_time_to_write_stats_files)
1983 next_time_to_write_stats_files = next_write;
1987 if (next_write && next_write < next_time_to_write_stats_files)
1988 next_time_to_write_stats_files = next_write;
1992 if (next_write && next_write < next_time_to_write_stats_files)
1993 next_time_to_write_stats_files = next_write;
2000reset_padding_counts_callback(time_t now,
const or_options_t *options)
2003 rep_hist_prep_published_padding_counts(now);
2010static int should_init_bridge_stats = 1;
2021 if (should_init_bridge_stats) {
2024 should_init_bridge_stats = 0;
2025 return WRITE_STATS_INTERVAL;
2032 }
else if (!should_init_bridge_stats) {
2035 should_init_bridge_stats = 1;
2037 return PERIODIC_EVENT_NO_UPDATE;
2051#define CLEAN_CACHES_INTERVAL (30*60)
2052 return CLEAN_CACHES_INTERVAL;
2076#define ROUTERLIST_PRUNING_INTERVAL (60*60)
2084 log_debug(
LD_GENERAL,
"Pruning routerlist...");
2088 return ROUTERLIST_PRUNING_INTERVAL;
2104 int networkstatus_dl_check_interval = 60;
2108 || (we_are_bootstrapping && prefer_mirrors)) {
2109 networkstatus_dl_check_interval = 1;
2113 return PERIODIC_EVENT_NO_UPDATE;
2116 return networkstatus_dl_check_interval;
2130 return PERIODIC_EVENT_NO_UPDATE;
2133static int heartbeat_callback_first_time = 1;
2146 return PERIODIC_EVENT_NO_UPDATE;
2150 if (heartbeat_callback_first_time) {
2151 heartbeat_callback_first_time = 0;
2165#define CDM_CLEAN_CALLBACK_INTERVAL 600
2167clean_consdiffmgr_callback(time_t now,
const or_options_t *options)
2173 return CDM_CLEAN_CALLBACK_INTERVAL;
2181hs_service_callback(time_t now,
const or_options_t *options)
2205control_per_second_events_callback(time_t now,
const or_options_t *options)
2238 monotime_coarse_t last_updated;
2244#define NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE 20
2247 if (
ABS(seconds_elapsed) >= NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE) {
2254#define NUM_JUMPED_SECONDS_BEFORE_WARN 100
2257#define NUM_IDLE_SECONDS_BEFORE_WARN 3600
2259 if (seconds_elapsed < -NUM_JUMPED_SECONDS_BEFORE_WARN) {
2263 }
else if (seconds_elapsed >= NUM_JUMPED_SECONDS_BEFORE_WARN) {
2265 const int32_t monotime_msec_passed =
2268 const int monotime_sec_passed = monotime_msec_passed / 1000;
2269 const int discrepancy = monotime_sec_passed - (int)seconds_elapsed;
2279 const bool clock_jumped = abs(discrepancy) > 2;
2281 if (clock_jumped || seconds_elapsed >= NUM_IDLE_SECONDS_BEFORE_WARN) {
2284 }
else if (seconds_elapsed > 0) {
2292#ifdef HAVE_SYSTEMD_209
2301 sd_notify(0,
"WATCHDOG=1");
2305#define UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST (6*60*60)
2323 if (on_client_conn) {
2326 if (init_keys_client() < 0)
2327 log_warn(
LD_GENERAL,
"Unable to rotate keys after IP change!");
2331 if (
get_uptime() > UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST)
2353 if (check_dns_honesty_event) {
2385 struct timeval one_second = { 1, 0 };
2391#ifdef HAVE_SYSTEMD_209
2392 uint64_t watchdog_delay;
2394 if (sd_watchdog_enabled(1, &watchdog_delay) > 0) {
2395 if (! systemd_watchdog_timer) {
2400 watchdog_delay /= 2;
2401 watchdog.tv_sec = watchdog_delay / 1000000;
2402 watchdog.tv_usec = watchdog_delay % 1000000;
2406 systemd_watchdog_callback,
2412#ifdef ENABLE_RESTART_DEBUGGING
2414 static int first_time = 1;
2416 if (first_time && getenv(
"TOR_DEBUG_RESTART")) {
2418 const char *sec_str = getenv(
"TOR_DEBUG_RESTART_AFTER_SECONDS");
2422 (sec =
tor_parse_long(sec_str, 10, 0, INT_MAX, &sec_ok, NULL)) &&
2428 struct timeval restart_after = { (time_t) sec, 0 };
2429 tor_shutdown_event_loop_for_restart_event =
2431 tor_shutdown_event_loop_for_restart_cb, NULL);
2432 event_add(tor_shutdown_event_loop_for_restart_event, &restart_after);
2454 if (nt_service_is_stopping())
2485 if (loop_result == 0) {
2488 }
else if (loop_result == -1) {
2491 }
else if (loop_result == 1) {
2501 if (loop_result < 0) {
2502 int e = tor_socket_errno(-1);
2504 if (e != EINTR && !ERRNO_IS_EINPROGRESS(e)) {
2505 log_err(
LD_NET,
"libevent call with %s failed: %s [%d]",
2509 }
else if (e == EINVAL) {
2511 "EINVAL from libevent: should you upgrade libevent?");
2513 log_err(
LD_NET,
"Too many libevent errors, too fast: dying");
2518 tor_assert_nonfatal_once(! ERRNO_IS_EINPROGRESS(e));
2519 log_debug(
LD_NET,
"libevent call interrupted.");
2540 int loop_result = 1;
2547 }
while (loop_result == 1);
2570tor_mainloop_free_all(
void)
2575 teardown_periodic_events();
2578 mainloop_event_free(directory_all_unreachable_cb_event);
2583 mainloop_event_free(rescan_periodic_events_ev);
2585#ifdef HAVE_SYSTEMD_209
2586 periodic_timer_free(systemd_watchdog_timer);
2591 memset(&global_bucket, 0,
sizeof(global_bucket));
2592 memset(&global_relayed_bucket, 0,
sizeof(global_relayed_bucket));
2602 should_init_bridge_stats = 1;
2603 heartbeat_callback_first_time = 1;
#define fmt_and_decorate_addr(a)
void addressmap_clear_transient(void)
void update_approx_time(time_t now)
int authdir_mode_bridge(const or_options_t *options)
Header file for directory authority mode.
void fetch_bridge_descriptors(const or_options_t *options, time_t now)
Header file for circuitbuild.c.
size_t buf_move_all(buf_t *buf_out, buf_t *buf_in)
size_t buf_datalen(const buf_t *buf)
Header file for buffers.c.
int buf_flush_to_socket(buf_t *buf, tor_socket_t s, size_t sz)
Header file for buffers_net.c.
int buf_flush_to_tls(buf_t *buf, tor_tls_t *tls, size_t flushlen)
Header for buffers_tls.c.
Fixed-size cell structure.
int channel_is_bad_for_new_circs(channel_t *chan)
void channel_run_cleanup(void)
void channel_update_bad_for_new_circs(const char *digest, int force)
void channel_listener_run_cleanup(void)
unsigned int channel_num_circuits(channel_t *chan)
Header file for channel.c.
channelpadding_decision_t channelpadding_decide_to_pad_channel(channel_t *chan)
Header file for channeltls.c.
void circuit_note_clock_jumped(int64_t seconds_elapsed, bool was_idle)
void circuit_upgrade_circuits_from_guard_wait(void)
Header file for circuitbuild.c.
void circuit_close_all_marked(void)
void circuit_mark_all_dirty_circs_as_unusable(void)
void circuit_mark_all_unused_circs(void)
Header file for circuitlist.c.
void circuit_expire_waiting_for_better_guard(void)
void circuit_expire_old_circs_as_needed(time_t now)
void reset_bandwidth_test(void)
void circuit_expire_building(void)
void circuit_build_needed_circs(time_t now)
Header file for circuituse.c.
bool tor_libevent_is_initialized(void)
void tor_libevent_exit_loop_after_callback(struct event_base *base)
int tor_libevent_run_event_loop(struct event_base *base, int once)
mainloop_event_t * mainloop_event_postloop_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *tv)
periodic_timer_t * periodic_timer_new(struct event_base *base, const struct timeval *tv, void(*cb)(periodic_timer_t *timer, void *data), void *data)
const char * tor_libevent_get_method(void)
struct event_base * tor_libevent_get_base(void)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
void mainloop_event_activate(mainloop_event_t *event)
Header for compat_libevent.c.
static int32_t monotime_coarse_diff_msec32(const monotime_coarse_t *start, const monotime_coarse_t *end)
const char * escaped_safe_str_client(const char *address)
int options_any_client_port_set(const or_options_t *options)
const or_options_t * get_options(void)
Header file for config.c.
#define MIN_HEARTBEAT_PERIOD
connection_t * connection_get_by_type_nonlinked(int type)
int connection_wants_to_flush(connection_t *conn)
int connection_is_moribund(connection_t *conn)
void connection_consider_empty_write_buckets(connection_t *conn)
void connection_close_immediate(connection_t *conn)
const char * conn_type_to_string(int type)
void assert_connection_ok(connection_t *conn, time_t now)
int connection_process_inbuf(connection_t *conn, int package_partial)
ssize_t connection_bucket_write_limit(connection_t *conn, time_t now)
int retry_all_listeners(smartlist_t *new_conns, int close_all_noncontrol)
int connection_state_is_open(connection_t *conn)
connection_t * connection_get_by_type_state(int type, int state)
void log_failed_proxy_connection(connection_t *conn)
void connection_write_bw_exhausted(connection_t *conn, bool is_global_bw)
void connection_about_to_close_connection(connection_t *conn)
void connection_expire_held_open(void)
const char * conn_state_to_string(int type, int state)
Header file for connection.c.
#define CONN_TYPE_AP_DNS_LISTENER
void connection_ap_expire_beginning(void)
int connection_edge_end_errno(edge_connection_t *conn)
entry_connection_t * TO_ENTRY_CONN(connection_t *c)
edge_connection_t * TO_EDGE_CONN(connection_t *c)
Header file for connection_edge.c.
#define AP_CONN_STATE_CIRCUIT_WAIT
or_connection_t * TO_OR_CONN(connection_t *c)
void connection_or_write_cell_to_buf(const cell_t *cell, or_connection_t *conn)
void connection_or_clear_identity(or_connection_t *conn)
void connection_or_connect_failed(or_connection_t *conn, int reason, const char *msg)
void connection_or_close_normally(or_connection_t *orconn, int flush)
Header file for connection_or.c.
#define DIR_CONN_IS_SERVER(conn)
time_t conn_stats_save(time_t now)
Header for feature/stats/connstats.c.
int consdiffmgr_cleanup(void)
Header for consdiffmgr.c.
Header file for control.c.
#define LOG_FN_CONN(conn, args)
int control_event_conn_bandwidth(connection_t *conn)
int control_event_signal(uintptr_t signal_num)
int control_event_general_error(const char *format,...)
void control_per_second_events(void)
int control_any_per_second_event_enabled(void)
Header file for control_events.c.
Header file for cpuworker.c.
int crypto_seed_rng(void)
Common functions for using (pseudo-)random number generators.
int connection_dir_reached_eof(dir_connection_t *conn)
int dirclient_too_idle_to_fetch_descriptors(const or_options_t *options, time_t now)
int dirclient_fetches_from_authorities(const or_options_t *options)
Header for feature/dirclient/dirclient_modes.c.
dir_connection_t * TO_DIR_CONN(connection_t *c)
Header file for directory.c.
#define DIR_PURPOSE_FETCH_SERVERDESC
void dns_reset_correctness_checks(void)
void assert_connection_edge_not_dns_pending(edge_connection_t *conn)
void dnsserv_close_listener(connection_t *conn)
Header file for dnsserv.c.
Entry connection structure.
void purge_vanguards_lite(void)
void maintain_layer2_guards(void)
int guards_update_all(void)
Header file for circuitbuild.c.
Header file for geoip_stats.c.
time_t geoip_entry_stats_write(time_t now)
time_t geoip_dirreq_stats_write(time_t now)
void geoip_bridge_stats_init(time_t now)
int should_record_bridge_info(const or_options_t *options)
time_t geoip_bridge_stats_write(time_t now)
void consider_hibernation(time_t now)
int accounting_is_enabled(const or_options_t *options)
void accounting_run_housekeeping(time_t now)
int we_are_hibernating(void)
Header file for hibernate.c.
void hs_cache_client_intro_state_clean(time_t now)
void hs_cache_clean_as_client(time_t now)
void hs_cache_clean_as_dir(time_t now)
Header file for hs_cache.c.
void hs_client_purge_state(void)
Header file containing client data for the HS subsystem.
unsigned int hs_service_get_num_services(void)
void hs_service_run_scheduled_events(time_t now)
Header file containing service data for the HS subsystem.
void tor_log(int severity, log_domain_mask_t domain, const char *format,...)
#define log_fn(severity, domain, args,...)
#define log_fn_ratelim(ratelim, severity, domain, args,...)
static monotime_coarse_t current_second_last_changed
static struct event * initialize_periodic_events_event
void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w)
#define MAX_SIGNEWNYM_RATE
static int main_loop_should_exit
#define LAZY_DESCRIPTOR_RETRY_INTERVAL
void connection_watch_events(connection_t *conn, watchable_events_t events)
void dns_servers_relaunch_checks(void)
STATIC int check_network_participation_callback(time_t now, const or_options_t *options)
static int add_entropy_callback(time_t now, const or_options_t *options)
static int periodic_events_initialized
static int rend_cache_failure_clean_callback(time_t now, const or_options_t *options)
static time_t time_of_last_signewnym
static void conn_read_callback(evutil_socket_t fd, short event, void *_conn)
static int clean_caches_callback(time_t now, const or_options_t *options)
static int main_loop_exit_value
static mainloop_event_t * schedule_active_linked_connections_event
static mainloop_event_t * scheduled_shutdown_ev
static void increment_main_loop_success_count(void)
static void rescan_periodic_events_cb(mainloop_event_t *event, void *arg)
int connection_add_impl(connection_t *conn, int is_connecting)
static void scheduled_shutdown_cb(mainloop_event_t *ev, void *arg)
void note_that_we_maybe_cant_complete_circuits(void)
void connection_stop_reading(connection_t *conn)
static smartlist_t * active_linked_connection_lst
void connection_stop_reading_from_linked_conn(connection_t *conn)
int connection_in_array(connection_t *conn)
static struct event * shutdown_did_not_work_event
int have_completed_a_circuit(void)
void ip_address_changed(int on_client_conn)
static int retry_listeners_callback(time_t now, const or_options_t *options)
void note_that_we_completed_a_circuit(void)
static int write_stats_file_callback(time_t now, const or_options_t *options)
void connection_unregister_events(connection_t *conn)
void directory_all_unreachable(time_t now)
int connection_remove(connection_t *conn)
void add_connection_to_closeable_list(connection_t *conn)
STATIC void close_closeable_connections(void)
void reschedule_directory_downloads(void)
uint64_t get_bytes_read(void)
void initialize_periodic_events(void)
void mainloop_schedule_shutdown(int delay_sec)
int connection_is_on_closeable_list(connection_t *conn)
static void connection_unlink(connection_t *conn)
void connection_start_reading(connection_t *conn)
static void increment_main_loop_idle_count(void)
static int manage_vglite_callback(time_t now, const or_options_t *options)
#define GREEDY_DESCRIPTOR_RETRY_INTERVAL
void update_current_time(time_t now)
void do_signewnym(time_t now)
static int check_expired_networkstatus_callback(time_t now, const or_options_t *options)
static int launch_descriptor_fetches_callback(time_t now, const or_options_t *options)
void initialize_mainloop_events(void)
static int fetch_networkstatus_callback(time_t now, const or_options_t *options)
static uint64_t stats_n_bytes_written
static uint64_t stats_n_bytes_read
static int second_elapsed_callback(time_t now, const or_options_t *options)
int connection_is_writing(connection_t *conn)
static void signewnym_impl(time_t now)
int connection_is_reading(const connection_t *conn)
void schedule_rescan_periodic_events(void)
void connection_start_writing(connection_t *conn)
static void run_connection_housekeeping(int i, time_t now)
uint64_t get_main_loop_error_count(void)
static int connection_check_event(connection_t *conn, struct event *ev)
static void shutdown_did_not_work_callback(evutil_socket_t fd, short event, void *arg) ATTR_NORETURN
static void postloop_cleanup_cb(mainloop_event_t *ev, void *arg)
static int record_bridge_stats_callback(time_t now, const or_options_t *options)
static int can_complete_circuits
static long stats_n_seconds_working
smartlist_t * get_connection_array(void)
static int signewnym_is_pending
uint64_t get_main_loop_idle_count(void)
void reschedule_or_state_save(void)
static void schedule_active_linked_connections_cb(mainloop_event_t *event, void *arg)
void tor_shutdown_event_loop_and_exit(int exitcode)
static ratelim_t libevent_error_ratelim
static int conn_close_if_marked(int i)
void tor_init_connection_lists(void)
static time_t current_second
static void conn_write_callback(evutil_socket_t fd, short event, void *_conn)
void reset_all_main_loop_timers(void)
static unsigned newnym_epoch
STATIC smartlist_t * connection_array
static smartlist_t * closeable_connection_lst
static void handle_deferred_signewnym_cb(mainloop_event_t *event, void *arg)
STATIC int get_my_roles(const or_options_t *options)
static mainloop_event_t * postloop_cleanup_ev
static int connection_should_read_from_linked_conn(connection_t *conn)
int connection_count_moribund(void)
uint64_t get_main_loop_success_count(void)
static void connection_start_reading_from_linked_conn(connection_t *conn)
void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs)
void connection_stop_writing(connection_t *conn)
uint64_t get_bytes_written(void)
static int save_state_callback(time_t now, const or_options_t *options)
static int run_main_loop_once(void)
static void increment_main_loop_error_count(void)
static int heartbeat_callback(time_t now, const or_options_t *options)
static uint64_t stats_n_main_loop_successes
void reset_main_loop_counters(void)
static uint64_t stats_n_main_loop_idle
int tor_event_loop_shutdown_is_pending(void)
static int rotate_x509_certificate_callback(time_t now, const or_options_t *options)
static int called_loop_once
time_t time_of_process_start
static void directory_all_unreachable_cb(mainloop_event_t *event, void *arg)
void mainloop_schedule_postloop_cleanup(void)
static void initialize_periodic_events_cb(evutil_socket_t fd, short events, void *data)
void rescan_periodic_events(const or_options_t *options)
unsigned get_signewnym_epoch(void)
static int prune_old_routers_callback(time_t now, const or_options_t *options)
static uint64_t stats_n_main_loop_errors
STATIC int run_main_loop_until_done(void)
static mainloop_event_t * handle_deferred_signewnym_ev
Header file for mainloop.c.
int usable_consensus_flavor(void)
int microdesc_cache_rebuild(microdesc_cache_t *cache, int force)
Header file for microdesc.c.
int net_is_disabled(void)
void netstatus_note_clock_jumped(time_t seconds_diff)
void set_network_participation(bool participation)
time_t get_last_user_activity_time(void)
void note_user_activity(time_t now)
bool is_participating_on_network(void)
void update_networkstatus_downloads(time_t now)
int networkstatus_consensus_reasonably_live(const networkstatus_t *consensus, time_t now)
networkstatus_t * networkstatus_get_reasonably_live_consensus(time_t now, int flavor)
networkstatus_t * networkstatus_get_latest_consensus(void)
int networkstatus_consensus_is_bootstrapping(time_t now)
int should_delay_dir_fetches(const or_options_t *options, const char **msg_out)
Header file for networkstatus.c.
Networkstatus consensus/vote structure.
void router_dir_info_changed(void)
const char * get_dir_info_status_string(void)
int router_have_minimum_dir_info(void)
Header file for nodelist.c.
Header file for ntmain.c.
Master header file for Tor-specific functionality.
#define MAX_SSL_KEY_LIFETIME_INTERNAL
#define END_STREAM_REASON_NET_UNREACHABLE
The or_state_t structure, which represents Tor's state file.
#define OR_CONN_STATE_CONNECTING
#define OR_CONN_STATE_OPEN
long tor_parse_long(const char *s, int base, long min, long max, int *ok, char **next)
void periodic_events_rescan_by_roles(int roles, bool net_disabled)
void periodic_events_connect_all(void)
void periodic_events_register(periodic_event_item_t *item)
int safe_timer_diff(time_t now, time_t next)
void periodic_events_disconnect_all(void)
void periodic_event_reschedule(periodic_event_item_t *event)
void periodic_events_reset_all(void)
int any_predicted_circuits(time_t now)
Header file for predict_ports.c.
int proxy_mode(const or_options_t *options)
Header file for proxymode.c.
quiet_level_t quiet_level
void rep_hist_reset_padding_counts(void)
time_t rep_hist_desc_stats_write(time_t now)
void rep_history_clean(time_t before)
time_t rep_hist_hs_stats_write(time_t now, bool is_v3)
time_t rep_hist_buffer_stats_write(time_t now)
time_t rep_hist_exit_stats_write(time_t now)
Header file for rephist.c.
#define REPHIST_CELL_PADDING_COUNTS_INTERVAL
int router_initialize_tls_context(void)
void mark_my_descriptor_dirty(const char *reason)
Router descriptor structure.
int generate_ed_link_cert(const or_options_t *options, time_t now, int force)
void update_extrainfo_downloads(time_t now)
void routerlist_remove_old_routers(void)
void update_all_descriptor_downloads(time_t now)
Header file for routerlist.c.
int dir_server_mode(const or_options_t *options)
int server_mode(const or_options_t *options)
Header file for routermode.c.
void router_do_reachability_checks(void)
void router_reset_reachability(void)
Header file for selftest.c.
int smartlist_contains(const smartlist_t *sl, const void *element)
smartlist_t * smartlist_new(void)
void smartlist_add(smartlist_t *sl, void *element)
void smartlist_remove(smartlist_t *sl, const void *element)
void smartlist_del(smartlist_t *sl, int idx)
#define SMARTLIST_FOREACH_BEGIN(sl, type, var)
#define SMARTLIST_FOREACH(sl, type, var, cmd)
Client request structure.
or_state_t * get_or_state(void)
int or_state_save(time_t now)
int log_heartbeat(time_t now)
time_t timestamp_last_had_circuits
uint64_t global_identifier
time_t timestamp_last_read_allowed
unsigned int writing_to_linked_conn
struct event * write_event
struct connection_t * linked_conn
unsigned int hold_open_until_flushed
unsigned int reading_from_linked_conn
uint16_t marked_for_close
const char * marked_for_close_file
unsigned int active_on_link
struct event * read_event
time_t timestamp_last_write_allowed
unsigned int edge_has_sent_end
socks_request_t * socks_request
time_t timestamp_lastempty
unsigned int is_canonical
int TestingDirConnectionMaxStall
uint64_t OwningControllerFD
int DormantTimeoutEnabled
int DormantTimeoutDisabledByIdleStreams
int HiddenServiceStatistics
int ConnDirectionStatistics
int BridgeAuthoritativeDir
int n_calls_since_last_time
char address[MAX_SOCKS_ADDR_LEN]
#define MOCK_IMPL(rv, funcname, arglist)
Headers for transports.c.
#define tor_fragile_assert()
int tor_digest_is_zero(const char *digest)