tor  master
Macros | Typedefs | Enumerations | Functions | Variables
main.h File Reference

Header file for main.c. More...

This graph shows which files directly or indirectly include this file:

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)
 

Typedefs

typedef enum watchable_events watchable_events_t
 

Enumerations

enum  watchable_events { 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)
 
 MOCK_DECL (smartlist_t *, get_connection_array,(void))
 
 MOCK_DECL (uint64_t, get_bytes_read,(void))
 
 MOCK_DECL (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)
 
 MOCK_DECL (void, connection_stop_reading,(connection_t *conn))
 
 MOCK_DECL (void, connection_start_reading,(connection_t *conn))
 
int connection_is_writing (connection_t *conn)
 
 MOCK_DECL (void, connection_stop_writing,(connection_t *conn))
 
 MOCK_DECL (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)
 
 MOCK_DECL (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 at_interface)
 
void dns_servers_relaunch_checks (void)
 
void reset_all_main_loop_timers (void)
 
void reschedule_descriptor_update_check (void)
 
void reschedule_directory_downloads (void)
 
void reschedule_or_state_save (void)
 
void reschedule_dirvote (const or_options_t *options)
 
void mainloop_schedule_postloop_cleanup (void)
 
void rescan_periodic_events (const or_options_t *options)
 
void update_current_time (time_t now)
 
 MOCK_DECL (long, get_uptime,(void))
 
 MOCK_DECL (void, reset_uptime,(void))
 
unsigned get_signewnym_epoch (void)
 
void handle_signals (void)
 
void activate_signal (int signal_num)
 
int try_locking (const or_options_t *options, int err_if_locked)
 
int have_lockfile (void)
 
void release_lockfile (void)
 
void tor_remove_file (const char *filename)
 
void tor_cleanup (void)
 
void tor_free_all (int postfork)
 
int do_main_loop (void)
 
int tor_init (int argc, char **argv)
 
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 reschedule_per_second_timer (void)
 

Variables

time_t time_of_process_start
 
int quiet_level
 
token_bucket_rw_t global_bucket
 
token_bucket_rw_t global_relayed_bucket
 

Detailed Description

Header file for main.c.

Typedef Documentation

◆ watchable_events_t

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

Enumeration Type Documentation

◆ watchable_events

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

Function Documentation

◆ add_connection_to_closeable_list()

void add_connection_to_closeable_list ( connection_t conn)

Schedule conn to be closed.

Here is the call graph for this function:

◆ 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.

◆ connection_in_array()

int connection_in_array ( connection_t conn)

Return true iff conn is in the current poll array.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_is_reading()

int connection_is_reading ( connection_t conn)

Return true iff conn is listening for read events.

◆ connection_is_writing()

int connection_is_writing ( connection_t conn)

Return true iff conn is listening for write events.

◆ 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.

◆ 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.

Here is the call graph for this function:

◆ connection_unregister_events()

void connection_unregister_events ( connection_t conn)

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

◆ 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)

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ do_main_loop()

int do_main_loop ( void  )

Tor main loop.

Here is the call graph for this function:

◆ get_main_loop_error_count()

uint64_t get_main_loop_error_count ( void  )

Get the main loop error counter.

◆ get_main_loop_idle_count()

uint64_t get_main_loop_idle_count ( void  )

Get the main loop idle counter.

◆ get_main_loop_success_count()

uint64_t get_main_loop_success_count ( void  )

Get the main loop success counter.

◆ get_signewnym_epoch()

unsigned get_signewnym_epoch ( void  )

Return the number of times that signewnym has been called.

◆ handle_signals()

void handle_signals ( void  )

Set up the signal handler events for this process, and register them with libevent if appropriate.

◆ 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.

Here is the caller graph for this function:

◆ have_lockfile()

int have_lockfile ( void  )

Return true iff we've successfully acquired the lock file.

◆ ip_address_changed()

void ip_address_changed ( int  at_interface)

Called when our IP address seems to have changed. at_interface should be true if we detected a change in our interface, and false if we detected a change in our published address.

◆ mainloop_schedule_postloop_cleanup()

void mainloop_schedule_postloop_cleanup ( void  )

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

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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.

◆ 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.

Here is the caller graph for this function:

◆ release_lockfile()

void release_lockfile ( void  )

If we have successfully acquired the lock file, release it.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ reschedule_descriptor_update_check()

void reschedule_descriptor_update_check ( void  )

Update our schedule so that we'll check whether we need to update our descriptor immediately, rather than after up to CHECK_DESCRIPTOR_INTERVAL seconds.

Here is the call graph for this function:

◆ reschedule_directory_downloads()

void reschedule_directory_downloads ( void  )

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

Here is the call graph for this function:

◆ reschedule_dirvote()

void reschedule_dirvote ( const or_options_t options)

Reschedule the directory-authority voting event. Run this whenever the schedule has changed.

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_per_second_timer()

void reschedule_per_second_timer ( void  )

Enable or disable the per-second timer as appropriate, creating it if necessary.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ reset_main_loop_counters()

void reset_main_loop_counters ( void  )

Reset our main loop counters.

◆ 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.

◆ tor_cleanup()

void tor_cleanup ( void  )

Do whatever cleanup is necessary before shutting Tor down.

Here is the call graph for this function:

◆ 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.

◆ tor_free_all()

void tor_free_all ( int  postfork)

Free all memory that we might have allocated somewhere. If postfork, we are a worker process and we want to free only the parts of memory that we won't touch. If !postfork, Tor is shutting down and we should free everything.

Helps us find the real leaks with dmalloc and the like. Also valgrind should then report 0 reachable in its leak report (in an ideal world – in practice libevent, SSL, libc etc never quite free everything).

◆ tor_remove_file()

void tor_remove_file ( const char *  filename)

Remove the specified file, and log a warning if the operation fails for any reason other than the file not existing. Ignores NULL filenames.

Here is the caller graph for this function:

◆ 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.

◆ try_locking()

int try_locking ( const or_options_t options,
int  err_if_locked 
)

Try to grab the lock file described in options, if we do not already have it. If err_if_locked is true, warn if somebody else is holding the lock, and exit if we can't get it after waiting. Otherwise, return -1 if we can't get the lockfile. Return 0 on success.

◆ 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 do we tolerate?

How much idleness do we tolerate?

Variable Documentation

◆ quiet_level

int quiet_level

Decides our behavior when no logs are configured/before any logs have been configured. For 0, we log notice to stdout as normal. For 1, we log warnings only. For 2, we log nothing.

◆ time_of_process_start

time_t time_of_process_start

What time did this process start up?