2010-07-23 19:58:06 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 16:13:17 -04:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2010-07-23 19:58:06 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file main.h
|
|
|
|
* \brief Header file for main.c.
|
|
|
|
**/
|
|
|
|
|
2012-10-12 12:13:10 -04:00
|
|
|
#ifndef TOR_MAIN_H
|
|
|
|
#define TOR_MAIN_H
|
2010-07-23 19:58:06 +02:00
|
|
|
|
2014-11-20 12:03:46 -05:00
|
|
|
int have_completed_a_circuit(void);
|
|
|
|
void note_that_we_completed_a_circuit(void);
|
|
|
|
void note_that_we_maybe_cant_complete_circuits(void);
|
2010-07-23 19:58:06 +02:00
|
|
|
|
2009-08-11 15:03:43 -04:00
|
|
|
int connection_add_impl(connection_t *conn, int is_connecting);
|
|
|
|
#define connection_add(conn) connection_add_impl((conn), 0)
|
|
|
|
#define connection_add_connecting(conn) connection_add_impl((conn), 1)
|
2010-07-23 19:58:06 +02:00
|
|
|
int connection_remove(connection_t *conn);
|
|
|
|
void connection_unregister_events(connection_t *conn);
|
|
|
|
int connection_in_array(connection_t *conn);
|
|
|
|
void add_connection_to_closeable_list(connection_t *conn);
|
|
|
|
int connection_is_on_closeable_list(connection_t *conn);
|
|
|
|
|
2016-07-02 08:02:47 +00:00
|
|
|
MOCK_DECL(smartlist_t *, get_connection_array, (void));
|
2014-04-15 22:20:34 +10:00
|
|
|
MOCK_DECL(uint64_t,get_bytes_read,(void));
|
|
|
|
MOCK_DECL(uint64_t,get_bytes_written,(void));
|
2010-07-23 19:58:06 +02:00
|
|
|
|
2011-03-16 17:05:37 -04:00
|
|
|
/** Bitmask for events that we can turn on and off with
|
|
|
|
* connection_watch_events. */
|
2010-07-23 19:58:06 +02:00
|
|
|
typedef enum watchable_events {
|
2009-07-31 11:11:45 -04:00
|
|
|
/* Yes, it is intentional that these match Libevent's EV_READ and EV_WRITE */
|
2011-03-16 17:05:37 -04:00
|
|
|
READ_EVENT=0x02, /**< We want to know when a connection is readable */
|
|
|
|
WRITE_EVENT=0x04 /**< We want to know when a connection is writable */
|
2010-07-23 19:58:06 +02:00
|
|
|
} watchable_events_t;
|
|
|
|
void connection_watch_events(connection_t *conn, watchable_events_t events);
|
|
|
|
int connection_is_reading(connection_t *conn);
|
2013-08-01 17:29:10 -04:00
|
|
|
MOCK_DECL(void,connection_stop_reading,(connection_t *conn));
|
|
|
|
MOCK_DECL(void,connection_start_reading,(connection_t *conn));
|
2010-07-23 19:58:06 +02:00
|
|
|
|
|
|
|
int connection_is_writing(connection_t *conn);
|
2013-08-01 17:29:10 -04:00
|
|
|
MOCK_DECL(void,connection_stop_writing,(connection_t *conn));
|
|
|
|
MOCK_DECL(void,connection_start_writing,(connection_t *conn));
|
2010-07-23 19:58:06 +02:00
|
|
|
|
2017-10-20 09:59:48 -04:00
|
|
|
void tell_event_loop_to_run_external_code(void);
|
2017-10-20 10:16:00 -04:00
|
|
|
void tor_shutdown_event_loop_and_exit(int exitcode);
|
|
|
|
int tor_event_loop_shutdown_is_pending(void);
|
2016-10-31 00:20:22 -04:00
|
|
|
|
2010-07-23 19:58:06 +02:00
|
|
|
void connection_stop_reading_from_linked_conn(connection_t *conn);
|
|
|
|
|
2016-07-02 04:39:45 +00:00
|
|
|
MOCK_DECL(int, connection_count_moribund, (void));
|
2016-06-30 13:27:35 +00:00
|
|
|
|
2010-07-23 19:58:06 +02:00
|
|
|
void directory_all_unreachable(time_t now);
|
2016-02-22 02:54:32 -05:00
|
|
|
void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs);
|
2010-07-23 19:58:06 +02:00
|
|
|
|
|
|
|
void ip_address_changed(int at_interface);
|
|
|
|
void dns_servers_relaunch_checks(void);
|
2015-02-09 01:05:31 -05:00
|
|
|
void reset_all_main_loop_timers(void);
|
2014-04-01 17:30:20 -04:00
|
|
|
void reschedule_descriptor_update_check(void);
|
2015-08-13 09:41:43 -04:00
|
|
|
void reschedule_directory_downloads(void);
|
2010-07-23 19:58:06 +02:00
|
|
|
|
2014-04-15 22:20:34 +10:00
|
|
|
MOCK_DECL(long,get_uptime,(void));
|
|
|
|
|
2011-07-06 16:39:54 -04:00
|
|
|
unsigned get_signewnym_epoch(void);
|
2010-12-01 03:32:42 +02:00
|
|
|
|
2010-07-23 19:58:06 +02:00
|
|
|
void handle_signals(int is_parent);
|
2015-08-12 11:25:00 -04:00
|
|
|
void activate_signal(int signal_num);
|
2010-07-23 19:58:06 +02:00
|
|
|
|
2011-06-14 13:01:38 -04:00
|
|
|
int try_locking(const or_options_t *options, int err_if_locked);
|
2010-07-23 19:58:06 +02:00
|
|
|
int have_lockfile(void);
|
|
|
|
void release_lockfile(void);
|
|
|
|
|
|
|
|
void tor_cleanup(void);
|
|
|
|
void tor_free_all(int postfork);
|
|
|
|
|
|
|
|
int do_main_loop(void);
|
|
|
|
int tor_init(int argc, char **argv);
|
|
|
|
|
2016-06-02 09:46:12 -04:00
|
|
|
extern time_t time_of_process_start;
|
|
|
|
extern long stats_n_seconds_working;
|
|
|
|
extern int quiet_level;
|
|
|
|
extern int global_read_bucket;
|
|
|
|
extern int global_write_bucket;
|
|
|
|
extern int global_relayed_read_bucket;
|
|
|
|
extern int global_relayed_write_bucket;
|
|
|
|
|
2013-08-01 13:15:58 -04:00
|
|
|
#ifdef MAIN_PRIVATE
|
|
|
|
STATIC void init_connection_lists(void);
|
|
|
|
STATIC void close_closeable_connections(void);
|
2015-11-17 09:26:50 -05:00
|
|
|
STATIC void initialize_periodic_events(void);
|
|
|
|
STATIC void teardown_periodic_events(void);
|
2017-05-08 15:38:05 -04:00
|
|
|
#ifdef TOR_UNIT_TESTS
|
|
|
|
extern smartlist_t *connection_array;
|
|
|
|
#endif
|
2017-09-15 16:24:44 -04:00
|
|
|
#endif /* defined(MAIN_PRIVATE) */
|
2013-08-01 13:15:58 -04:00
|
|
|
|
2017-09-15 16:24:44 -04:00
|
|
|
#endif /* !defined(TOR_MAIN_H) */
|
2010-07-23 19:58:06 +02:00
|
|
|
|