tor
master
|
Header file for main.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) |
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 |
Header file for main.c.
typedef enum watchable_events watchable_events_t |
Bitmask for events that we can turn on and off with connection_watch_events.
enum watchable_events |
void add_connection_to_closeable_list | ( | connection_t * | conn | ) |
Schedule conn to be closed.
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.
int connection_in_array | ( | connection_t * | conn | ) |
Return true iff conn is in the current poll array.
int connection_is_on_closeable_list | ( | connection_t * | conn | ) |
Return 1 if conn is on the closeable list, else return 0.
int connection_is_reading | ( | connection_t * | conn | ) |
Return true iff conn is listening for read events.
int connection_is_writing | ( | connection_t * | conn | ) |
Return true iff conn is listening for write events.
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.
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.
void connection_unregister_events | ( | connection_t * | conn | ) |
Tell libevent that we don't care about conn any more.
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)
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.
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.
void dns_servers_relaunch_checks | ( | void | ) |
Forget what we've learned about the correctness of our DNS servers, and start learning again.
int do_main_loop | ( | void | ) |
Tor main loop.
uint64_t get_main_loop_error_count | ( | void | ) |
Get the main loop error counter.
uint64_t get_main_loop_idle_count | ( | void | ) |
Get the main loop idle counter.
uint64_t get_main_loop_success_count | ( | void | ) |
Get the main loop success counter.
unsigned get_signewnym_epoch | ( | void | ) |
Return the number of times that signewnym has been called.
void handle_signals | ( | void | ) |
Set up the signal handler events for this process, and register them with libevent if appropriate.
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.
int have_lockfile | ( | void | ) |
Return true iff we've successfully acquired the lock file.
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.
void mainloop_schedule_postloop_cleanup | ( | void | ) |
Schedule a post-loop event to clean up marked channels, connections, and circuits.
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.
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.
void release_lockfile | ( | void | ) |
If we have successfully acquired the lock file, release it.
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.
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.
void reschedule_directory_downloads | ( | void | ) |
Update our schedule so that we'll check whether we need to fetch directory info immediately.
void reschedule_dirvote | ( | const or_options_t * | options | ) |
Reschedule the directory-authority voting event. Run this whenever the schedule has changed.
void reschedule_or_state_save | ( | void | ) |
Reschedule the event for saving the state file.
Run this when the state becomes dirty.
void reschedule_per_second_timer | ( | void | ) |
Enable or disable the per-second timer as appropriate, creating it if necessary.
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.
void reset_main_loop_counters | ( | void | ) |
Reset our main loop counters.
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.
void tor_cleanup | ( | void | ) |
Do whatever cleanup is necessary before shutting Tor down.
int tor_event_loop_shutdown_is_pending | ( | void | ) |
Return true iff tor_shutdown_event_loop_and_exit() has been called.
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).
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.
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.
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.
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?
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_t time_of_process_start |
What time did this process start up?