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 */
9 * \brief Header file for main.c.
15 int have_completed_a_circuit(void);
16 void note_that_we_completed_a_circuit(void);
17 void note_that_we_maybe_cant_complete_circuits(void);
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)
22 int connection_remove(connection_t
*conn
);
23 void connection_unregister_events(connection_t
*conn
);
24 int connection_in_array(connection_t
*conn
);
25 void add_connection_to_closeable_list(connection_t
*conn
);
26 int connection_is_on_closeable_list(connection_t
*conn
);
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));
32 /** Bitmask for events that we can turn on and off with
33 * connection_watch_events. */
34 typedef enum watchable_events
{
35 /* Yes, it is intentional that these match Libevent's EV_READ and EV_WRITE */
36 READ_EVENT
=0x02, /**< We want to know when a connection is readable */
37 WRITE_EVENT
=0x04 /**< We want to know when a connection is writable */
39 void connection_watch_events(connection_t
*conn
, watchable_events_t events
);
40 int connection_is_reading(connection_t
*conn
);
41 MOCK_DECL(void,connection_stop_reading
,(connection_t
*conn
));
42 MOCK_DECL(void,connection_start_reading
,(connection_t
*conn
));
44 int connection_is_writing(connection_t
*conn
);
45 MOCK_DECL(void,connection_stop_writing
,(connection_t
*conn
));
46 MOCK_DECL(void,connection_start_writing
,(connection_t
*conn
));
48 void tell_event_loop_to_run_external_code(void);
49 void tor_shutdown_event_loop_and_exit(int exitcode
);
50 int tor_event_loop_shutdown_is_pending(void);
52 void connection_stop_reading_from_linked_conn(connection_t
*conn
);
54 MOCK_DECL(int, connection_count_moribund
, (void));
56 void directory_all_unreachable(time_t now
);
57 void directory_info_has_arrived(time_t now
, int from_cache
, int suppress_logs
);
59 void ip_address_changed(int at_interface
);
60 void dns_servers_relaunch_checks(void);
61 void reset_all_main_loop_timers(void);
62 void reschedule_descriptor_update_check(void);
63 void reschedule_directory_downloads(void);
65 MOCK_DECL(long,get_uptime
,(void));
67 unsigned get_signewnym_epoch(void);
69 void handle_signals(int is_parent
);
70 void activate_signal(int signal_num
);
72 int try_locking(const or_options_t
*options
, int err_if_locked
);
73 int have_lockfile(void);
74 void release_lockfile(void);
76 void tor_cleanup(void);
77 void tor_free_all(int postfork
);
79 int do_main_loop(void);
80 int tor_init(int argc
, char **argv
);
82 void reset_main_loop_counters(void);
83 uint64_t get_main_loop_success_count(void);
84 uint64_t get_main_loop_error_count(void);
85 uint64_t get_main_loop_idle_count(void);
87 extern time_t time_of_process_start
;
88 extern long stats_n_seconds_working
;
89 extern int quiet_level
;
90 extern int global_read_bucket
;
91 extern int global_write_bucket
;
92 extern int global_relayed_read_bucket
;
93 extern int global_relayed_write_bucket
;
96 STATIC
void init_connection_lists(void);
97 STATIC
void close_closeable_connections(void);
98 STATIC
void initialize_periodic_events(void);
99 STATIC
void teardown_periodic_events(void);
100 #ifdef TOR_UNIT_TESTS
101 extern smartlist_t
*connection_array
;
103 #endif /* defined(MAIN_PRIVATE) */
105 #endif /* !defined(TOR_MAIN_H) */