Tor  0.4.7.0-alpha-dev
Macros | Enumerations | Functions | Variables
mainloop.h File Reference

Header file for mainloop.c. More...

Go to the source code of this file.

Macros

#define connection_add(conn)   connection_add_impl((conn), 0)
 
#define connection_add_connecting(conn)   connection_add_impl((conn), 1)
 

Enumerations

enum  watchable_events_t { READ_EVENT =0x02 , WRITE_EVENT =0x04 }
 

Functions

int have_completed_a_circuit (void)
 
void note_that_we_completed_a_circuit (void)
 
void note_that_we_maybe_cant_complete_circuits (void)
 
int connection_add_impl (connection_t *conn, int is_connecting)
 
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)
 
smartlist_tget_connection_array (void)
 
uint64_t get_bytes_read (void)
 
uint64_t get_bytes_written (void)
 
void stats_increment_bytes_read_and_written (uint64_t r, uint64_t w)
 
void connection_watch_events (connection_t *conn, watchable_events_t events)
 
int connection_is_reading (connection_t *conn)
 
void connection_stop_reading (connection_t *conn)
 
void connection_start_reading (connection_t *conn)
 
int connection_is_writing (connection_t *conn)
 
void connection_stop_writing (connection_t *conn)
 
void connection_start_writing (connection_t *conn)
 
void tor_shutdown_event_loop_and_exit (int exitcode)
 
int tor_event_loop_shutdown_is_pending (void)
 
void connection_stop_reading_from_linked_conn (connection_t *conn)
 
int connection_count_moribund (void)
 
void directory_all_unreachable (time_t now)
 
void directory_info_has_arrived (time_t now, int from_cache, int suppress_logs)
 
void ip_address_changed (int on_client_conn)
 
void dns_servers_relaunch_checks (void)
 
void reset_all_main_loop_timers (void)
 
void reschedule_directory_downloads (void)
 
void reschedule_or_state_save (void)
 
void mainloop_schedule_postloop_cleanup (void)
 
void rescan_periodic_events (const or_options_t *options)
 
void schedule_rescan_periodic_events (void)
 
void update_current_time (time_t now)
 
long get_uptime (void)
 
void reset_uptime (void)
 
unsigned get_signewnym_epoch (void)
 
int do_main_loop (void)
 
void reset_main_loop_counters (void)
 
uint64_t get_main_loop_success_count (void)
 
uint64_t get_main_loop_error_count (void)
 
uint64_t get_main_loop_idle_count (void)
 
void periodic_events_on_new_options (const or_options_t *options)
 
void do_signewnym (time_t)
 
time_t get_last_signewnym_time (void)
 
void mainloop_schedule_shutdown (int delay_sec)
 
void tor_init_connection_lists (void)
 
void initialize_mainloop_events (void)
 
void initialize_periodic_events (void)
 
void tor_mainloop_free_all (void)
 

Variables

time_t time_of_process_start
 
struct token_bucket_rw_t global_bucket
 
struct token_bucket_rw_t global_relayed_bucket
 

Detailed Description

Header file for mainloop.c.

Definition in file mainloop.h.

Enumeration Type Documentation

◆ watchable_events_t

Bitmask for events that we can turn on and off with connection_watch_events.

Enumerator
READ_EVENT 

We want to know when a connection is readable

WRITE_EVENT 

We want to know when a connection is writable

Definition at line 35 of file mainloop.h.

Function Documentation

◆ add_connection_to_closeable_list()

void add_connection_to_closeable_list ( connection_t conn)

Schedule conn to be closed.

Definition at line 424 of file mainloop.c.

◆ connection_add_impl()

int connection_add_impl ( connection_t conn,
int  is_connecting 
)

Add conn to the array of connections that we can poll on. The connection's socket must be set; the connection starts out non-reading and non-writing.

Definition at line 244 of file mainloop.c.

◆ connection_count_moribund()

int connection_count_moribund ( void  )

Count moribund connections for the OOS handler

Definition at line 853 of file mainloop.c.

◆ connection_in_array()

int connection_in_array ( connection_t conn)

Return true iff conn is in the current poll array.

Definition at line 442 of file mainloop.c.

Referenced by connection_free_().

◆ connection_is_on_closeable_list()

int connection_is_on_closeable_list ( connection_t conn)

Return 1 if conn is on the closeable list, else return 0.

Definition at line 435 of file mainloop.c.

Referenced by connection_free_().

◆ connection_is_reading()

int connection_is_reading ( connection_t conn)

Return true iff conn is listening for read events.

Definition at line 508 of file mainloop.c.

Referenced by set_streams_blocked_on_circ().

◆ connection_is_writing()

int connection_is_writing ( connection_t conn)

Return true iff conn is listening for write events.

Definition at line 654 of file mainloop.c.

◆ connection_remove()

int connection_remove ( connection_t conn)

Remove the connection from the global list, and remove the corresponding poll entry. Calling this function will shift the last connection (if any) into the position occupied by conn.

