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");
348 assert_connection_edge_not_dns_pending(
TO_EDGE_CONN(conn));
366 connection_free(conn);
387 event_active(conn->read_event, EV_READ, 1));
585 log_warn(
LD_BUG,
"Event missing on connection %p [%s;%s]. "
586 "socket=%d. linked=%d. "
587 "is_dns_request=%d. Marked_for_close=%s:%d",
591 (
int)conn->
s, (
int)conn->
linked,
626 log_warn(
LD_NET,
"Error from libevent setting read event state for %d "
629 tor_socket_strerror(tor_socket_errno(conn->
s)));
652 "Request to start reading on an edgeconn blocked with XOFF");
656 log_warn(
LD_NET,
"Error from libevent setting read event state for %d "
659 tor_socket_strerror(tor_socket_errno(conn->
s)));
699 log_warn(
LD_NET,
"Error from libevent setting write event state for %d "
702 tor_socket_strerror(tor_socket_errno(conn->
s)));
723 log_warn(
LD_NET,
"Error from libevent setting write event state for %d "
726 tor_socket_strerror(tor_socket_errno(conn->
s)));
762 tor_assert_unreached();
766#ifdef ENABLE_RESTART_DEBUGGING
767static struct event *tor_shutdown_event_loop_for_restart_event = NULL;
769tor_shutdown_event_loop_for_restart_cb(
770 evutil_socket_t fd,
short event,
void *arg)
775 tor_event_free(tor_shutdown_event_loop_for_restart_event);
800 struct timeval ten_seconds = { 10, 0 };
884 } SMARTLIST_FOREACH_END(conn);
898 log_debug(
LD_NET,
"socket %d wants to read.",(
int)conn->
s);
912 if (connection_handle_read(conn) < 0) {
915 log_warn(
LD_BUG,
"Unhandled error on read for %s connection "
922 connection_mark_for_close(conn);
945 if (connection_handle_write(conn, 0) < 0) {
949 "unhandled error on write for %s connection (fd %d); removing",
956 edge_conn->
end_reason = END_STREAM_REASON_INTERNAL;
960 connection_mark_for_close(conn);
990 log_debug(
LD_NET,
"Cleaning up connection (fd "TOR_SOCKET_T_FORMAT
").",
1006 "Conn (addr %s, fd %d, type %s, state %d) marked, but wants "
1007 "to flush %"TOR_PRIuSZ
" bytes. (Marked at %s:%d)",
1010 connection_get_outbuf_len(conn),
1019 log_debug(
LD_GENERAL,
"Flushed last %d bytes from a linked conn; "
1020 "%d left; wants-to-flush==%d", retval,
1021 (
int)connection_get_outbuf_len(conn),
1023 }
else if (connection_speaks_cells(conn)) {
1036 "Holding conn (fd %d) open for more flushing.",
1040 }
else if (sz == 0) {
1067 "bytes to address %s. If this happens a lot, either "
1068 "something is wrong with your network connection, or "
1069 "something is wrong with theirs. "
1070 "(fd %d, type %s, state %d, marked at %s:%d).",
1071 (
int)connection_get_outbuf_len(conn),
1099 "Is your network connection down? "
1100 "Failing connection to '%s:%d'.",
1103 connection_mark_unattached_ap(entry_conn,
1124 if (!directory_all_unreachable_cb_event) {
1125 directory_all_unreachable_cb_event =
1127 tor_assert(directory_all_unreachable_cb_event);
1144 if (invalidate_circs) {
1150 int quiet = suppress_logs || from_cache ||
1153 "I learned some more directory information, but not enough to "
1184 int have_any_circuits;
1185 int past_keepalive =
1188 if (conn->
outbuf && !connection_get_outbuf_len(conn) &&
1206 log_info(
LD_DIR,
"Expiring wedged directory conn (fd %d, purpose %d)",
1211 connection_get_inbuf_len(conn) >= 1024) {
1212 log_info(
LD_DIR,
"Trying to extract information from wedged server desc "
1216 connection_mark_for_close(conn);
1221 if (!connection_speaks_cells(conn))
1230 chan = TLS_CHAN_TO_BASE(or_conn->
chan);
1234 have_any_circuits = 1;
1237 have_any_circuits = 0;
1241 ! have_any_circuits) {
1245 "Expiring non-used OR connection to fd %d (%s:%d) [Too old].",
1249 END_OR_CONN_REASON_TIMEOUT,
1250 "Tor gave up on the connection");
1253 if (past_keepalive) {
1255 log_info(
LD_OR,
"Expiring non-open OR connection to fd %d (%s:%d).",
1260 ! have_any_circuits &&
1261 !connection_get_outbuf_len(conn)) {
1264 log_info(
LD_OR,
"Expiring non-used OR connection to fd %d (%s:%d) "
1265 "[Hibernating or exiting].",
1268 }
else if (!have_any_circuits &&
1271 log_info(
LD_OR,
"Expiring non-used OR connection %"PRIu64
" to fd %d "
1272 "(%s:%d) [no circuits for %d; timeout %d; %scanonical].",
1284 "Expiring stuck OR connection to fd %d (%s:%d). (%d bytes to "
1285 "flush; %d seconds since last write)",
1287 conn->
port, (
int)connection_get_outbuf_len(conn),
1290 }
else if (past_keepalive && !connection_get_outbuf_len(conn)) {
1294 memset(&cell,0,
sizeof(
cell_t));
1309 log_info(
LD_CONTROL,
"Ignoring SIGNAL NEWNYM because client functionality "
1332 log_info(
LD_CONTROL,
"Honoring delayed NEWNYM request");
1341 const time_t delay_sec =
1349 const struct timeval delay_tv = { delay_sec, 0 };
1353 "Rate limiting NEWNYM request: delaying by %d second(s)",
1374#define CALLBACK(name) \
1375 static int name ## _callback(time_t, const or_options_t *)
1377CALLBACK(add_entropy);
1378CALLBACK(check_expired_networkstatus);
1379CALLBACK(clean_caches);
1380CALLBACK(clean_consdiffmgr);
1381CALLBACK(fetch_networkstatus);
1383CALLBACK(hs_service);
1384CALLBACK(launch_descriptor_fetches);
1385CALLBACK(prune_old_routers);
1386CALLBACK(record_bridge_stats);
1387CALLBACK(rend_cache_failure_clean);
1388CALLBACK(reset_padding_counts);
1389CALLBACK(retry_listeners);
1390CALLBACK(rotate_x509_certificate);
1391CALLBACK(save_state);
1392CALLBACK(write_stats_file);
1394CALLBACK(second_elapsed);
1395CALLBACK(manage_vglite);
1400#define CALLBACK(name, r, f) \
1401 PERIODIC_EVENT(name, PERIODIC_EVENT_ROLE_ ## r, f)
1402#define FL(name) (PERIODIC_EVENT_FLAG_ ## name)
1409 CALLBACK(add_entropy, ALL, 0),
1410 CALLBACK(heartbeat, ALL, 0),
1411 CALLBACK(reset_padding_counts, ALL, 0),
1415 CALLBACK(second_elapsed, NET_PARTICIPANT,
1416 FL(RUN_ON_DISABLE)),
1419 CALLBACK(manage_vglite, NET_PARTICIPANT, FL(NEED_NET)),
1423 CALLBACK(retry_listeners, NET_PARTICIPANT, FL(NEED_NET)),
1426 CALLBACK(check_expired_networkstatus, NET_PARTICIPANT, 0),
1427 CALLBACK(fetch_networkstatus, NET_PARTICIPANT, 0),
1428 CALLBACK(launch_descriptor_fetches, NET_PARTICIPANT, FL(NEED_NET)),
1429 CALLBACK(rotate_x509_certificate, NET_PARTICIPANT, 0),
1430 CALLBACK(check_network_participation, NET_PARTICIPANT, 0),
1434 CALLBACK(clean_caches, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1435 CALLBACK(save_state, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1436 CALLBACK(write_stats_file, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1437 CALLBACK(prune_old_routers, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1440 CALLBACK(hs_service, HS_SERVICE, FL(NEED_NET)),
1443 CALLBACK(record_bridge_stats, BRIDGE, 0),
1447 CALLBACK(rend_cache_failure_clean, NET_PARTICIPANT, FL(RUN_ON_DISABLE)),
1450 CALLBACK(clean_consdiffmgr, DIRSERVER, 0),
1455 END_OF_PERIODIC_EVENTS
1490 int roles = PERIODIC_EVENT_ROLE_ALL;
1492 int is_relay = server_mode(options);
1493 int is_dirauth = authdir_mode_v3(options);
1494 int is_bridgeauth = authdir_mode_bridge(options);
1496 int is_dirserver = dir_server_mode(options);
1503 options->ControlPort_set ||
1507 is_relay || is_hidden_service;
1509 if (is_bridge) roles |= PERIODIC_EVENT_ROLE_BRIDGE;
1510 if (is_client) roles |= PERIODIC_EVENT_ROLE_CLIENT;
1511 if (is_relay) roles |= PERIODIC_EVENT_ROLE_RELAY;
1512 if (is_dirauth) roles |= PERIODIC_EVENT_ROLE_DIRAUTH;
1513 if (is_bridgeauth) roles |= PERIODIC_EVENT_ROLE_BRIDGEAUTH;
1514 if (is_hidden_service) roles |= PERIODIC_EVENT_ROLE_HS_SERVICE;
1515 if (is_dirserver) roles |= PERIODIC_EVENT_ROLE_DIRSERVER;
1516 if (is_net_participant) roles |= PERIODIC_EVENT_ROLE_NET_PARTICIPANT;
1517 if (sending_control_events) roles |= PERIODIC_EVENT_ROLE_CONTROLEV;
1552 for (
int i = 0; mainloop_periodic_events[i].
name; ++i) {
1559#define NAMED_CALLBACK(name) \
1560 STMT_BEGIN name ## _event = periodic_events_find( #name ); STMT_END
1563 NAMED_CALLBACK(prune_old_routers);
1564 NAMED_CALLBACK(fetch_networkstatus);
1565 NAMED_CALLBACK(launch_descriptor_fetches);
1566 NAMED_CALLBACK(check_dns_honesty);
1567 NAMED_CALLBACK(save_state);
1571teardown_periodic_events(
void)
1574 fetch_networkstatus_event = NULL;
1575 launch_descriptor_fetches_event = NULL;
1576 check_dns_honesty_event = NULL;
1577 save_state_event = NULL;
1578 prune_old_routers_event = NULL;
1599 if (!rescan_periodic_events_ev) {
1600 rescan_periodic_events_ev =
1619periodic_events_on_new_options(
const or_options_t *options)
1676 log_notice(
LD_GENERAL,
"Clean shutdown finished. Exiting.");
1684 const struct timeval delay_tv = { delay_sec, 0 };
1699#define VANGUARDS_LITE_INTERVAL (15*60)
1703 return VANGUARDS_LITE_INTERVAL;
1790 return PERIODIC_EVENT_NO_UPDATE;
1807 static int first = 1;
1817 log_info(
LD_GENERAL,
"Rotating tls context.");
1819 log_err(
LD_BUG,
"Error reinitializing TLS context");
1820 tor_assert_unreached();
1822 if (generate_ed_link_cert(options, now, 1)) {
1823 log_err(
LD_OR,
"Unable to update Ed25519->TLS link certificate for "
1824 "new TLS context.");
1825 tor_assert_unreached();
1845 log_warn(
LD_GENERAL,
"Tried to re-seed RNG, but failed. We already "
1846 "seeded once, though, so we won't exit here.");
1850#define ENTROPY_INTERVAL (60*60)
1851 return ENTROPY_INTERVAL;
1860 if (server_mode(options)) {
1861 goto found_activity;
1867 goto found_activity;
1874 goto found_activity;
1882 goto found_activity;
1888#define CHECK_PARTICIPATION_INTERVAL (5*60)
1892 time_t time_since_last_activity = 0;
1896 log_notice(
LD_GENERAL,
"No user activity in a long time: becoming"
1902 return CHECK_PARTICIPATION_INTERVAL;
1906 return CHECK_PARTICIPATION_INTERVAL;
1925#define CHECK_EXPIRED_NS_INTERVAL (2*60)
1926 return CHECK_EXPIRED_NS_INTERVAL;
1938 if (next_write == TIME_MAX) {
1950 if (save_state_event == NULL) {
1965#define CHECK_WRITE_STATS_INTERVAL (60*60)
1966 time_t next_time_to_write_stats_files = now + CHECK_WRITE_STATS_INTERVAL;
1970 if (next_write && next_write < next_time_to_write_stats_files)
1971 next_time_to_write_stats_files = next_write;
1974 time_t next_write = geoip_dirreq_stats_write(now);
1975 if (next_write && next_write < next_time_to_write_stats_files)
1976 next_time_to_write_stats_files = next_write;
1979 time_t next_write = geoip_entry_stats_write(now);
1980 if (next_write && next_write < next_time_to_write_stats_files)
1981 next_time_to_write_stats_files = next_write;
1985 if (next_write && next_write < next_time_to_write_stats_files)
1986 next_time_to_write_stats_files = next_write;
1989 if (next_write && next_write < next_time_to_write_stats_files)
1990 next_time_to_write_stats_files = next_write;
1994 if (next_write && next_write < next_time_to_write_stats_files)
1995 next_time_to_write_stats_files = next_write;
1999 if (next_write && next_write < next_time_to_write_stats_files)
2000 next_time_to_write_stats_files = next_write;
2004 if (next_write && next_write < next_time_to_write_stats_files)
2005 next_time_to_write_stats_files = next_write;
2012reset_padding_counts_callback(time_t now,
const or_options_t *options)
2015 rep_hist_prep_published_padding_counts(now);
2022static int should_init_bridge_stats = 1;
2032 if (should_record_bridge_info(options)) {
2033 if (should_init_bridge_stats) {
2035 geoip_bridge_stats_init(now);
2036 should_init_bridge_stats = 0;
2037 return WRITE_STATS_INTERVAL;
2041 time_t next = geoip_bridge_stats_write(now);
2044 }
else if (!should_init_bridge_stats) {
2047 should_init_bridge_stats = 1;
2049 return PERIODIC_EVENT_NO_UPDATE;
2063#define CLEAN_CACHES_INTERVAL (30*60)
2064 return CLEAN_CACHES_INTERVAL;
2088#define ROUTERLIST_PRUNING_INTERVAL (60*60)
2096 log_debug(
LD_GENERAL,
"Pruning routerlist...");
2100 return ROUTERLIST_PRUNING_INTERVAL;
2116 int networkstatus_dl_check_interval = 60;
2120 || (we_are_bootstrapping && prefer_mirrors)) {
2121 networkstatus_dl_check_interval = 1;
2125 return PERIODIC_EVENT_NO_UPDATE;
2128 return networkstatus_dl_check_interval;
2142 return PERIODIC_EVENT_NO_UPDATE;
2145static int heartbeat_callback_first_time = 1;
2158 return PERIODIC_EVENT_NO_UPDATE;
2162 if (heartbeat_callback_first_time) {
2163 heartbeat_callback_first_time = 0;
2177#define CDM_CLEAN_CALLBACK_INTERVAL 600
2179clean_consdiffmgr_callback(time_t now,
const or_options_t *options)
2182 if (dir_server_mode(options)) {
2185 return CDM_CLEAN_CALLBACK_INTERVAL;
2193hs_service_callback(time_t now,
const or_options_t *options)
2217control_per_second_events_callback(time_t now,
const or_options_t *options)
2250 monotime_coarse_t last_updated;
2256#define NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE 20
2259 if (
ABS(seconds_elapsed) >= NUM_JUMPED_SECONDS_BEFORE_NETSTATUS_UPDATE) {
2266#define NUM_JUMPED_SECONDS_BEFORE_WARN 100
2269#define NUM_IDLE_SECONDS_BEFORE_WARN 3600
2271 if (seconds_elapsed < -NUM_JUMPED_SECONDS_BEFORE_WARN) {
2275 }
else if (seconds_elapsed >= NUM_JUMPED_SECONDS_BEFORE_WARN) {
2277 const int32_t monotime_msec_passed =
2280 const int monotime_sec_passed = monotime_msec_passed / 1000;
2281 const int discrepancy = monotime_sec_passed - (int)seconds_elapsed;
2291 const bool clock_jumped = abs(discrepancy) > 2;
2293 if (clock_jumped || seconds_elapsed >= NUM_IDLE_SECONDS_BEFORE_WARN) {
2296 }
else if (seconds_elapsed > 0) {
2304#ifdef HAVE_SYSTEMD_209
2313 sd_notify(0,
"WATCHDOG=1");
2317#define UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST (6*60*60)
2333 int server = server_mode(options);
2335 if (on_client_conn) {
2338 if (init_keys_client() < 0)
2339 log_warn(
LD_GENERAL,
"Unable to rotate keys after IP change!");
2343 if (
get_uptime() > UPTIME_CUTOFF_FOR_NEW_BANDWIDTH_TEST)
2346 router_reset_reachability();
2365 dns_reset_correctness_checks();
2366 if (check_dns_honesty_event) {
2398 struct timeval one_second = { 1, 0 };
2404#ifdef HAVE_SYSTEMD_209
2405 uint64_t watchdog_delay;
2407 if (sd_watchdog_enabled(1, &watchdog_delay) > 0) {
2408 if (! systemd_watchdog_timer) {
2413 watchdog_delay /= 2;
2414 watchdog.tv_sec = watchdog_delay / 1000000;
2415 watchdog.tv_usec = watchdog_delay % 1000000;
2419 systemd_watchdog_callback,
2425#ifdef ENABLE_RESTART_DEBUGGING
2427 static int first_time = 1;
2429 if (first_time && getenv(
"TOR_DEBUG_RESTART")) {
2431 const char *sec_str = getenv(
"TOR_DEBUG_RESTART_AFTER_SECONDS");
2435 (sec =
tor_parse_long(sec_str, 10, 0, INT_MAX, &sec_ok, NULL)) &&
2441 struct timeval restart_after = { (time_t) sec, 0 };
2442 tor_shutdown_event_loop_for_restart_event =
2444 tor_shutdown_event_loop_for_restart_cb, NULL);
2445 event_add(tor_shutdown_event_loop_for_restart_event, &restart_after);
2467 if (nt_service_is_stopping())
2498 if (loop_result == 0) {
2501 }
else if (loop_result == -1) {
2504 }
else if (loop_result == 1) {
2514 if (loop_result < 0) {
2515 int e = tor_socket_errno(-1);
2517 if (e != EINTR && !ERRNO_IS_EINPROGRESS(e)) {
2518 log_err(
LD_NET,
"libevent call with %s failed: %s [%d]",
2522 }
else if (e == EINVAL) {
2524 "EINVAL from libevent: should you upgrade libevent?");
2526 log_err(
LD_NET,
"Too many libevent errors, too fast: dying");
2531 tor_assert_nonfatal_once(! ERRNO_IS_EINPROGRESS(e));
2532 log_debug(
LD_NET,
"libevent call interrupted.");
2553 int loop_result = 1;
2560 }
while (loop_result == 1);
2583tor_mainloop_free_all(
void)
2588 teardown_periodic_events();
2591 mainloop_event_free(directory_all_unreachable_cb_event);
2596 mainloop_event_free(rescan_periodic_events_ev);
2598#ifdef HAVE_SYSTEMD_209
2599 periodic_timer_free(systemd_watchdog_timer);
2604 memset(&global_bucket, 0,
sizeof(global_bucket));
2605 memset(&global_relayed_bucket, 0,
sizeof(global_relayed_bucket));
2615 should_init_bridge_stats = 1;
2616 heartbeat_callback_first_time = 1;
#define fmt_and_decorate_addr(a)
void addressmap_clear_transient(void)
void update_approx_time(time_t now)
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 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.
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.
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.
Header file for routermode.c.
void router_do_reachability_checks(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)
void pt_update_bridge_lines(void)
Headers for transports.c.
#define tor_fragile_assert()
int tor_digest_is_zero(const char *digest)