tor  0.4.0.0-alpha-dev
Functions
hibernate.h File Reference
#include "lib/testsupport/testsupport.h"

Go to the source code of this file.

Functions

int accounting_parse_options (const or_options_t *options, int validate_only)
 
 MOCK_DECL (int, accounting_is_enabled,(const or_options_t *options))
 
int accounting_get_interval_length (void)
 
 MOCK_DECL (time_t, accounting_get_end_time,(void))
 
void configure_accounting (time_t now)
 
uint64_t get_accounting_bytes (void)
 
void accounting_run_housekeeping (time_t now)
 
void accounting_add_bytes (size_t n_read, size_t n_written, int seconds)
 
int accounting_record_bandwidth_usage (time_t now, or_state_t *state)
 
void hibernate_begin_shutdown (void)
 
 MOCK_DECL (int, we_are_hibernating,(void))
 
 MOCK_DECL (int, we_are_fully_hibernating,(void))
 
void consider_hibernation (time_t now)
 
int getinfo_helper_accounting (control_connection_t *conn, const char *question, char **answer, const char **errmsg)
 
uint64_t get_accounting_max_total (void)
 
void accounting_free_all (void)
 

Detailed Description

Header file for hibernate.c.

Definition in file hibernate.h.

Function Documentation

◆ accounting_add_bytes()

void accounting_add_bytes ( size_t  n_read,
size_t  n_written,
int  seconds 
)

Called from connection.c to tell us that seconds seconds have passed, n_read bytes have been read, and n_written bytes have been written.

Definition at line 331 of file hibernate.c.

References n_bytes_read_in_interval, n_bytes_written_in_interval, and n_seconds_active_in_interval.

Referenced by record_num_bytes_transferred_impl().

◆ accounting_free_all()

void accounting_free_all ( void  )

Free all resources held by the accounting module

Definition at line 1254 of file hibernate.c.

◆ accounting_get_interval_length()

int accounting_get_interval_length ( void  )

If accounting is enabled, return how long (in seconds) this interval lasts.

Definition at line 315 of file hibernate.c.

References interval_end_time, and interval_start_time.

Referenced by router_should_be_dirserver().

◆ accounting_parse_options()

int accounting_parse_options ( const or_options_t options,
int  validate_only 
)

Configure accounting start/end time settings based on options->AccountingStart. Return 0 on success, -1 on failure. If validate_only is true, do not change the current settings.

Definition at line 190 of file hibernate.c.

References or_options_t::AccountingStart, and cfg_unit.

◆ accounting_record_bandwidth_usage()

int accounting_record_bandwidth_usage ( time_t  now,
or_state_t state 
)

Save all our bandwidth tracking information to disk. Return 0 on success, -1 on failure.

Definition at line 705 of file hibernate.c.

References or_state_t::AccountingIntervalStart, and interval_start_time.

Referenced by accounting_run_housekeeping(), and tor_cleanup().

◆ accounting_run_housekeeping()

void accounting_run_housekeeping ( time_t  now)

Invoked once per second. Checks whether it is time to hibernate, record bandwidth used, etc.

Definition at line 585 of file hibernate.c.

References accounting_record_bandwidth_usage(), configure_accounting(), interval_end_time, and time_to_record_bandwidth_usage().

Referenced by second_elapsed_callback(), and wakeup_event_callback().

◆ configure_accounting()

void configure_accounting ( time_t  now)

Initialize the accounting subsystem.

Definition at line 430 of file hibernate.c.

References interval_start_time, read_bandwidth_usage(), and start_of_accounting_period_containing().

Referenced by accounting_run_housekeeping().

◆ consider_hibernation()

void consider_hibernation ( time_t  now)

Consider our environment and decide if it's time to start/stop hibernating.

Definition at line 1098 of file hibernate.c.

Referenced by second_elapsed_callback(), and wakeup_event_callback().

◆ get_accounting_bytes()

uint64_t get_accounting_bytes ( void  )

Return the relevant number of bytes sent/received this interval based on the set AccountingRule

Definition at line 478 of file hibernate.c.

References MAX, n_bytes_read_in_interval, and n_bytes_written_in_interval.

Referenced by hibernate_hard_limit_reached().

◆ getinfo_helper_accounting()

int getinfo_helper_accounting ( control_connection_t conn,
const char *  question,
char **  answer,
const char **  errmsg 
)

Helper function: called when we get a GETINFO request for an accounting-related key on the control connection conn. If we can answer the request for question, then set *answer to a newly allocated string holding the result. Otherwise, set *answer to NULL.

Definition at line 1170 of file hibernate.c.

◆ hibernate_begin_shutdown()

void hibernate_begin_shutdown ( void  )

A wrapper around hibernate_begin, for when we get SIGINT.

Definition at line 927 of file hibernate.c.

References hibernate_begin().