Definition at line 297 of file mainloop.c.

Referenced by connection_unlink().

◆ connection_start_reading()

void connection_start_reading ( connection_t conn)

◆ connection_start_writing()

void connection_start_writing ( connection_t conn)

Tell the main loop to start notifying conn of any write events.

Definition at line 687 of file mainloop.c.

Referenced by connection_watch_events(), connection_write_to_buf_commit(), and reenable_blocked_connections_cb().

◆ connection_stop_reading()

void connection_stop_reading ( connection_t conn)

Tell the main loop to stop notifying conn of any read events.

Definition at line 609 of file mainloop.c.

Referenced by connection_read_bw_exhausted(), connection_watch_events(), and set_streams_blocked_on_circ().

◆ connection_stop_reading_from_linked_conn()

void connection_stop_reading_from_linked_conn ( connection_t conn)

Tell the main loop to stop reading bytes into conn from its linked connection, if is currently doing so. Called by connection_stop_reading, connection_stop_writing, and connection_read.

Definition at line 819 of file mainloop.c.

Referenced by connection_stop_reading(), and connection_stop_writing().

◆ connection_stop_writing()

void connection_stop_writing ( connection_t conn)

Tell the main loop to stop notifying conn of any write events.

Definition at line 664 of file mainloop.c.

Referenced by connection_finished_flushing(), connection_watch_events(), and connection_write_bw_exhausted().

◆ connection_unregister_events()

void connection_unregister_events ( connection_t conn)

Tell libevent that we don't care about conn any more.

Definition at line 275 of file mainloop.c.

◆ connection_watch_events()

void connection_watch_events ( connection_t conn,
watchable_events_t  events 
)

Set the event mask on conn to events. (The event mask is a bitmask whose bits are READ_EVENT and WRITE_EVENT)

Definition at line 493 of file mainloop.c.

◆ directory_all_unreachable()

void directory_all_unreachable ( time_t  now)

We've just tried every dirserver we know about, and none of them were reachable. Assume the network is down. Change state so next time an application connection arrives we'll delay it and try another directory fetch. Kill off all the circuit_wait streams that are waiting now, since they will all timeout anyway.

Definition at line 1097 of file mainloop.c.

◆ directory_info_has_arrived()

void directory_info_has_arrived ( time_t  now,
int  from_cache,
int  suppress_logs 
)

This function is called whenever we successfully pull down some new network statuses or server descriptors.

Definition at line 1115 of file mainloop.c.

◆ dns_servers_relaunch_checks()

void dns_servers_relaunch_checks ( void  )

Forget what we've learned about the correctness of our DNS servers, and start learning again.

Definition at line 2320 of file mainloop.c.

◆ do_main_loop()

int do_main_loop ( void  )

Tor main loop.

Definition at line 2346 of file mainloop.c.

◆ do_signewnym()

void do_signewnym ( time_t  now)

Either perform a signewnym or schedule one, depending on rate limiting.

Definition at line 1316 of file mainloop.c.

◆ get_bytes_read()

uint64_t get_bytes_read ( void  )

Return the amount of network traffic read, in bytes, over the life of this process.

Definition at line 463 of file mainloop.c.

Referenced by control_get_bytes_rw_last_sec(), and log_heartbeat().

◆ get_bytes_written()

uint64_t get_bytes_written ( void  )

Return the amount of network traffic read, in bytes, over the life of this process.

Definition at line 473 of file mainloop.c.

Referenced by control_get_bytes_rw_last_sec(), and log_heartbeat().

◆ get_connection_array()

smartlist_t* get_connection_array ( void  )

◆ get_main_loop_error_count()

uint64_t get_main_loop_error_count ( void  )

Get the main loop error counter.

Definition at line 548 of file mainloop.c.

◆ get_main_loop_idle_count()

uint64_t get_main_loop_idle_count ( void  )

Get the main loop idle counter.

Definition at line 562 of file mainloop.c.

◆ get_main_loop_success_count()

uint64_t get_main_loop_success_count ( void  )

Get the main loop success counter.

Definition at line 534 of file mainloop.c.

◆ get_signewnym_epoch()

unsigned get_signewnym_epoch ( void  )

Return the number of times that signewnym has been called.

Definition at line 1340 of file mainloop.c.

◆ get_uptime()

long get_uptime ( void  )

◆ have_completed_a_circuit()

int have_completed_a_circuit ( void  )

Return 1 if we have successfully built a circuit, and nothing has changed to make us think that maybe we can't.

Definition at line 218 of file mainloop.c.

Referenced by check_for_reachability_bw_callback(), directory_info_has_arrived(), and reachability_warnings_callback().

◆ initialize_mainloop_events()

void initialize_mainloop_events ( void  )

Initialize some mainloop_event_t objects that we require.

Definition at line 2332 of file mainloop.c.

Referenced by do_main_loop().

◆ initialize_periodic_events()

