tor  master
main.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-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_MAIN_H
13 #define TOR_MAIN_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 
28 MOCK_DECL(smartlist_t *, get_connection_array, (void));
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 
35 typedef enum watchable_events {
36  /* Yes, it is intentional that these match Libevent's EV_READ and EV_WRITE */
37  READ_EVENT=0x02,
42 MOCK_DECL(void,connection_stop_reading,(connection_t *conn));
43 MOCK_DECL(void,connection_start_reading,(connection_t *conn));
44 
46 MOCK_DECL(void,connection_stop_writing,(connection_t *conn));
47 MOCK_DECL(void,connection_start_writing,(connection_t *conn));
48 
49 void tor_shutdown_event_loop_and_exit(int exitcode);
51 
53 
54 MOCK_DECL(int, connection_count_moribund, (void));
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 at_interface);
64 void reschedule_or_state_save(void);
65 void reschedule_dirvote(const or_options_t *options);
67 void rescan_periodic_events(const or_options_t *options);
68 
69 void update_current_time(time_t now);
70 
71 MOCK_DECL(long,get_uptime,(void));
72 MOCK_DECL(void,reset_uptime,(void));
73 
74 unsigned get_signewnym_epoch(void);
75 
76 void handle_signals(void);
77 void activate_signal(int signal_num);
78 
79 int try_locking(const or_options_t *options, int err_if_locked);
80 int have_lockfile(void);
81 void release_lockfile(void);
82 
83 void tor_remove_file(const char *filename);
84 
85 void tor_cleanup(void);
86 void tor_free_all(int postfork);
87 
88 int do_main_loop(void);
89 int tor_init(int argc, char **argv);
90 
91 void reset_main_loop_counters(void);
92 uint64_t get_main_loop_success_count(void);
93 uint64_t get_main_loop_error_count(void);
94 uint64_t get_main_loop_idle_count(void);
95 
96 void periodic_events_on_new_options(const or_options_t *options);
98 
99 extern time_t time_of_process_start;
100 extern int quiet_level;
101 extern token_bucket_rw_t global_bucket;
102 extern token_bucket_rw_t global_relayed_bucket;
103 
104 #ifdef MAIN_PRIVATE
105 STATIC void init_connection_lists(void);
106 STATIC void initialize_mainloop_events(void);
107 STATIC void close_closeable_connections(void);
108 STATIC void initialize_periodic_events(void);
109 STATIC void teardown_periodic_events(void);
110 STATIC int get_my_roles(const or_options_t *options);
111 #ifdef TOR_UNIT_TESTS
113 
114 /* We need the periodic_event_item_t definition. */
115 #include "periodic.h"
116 extern periodic_event_item_t periodic_events[];
117 #endif
118 #endif /* defined(MAIN_PRIVATE) */
119 
120 #endif /* !defined(TOR_MAIN_H) */
121 
void directory_all_unreachable(time_t now)
Definition: main.c:1112
void note_that_we_maybe_cant_complete_circuits(void)
Definition: main.c:264
STATIC void init_connection_lists(void)
Definition: main.c:431
Definition: or.h:3657
Definition: main.h:37
int connection_is_reading(connection_t *conn)
Definition: main.c:527
int tor_event_loop_shutdown_is_pending(void)
Definition: main.c:807
int connection_add_impl(connection_t *conn, int is_connecting)
Definition: main.c:274
void connection_unregister_events(connection_t *conn)
Definition: main.c:305
uint64_t get_main_loop_idle_count(void)
Definition: main.c:581
void note_that_we_completed_a_circuit(void)
Definition: main.c:256
watchable_events
Definition: main.h:35
int connection_in_array(connection_t *conn)
Definition: main.c:461
void reschedule_or_state_save(void)
Definition: main.c:2059
void reschedule_directory_downloads(void)
Definition: main.c:1645
Definition: token_bucket.h:59
void dns_servers_relaunch_checks(void)
Definition: main.c:2672
int connection_remove(connection_t *conn)
Definition: main.c:327
void ip_address_changed(int at_interface)
Definition: main.c:2638
void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w)
Definition: main.c:502
void mainloop_schedule_postloop_cleanup(void)
Definition: main.c:1673
MOCK_DECL(int, router_have_minimum_dir_info,(void))
STATIC void close_closeable_connections(void)
Definition: main.c:852
void tor_cleanup(void)
Definition: main.c:3754
void release_lockfile(void)
Definition: main.c:3621
Definition: container.h:18
STATIC smartlist_t * connection_array
Definition: main.c:194
void tor_free_all(int postfork)
Definition: main.c:3638
STATIC int get_my_roles(const or_options_t *options)
Definition: main.c:1490
STATIC void initialize_periodic_events(void)
Definition: main.c:1538
Definition: main.h:38
void connection_stop_reading_from_linked_conn(connection_t *conn)
Definition: main.c:834
Definition: or.h:1326
int have_completed_a_circuit(void)
Definition: main.c:248
int have_lockfile(void)
Definition: main.c:3614
void add_connection_to_closeable_list(connection_t *conn)
Definition: main.c:443
void tor_remove_file(const char *filename)
Definition: main.c:3744
void reschedule_descriptor_update_check(void)
Definition: main.c:1633
void rescan_periodic_events(const or_options_t *options)
Definition: main.c:1579
void update_current_time(time_t now)
Definition: main.c:2540
void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs)
Definition: main.c:1130
int connection_is_on_closeable_list(connection_t *conn)
Definition: main.c:454
void reset_main_loop_counters(void)
Definition: main.c:537
int quiet_level
Definition: main.c:233
STATIC void initialize_mainloop_events(void)
Definition: main.c:2778
int connection_is_writing(connection_t *conn)
Definition: main.c:673
int tor_init(int argc, char *argv[])
Definition: main.c:3423
void reschedule_per_second_timer(void)
Definition: main.c:2505
void reschedule_dirvote(const or_options_t *options)
Definition: main.c:2011
void tor_shutdown_event_loop_and_exit(int exitcode)
Definition: main.c:783
void connection_watch_events(connection_t *conn, watchable_events_t events)
Definition: main.c:512
Definition: periodic.h:53
int do_main_loop(void)
Definition: main.c:2792
uint64_t get_main_loop_success_count(void)
Definition: main.c:553
void handle_signals(void)
Definition: main.c:3376
time_t time_of_process_start
Definition: main.c:172
uint64_t get_main_loop_error_count(void)
Definition: main.c:567
void reset_all_main_loop_timers(void)
Definition: main.c:1465
unsigned get_signewnym_epoch(void)
Definition: main.c:1331
enum watchable_events watchable_events_t
int try_locking(const or_options_t *options, int err_if_locked)
Definition: main.c:3578