tor
master
|
Functions to close listeners, stop allowing new circuits, etc in preparation for closing down or going dormant; and to track bandwidth and time intervals to know when to hibernate and when to stop hibernating. More...
#include "or.h"
#include "channel.h"
#include "channeltls.h"
#include "config.h"
#include "connection.h"
#include "connection_edge.h"
#include "connection_or.h"
#include "control.h"
#include "crypto_rand.h"
#include "hibernate.h"
#include "main.h"
#include "router.h"
#include "statefile.h"
Enumerations | |
enum | time_unit_t { UNIT_MONTH =1, UNIT_WEEK =2, UNIT_DAY =3 } |
Functions | |
int | accounting_parse_options (const or_options_t *options, int validate_only) |
MOCK_IMPL (int, accounting_is_enabled,(const or_options_t *options)) | |
int | accounting_get_interval_length (void) |
MOCK_IMPL (time_t, accounting_get_end_time,(void)) | |
void | accounting_add_bytes (size_t n_read, size_t n_written, int seconds) |
void | configure_accounting (time_t now) |
uint64_t | get_accounting_bytes (void) |
void | accounting_run_housekeeping (time_t now) |
int | accounting_record_bandwidth_usage (time_t now, or_state_t *state) |
void | hibernate_begin_shutdown (void) |
MOCK_IMPL (int, we_are_hibernating,(void)) | |
MOCK_IMPL (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) |
void | accounting_free_all (void) |
Functions to close listeners, stop allowing new circuits, etc in preparation for closing down or going dormant; and to track bandwidth and time intervals to know when to hibernate and when to stop hibernating.
Ordinarily a Tor relay is "Live".
A live relay can stop accepting connections for one of two reasons: either it is trying to conserve bandwidth because of bandwidth accounting rules ("soft hibernation"), or it is about to shut down ("exiting").
enum time_unit_t |
Possible accounting periods.
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.
void accounting_free_all | ( | void | ) |
Free all resources held by the accounting module
int accounting_get_interval_length | ( | void | ) |
If accounting is enabled, return how long (in seconds) this interval lasts.
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.
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.
void accounting_run_housekeeping | ( | time_t | now | ) |
Invoked once per second. Checks whether it is time to hibernate, record bandwidth used, etc.
void configure_accounting | ( | time_t | now | ) |
Initialize the accounting subsystem.
void consider_hibernation | ( | time_t | now | ) |
Consider our environment and decide if it's time to start/stop hibernating.
uint64_t get_accounting_bytes | ( | void | ) |
Return the relevant number of bytes sent/received this interval based on the set AccountingRule
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.
void hibernate_begin_shutdown | ( | void | ) |
A wrapper around hibernate_begin, for when we get SIGINT.
MOCK_IMPL | ( | int | , |
accounting_is_enabled | , | ||
(const or_options_t *options) | |||
) |
If we want to manage the accounting system and potentially hibernate, return 1, else return 0.
MOCK_IMPL | ( | time_t | , |
accounting_get_end_time | , | ||
(void) | |||
) |
Return the time at which the current accounting interval will end.
MOCK_IMPL | ( | int | , |
we_are_hibernating | , | ||
(void) | |||
) |
Return true iff we are currently hibernating – that is, if we are in any non-live state.
MOCK_IMPL | ( | int | , |
we_are_fully_hibernating | , | ||
(void) | |||
) |
Return true iff we are currently fully hibernating – that is, if we are in a state where we expect to handle no network activity at all.