mainloop.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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-2019, The Tor Project, Inc. */
  5. /* See LICENSE for licensing information */
  6. /**
  7. * \file mainloop.h
  8. * \brief Header file for mainloop.c.
  9. **/
  10. #ifndef TOR_MAINLOOP_H
  11. #define TOR_MAINLOOP_H
  12. int have_completed_a_circuit(void);
  13. void note_that_we_completed_a_circuit(void);
  14. void note_that_we_maybe_cant_complete_circuits(void);
  15. int connection_add_impl(connection_t *conn, int is_connecting);
  16. #define connection_add(conn) connection_add_impl((conn), 0)
  17. #define connection_add_connecting(conn) connection_add_impl((conn), 1)
  18. int connection_remove(connection_t *conn);
  19. void connection_unregister_events(connection_t *conn);
  20. int connection_in_array(connection_t *conn);
  21. void add_connection_to_closeable_list(connection_t *conn);
  22. int connection_is_on_closeable_list(connection_t *conn);
  23. MOCK_DECL(smartlist_t *, get_connection_array, (void));
  24. MOCK_DECL(uint64_t,get_bytes_read,(void));
  25. MOCK_DECL(uint64_t,get_bytes_written,(void));
  26. void stats_increment_bytes_read_and_written(uint64_t r, uint64_t w);
  27. /** Bitmask for events that we can turn on and off with
  28. * connection_watch_events. */
  29. typedef enum watchable_events {
  30. /* Yes, it is intentional that these match Libevent's EV_READ and EV_WRITE */
  31. READ_EVENT=0x02, /**< We want to know when a connection is readable */
  32. WRITE_EVENT=0x04 /**< We want to know when a connection is writable */
  33. } watchable_events_t;
  34. void connection_watch_events(connection_t *conn, watchable_events_t events);
  35. int connection_is_reading(connection_t *conn);
  36. MOCK_DECL(void,connection_stop_reading,(connection_t *conn));
  37. MOCK_DECL(void,connection_start_reading,(connection_t *conn));
  38. int connection_is_writing(connection_t *conn);
  39. MOCK_DECL(void,connection_stop_writing,(connection_t *conn));
  40. MOCK_DECL(void,connection_start_writing,(connection_t *conn));
  41. void tor_shutdown_event_loop_and_exit(int exitcode);
  42. int tor_event_loop_shutdown_is_pending(void);
  43. void connection_stop_reading_from_linked_conn(connection_t *conn);
  44. MOCK_DECL(int, connection_count_moribund, (void));
  45. void directory_all_unreachable(time_t now);
  46. void directory_info_has_arrived(time_t now, int from_cache, int suppress_logs);
  47. void ip_address_changed(int at_interface);
  48. void dns_servers_relaunch_checks(void);
  49. void reset_all_main_loop_timers(void);
  50. void reschedule_descriptor_update_check(void);
  51. void reschedule_directory_downloads(void);
  52. void reschedule_or_state_save(void);
  53. void reschedule_dirvote(const or_options_t *options);
  54. void mainloop_schedule_postloop_cleanup(void);
  55. void rescan_periodic_events(const or_options_t *options);
  56. void update_current_time(time_t now);
  57. MOCK_DECL(long,get_uptime,(void));
  58. MOCK_DECL(void,reset_uptime,(void));
  59. unsigned get_signewnym_epoch(void);
  60. int do_main_loop(void);
  61. void reset_main_loop_counters(void);
  62. uint64_t get_main_loop_success_count(void);
  63. uint64_t get_main_loop_error_count(void);
  64. uint64_t get_main_loop_idle_count(void);
  65. void periodic_events_on_new_options(const or_options_t *options);
  66. void reschedule_per_second_timer(void);
  67. void do_signewnym(time_t);
  68. time_t get_last_signewnym_time(void);
  69. void tor_init_connection_lists(void);
  70. void initialize_mainloop_events(void);
  71. void tor_mainloop_free_all(void);
  72. struct token_bucket_rw_t;
  73. extern time_t time_of_process_start;
  74. extern int quiet_level;
  75. extern struct token_bucket_rw_t global_bucket;
  76. extern struct token_bucket_rw_t global_relayed_bucket;
  77. #ifdef MAINLOOP_PRIVATE
  78. STATIC void close_closeable_connections(void);
  79. STATIC void initialize_periodic_events(void);
  80. STATIC void teardown_periodic_events(void);
  81. STATIC int get_my_roles(const or_options_t *);
  82. #ifdef TOR_UNIT_TESTS
  83. extern smartlist_t *connection_array;
  84. /* We need the periodic_event_item_t definition. */
  85. #include "core/mainloop/periodic.h"
  86. extern periodic_event_item_t periodic_events[];
  87. #endif
  88. #endif /* defined(MAIN_PRIVATE) */
  89. #endif