tor  master
Macros | Enumerations | Functions
hibernate.c File Reference

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"
Include dependency graph for hibernate.c:

Macros

#define HIBERNATE_PRIVATE
 
#define MIN_TIME_FOR_MEASUREMENT   (1800)
 
#define NOTE_INTERVAL   (600)
 
#define NOTE_BYTES   20*(1024*1024)
 
#define ROUND_UP(x)   (((x) + 0x3ff) & ~0x3ff)
 
#define SOFT_LIM_PCT   (.95)
 
#define SOFT_LIM_BYTES   (500*1024*1024)
 
#define SOFT_LIM_MINUTES   (3*60)
 

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)
 

Detailed Description

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").

Enumeration Type Documentation

◆ time_unit_t

Possible accounting periods.

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.

◆ accounting_free_all()

void accounting_free_all ( void  )

Free all resources held by the accounting module

◆ accounting_get_interval_length()

int accounting_get_interval_length ( void  )

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

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

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

Here is the caller graph for this function:

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

◆ configure_accounting()

void configure_accounting ( time_t  now)

Initialize the accounting subsystem.

◆ consider_hibernation()

void consider_hibernation ( time_t  now)

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

◆ get_accounting_bytes()

uint64_t get_accounting_bytes ( void  )

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

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

◆ hibernate_begin_shutdown()

void hibernate_begin_shutdown ( void  )

A wrapper around hibernate_begin, for when we get SIGINT.

◆ MOCK_IMPL() [1/4]

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() [2/4]

MOCK_IMPL ( time_t  ,
accounting_get_end_time  ,
(void)   
)

Return the time at which the current accounting interval will end.

◆ MOCK_IMPL() [3/4]

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() [4/4]

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.