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.",
279 log_warn(
LD_BUG,
"Error removing read event for %d", (
int)conn->
s);
284 log_warn(
LD_BUG,
"Error removing write event for %d", (
int)conn->
s);
304 log_debug(
LD_NET,
"removing socket %d (type %s), n_conns now %d",
309 log_info(
LD_NET,
"Closing SOCKS Unix socket connection");
374 connection_free(conn);
395 event_active(conn->read_event, EV_READ, 1));
589 log_warn(
LD_BUG,
"Event missing on connection %p [%s;%s]. "
590 "socket=%d. linked=%d. "
591 "is_dns_request=%d. Marked_for_close=%s:%d",
595 (
int)conn->
s, (
int)conn->
linked,
622 log_warn(
LD_NET,
"Error from libevent setting read event state for %d "
625 tor_socket_strerror(tor_socket_errno(conn->
s)));
645 log_warn(
LD_NET,
"Error from libevent setting read event state for %d "
648 tor_socket_strerror(tor_socket_errno(conn->
s)));
678 log_warn(
LD_NET,
"Error from libevent setting write event state for %d "
681 tor_socket_strerror(tor_socket_errno(conn->
s)));
702 log_warn(
LD_NET,
"Error from libevent setting write event state for %d "
705 tor_socket_strerror(tor_socket_errno(conn->
s)));
741 tor_assert_unreached();
745 #ifdef ENABLE_RESTART_DEBUGGING
746 static struct event *tor_shutdown_event_loop_for_restart_event = NULL;
748 tor_shutdown_event_loop_for_restart_cb(
749 evutil_socket_t fd,
short event,
void *arg)
754 tor_event_free(tor_shutdown_event_loop_for_restart_event);
779 struct timeval ten_seconds = { 10, 0 };
863 } SMARTLIST_FOREACH_END(conn);
877 log_debug(
LD_NET,
"socket %d wants to read.",(
int)conn->
s);
891 if (connection_handle_read(conn) < 0) {
894 log_warn(
LD_BUG,
"Unhandled error on read for %s connection "
901 connection_mark_for_close(conn);
924 if (connection_handle_write(conn, 0) < 0) {
928 "unhandled error on write for %s connection (fd %d); removing",
935 edge_conn->
end_reason = END_STREAM_REASON_INTERNAL;
939 connection_mark_for_close(conn);
969 log_debug(
LD_NET,
"Cleaning up connection (fd "TOR_SOCKET_T_FORMAT
").",
985 "Conn (addr %s, fd %d, type %s, state %d) marked, but wants "
986 "to flush %"TOR_PRIuSZ
" bytes. (Marked at %s:%d)",
989 connection_get_outbuf_len(conn),
998 log_debug(
LD_GENERAL,
"Flushed last %d bytes from a linked conn; "
999 "%d left; wants-to-flush==%d", retval,
1000 (
int)connection_get_outbuf_len(conn),
1002 }
else if (connection_speaks_cells(conn)) {
1015 "Holding conn (fd %d) open for more flushing.",
1019 }
else if (sz == 0) {
1046 "bytes to address %s. If this happens a lot, either "
1047 "something is wrong with your network connection, or "
1048 "something is wrong with theirs. "
1049 "(fd %d, type %s, state %d, marked at %s:%d).",
1050 (
int)connection_get_outbuf_len(conn),
1078 "Is your network connection down? "
1079 "Failing connection to '%s:%d'.",
1082 connection_mark_unattached_ap(entry_conn,
1103 if (!directory_all_unreachable_cb_event) {
1104 directory_all_unreachable_cb_event =
1106 tor_assert(directory_all_unreachable_cb_event);
1123 if (invalidate_circs) {
1129 int quiet = suppress_logs || from_cache ||
1132 "I learned some more directory information, but not enough to "
1163 int have_any_circuits;
1164 int past_keepalive =
1167 if (conn->
outbuf && !connection_get_outbuf_len(conn) &&
1185 log_info(
LD_DIR,
"Expiring wedged directory conn (fd %d, purpose %d)",
1190 connection_get_inbuf_len(conn) >= 1024) {
1191 log_info(
LD_DIR,
"Trying to extract information from wedged server desc "
1195 connection_mark_for_close(conn);
1200 if (!connection_speaks_cells(conn))
1209 chan = TLS_CHAN_TO_BASE(or_conn->
chan);
1213 have_any_circuits = 1;
1216 have_any_circuits = 0;
1220 ! have_any_circuits) {
1224 "Expiring non-used OR connection to fd %d (%s:%d) [Too old].",
1228 END_OR_CONN_REASON_TIMEOUT,
1229 "Tor gave up on the connection");
1232 if (past_keepalive) {
1234 log_info(
LD_OR,
"Expiring non-open OR connection to fd %d (%s:%d).",
1239 ! have_any_circuits &&
1240 !connection_get_outbuf_len(conn)) {
1243 log_info(
LD_OR,
"Expiring non-used OR connection to fd %d (%s:%d) "
1244 "[Hibernating or exiting].",
1247 }
else if (!have_any_circuits &&
1250 log_info(
LD_OR,
"Expiring non-used OR connection %"PRIu64
" to fd %d "
1251 "(%s:%d) [no circuits for %d; timeout %d; %scanonical].",
1263 "Expiring stuck OR connection to fd %d (%s:%d). (%d bytes to "
1264 "flush; %d seconds since last write)",
1266 (
int)connection_get_outbuf_len(conn),
1269 }
else if (past_keepalive && !connection_get_outbuf_len(conn)) {
1273 memset(&cell,0,
sizeof(
cell_t));
1288 log_info(
LD_CONTROL,
"Ignoring SIGNAL NEWNYM because client functionality "
1310 log_info(
LD_CONTROL,
"Honoring delayed NEWNYM request");
1319 const time_t delay_sec =
1327 const struct timeval delay_tv = { delay_sec, 0 };
1331 "Rate limiting NEWNYM request: delaying by %d second(s)",
1352 #define CALLBACK(name) \
1353 static int name ## _callback(time_t, const or_options_t *)
1355 CALLBACK(add_entropy);
1356 CALLBACK(check_expired_networkstatus);
1357 CALLBACK(clean_caches);
1358 CALLBACK(clean_consdiffmgr);
1359 CALLBACK(fetch_networkstatus);
1360 CALLBACK(heartbeat);
1361 CALLBACK(hs_service);
1362 CALLBACK(launch_descriptor_fetches);
1363 CALLBACK(prune_old_routers);
1364 CALLBACK(record_bridge_stats);
1365 CALLBACK(rend_cache_failure_clean);
1366 CALLBACK(reset_padding_counts);
1367 CALLBACK(retry_listeners);
1368 CALLBACK(rotate_x509_certificate);
1369 CALLBACK(save_state);
1370 CALLBACK(write_stats_file);
1372 CALLBACK(second_elapsed);
1377 #define CALLBACK(name, r, f) \
1378 PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f)
1379 #define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
1386 CALLBACK(add_entropy, ALL, 0),
1387 CALLBACK(heartbeat, ALL, 0),
1388 CALLBACK(reset_padding_counts, ALL, 0),
1392 CALLBACK(second_elapsed, NET_PARTICIPANT,
1393 FL(RUN_ON_DISABLE)),
1397 CALLBACK(retry_listeners, NET_PARTICIPANT, FL(NEED_NET)),
1400 CALLBACK(check_expired_networkstatus, NET_PARTICIPANT, 0),
1401 CALLBACK(fetch_networkstatus, NET_PARTICIPANT, 0),
1402 CALLBACK(launch_descriptor_fetches, NET_PARTICIPANT, FL(NEED_NET)),
1403 CALLBACK(rotate_x509_certificate, NET_PARTICIPANT, 0),
1404 CALLBACK(check_network_participation, NET_PARTICIPANT, 0),
1408 CALLBACK(clean_caches, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1409 CALLBACK(save_state, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1410 CALLBACK(write_stats_file, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1411 CALLBACK(prune_old_routers, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1414 CALLBACK(hs_service, HS_SERVICE, FL(NEED_NET)),
1417 CALLBACK(record_bridge_stats, BRIDGE, 0),
1421 CALLBACK(rend_cache_failure_clean, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1424 CALLBACK(clean_consdiffmgr, DIRSERVER, 0),
1429 END_OF_PERIODIC_EVENTS
1464 int roles = PERIODIC_EVENT_ROLE_ALL;
1467 int is_dirauth = authdir_mode_v3(options);
1477 options->ControlPort_set ||
1481 is_relay || is_hidden_service;
1483 if (is_bridge) roles |= PERIODIC_EVENT_ROLE_BRIDGE;
1484 if (is_client) roles |= PERIODIC_EVENT_ROLE_CLIENT;
1485 if (is_relay) roles |= PERIODIC_EVENT_ROLE_RELAY;
1486 if (is_dirauth) roles |= PERIODIC_EVENT_ROLE_DIRAUTH;
1487 if (is_bridgeauth) roles |= PERIODIC_EVENT_ROLE_BRIDGEAUTH;
1488 if (is_hidden_service) roles |= PERIODIC_EVENT_ROLE_HS_SERVICE;
1489 if (is_dirserver) roles |= PERIODIC_EVENT_ROLE_DIRSERVER;
1490 if (is_net_participant) roles |= PERIODIC_EVENT_ROLE_NET_PARTICIPANT;
1491 if (sending_control_events) roles |= PERIODIC_EVENT_ROLE_CONTROLEV;
1526 for (
int i = 0; mainloop_periodic_events[i].
name; ++i) {
1533 #define NAMED_CALLBACK(name) \
1534 STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END
1537 NAMED_CALLBACK(prune_old_routers);
1538 NAMED_CALLBACK(fetch_networkstatus);
1539 NAMED_CALLBACK(launch_descriptor_fetches);
1540 NAMED_CALLBACK(check_dns_honesty);
1541 NAMED_CALLBACK(save_state);
1545 teardown_periodic_events(
void)
1548 fetch_networkstatus_event = NULL;
1549 launch_descriptor_fetches_event = NULL;
1550 check_dns_honesty_event = NULL;
1551 save_state_event = NULL;
1552 prune_old_routers_event = NULL;
1573 if (!rescan_periodic_events_ev) {
1574 rescan_periodic_events_ev =
1593 periodic_events_on_new_options(
const or_options_t *options)
1650 log_notice(
LD_GENERAL,
"Clean shutdown finished. Exiting.");
1658 const struct timeval delay_tv = { delay_sec, 0 };
1749 return PERIODIC_EVENT_NO_UPDATE;
1766 static int first = 1;
1776 log_info(
LD_GENERAL,
"Rotating tls context.");
1778 log_err(
LD_BUG,
"Error reinitializing TLS context");
1779 tor_assert_unreached();
1782 log_err(
LD_OR,
"Unable to update Ed25519->TLS link certificate for "
1783 "new TLS context.");
1784 tor_assert_unreached();
1804 log_warn(
LD_GENERAL,
"Tried to re-seed RNG, but failed. We already "
1805 "seeded once, though, so we won't exit here.");
1809 #define ENTROPY_INTERVAL (60*60)
1810 return ENTROPY_INTERVAL;
1820 goto found_activity;
1826 goto found_activity;
1833 goto found_activity;
1841 goto found_activity;
1847 #define CHECK_PARTICIPATION_INTERVAL (5*60)
1851 time_t time_since_last_activity = 0;
1855 log_notice(
LD_GENERAL,
"No user activity in a long time: becoming"
1861 return CHECK_PARTICIPATION_INTERVAL;
1865 return CHECK_PARTICIPATION_INTERVAL;
1884 #define CHECK_EXPIRED_NS_INTERVAL (2*60)
1885 return CHECK_EXPIRED_NS_INTERVAL;
1897 if (next_write == TIME_MAX) {
1909 if (save_state_event == NULL) {
1924 #define CHECK_WRITE_STATS_INTERVAL (60*60)
1925 time_t next_time_to_write_stats_files = now + CHECK_WRITE_STATS_INTERVAL;
1929 if (next_write && next_write < next_time_to_write_stats_files)
1930 next_time_to_write_stats_files = next_write;
1934 if (next_write && next_write < next_time_to_write_stats_files)
1935 next_time_to_write_stats_files = next_write;
1939 if (next_write && next_write < next_time_to_write_stats_files)
1940 next_time_to_write_stats_files = next_write;
1944 if (next_write && next_write < next_time_to_write_stats_files)
1945 next_time_to_write_stats_files = next_write;
1948 if (next_write && next_write < next_time_to_write_stats_files)
1949 next_time_to_write_stats_files = next_write;
1953 if (next_write && next_write < next_time_to_write_stats_files)
1954 next_time_to_write_stats_files = next_write;
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;
1971 reset_padding_counts_callback(time_t now,
const or_options_t *options)
1974 rep_hist_prep_published_padding_counts(now);
1981 static int should_init_bridge_stats = 1;
1992 if (should_init_bridge_stats) {
1995 should_init_bridge_stats = 0;
1996 return WRITE_STATS_INTERVAL;
2003 }
else if (!should_init_bridge_stats) {
2006 should_init_bridge_stats = 1;
2008 return PERIODIC_EVENT_NO_UPDATE;
2022 #define CLEAN_CACHES_INTERVAL (30*60)
2023 return CLEAN_CACHES_INTERVAL;
2047 #define ROUTERLIST_PRUNING_INTERVAL (60*60)
2055 log_debug(
LD_GENERAL,
"Pruning routerlist...");
2059 return ROUTERLIST_PRUNING_INTERVAL;
2075 int networkstatus_dl_check_interval = 60;
2079 || (we_are_bootstrapping && prefer_mirrors)) {
2080 networkstatus_dl_check_interval = 1;
2084 return PERIODIC_EVENT_NO_UPDATE;
2087 return networkstatus_dl_check_interval;
2101 return PERIODIC_EVENT_NO_UPDATE;
2104 static int heartbeat_callback_first_time = 1;
2117 return PERIODIC_EVENT_NO_UPDATE;
2121 if (heartbeat_callback_first_time) {
2122 heartbeat_callback_first_time = 0;
2136 #define CDM_CLEAN_CALLBACK_INTERVAL 600
2138 clean_consdiffmgr_callback(time_t now,
const or_options_t *options)
2144 return CDM_CLEAN_CALLBACK_INTERVAL;
2152 hs_service_callback(time_t now,
const or_options_t *options)
2176 control_per_second_events_callback(time_t now,
const or_options_t *options)
2209 monotime_coarse_t last_updated;
2215 #define NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE 20
2218 if (
ABS(seconds_elapsed) >= NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE) {
2225 #define NUM_JUMPED_SECONDS_BEFORE_WARN 100
2228 #define NUM_IDLE_SECONDS_BEFORE_WARN 3600
2230 if (seconds_elapsed < -NUM_JUMPED_SECONDS_BEFORE_WARN) {
2234 }
else if (seconds_elapsed >= NUM_JUMPED_SECONDS_BEFORE_WARN) {
2236 const int32_t monotime_msec_passed =
2239 const int monotime_sec_passed = monotime_msec_passed / 1000;
2240 const int discrepancy = monotime_sec_passed - (int)seconds_elapsed;
2250 const bool clock_jumped = abs(discrepancy) > 2;
2252 if (clock_jumped || seconds_elapsed >= NUM_IDLE_SECONDS_BEFORE_WARN) {
2255 }
else if (seconds_elapsed > 0) {
2263 #ifdef HAVE_SYSTEMD_209
2272 sd_notify(0,
"WATCHDOG=1");
2276 #define UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST (6*60*60)
2294 if (on_client_conn) {
2297 if (init_keys_client() < 0)
2298 log_warn(
LD_GENERAL,
"Unable to rotate keys after IP change!");
2302 if (
get_uptime() > UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST)
2324 if (check_dns_honesty_event) {
2356 struct timeval one_second = { 1, 0 };
2362 #ifdef HAVE_SYSTEMD_209
2363 uint64_t watchdog_delay;
2365 if (sd_watchdog_enabled(1, &watchdog_delay) > 0) {
2366 if (! systemd_watchdog_timer) {
2371 watchdog_delay /= 2;
2372 watchdog.tv_sec = watchdog_delay / 1000000;
2373 watchdog.tv_usec = watchdog_delay % 1000000;
2377 systemd_watchdog_callback,
2383 #ifdef ENABLE_RESTART_DEBUGGING
2385 static int first_time = 1;
2387 if (first_time && getenv(
"TOR_DEBUG_RESTART")) {
2389 const char *sec_str = getenv(
"TOR_DEBUG_RESTART_AFTER_SECONDS");
2393 (sec =
tor_parse_long(sec_str, 10, 0, INT_MAX, &sec_ok, NULL)) &&
2399 struct timeval restart_after = { (time_t) sec, 0 };
2400 tor_shutdown_event_loop_for_restart_event =
2402 tor_shutdown_event_loop_for_restart_cb, NULL);
2403 event_add(tor_shutdown_event_loop_for_restart_event, &restart_after);
2425 if (nt_service_is_stopping())
2456 if (loop_result == 0) {
2459 }
else if (loop_result == -1) {
2462 }
else if (loop_result == 1) {
2472 if (loop_result < 0) {
2473 int e = tor_socket_errno(-1);
2475 if (e != EINTR && !ERRNO_IS_EINPROGRESS(e)) {
2476 log_err(
LD_NET,
"libevent call with %s failed: %s [%d]",
2480 }
else if (e == EINVAL) {
2482 "EINVAL from libevent: should you upgrade libevent?");
2484 log_err(
LD_NET,
"Too many libevent errors, too fast: dying");
2489 tor_assert_nonfatal_once(! ERRNO_IS_EINPROGRESS(e));
2490 log_debug(
LD_NET,
"libevent call interrupted.");
2511 int loop_result = 1;
2518 }
while (loop_result == 1);
2541 tor_mainloop_free_all(
void)
2546 teardown_periodic_events();
2549 mainloop_event_free(directory_all_unreachable_cb_event);
2554 mainloop_event_free(rescan_periodic_events_ev);
2556 #ifdef HAVE_SYSTEMD_209
2557 periodic_timer_free(systemd_watchdog_timer);
2562 memset(&global_bucket, 0,
sizeof(global_bucket));
2563 memset(&global_relayed_bucket, 0,
sizeof(global_relayed_bucket));
2573 should_init_bridge_stats = 1;
2574 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)
struct event_base * tor_libevent_get_base(void)
mainloop_event_t * mainloop_event_postloop_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
const char * tor_libevent_get_method(void)
periodic_timer_t * periodic_timer_new(struct event_base *base, const struct timeval *tv, void(*cb)(periodic_timer_t *timer, void *data), void *data)
void tor_libevent_exit_loop_after_callback(struct event_base *base)
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
int tor_libevent_run_event_loop(struct event_base *base, int once)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *tv)
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 or_options_t * get_options(void)
int options_any_client_port_set(const or_options_t *options)
const char * escaped_safe_str_client(const char *address)
Header file for config.c.
#define MIN_HEARTBEAT_PERIOD
const char * conn_state_to_string(int type, int state)
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)
void assert_connection_ok(connection_t *conn, time_t now)
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)
const char * conn_type_to_string(int type)
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)
connection_t * connection_get_by_type_nonlinked(int type)
void connection_expire_held_open(void)
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)
edge_connection_t * TO_EDGE_CONN(connection_t *c)
entry_connection_t * TO_ENTRY_CONN(connection_t *c)
Header file for connection_edge.c.
#define AP_CONN_STATE_CIRCUIT_WAIT
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)
or_connection_t * TO_OR_CONN(connection_t *c)
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.
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)
#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)
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
static int signewnym_is_pending
uint64_t get_main_loop_idle_count(void)
int connection_is_reading(connection_t *conn)
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)
smartlist_t * get_connection_array(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.
smartlist_t * smartlist_new(void)
int smartlist_contains(const smartlist_t *sl, const void *element)
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)