#include "or.h"
#include "ht.h"
Data Structures | |
struct | link_history_t |
struct | or_history_t |
struct | bw_array_t |
struct | circ_buffer_stats_t |
Defines | |
#define | STABILITY_EPSILON 0.0001 |
#define | STABILITY_ALPHA 0.95 |
#define | STABILITY_INTERVAL (12*60*60) |
#define | PUT(s) STMT_BEGIN if (fputs((s),f)<0) goto err; STMT_END |
#define | PRINTF(args) STMT_BEGIN if (fprintf args <0) goto err; STMT_END |
#define | MAX_STABILITY_DOC_BUILD_RATE (3*60) |
#define | NUM_SECS_ROLLING_MEASURE 10 |
#define | NUM_SECS_BW_SUM_INTERVAL (15*60) |
#define | NUM_SECS_BW_SUM_IS_VALID (24*60*60) |
#define | NUM_TOTALS (NUM_SECS_BW_SUM_IS_VALID/NUM_SECS_BW_SUM_INTERVAL) |
#define | EXIT_STATS_ROUND_UP_BYTES 1024 |
#define | EXIT_STATS_ROUND_UP_STREAMS 4 |
#define | EXIT_STATS_NUM_PORTS 65536 |
#define | EXIT_STATS_THRESHOLD_RECIPROCAL 10000 |
#define | PREDICTED_CIRCS_RELEVANCE_TIME (60*60) |
#define | SHARES 10 |
Functions | |
static void | bw_arrays_init (void) |
static void | predicted_ports_init (void) |
static or_history_t * | get_or_history (const char *id) |
static link_history_t * | get_link_history (const char *from_id, const char *to_id) |
static void | _free_link_history (void *val) |
static void | free_or_history (void *_hist) |
static void | update_or_history (or_history_t *hist, time_t when) |
void | rep_hist_init (void) |
static void | mark_or_down (or_history_t *hist, time_t when, int failed) |
static void | mark_or_up (or_history_t *hist, time_t when) |
void | rep_hist_note_connect_failed (const char *id, time_t when) |
void | rep_hist_note_connect_succeeded (const char *id, time_t when) |
void | rep_hist_note_disconnect (const char *id, time_t when) |
void | rep_hist_note_connection_died (const char *id, time_t when) |
void | rep_hist_note_router_reachable (const char *id, time_t when) |
void | rep_hist_note_router_unreachable (const char *id, time_t when) |
time_t | rep_hist_downrate_old_runs (time_t now) |
static double | get_stability (or_history_t *hist, time_t when) |
static long | get_total_weighted_time (or_history_t *hist, time_t when) |
static double | get_weighted_fractional_uptime (or_history_t *hist, time_t when) |
double | rep_hist_get_stability (const char *id, time_t when) |
double | rep_hist_get_weighted_fractional_uptime (const char *id, time_t when) |
long | rep_hist_get_weighted_time_known (const char *id, time_t when) |
int | rep_hist_have_measured_enough_stability (void) |
void | rep_hist_note_extend_succeeded (const char *from_id, const char *to_id) |
void | rep_hist_note_extend_failed (const char *from_id, const char *to_id) |
void | rep_hist_dump_stats (time_t now, int severity) |
void | rep_history_clean (time_t before) |
int | rep_hist_record_mtbf_data (time_t now, int missing_means_down) |
static char * | rep_hist_format_router_status (or_history_t *hist, time_t now) |
const char * | rep_hist_get_router_stability_doc (time_t now) |
static int | find_next_with (smartlist_t *sl, int i, const char *prefix) |
static int | parse_possibly_bad_iso_time (const char *s, time_t *time_out) |
static INLINE time_t | correct_time (time_t t, time_t now, time_t stored_at, time_t started_measuring) |
int | rep_hist_load_mtbf_data (time_t now) |
static void | commit_max (bw_array_t *b) |
static INLINE void | advance_obs (bw_array_t *b) |
static INLINE void | add_obs (bw_array_t *b, time_t when, uint64_t n) |
static bw_array_t * | bw_array_new (void) |
void | rep_hist_note_bytes_written (size_t num_bytes, time_t when) |
void | rep_hist_note_bytes_read (size_t num_bytes, time_t when) |
void | rep_hist_exit_stats_init (time_t now) |
void | rep_hist_exit_stats_write (time_t now) |
void | rep_hist_note_exit_bytes_written (uint16_t port, size_t num_bytes) |
void | rep_hist_note_exit_bytes_read (uint16_t port, size_t num_bytes) |
void | rep_hist_note_exit_stream_opened (uint16_t port) |
static uint64_t | find_largest_max (bw_array_t *b) |
int | rep_hist_bandwidth_assess (void) |
static size_t | rep_hist_fill_bandwidth_history (char *buf, size_t len, bw_array_t *b) |
char * | rep_hist_get_bandwidth_lines (int for_extrainfo) |
void | rep_hist_update_state (or_state_t *state) |
int | rep_hist_load_state (or_state_t *state, char **err) |
static void | add_predicted_port (time_t now, uint16_t port) |
static void | predicted_ports_free (void) |
void | rep_hist_note_used_port (time_t now, uint16_t port) |
smartlist_t * | rep_hist_get_predicted_ports (time_t now) |
void | rep_hist_note_used_resolve (time_t now) |
void | rep_hist_note_used_internal (time_t now, int need_uptime, int need_capacity) |
int | rep_hist_get_predicted_internal (time_t now, int *need_uptime, int *need_capacity) |
int | any_predicted_circuits (time_t now) |
int | rep_hist_circbuilding_dormant (time_t now) |
void | note_crypto_pk_op (pk_op_t operation) |
void | dump_pk_ops (int severity) |
void | rep_hist_free_all (void) |
void | rep_hist_buffer_stats_init (time_t now) |
void | rep_hist_buffer_stats_add_circ (circuit_t *circ, time_t end_of_interval) |
static int | _buffer_stats_compare_entries (const void **_a, const void **_b) |
void | rep_hist_buffer_stats_write (time_t now) |
Variables | |
uint64_t | rephist_total_alloc = 0 |
uint32_t | rephist_total_num = 0 |
static time_t | stability_last_downrated = 0 |
static time_t | started_tracking_stability = 0 |
static digestmap_t * | history_map = NULL |
static char * | last_stability_doc = NULL |
static time_t | built_last_stability_doc_at = 0 |
static int | n_bogus_times = 0 |
static bw_array_t * | read_array = NULL |
static bw_array_t * | write_array = NULL |
static uint64_t * | exit_bytes_read = NULL |
static uint64_t * | exit_bytes_written = NULL |
static uint32_t * | exit_streams = NULL |
static time_t | start_of_exit_stats_interval |
static smartlist_t * | predicted_ports_list = NULL |
static smartlist_t * | predicted_ports_times = NULL |
static time_t | predicted_internal_time = 0 |
static time_t | predicted_internal_uptime_time = 0 |
static time_t | predicted_internal_capacity_time = 0 |
struct { | |
unsigned long n_signed_dir_objs | |
unsigned long n_signed_routerdescs | |
unsigned long n_verified_dir_objs | |
unsigned long n_verified_routerdescs | |
unsigned long n_onionskins_encrypted | |
unsigned long n_onionskins_decrypted | |
unsigned long n_tls_client_handshakes | |
unsigned long n_tls_server_handshakes | |
unsigned long n_rend_client_ops | |
unsigned long n_rend_mid_ops | |
unsigned long n_rend_server_ops | |
} | pk_op_counts |
static time_t | start_of_buffer_stats_interval |
smartlist_t * | circuits_for_buffer_stats = NULL |
#define EXIT_STATS_NUM_PORTS 65536 |
Number of TCP ports
Referenced by rep_hist_exit_stats_init(), and rep_hist_exit_stats_write().
#define EXIT_STATS_ROUND_UP_BYTES 1024 |
To what multiple should byte numbers be rounded up?
Referenced by rep_hist_exit_stats_write().
#define EXIT_STATS_ROUND_UP_STREAMS 4 |
To what multiple should stream counts be rounded up?
Referenced by rep_hist_exit_stats_write().
#define EXIT_STATS_THRESHOLD_RECIPROCAL 10000 |
Reciprocal of threshold (= 0.01%) of total bytes that a port needs to see in order to be included in exit stats.
Referenced by rep_hist_exit_stats_write().
#define MAX_STABILITY_DOC_BUILD_RATE (3*60) |
Shortest allowable time between building two stability documents.
Referenced by rep_hist_get_router_stability_doc().
#define NUM_SECS_BW_SUM_INTERVAL (15*60) |
How large are the intervals for which we track and report bandwidth use?
Referenced by bw_array_new(), commit_max(), rep_hist_fill_bandwidth_history(), rep_hist_get_bandwidth_lines(), rep_hist_load_state(), and rep_hist_update_state().
#define NUM_SECS_BW_SUM_IS_VALID (24*60*60) |
How far in the past do we remember and publish bandwidth use?
#define NUM_SECS_ROLLING_MEASURE 10 |
For how many seconds do we keep track of individual per-second bandwidth totals?
Referenced by advance_obs(), rep_hist_bandwidth_assess(), and rep_hist_load_state().
#define NUM_TOTALS (NUM_SECS_BW_SUM_IS_VALID/NUM_SECS_BW_SUM_INTERVAL) |
How many bandwidth usage intervals do we remember? (derived)
Referenced by commit_max(), find_largest_max(), rep_hist_fill_bandwidth_history(), rep_hist_get_bandwidth_lines(), rep_hist_load_state(), and rep_hist_update_state().
#define PREDICTED_CIRCS_RELEVANCE_TIME (60*60) |
For this long after we've seen a request for a given port, assume that we'll want to make connections to the same port in the future.
Referenced by any_predicted_circuits(), rep_hist_get_predicted_internal(), and rep_hist_get_predicted_ports().
#define STABILITY_ALPHA 0.95 |
Value by which to discount all old intervals for MTBF purposes. This is compounded every STABILITY_INTERVAL.
Referenced by rep_hist_downrate_old_runs().
#define STABILITY_EPSILON 0.0001 |
If the total weighted run count of all runs for a router ever falls below this amount, the router can be treated as having 0 MTBF.
Referenced by get_stability(), and rep_history_clean().
#define STABILITY_INTERVAL (12*60*60) |
Interval at which to discount all old intervals for MTBF purposes.
Referenced by rep_hist_downrate_old_runs().
static int _buffer_stats_compare_entries | ( | const void ** | _a, | |
const void ** | _b | |||
) | [static] |
Sorting helper: return -1, 1, or 0 based on comparison of two circ_buffer_stats_t
Referenced by rep_hist_buffer_stats_write().
static void _free_link_history | ( | void * | val | ) | [static] |
Helper: free storage held by a single link history entry.
References rephist_total_alloc, and tor_free.
Referenced by free_or_history().
static INLINE void add_obs | ( | bw_array_t * | b, | |
time_t | when, | |||
uint64_t | n | |||
) | [static] |
Add n bytes to the number of bytes in b for second when.
References advance_obs(), bw_array_t::cur_obs_idx, bw_array_t::cur_obs_time, bw_array_t::obs, and bw_array_t::total_in_period.
Referenced by rep_hist_load_state(), rep_hist_note_bytes_read(), and rep_hist_note_bytes_written().
static void add_predicted_port | ( | time_t | now, | |
uint16_t | port | |||
) | [static] |
We just got an application request for a connection with port port. Remember it for the future, so we can keep some circuits open that will exit to this port.
References rephist_total_alloc, and smartlist_add().
Referenced by predicted_ports_init(), and rep_hist_note_used_port().
static INLINE void advance_obs | ( | bw_array_t * | b | ) | [static] |
Shift the current observation time of 'b' forward by one second.
References commit_max(), bw_array_t::cur_obs_idx, bw_array_t::cur_obs_time, bw_array_t::max_total, bw_array_t::next_period, NUM_SECS_ROLLING_MEASURE, bw_array_t::obs, and bw_array_t::total_obs.
Referenced by add_obs().
int any_predicted_circuits | ( | time_t | now | ) |
Any ports used lately? These are pre-seeded if we just started up or if we're running a hidden service.
References PREDICTED_CIRCS_RELEVANCE_TIME, and predicted_internal_time.
Referenced by directory_info_has_arrived(), options_act(), rep_hist_circbuilding_dormant(), and run_scheduled_events().
static bw_array_t* bw_array_new | ( | void | ) | [static] |
Allocate, initialize, and return a new bw_array.
References bw_array_t::cur_obs_time, bw_array_t::next_period, NUM_SECS_BW_SUM_INTERVAL, and rephist_total_alloc.
Referenced by bw_arrays_init(), and rep_hist_load_state().
static void bw_arrays_init | ( | void | ) | [static] |
static void commit_max | ( | bw_array_t * | b | ) | [static] |
Shift the current period of b forward by one.
References bw_array_t::max_total, bw_array_t::maxima, bw_array_t::next_max_idx, bw_array_t::next_period, bw_array_t::num_maxes_set, NUM_SECS_BW_SUM_INTERVAL, NUM_TOTALS, bw_array_t::total_in_period, and bw_array_t::totals.
Referenced by advance_obs().
static INLINE time_t correct_time | ( | time_t | t, | |
time_t | now, | |||
time_t | stored_at, | |||
time_t | started_measuring | |||
) | [static] |
We've read a time t from a file stored at stored_at, which says we started measuring at started_measuring. Return a new number that's about as much before now as t was before stored_at.
Referenced by rep_hist_load_mtbf_data().
void dump_pk_ops | ( | int | severity | ) |
Log the number of times we've done each public/private-key operation.
References LD_HIST, and pk_op_counts.
Referenced by dumpstats().
static uint64_t find_largest_max | ( | bw_array_t * | b | ) | [static] |
Helper: Return the largest value in b->maxima. (This is equal to the most bandwidth used in any NUM_SECS_ROLLING_MEASURE period for the last NUM_SECS_BW_SUM_IS_VALID seconds.)
References bw_array_t::maxima, and NUM_TOTALS.
Referenced by rep_hist_bandwidth_assess().
static int find_next_with | ( | smartlist_t * | sl, | |
int | i, | |||
const char * | prefix | |||
) | [static] |
Helper: return the first j >= i such that !strcmpstart(sl[j], prefix) and such that no line sl[k] with i <= k < j starts with "R ". Return -1 if no such line exists.
References strcmpstart().
Referenced by rep_hist_load_mtbf_data().
static void free_or_history | ( | void * | _hist | ) | [static] |
Helper: free storage held by a single OR history entry.
References _free_link_history(), digestmap_free(), or_history_t::link_history_map, rephist_total_alloc, rephist_total_num, and tor_free.
Referenced by rep_hist_free_all(), and rep_history_clean().
static link_history_t* get_link_history | ( | const char * | from_id, | |
const char * | to_id | |||
) | [static] |
Return the link_history_t for the link from the first named OR to the second, creating it if necessary. (ORs are identified by identity digest.)
References link_history_t::changed, DIGEST_LEN, digestmap_get(), digestmap_set(), get_or_history(), or_history_t::link_history_map, rephist_total_alloc, link_history_t::since, and tor_mem_is_zero().
Referenced by rep_hist_note_extend_failed(), and rep_hist_note_extend_succeeded().
static or_history_t* get_or_history | ( | const char * | id | ) | [static] |
Return the or_history_t for the OR with identity digest id, creating it if necessary.
References or_history_t::changed, DIGEST_LEN, digestmap_get(), digestmap_new(), digestmap_set(), history_map, or_history_t::link_history_map, rephist_total_alloc, rephist_total_num, or_history_t::since, and tor_mem_is_zero().
Referenced by get_link_history(), rep_hist_get_stability(), rep_hist_get_weighted_fractional_uptime(), rep_hist_get_weighted_time_known(), rep_hist_load_mtbf_data(), rep_hist_note_connect_failed(), rep_hist_note_connect_succeeded(), rep_hist_note_connection_died(), rep_hist_note_disconnect(), rep_hist_note_router_reachable(), and rep_hist_note_router_unreachable().
static double get_stability | ( | or_history_t * | hist, | |
time_t | when | |||
) | [static] |
Helper: Return the weighted MTBF of the router with history hist.
References STABILITY_EPSILON, or_history_t::start_of_run, or_history_t::total_run_weights, and or_history_t::weighted_run_length.
Referenced by rep_hist_dump_stats(), rep_hist_format_router_status(), and rep_hist_get_stability().
static long get_total_weighted_time | ( | or_history_t * | hist, | |
time_t | when | |||
) | [static] |
Return the total amount of time we've been observing, with each run of time downrated by the appropriate factor.
References or_history_t::start_of_downtime, or_history_t::start_of_run, and or_history_t::total_weighted_time.
Referenced by rep_hist_get_weighted_time_known().
static double get_weighted_fractional_uptime | ( | or_history_t * | hist, | |
time_t | when | |||
) | [static] |
Helper: Return the weighted percent-of-time-online of the router with history hist.
References or_history_t::start_of_downtime, or_history_t::start_of_run, or_history_t::total_weighted_time, and or_history_t::weighted_uptime.
Referenced by rep_hist_format_router_status(), and rep_hist_get_weighted_fractional_uptime().
static void mark_or_down | ( | or_history_t * | hist, | |
time_t | when, | |||
int | failed | |||
) | [static] |
Helper: note that we are no longer connected to the router with history hist. If failed, the connection failed; otherwise, it was closed correctly.
References or_history_t::down_since, or_history_t::up_since, and or_history_t::uptime.
Referenced by rep_hist_note_connect_failed(), rep_hist_note_connection_died(), and rep_hist_note_disconnect().
static void mark_or_up | ( | or_history_t * | hist, | |
time_t | when | |||
) | [static] |
Helper: note that we are connected to the router with history hist.
References or_history_t::down_since, or_history_t::downtime, and or_history_t::up_since.
Referenced by rep_hist_note_connect_succeeded().
void note_crypto_pk_op | ( | pk_op_t | operation | ) |
Increment the count of the number of times we've done operation.
References LD_BUG, and pk_op_counts.
Referenced by connection_tls_start_handshake(), dirserv_dump_directory_to_string(), extrainfo_parse_entry_from_string(), format_networkstatus_vote(), generate_runningrouters(), networkstatus_v2_parse_from_string(), onion_skin_create(), onion_skin_server_handshake(), rend_mid_establish_intro(), rend_parse_service_descriptor(), rend_parse_v2_service_descriptor(), rend_service_intro_has_opened(), rend_service_introduce(), router_dump_router_to_string(), router_parse_directory(), router_parse_entry_from_string(), and router_parse_runningrouters().
static int parse_possibly_bad_iso_time | ( | const char * | s, | |
time_t * | time_out | |||
) | [static] |
Parse the ISO-formatted time in s into *time_out, but rounds any pre-1970 date to Jan 1, 1970.
References n_bogus_times, parse_iso_time(), and tor_parse_long().
Referenced by rep_hist_load_mtbf_data().
static void predicted_ports_free | ( | void | ) | [static] |
Free whatever memory is needed for predicting which ports will be used.
References rephist_total_alloc, smartlist_free(), and tor_free.
Referenced by rep_hist_free_all().
static void predicted_ports_init | ( | void | ) | [static] |
Initialize whatever memory and structs are needed for predicting which ports will be used. Also seed it with port 80, so we'll build circuits on start-up.
References add_predicted_port(), and smartlist_create().
Referenced by rep_hist_init().
int rep_hist_bandwidth_assess | ( | void | ) |
Find the largest sums in the past NUM_SECS_BW_SUM_IS_VALID (roughly) seconds. Find one sum for reading and one for writing. They don't have to be at the same time.
Return the smaller of these sums, divided by NUM_SECS_ROLLING_MEASURE.
References find_largest_max(), and NUM_SECS_ROLLING_MEASURE.
Referenced by check_descriptor_bandwidth_changed(), and router_rebuild_descriptor().
void rep_hist_buffer_stats_add_circ | ( | circuit_t * | circ, | |
time_t | end_of_interval | |||
) |
Remember cell statistics for circuit circ at time end_of_interval and reset cell counters in case the circuit remains open in the next measurement interval.
References CIRCUIT_IS_ORIGIN, or_circuit_t::processed_cells, smartlist_add(), smartlist_create(), start_of_buffer_stats_interval, circuit_t::timestamp_created, TO_OR_CIRCUIT(), and or_circuit_t::total_cell_waiting_time.
Referenced by circuit_free(), and rep_hist_buffer_stats_write().
void rep_hist_buffer_stats_init | ( | time_t | now | ) |
Initialize buffer stats.
References start_of_buffer_stats_interval.
Referenced by run_scheduled_events().
void rep_hist_buffer_stats_write | ( | time_t | now | ) |
Write buffer statistics to $DATADIR/stats/buffer-stats.
References _buffer_stats_compare_entries(), _circuit_get_global_list(), abort_writing_to_file(), check_private_dir(), finish_writing_to_file(), format_iso_time(), get_datadir_fname, get_datadir_fname2, LD_HIST, circuit_t::next, rep_hist_buffer_stats_add_circ(), smartlist_add(), smartlist_clear(), smartlist_create(), smartlist_free(), smartlist_join_strings(), smartlist_sort(), start_of_buffer_stats_interval, start_writing_to_stdio_file(), tor_asprintf(), and tor_free.
Referenced by run_scheduled_events().
int rep_hist_circbuilding_dormant | ( | time_t | now | ) |
Return 1 if we have no need for circuits currently, else return 0.
References any_predicted_circuits(), check_whether_dirport_reachable(), check_whether_orport_reachable(), circuit_enough_testing_circs(), get_options(), and server_mode().
Referenced by directory_too_idle_to_fetch_descriptors().
time_t rep_hist_downrate_old_runs | ( | time_t | now | ) |
Helper: Discount all old MTBF data, if it is time to do so. Return the time at which we should next discount MTBF data.
References digestmap_iter_done(), digestmap_iter_get(), digestmap_iter_init(), digestmap_iter_next(), digestmap_new(), history_map, LD_HIST, STABILITY_ALPHA, STABILITY_INTERVAL, stability_last_downrated, or_history_t::total_run_weights, or_history_t::total_weighted_time, or_history_t::weighted_run_length, and or_history_t::weighted_uptime.
Referenced by run_scheduled_events().
void rep_hist_dump_stats | ( | time_t | now, | |
int | severity | |||
) |
Log all the reliability data we have remembered, with the chosen severity.
References base16_encode(), DIGEST_LEN, digestmap_isempty(), digestmap_iter_done(), digestmap_iter_get(), digestmap_iter_init(), digestmap_iter_next(), or_history_t::downtime, get_options(), get_stability(), HEX_DIGEST_LEN, history_map, LD_HIST, or_history_t::link_history_map, or_history_t::n_conn_fail, or_history_t::n_conn_ok, link_history_t::n_extend_fail, link_history_t::n_extend_ok, routerinfo_t::nickname, rep_history_clean(), router_get_by_digest(), tor_snprintf(), update_or_history(), and or_history_t::uptime.
Referenced by dumpstats().
void rep_hist_exit_stats_init | ( | time_t | now | ) |
Initialize exit port stats.
References exit_bytes_read, exit_bytes_written, EXIT_STATS_NUM_PORTS, exit_streams, and start_of_exit_stats_interval.
Referenced by run_scheduled_events().
void rep_hist_exit_stats_write | ( | time_t | now | ) |
Write exit stats to $DATADIR/stats/exit-stats and reset counters.
References abort_writing_to_file(), check_private_dir(), exit_bytes_read, exit_bytes_written, EXIT_STATS_NUM_PORTS, EXIT_STATS_ROUND_UP_BYTES, EXIT_STATS_ROUND_UP_STREAMS, EXIT_STATS_THRESHOLD_RECIPROCAL, exit_streams, finish_writing_to_file(), format_iso_time(), get_datadir_fname, get_datadir_fname2, LD_HIST, round_uint32_to_next_multiple_of(), round_uint64_to_next_multiple_of(), start_of_exit_stats_interval, start_writing_to_stdio_file(), tor_assert, and tor_free.
Referenced by run_scheduled_events().
static size_t rep_hist_fill_bandwidth_history | ( | char * | buf, | |
size_t | len, | |||
bw_array_t * | b | |||
) | [static] |
Print the bandwidth history of b (either read_array or write_array) into the buffer pointed to by buf. The format is simply comma separated numbers, from oldest to newest.
It returns the number of bytes written.
References get_options(), bw_array_t::next_max_idx, bw_array_t::num_maxes_set, NUM_SECS_BW_SUM_INTERVAL, NUM_TOTALS, or_options_t::RelayBandwidthRate, tor_assert, tor_snprintf(), and bw_array_t::totals.
Referenced by rep_hist_get_bandwidth_lines(), and rep_hist_update_state().
static char* rep_hist_format_router_status | ( | or_history_t * | hist, | |
time_t | now | |||
) | [static] |
Format the current tracked status of the router in hist at time now for analysis; return it in a newly allocated string.
References format_iso_time(), get_stability(), get_weighted_fractional_uptime(), or_history_t::start_of_downtime, or_history_t::start_of_run, tor_asprintf(), or_history_t::total_run_weights, or_history_t::total_weighted_time, or_history_t::weighted_run_length, and or_history_t::weighted_uptime.
Referenced by rep_hist_get_router_stability_doc().
void rep_hist_free_all | ( | void | ) |
Free all storage held by the OR/link history caches, by the bandwidth history arrays, or by the port history.
References built_last_stability_doc_at, digestmap_free(), exit_bytes_read, exit_bytes_written, exit_streams, free_or_history(), history_map, last_stability_doc, predicted_ports_free(), and tor_free.
Referenced by tor_free_all().
char* rep_hist_get_bandwidth_lines | ( | int | for_extrainfo | ) |
Allocate and return lines for representing this server's bandwidth history in its descriptor.
References format_iso_time(), bw_array_t::next_period, NUM_SECS_BW_SUM_INTERVAL, NUM_TOTALS, rep_hist_fill_bandwidth_history(), tor_assert, and tor_snprintf().
Referenced by extrainfo_dump_to_string().
int rep_hist_get_predicted_internal | ( | time_t | now, | |
int * | need_uptime, | |||
int * | need_capacity | |||
) |
Return 1 if we've used an internal circ recently; else return 0.
References PREDICTED_CIRCS_RELEVANCE_TIME, predicted_internal_capacity_time, predicted_internal_time, and predicted_internal_uptime_time.
Referenced by circuit_predict_and_launch_new().
smartlist_t* rep_hist_get_predicted_ports | ( | time_t | now | ) |
Return a pointer to the list of port numbers that are likely to be asked for in the near future.
The caller promises not to mess with it.
References LD_CIRC, PREDICTED_CIRCS_RELEVANCE_TIME, rephist_total_alloc, smartlist_del(), tor_assert, and tor_free.
Referenced by circuit_get_unhandled_ports().
const char* rep_hist_get_router_stability_doc | ( | time_t | now | ) |
Return a pointer to a NUL-terminated document describing our view of the stability of the routers we've been tracking. Return NULL on failure.
References routerinfo_t::addr, BASE64_DIGEST_LEN, built_last_stability_doc_at, routerinfo_t::cache_info, digest_to_base64(), format_iso_time(), history_map, routerinfo_t::is_hibernating, routerinfo_t::is_running, routerinfo_t::is_valid, last_stability_doc, MAX_STABILITY_DOC_BUILD_RATE, routerinfo_t::nickname, signed_descriptor_t::published_on, rep_hist_format_router_status(), rep_hist_have_measured_enough_stability(), router_get_by_digest(), smartlist_add(), smartlist_create(), smartlist_free(), smartlist_join_strings(), tor_dup_ip(), tor_free, tor_snprintf(), and routerinfo_t::uptime.
Referenced by directory_handle_command_get().
double rep_hist_get_stability | ( | const char * | id, | |
time_t | when | |||
) |
Return an estimated MTBF for the router whose identity digest is id. Return 0 if the router is unknown.
References get_or_history(), and get_stability().
Referenced by dirserv_compute_performance_thresholds(), and dirserv_thinks_router_is_unreliable().
double rep_hist_get_weighted_fractional_uptime | ( | const char * | id, | |
time_t | when | |||
) |
Return an estimated percent-of-time-online for the router whose identity digest is id. Return 0 if the router is unknown.
References get_or_history(), and get_weighted_fractional_uptime().
Referenced by set_routerstatus_from_routerinfo().
long rep_hist_get_weighted_time_known | ( | const char * | id, | |
time_t | when | |||
) |
Return a number representing how long we've known about the router whose digest is id. Return 0 if the router is unknown.
Be careful: this measure increases monotonically as we know the router for longer and longer, but it doesn't increase linearly.
References get_or_history(), and get_total_weighted_time().
Referenced by dirserv_compute_performance_thresholds(), and set_routerstatus_from_routerinfo().
int rep_hist_have_measured_enough_stability | ( | void | ) |
Return true if we've been measuring MTBFs for long enough to pronounce on Stability.
References started_tracking_stability.
Referenced by rep_hist_get_router_stability_doc().
void rep_hist_init | ( | void | ) |
Initialize the static data structures for tracking history.
References bw_arrays_init(), digestmap_new(), history_map, and predicted_ports_init().
Referenced by tor_init().
int rep_hist_load_mtbf_data | ( | time_t | now | ) |
Load MTBF data from disk. Returns 0 on success or recoverable error, -1 on failure.
References base16_decode(), correct_time(), DIGEST_LEN, escaped(), find_next_with(), get_datadir_fname, get_or_history(), HEX_DIGEST_LEN, LD_HIST, n_bogus_times, parse_iso_time(), parse_possibly_bad_iso_time(), read_file_to_str(), RFTS_IGNORE_MISSING, smartlist_create(), smartlist_free(), smartlist_split_string(), stability_last_downrated, or_history_t::start_of_downtime, or_history_t::start_of_run, started_tracking_stability, strcmpstart(), tor_free, tor_parse_long(), or_history_t::total_run_weights, or_history_t::total_weighted_time, or_history_t::weighted_run_length, and or_history_t::weighted_uptime.
Referenced by options_act().
int rep_hist_load_state | ( | or_state_t * | state, | |
char ** | err | |||
) |
Set bandwidth history from our saved state.
References add_obs(), bw_array_new(), or_state_t::BWHistoryReadEnds, or_state_t::BWHistoryReadInterval, or_state_t::BWHistoryReadValues, or_state_t::BWHistoryWriteEnds, or_state_t::BWHistoryWriteInterval, or_state_t::BWHistoryWriteValues, bw_array_t::cur_obs_time, LD_HIST, bw_array_t::max_total, bw_array_t::maxima, bw_array_t::next_period, NUM_SECS_BW_SUM_INTERVAL, NUM_SECS_ROLLING_MEASURE, NUM_TOTALS, bw_array_t::obs, tor_assert, tor_free, tor_parse_uint64(), and bw_array_t::total_obs.
Referenced by or_state_set().
void rep_hist_note_bytes_read | ( | size_t | num_bytes, | |
time_t | when | |||
) |
We wrote num_bytes more bytes in second when. (like rep_hist_note_bytes_written() above)
References add_obs().
Referenced by connection_buckets_decrement().
void rep_hist_note_bytes_written | ( | size_t | num_bytes, | |
time_t | when | |||
) |
We read num_bytes more bytes in second when.
Add num_bytes to the current running total for when.
when can go back to time, but it's safe to ignore calls earlier than the latest when you've heard of.
References add_obs().
Referenced by connection_buckets_decrement().
void rep_hist_note_connect_failed | ( | const char * | id, | |
time_t | when | |||
) |
Remember that an attempt to connect to the OR with identity digest id failed at when.
References or_history_t::changed, get_or_history(), mark_or_down(), and or_history_t::n_conn_fail.
Referenced by connection_about_to_close_connection().
void rep_hist_note_connect_succeeded | ( | const char * | id, | |
time_t | when | |||
) |
Remember that an attempt to connect to the OR with identity digest id succeeded at when.
References or_history_t::changed, get_or_history(), mark_or_up(), and or_history_t::n_conn_ok.
Referenced by connection_or_set_state_open().
void rep_hist_note_connection_died | ( | const char * | id, | |
time_t | when | |||
) |
Remember that our connection to the OR with identity digest id had an error and stopped working at when.
References or_history_t::changed, get_or_history(), and mark_or_down().
Referenced by connection_about_to_close_connection().
void rep_hist_note_disconnect | ( | const char * | id, | |
time_t | when | |||
) |
Remember that we intentionally closed our connection to the OR with identity digest id at when.
References or_history_t::changed, get_or_history(), and mark_or_down().
Referenced by connection_about_to_close_connection().
void rep_hist_note_exit_bytes_read | ( | uint16_t | port, | |
size_t | num_bytes | |||
) |
Note that we read num_bytes from an exit connection to port.
References exit_bytes_read, get_options(), and LD_HIST.
Referenced by connection_buckets_decrement().
void rep_hist_note_exit_bytes_written | ( | uint16_t | port, | |
size_t | num_bytes | |||
) |
Note that we wrote num_bytes to an exit connection to port.
References exit_bytes_written, get_options(), and LD_HIST.
Referenced by connection_buckets_decrement().
void rep_hist_note_exit_stream_opened | ( | uint16_t | port | ) |
Note that we opened an exit stream to port.
References exit_streams, get_options(), and LD_HIST.
Referenced by connection_edge_finished_connecting().
void rep_hist_note_extend_failed | ( | const char * | from_id, | |
const char * | to_id | |||
) |
Remember that we tried to extend from the OR with identity digest from_id to the OR with identity digest to_name, but failed.
References link_history_t::changed, get_link_history(), and link_history_t::n_extend_fail.
Referenced by circuit_rep_hist_note_result().
void rep_hist_note_extend_succeeded | ( | const char * | from_id, | |
const char * | to_id | |||
) |
Remember that we successfully extended from the OR with identity digest from_id to the OR with identity digest to_name.
References link_history_t::changed, get_link_history(), and link_history_t::n_extend_ok.
Referenced by circuit_rep_hist_note_result().
void rep_hist_note_router_reachable | ( | const char * | id, | |
time_t | when | |||
) |
We have just decided that this router with identity digest id is reachable, meaning we will give it a "Running" flag for the next while.
References DIGEST_LEN, format_local_iso_time(), get_or_history(), hex_str(), LD_HIST, or_history_t::start_of_downtime, or_history_t::start_of_run, started_tracking_stability, tor_assert, and or_history_t::total_weighted_time.
Referenced by dirserv_orconn_tls_done().
void rep_hist_note_router_unreachable | ( | const char * | id, | |
time_t | when | |||
) |
We have just decided that this router is unreachable, meaning we are taking away its "Running" flag.
References DIGEST_LEN, format_local_iso_time(), get_or_history(), hex_str(), LD_HIST, or_history_t::start_of_downtime, or_history_t::start_of_run, started_tracking_stability, tor_assert, or_history_t::total_run_weights, or_history_t::total_weighted_time, or_history_t::weighted_run_length, and or_history_t::weighted_uptime.
Referenced by dirserv_set_router_is_running(), rep_hist_record_mtbf_data(), and routerlist_remove().
void rep_hist_note_used_internal | ( | time_t | now, | |
int | need_uptime, | |||
int | need_capacity | |||
) |
Remember that we used an internal circ at time now.
References predicted_internal_capacity_time, predicted_internal_time, and predicted_internal_uptime_time.
Referenced by circuit_get_open_circ_or_launch(), directory_initiate_command_rend(), rend_service_introduce(), and rend_service_launch_establish_intro().
void rep_hist_note_used_port | ( | time_t | now, | |
uint16_t | port | |||
) |
Remember that port has been asked for as of time now. This is used for predicting what sorts of streams we'll make in the future and making exit circuits to anticipate that.
References add_predicted_port(), and tor_assert.
Referenced by directory_initiate_command_rend(), and rep_hist_note_used_resolve().
void rep_hist_note_used_resolve | ( | time_t | now | ) |
The user asked us to do a resolve. Rather than keeping track of timings and such of resolves, we fake it for now by treating it the same way as a connection to port 80. This way we will continue to have circuits lying around if the user only uses Tor for resolves.
References rep_hist_note_used_port().
int rep_hist_record_mtbf_data | ( | time_t | now, | |
int | missing_means_down | |||
) |
Write MTBF data to disk. Return 0 on success, negative on failure.
If missing_means_down, then if we're about to write an entry that is still considered up but isn't in our routerlist, consider it to be down.
References abort_writing_to_file(), base16_encode(), DIGEST_LEN, digestmap_iter_done(), digestmap_iter_get(), digestmap_iter_init(), digestmap_iter_next(), finish_writing_to_file(), format_iso_time(), get_datadir_fname, HEX_DIGEST_LEN, history_map, LD_HIST, rep_hist_note_router_unreachable(), router_get_by_digest(), stability_last_downrated, or_history_t::start_of_downtime, or_history_t::start_of_run, start_writing_to_stdio_file(), started_tracking_stability, tor_free, or_history_t::total_run_weights, or_history_t::total_weighted_time, or_history_t::weighted_run_length, and or_history_t::weighted_uptime.
Referenced by run_scheduled_events(), and tor_cleanup().
void rep_hist_update_state | ( | or_state_t * | state | ) |
Update state with the newest bandwidth history.
References or_options_t::AvoidDiskWrites, or_state_t::BWHistoryReadEnds, or_state_t::BWHistoryReadInterval, or_state_t::BWHistoryReadValues, or_state_t::BWHistoryWriteEnds, or_state_t::BWHistoryWriteInterval, or_state_t::BWHistoryWriteValues, get_options(), get_or_state(), bw_array_t::next_period, NUM_SECS_BW_SUM_INTERVAL, NUM_TOTALS, or_state_mark_dirty(), rep_hist_fill_bandwidth_history(), server_mode(), smartlist_create(), smartlist_free(), smartlist_split_string(), tor_free, tor_snprintf(), and bw_array_t::total_in_period.
Referenced by or_state_save().
void rep_history_clean | ( | time_t | before | ) |
Remove history info for routers/links that haven't changed since before.
References authdir_mode(), link_history_t::changed, or_history_t::changed, digestmap_iter_done(), digestmap_iter_get(), digestmap_iter_init(), digestmap_iter_next(), digestmap_iter_next_rmv(), free_or_history(), get_options(), history_map, or_history_t::link_history_map, rephist_total_alloc, STABILITY_EPSILON, or_history_t::start_of_run, tor_free, and or_history_t::total_run_weights.
Referenced by rep_hist_dump_stats(), and run_scheduled_events().
static void update_or_history | ( | or_history_t * | hist, | |
time_t | when | |||
) | [static] |
Update an or_history_t object hist so that its uptime/downtime count is up-to-date as of when.
References or_history_t::down_since, or_history_t::downtime, tor_assert, or_history_t::up_since, and or_history_t::uptime.
Referenced by rep_hist_dump_stats().
time_t built_last_stability_doc_at = 0 [static] |
The last time we created a stability analysis document, or 0 if we never have created one.
Referenced by rep_hist_free_all(), and rep_hist_get_router_stability_doc().
smartlist_t* circuits_for_buffer_stats = NULL |
Holds stats.
uint64_t* exit_bytes_read = NULL [static] |
Number of bytes read in current period by exit port
Referenced by rep_hist_exit_stats_init(), rep_hist_exit_stats_write(), rep_hist_free_all(), and rep_hist_note_exit_bytes_read().
uint64_t* exit_bytes_written = NULL [static] |
Number of bytes written in current period by exit port
Referenced by rep_hist_exit_stats_init(), rep_hist_exit_stats_write(), rep_hist_free_all(), and rep_hist_note_exit_bytes_written().
uint32_t* exit_streams = NULL [static] |
Number of streams opened in current period by exit port
Referenced by rep_hist_exit_stats_init(), rep_hist_exit_stats_write(), rep_hist_free_all(), and rep_hist_note_exit_stream_opened().
digestmap_t* history_map = NULL [static] |
Map from hex OR identity digest to or_history_t.
Referenced by get_or_history(), rep_hist_downrate_old_runs(), rep_hist_dump_stats(), rep_hist_free_all(), rep_hist_get_router_stability_doc(), rep_hist_init(), rep_hist_record_mtbf_data(), and rep_history_clean().
char* last_stability_doc = NULL [static] |
The last stability analysis document that we created, or NULL if we never have created one.
Referenced by rep_hist_free_all(), and rep_hist_get_router_stability_doc().
int n_bogus_times = 0 [static] |
How many bad times has parse_possibly_bad_iso_time parsed?
Referenced by parse_possibly_bad_iso_time(), and rep_hist_load_mtbf_data().
unsigned long n_onionskins_decrypted |
How many onionskins have we decrypted to do circuit build requests?
unsigned long n_onionskins_encrypted |
How many onionskins have we encrypted to build circuits?
unsigned long n_rend_client_ops |
How many PK operations have we done as a hidden service client?
unsigned long n_rend_mid_ops |
How many PK operations have we done as a hidden service midpoint?
unsigned long n_rend_server_ops |
How many PK operations have we done as a hidden service provider?
unsigned long n_signed_dir_objs |
How many directory objects have we signed?
unsigned long n_signed_routerdescs |
How many routerdescs have we signed?
unsigned long n_tls_client_handshakes |
How many times have we done the TLS handshake as a client?
unsigned long n_tls_server_handshakes |
How many times have we done the TLS handshake as a server?
unsigned long n_verified_dir_objs |
How many directory objects have we verified?
unsigned long n_verified_routerdescs |
How many routerdescs have we verified
struct { ... } pk_op_counts [static] |
Structure to track how many times we've done each public key operation.
Referenced by dump_pk_ops(), and note_crypto_pk_op().
time_t predicted_internal_capacity_time = 0 [static] |
The last time we needed an internal circ with good capacity.
Referenced by rep_hist_get_predicted_internal(), and rep_hist_note_used_internal().
time_t predicted_internal_time = 0 [static] |
The last time at which we needed an internal circ.
Referenced by any_predicted_circuits(), rep_hist_get_predicted_internal(), and rep_hist_note_used_internal().
time_t predicted_internal_uptime_time = 0 [static] |
The last time we needed an internal circ with good uptime.
Referenced by rep_hist_get_predicted_internal(), and rep_hist_note_used_internal().
smartlist_t* predicted_ports_list = NULL [static] |
A list of port numbers that have been used recently.
smartlist_t* predicted_ports_times = NULL [static] |
The corresponding most recently used time for each port.
bw_array_t* read_array = NULL [static] |
Recent history of bandwidth observations for read operations.
uint64_t rephist_total_alloc = 0 |
Total number of bytes currently allocated in fields used by rephist.c.
Referenced by _free_link_history(), add_predicted_port(), bw_array_new(), dumpmemusage(), free_or_history(), get_link_history(), get_or_history(), predicted_ports_free(), rep_hist_get_predicted_ports(), and rep_history_clean().
uint32_t rephist_total_num = 0 |
Number of or_history_t objects currently allocated.
Referenced by dumpmemusage(), free_or_history(), and get_or_history().
time_t stability_last_downrated = 0 [static] |
When did we last multiply all routers' weighted_run_length and total_run_weights by STABILITY_ALPHA?
Referenced by rep_hist_downrate_old_runs(), rep_hist_load_mtbf_data(), and rep_hist_record_mtbf_data().
time_t start_of_buffer_stats_interval [static] |
Start of the current buffer stats interval.
Referenced by rep_hist_buffer_stats_add_circ(), rep_hist_buffer_stats_init(), and rep_hist_buffer_stats_write().
time_t start_of_exit_stats_interval [static] |
When does the current exit stats period end?
Referenced by rep_hist_exit_stats_init(), and rep_hist_exit_stats_write().
time_t started_tracking_stability = 0 [static] |
bw_array_t* write_array = NULL [static] |
Recent history of bandwidth observations for write operations.