Tor  0.4.6.0-alpha-dev
mainloop.h
Go to the documentation of this file.
1 /* Copyright (c) 2001 Matej Pfajfar.
2  * Copyright (c) 2001-2004, Roger Dingledine.
3  * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4  * Copyright (c) 2007-2020, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file mainloop.h
9  * \brief Header file for mainloop.c.
10  **/
11 
12 #ifndef TOR_MAINLOOP_H
13 #define TOR_MAINLOOP_H
14 
15 int have_completed_a_circuit(void);
18 
19 int connection_add_impl(connection_t *conn, int is_connecting);
20 #define connection_add(conn) connection_add_impl((conn), 0)
21 #define connection_add_connecting(conn) connection_add_impl((conn), 1)
27 
29 MOCK_DECL(uint64_t,get_bytes_read,(void));
30 MOCK_DECL(uint64_t,get_bytes_written,(void));
31 void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w);
32 
33 /** Bitmask for events that we can turn on and off with
34  * connection_watch_events. */
35 typedef enum watchable_events {
36  /* Yes, it is intentional that these match Libevent's EV_READ and EV_WRITE */
37  READ_EVENT=0x02, /**< We want to know when a connection is readable */
38  WRITE_EVENT=0x04 /**< We want to know when a connection is writable */
44 
48 
49 void tor_shutdown_event_loop_and_exit(int exitcode);
51 
53 
55 
56 void directory_all_unreachable(time_t now);
57 void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs);
58 
59 void ip_address_changed(int on_client_conn);
63 void reschedule_or_state_save(void);
65 void rescan_periodic_events(const or_options_t *options);
67 
68 void update_current_time(time_t now);
69 
70 MOCK_DECL(long,get_uptime,(void));
71 MOCK_DECL(void,reset_uptime,(void));
72 
73 unsigned get_signewnym_epoch(void);
74 
75 int do_main_loop(void);
76 
77 void reset_main_loop_counters(void);
78 uint64_t get_main_loop_success_count(void);
79 uint64_t get_main_loop_error_count(void);
80 uint64_t get_main_loop_idle_count(void);
81 
82 void periodic_events_on_new_options(const or_options_t *options);
83 
84 void do_signewnym(time_t);
85 time_t get_last_signewnym_time(void);
86 
87 void mainloop_schedule_shutdown(int delay_sec);
88 
89 void tor_init_connection_lists(void);
92 void tor_mainloop_free_all(void);
93 
94 struct token_bucket_rw_t;
95 
96 extern time_t time_of_process_start;
97 extern struct token_bucket_rw_t global_bucket;
98 extern struct token_bucket_rw_t global_relayed_bucket;
99 
100 #ifdef MAINLOOP_PRIVATE
103 STATIC void teardown_periodic_events(void);
104 STATIC int get_my_roles(const or_options_t *);
106  const or_options_t *options);
107 
108 #ifdef TOR_UNIT_TESTS
110 
111 /* We need the periodic_event_item_t definition. */
112 #include "core/mainloop/periodic.h"
113 extern periodic_event_item_t mainloop_periodic_events[];
114 #endif /* defined(TOR_UNIT_TESTS) */
115 #endif /* defined(MAINLOOP_PRIVATE) */
116 
117 #endif /* !defined(TOR_MAINLOOP_H) */
time_of_process_start
time_t time_of_process_start
Definition: mainloop.c:144
connection_stop_reading
void connection_stop_reading(connection_t *conn)
Definition: mainloop.c:611
dns_servers_relaunch_checks
void dns_servers_relaunch_checks(void)
Definition: mainloop.c:2319
get_bytes_read
uint64_t get_bytes_read(void)
Definition: mainloop.c:465
connection_stop_writing
void connection_stop_writing(connection_t *conn)
Definition: mainloop.c:666
note_that_we_maybe_cant_complete_circuits
void note_that_we_maybe_cant_complete_circuits(void)
Definition: mainloop.c:236
get_signewnym_epoch
unsigned get_signewnym_epoch(void)
Definition: mainloop.c:1342
close_closeable_connections
STATIC void close_closeable_connections(void)
Definition: mainloop.c:839
connection_remove
int connection_remove(connection_t *conn)
Definition: mainloop.c:299
connection_unregister_events
void connection_unregister_events(connection_t *conn)
Definition: mainloop.c:277
periodic.h
Header for periodic.c.
tor_shutdown_event_loop_and_exit
void tor_shutdown_event_loop_and_exit(int exitcode)
Definition: mainloop.c:766
initialize_periodic_events
void initialize_periodic_events(void)
Definition: mainloop.c:1522
reset_all_main_loop_timers
void reset_all_main_loop_timers(void)
Definition: mainloop.c:1454
initialize_mainloop_events
void initialize_mainloop_events(void)
Definition: mainloop.c:2331
READ_EVENT
@ READ_EVENT
Definition: mainloop.h:37
connection_start_reading
void connection_start_reading(connection_t *conn)
Definition: mainloop.c:633
token_bucket_rw_t
Definition: token_bucket.h:59
connection_is_reading
int connection_is_reading(connection_t *conn)
Definition: mainloop.c:510
periodic_event_item_t
Definition: periodic.h:63
get_uptime
long get_uptime(void)
Definition: mainloop.c:2527
get_main_loop_success_count
uint64_t get_main_loop_success_count(void)
Definition: mainloop.c:536
add_connection_to_closeable_list
void add_connection_to_closeable_list(connection_t *conn)
Definition: mainloop.c:426
mainloop_schedule_postloop_cleanup
void mainloop_schedule_postloop_cleanup(void)
Definition: mainloop.c:1634
do_main_loop
int do_main_loop(void)
Definition: mainloop.c:2345
connection_add_impl
int connection_add_impl(connection_t *conn, int is_connecting)
Definition: mainloop.c:246
reset_main_loop_counters
void reset_main_loop_counters(void)
Definition: mainloop.c:520
note_that_we_completed_a_circuit
void note_that_we_completed_a_circuit(void)
Definition: mainloop.c:228
ip_address_changed
void ip_address_changed(int on_client_conn)
Definition: mainloop.c:2288
tor_event_loop_shutdown_is_pending
int tor_event_loop_shutdown_is_pending(void)
Definition: mainloop.c:794
connection_start_writing
void connection_start_writing(connection_t *conn)
Definition: mainloop.c:689
rescan_periodic_events
void rescan_periodic_events(const or_options_t *options)
Definition: mainloop.c:1586
get_main_loop_idle_count
uint64_t get_main_loop_idle_count(void)
Definition: mainloop.c:564
update_current_time
void update_current_time(time_t now)
Definition: mainloop.c:2196
MOCK_DECL
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127
stats_increment_bytes_read_and_written
void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w)
Definition: mainloop.c:485
connection_watch_events
void connection_watch_events(connection_t *conn, watchable_events_t events)
Definition: mainloop.c:495
connection_t
Definition: connection_st.h:45
mainloop_schedule_shutdown
void mainloop_schedule_shutdown(int delay_sec)
Definition: mainloop.c:1659
get_my_roles
STATIC int get_my_roles(const or_options_t *options)
Definition: mainloop.c:1462
tor_init_connection_lists
void tor_init_connection_lists(void)
Definition: mainloop.c:414
connection_array
STATIC smartlist_t * connection_array
Definition: mainloop.c:166
watchable_events_t
watchable_events_t
Definition: mainloop.h:35
have_completed_a_circuit
int have_completed_a_circuit(void)
Definition: mainloop.c:220
connection_in_array
int connection_in_array(connection_t *conn)
Definition: mainloop.c:444
run_main_loop_until_done
STATIC int run_main_loop_until_done(void)
Definition: mainloop.c:2508
connection_stop_reading_from_linked_conn
void connection_stop_reading_from_linked_conn(connection_t *conn)
Definition: mainloop.c:821
check_network_participation_callback
STATIC int check_network_participation_callback(time_t now, const or_options_t *options)
Definition: mainloop.c:1819
schedule_rescan_periodic_events
void schedule_rescan_periodic_events(void)
Definition: mainloop.c:1574
do_signewnym
void do_signewnym(time_t)
Definition: mainloop.c:1318
get_connection_array
smartlist_t * get_connection_array(void)
Definition: mainloop.c:453
reset_uptime
void reset_uptime(void)
Definition: mainloop.c:2534
directory_info_has_arrived
void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs)
Definition: mainloop.c:1117
connection_is_on_closeable_list
int connection_is_on_closeable_list(connection_t *conn)
Definition: mainloop.c:437
reschedule_or_state_save
void reschedule_or_state_save(void)
Definition: mainloop.c:1904
connection_count_moribund
int connection_count_moribund(void)
Definition: mainloop.c:855
reschedule_directory_downloads
void reschedule_directory_downloads(void)
Definition: mainloop.c:1606
or_options_t
Definition: or_options_st.h:64
STATIC
#define STATIC
Definition: testsupport.h:32
directory_all_unreachable
void directory_all_unreachable(time_t now)
Definition: mainloop.c:1099
WRITE_EVENT
@ WRITE_EVENT
Definition: mainloop.h:38
get_bytes_written
uint64_t get_bytes_written(void)
Definition: mainloop.c:475
smartlist_t
Definition: smartlist_core.h:26
get_main_loop_error_count
uint64_t get_main_loop_error_count(void)
Definition: mainloop.c:550
connection_is_writing
int connection_is_writing(connection_t *conn)
Definition: mainloop.c:656