void initialize_periodic_events ( void  )

Set up all the members of mainloop_periodic_events[], and configure them all to be launched from a callback.

Definition at line 1519 of file mainloop.c.

◆ ip_address_changed()

void ip_address_changed ( int  on_client_conn)

Called when our IP address seems to have changed. on_client_conn should be true if:

  • we detected a change in our interface address, using an outbound connection, and therefore
  • our client TLS keys need to be rotated. Otherwise, it should be false, and:
  • we detected a change in our published address (using some other method), and therefore
  • the published addresses in our descriptor need to change.

Definition at line 2289 of file mainloop.c.

◆ mainloop_schedule_postloop_cleanup()

void mainloop_schedule_postloop_cleanup ( void  )

Schedule a post-loop event to clean up marked channels, connections, and circuits.

Definition at line 1631 of file mainloop.c.

Referenced by add_connection_to_closeable_list().

◆ mainloop_schedule_shutdown()

void mainloop_schedule_shutdown ( int  delay_sec)

Schedule the mainloop to exit after delay_sec seconds.

Definition at line 1656 of file mainloop.c.

◆ note_that_we_completed_a_circuit()

void note_that_we_completed_a_circuit ( void  )

Note that we have successfully built a circuit, so that reachability testing and introduction points and so on may be attempted.

Definition at line 226 of file mainloop.c.

◆ note_that_we_maybe_cant_complete_circuits()

void note_that_we_maybe_cant_complete_circuits ( void  )

Note that something has happened (like a clock jump, or DisableNetwork) to make us think that maybe we can't complete circuits.

Definition at line 234 of file mainloop.c.

Referenced by circuit_note_clock_jumped().

◆ rescan_periodic_events()

void rescan_periodic_events ( const or_options_t options)

Do a pass at all our periodic events, disable those we don't need anymore and enable those we need now using the given options.

Definition at line 1583 of file mainloop.c.

Referenced by hs_service_map_has_changed(), on_hibernate_state_change(), and rescan_periodic_events_cb().

◆ reschedule_directory_downloads()

void reschedule_directory_downloads ( void  )

Update our schedule so that we'll check whether we need to fetch directory info immediately.

Definition at line 1603 of file mainloop.c.

◆ reschedule_or_state_save()

void reschedule_or_state_save ( void  )

Reschedule the event for saving the state file.

Run this when the state becomes dirty.

Definition at line 1907 of file mainloop.c.

Referenced by or_state_mark_dirty().

◆ reset_all_main_loop_timers()

void reset_all_main_loop_timers ( void  )

Reset all the periodic events so we'll do all our actions again as if we just started up. Useful if our clock just moved back a long time from the future, so we don't wait until that future arrives again before acting.

Definition at line 1452 of file mainloop.c.

Referenced by circuit_note_clock_jumped().

◆ reset_main_loop_counters()

void reset_main_loop_counters ( void  )

Reset our main loop counters.

Definition at line 518 of file mainloop.c.

◆ reset_uptime()

void reset_uptime ( void  )

Reset Tor's uptime.

Definition at line 2535 of file mainloop.c.

Referenced by directory_all_unreachable().

◆ schedule_rescan_periodic_events()

void schedule_rescan_periodic_events ( void  )

Schedule an event that will rescan which periodic events should run.

Definition at line 1571 of file mainloop.c.

◆ stats_increment_bytes_read_and_written()

void stats_increment_bytes_read_and_written ( uint64_t  r,
uint64_t  w 
)

Increment the amount of network traffic read and written, over the life of this process.

Definition at line 483 of file mainloop.c.

Referenced by record_num_bytes_transferred_impl().

◆ tor_event_loop_shutdown_is_pending()

int tor_event_loop_shutdown_is_pending ( void  )

Return true iff tor_shutdown_event_loop_and_exit() has been called.

Definition at line 792 of file mainloop.c.

Referenced by set_options().

◆ tor_init_connection_lists()

void tor_init_connection_lists ( void  )

Initialize the global connection list, closeable connection list, and active connection list.

Definition at line 412 of file mainloop.c.

Referenced by tor_init().

◆ tor_shutdown_event_loop_and_exit()

void tor_shutdown_event_loop_and_exit ( int  exitcode)

After finishing the current callback (if any), shut down the main loop, clean up the process, and exit with exitcode.

Definition at line 764 of file mainloop.c.

◆ update_current_time()

void update_current_time ( time_t  now)

Set the current time to "now", which should be the value returned by time(). Check for clock jumps and track the total number of seconds we have been running.

How much clock jumping means that we should adjust our idea of when to go dormant?

How much clock jumping do we tolerate?

How much idleness do we tolerate?

Definition at line 2197 of file mainloop.c.

Referenced by periodic_event_dispatch(), and signal_callback().

Variable Documentation

◆ time_of_process_start

time_t time_of_process_start
extern

What time did this process start up?

Definition at line 142 of file mainloop.c.

Referenced by tor_init().