Tor 0.4.9.0-alpha-dev
|
Handles parsing and encoding the persistent 'state' file that carries miscellaneous persistent state between Tor invocations. More...
#include "core/or/or.h"
#include "core/or/circuitstats.h"
#include "app/config/config.h"
#include "feature/relay/transport_config.h"
#include "lib/confmgt/confmgt.h"
#include "core/mainloop/mainloop.h"
#include "core/mainloop/netstatus.h"
#include "core/mainloop/connection.h"
#include "feature/control/control_events.h"
#include "feature/client/entrynodes.h"
#include "feature/hibernate/hibernate.h"
#include "feature/stats/bwhist.h"
#include "feature/relay/router.h"
#include "feature/relay/routermode.h"
#include "lib/sandbox/sandbox.h"
#include "app/config/statefile.h"
#include "app/main/subsysmgr.h"
#include "lib/encoding/confline.h"
#include "lib/net/resolve.h"
#include "lib/version/torversion.h"
#include "app/config/or_state_st.h"
Go to the source code of this file.
Macros | |
#define | STATEFILE_PRIVATE |
#define | VAR(varname, conftype, member, initvalue) CONFIG_VAR_ETYPE(or_state_t, varname, conftype, member, 0, initvalue) |
#define | V(member, conftype, initvalue) VAR(#member, conftype, member, initvalue) |
#define | OR_STATE_MAGIC 0x57A73f57 |
#define | CHECK_STATE_MAGIC(s) |
#define | STATE_WRITE_RETRY_INTERVAL 3600 |
#define | STATE_RELAY_CHECKPOINT_INTERVAL (12*60*60) |
Variables | |
static config_abbrev_t | state_abbrevs_ [] |
static const char * | obsolete_state_keys [] |
static const config_var_t | state_vars_ [] |
static struct_member_t | state_extra_var |
static const config_format_t | state_format |
static config_mgr_t * | state_mgr = NULL |
static or_state_t * | global_state = NULL |
static int | last_state_file_write_failed = 0 |
Handles parsing and encoding the persistent 'state' file that carries miscellaneous persistent state between Tor invocations.
This 'state' file is a typed key-value store that allows multiple entries for the same key. It follows the same metaformat as described in confmgt.c, and uses the same code to read and write itself.
The state file is most suitable for small values that don't change too frequently. For values that become very large, we typically use a separate file – for example, see how we handle microdescriptors, by storing them in a separate file with a journal.
The current state is accessed via get_or_state(), which returns a singleton or_state_t object. Functions that change it should call or_state_mark_dirty() to ensure that it will get written to disk.
The or_state_save() function additionally calls various functioens throughout Tor that might want to flush more state to the the disk, including some in rephist.c, entrynodes.c, circuitstats.c, hibernate.c.
Definition in file statefile.c.
#define CHECK_STATE_MAGIC | ( | s | ) |
Definition at line 211 of file statefile.c.
#define OR_STATE_MAGIC 0x57A73f57 |
Magic value for or_state_t.
Definition at line 169 of file statefile.c.
#define STATE_RELAY_CHECKPOINT_INTERVAL (12*60*60) |
If we're a relay, how often should we checkpoint our state file even if nothing else dirties it? This will checkpoint ongoing stats like bandwidth used, per-country user stats, etc.
Definition at line 558 of file statefile.c.
#define STATE_WRITE_RETRY_INTERVAL 3600 |
If writing the state to disk fails, try again after this many seconds.
Definition at line 553 of file statefile.c.
#define STATEFILE_PRIVATE |
Definition at line 31 of file statefile.c.
#define V | ( | member, | |
conftype, | |||
initvalue | |||
) | VAR(#member, conftype, member, initvalue) |
Definition at line 99 of file statefile.c.
#define VAR | ( | varname, | |
conftype, | |||
member, | |||
initvalue | |||
) | CONFIG_VAR_ETYPE(or_state_t, varname, conftype, member, 0, initvalue) |
Definition at line 97 of file statefile.c.
int did_last_state_file_write_fail | ( | void | ) |
Return whether the state file failed to write last time we tried.
Definition at line 547 of file statefile.c.
DUMMY_TYPECHECK_INSTANCE | ( | or_state_t | ) |
dummy instance of or_state_t, used for type-checking its members with CONF_CHECK_VAR_TYPE.
or_state_t * get_or_state | ( | void | ) |
Return the persistent state struct for this Tor.
Definition at line 220 of file statefile.c.
Referenced by accounting_run_housekeeping(), entry_guards_changed_for_guard_selection(), entry_guards_update_state(), get_transport_in_state_by_name(), read_bandwidth_usage(), rotate_onion_key(), save_state_callback(), save_transport_to_state(), and tor_cleanup().
STATIC const config_mgr_t * get_state_mgr | ( | void | ) |
Return the configuration manager for state-file objects.
Definition at line 200 of file statefile.c.
Referenced by or_state_validate().
char * get_stored_bindaddr_for_server_transport | ( | const char * | transport | ) |
Return a string containing the address:port that a proxy transport should bind on. The string is stored on the heap and must be freed by the caller of this function.
If we didn't find references for this pluggable transport in the state file, we should instruct the pluggable transport proxy to listen on INADDR_ANY on a random ephemeral port.
Definition at line 689 of file statefile.c.
Referenced by get_bindaddr_for_server_proxy().
|
static |
Return string containing the address:port part of the TransportProxy line for transport transport. If the line is corrupted, return NULL.
Definition at line 663 of file statefile.c.
Referenced by get_stored_bindaddr_for_server_transport(), and save_transport_to_state().
STATIC config_line_t * get_transport_in_state_by_name | ( | const char * | transport | ) |
Return the config line for transport transport in the current state. Return NULL if there is no config line for transport.
Definition at line 625 of file statefile.c.
Referenced by get_stored_bindaddr_for_server_transport(), and save_transport_to_state().
STATIC void or_state_free_ | ( | or_state_t * | state | ) |
Definition at line 793 of file statefile.c.
void or_state_free_all | ( | void | ) |
Definition at line 802 of file statefile.c.
int or_state_load | ( | void | ) |
Reload the persistent state from disk, generating a new state as needed. Return 0 on success, less than 0 on failure.
Definition at line 412 of file statefile.c.
int or_state_loaded | ( | void | ) |
Return true iff we have loaded the global state for this Tor
Definition at line 228 of file statefile.c.
void or_state_mark_dirty | ( | or_state_t * | state, |
time_t | when | ||
) |
Change the next_write time of state to when, unless the state is already scheduled to be written to disk earlier than when.
Definition at line 784 of file statefile.c.
Referenced by entry_guards_changed_for_guard_selection(), entry_guards_update_state(), and tor_cleanup().
STATIC or_state_t * or_state_new | ( | void | ) |
Definition at line 400 of file statefile.c.
STATIC void or_state_remove_obsolete_lines | ( | config_line_t ** | extra_lines | ) |
Remove from extra_lines
every element whose key appears in obsolete_state_keys
.
Definition at line 513 of file statefile.c.
int or_state_save | ( | time_t | now | ) |
Write the persistent state to disk. Return 0 for success, <0 on failure.
Definition at line 562 of file statefile.c.
Referenced by save_state_callback(), and tor_cleanup().
|
static |
Save a broken state file to a backup location.
Definition at line 364 of file statefile.c.
|
static |
Replace the current persistent state with new_state
Definition at line 332 of file statefile.c.
|
static |
Return 0 if every setting in state is reasonable, and a permissible transition from old_state. Else warn and return -1. Should have no side effects, except for normalizing the contents of state.
Definition at line 302 of file statefile.c.
|
static |
Legacy validation/normalization callback for or_state_t. See legacy_validate_fn_t for more information.
Definition at line 312 of file statefile.c.
void save_transport_to_state | ( | const char * | transport, |
const tor_addr_t * | addr, | ||
uint16_t | port | ||
) |
Save transport listening on addr:port to state
find where to write on the state
Definition at line 722 of file statefile.c.
Referenced by register_server_proxy().
|
static |
Return true if line is a valid state TransportProxy line. Return false otherwise.
Definition at line 236 of file statefile.c.
Referenced by validate_transports_in_state().
|
static |
Return 0 if all TransportProxy lines in state are well formed. Otherwise, return -1.
Definition at line 279 of file statefile.c.
|
static |
Persistent serialized state.
Definition at line 216 of file statefile.c.
Referenced by get_or_state(), and or_state_loaded().
|
static |
Did the last time we tried to write the state file fail? If so, we should consider disabling such features as preemptive circuit generation to compute circuit-build-time.
Definition at line 543 of file statefile.c.
Referenced by did_last_state_file_write_fail().
|
static |
A list of obsolete keys that we do not and should not preserve.
We could just let these live in ExtraLines indefinitely, but they're never going to be used again, and every version that used them has been obsolete for a long time.
Definition at line 70 of file statefile.c.
Referenced by or_state_remove_obsolete_lines().
|
static |
A list of state-file "abbreviations," for compatibility.
Definition at line 60 of file statefile.c.
|
static |
"Extra" variable in the state that receives lines we can't parse. This lets us preserve options from versions of Tor newer than us.
Definition at line 173 of file statefile.c.
|
static |
Configuration format for or_state_t.
Definition at line 180 of file statefile.c.
|
static |
Definition at line 196 of file statefile.c.
|
static |
Array of "state" variables saved to the ~/.tor/state file.
Definition at line 104 of file statefile.c.