2012-10-15 20:48:34 +02:00
|
|
|
/* Copyright (c) 2001 Matej Pfajfar.
|
|
|
|
* Copyright (c) 2001-2004, Roger Dingledine.
|
|
|
|
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
|
2017-03-15 21:13:17 +01:00
|
|
|
* Copyright (c) 2007-2017, The Tor Project, Inc. */
|
2012-10-15 20:48:34 +02:00
|
|
|
/* See LICENSE for licensing information */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* \file circuitstats.h
|
|
|
|
* \brief Header file for circuitstats.c
|
|
|
|
**/
|
|
|
|
|
|
|
|
#ifndef TOR_CIRCUITSTATS_H
|
|
|
|
#define TOR_CIRCUITSTATS_H
|
|
|
|
|
2013-08-21 18:10:05 +02:00
|
|
|
const circuit_build_times_t *get_circuit_build_times(void);
|
|
|
|
circuit_build_times_t *get_circuit_build_times_mutable(void);
|
2013-08-21 17:59:19 +02:00
|
|
|
double get_circuit_build_close_time_ms(void);
|
|
|
|
double get_circuit_build_timeout_ms(void);
|
2012-10-15 20:48:34 +02:00
|
|
|
|
2017-01-18 18:53:01 +01:00
|
|
|
int circuit_build_times_disabled(const or_options_t *options);
|
2017-05-16 17:20:12 +02:00
|
|
|
int circuit_build_times_disabled_(const or_options_t *options,
|
|
|
|
int ignore_consensus);
|
|
|
|
|
2013-08-21 18:10:05 +02:00
|
|
|
int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt);
|
|
|
|
void circuit_build_times_update_state(const circuit_build_times_t *cbt,
|
2012-10-15 20:48:34 +02:00
|
|
|
or_state_t *state);
|
|
|
|
int circuit_build_times_parse_state(circuit_build_times_t *cbt,
|
|
|
|
or_state_t *state);
|
|
|
|
void circuit_build_times_count_timeout(circuit_build_times_t *cbt,
|
|
|
|
int did_onehop);
|
|
|
|
int circuit_build_times_count_close(circuit_build_times_t *cbt,
|
|
|
|
int did_onehop, time_t start_time);
|
|
|
|
void circuit_build_times_set_timeout(circuit_build_times_t *cbt);
|
|
|
|
int circuit_build_times_add_time(circuit_build_times_t *cbt,
|
|
|
|
build_time_t time);
|
2013-08-21 18:10:05 +02:00
|
|
|
int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt);
|
2017-08-04 23:16:38 +02:00
|
|
|
void circuit_build_times_handle_completed_hop(origin_circuit_t *circ);
|
2012-10-15 20:48:34 +02:00
|
|
|
|
2013-08-21 18:10:05 +02:00
|
|
|
int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt);
|
2012-10-15 20:48:34 +02:00
|
|
|
void circuit_build_times_init(circuit_build_times_t *cbt);
|
|
|
|
void circuit_build_times_free_timeouts(circuit_build_times_t *cbt);
|
|
|
|
void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
|
|
|
|
networkstatus_t *ns);
|
|
|
|
double circuit_build_times_timeout_rate(const circuit_build_times_t *cbt);
|
|
|
|
double circuit_build_times_close_rate(const circuit_build_times_t *cbt);
|
|
|
|
|
2013-08-21 18:37:35 +02:00
|
|
|
void circuit_build_times_update_last_circ(circuit_build_times_t *cbt);
|
2017-12-07 01:04:09 +01:00
|
|
|
void circuit_build_times_mark_circ_as_measurement_only(origin_circuit_t *circ);
|
2013-08-21 18:37:35 +02:00
|
|
|
|
2012-10-15 20:48:34 +02:00
|
|
|
#ifdef CIRCUITSTATS_PRIVATE
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC double circuit_build_times_calculate_timeout(circuit_build_times_t *cbt,
|
2012-10-15 20:48:34 +02:00
|
|
|
double quantile);
|
2013-06-06 23:58:28 +02:00
|
|
|
STATIC int circuit_build_times_update_alpha(circuit_build_times_t *cbt);
|
|
|
|
STATIC void circuit_build_times_reset(circuit_build_times_t *cbt);
|
|
|
|
|
|
|
|
/* Network liveness functions */
|
|
|
|
STATIC int circuit_build_times_network_check_changed(
|
|
|
|
circuit_build_times_t *cbt);
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(CIRCUITSTATS_PRIVATE) */
|
2013-06-06 23:58:28 +02:00
|
|
|
|
|
|
|
#ifdef TOR_UNIT_TESTS
|
2012-10-15 20:48:34 +02:00
|
|
|
build_time_t circuit_build_times_generate_sample(circuit_build_times_t *cbt,
|
|
|
|
double q_lo, double q_hi);
|
2013-06-06 23:58:28 +02:00
|
|
|
double circuit_build_times_cdf(circuit_build_times_t *cbt, double x);
|
2012-10-15 20:48:34 +02:00
|
|
|
void circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
|
|
|
|
double quantile, double time_ms);
|
|
|
|
void circuitbuild_running_unit_tests(void);
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(TOR_UNIT_TESTS) */
|
2012-10-15 20:48:34 +02:00
|
|
|
|
|
|
|
/* Network liveness functions */
|
|
|
|
void circuit_build_times_network_is_live(circuit_build_times_t *cbt);
|
2013-08-21 18:10:05 +02:00
|
|
|
int circuit_build_times_network_check_live(const circuit_build_times_t *cbt);
|
2012-10-15 20:48:34 +02:00
|
|
|
void circuit_build_times_network_circ_success(circuit_build_times_t *cbt);
|
|
|
|
|
2013-08-21 18:37:35 +02:00
|
|
|
#ifdef CIRCUITSTATS_PRIVATE
|
|
|
|
/** Structure for circuit build times history */
|
2013-08-25 18:22:20 +02:00
|
|
|
struct circuit_build_times_s {
|
2013-08-21 18:37:35 +02:00
|
|
|
/** The circular array of recorded build times in milliseconds */
|
|
|
|
build_time_t circuit_build_times[CBT_NCIRCUITS_TO_OBSERVE];
|
|
|
|
/** Current index in the circuit_build_times circular array */
|
|
|
|
int build_times_idx;
|
|
|
|
/** Total number of build times accumulated. Max CBT_NCIRCUITS_TO_OBSERVE */
|
|
|
|
int total_build_times;
|
|
|
|
/** Information about the state of our local network connection */
|
|
|
|
network_liveness_t liveness;
|
|
|
|
/** Last time we built a circuit. Used to decide to build new test circs */
|
|
|
|
time_t last_circ_at;
|
|
|
|
/** "Minimum" value of our pareto distribution (actually mode) */
|
|
|
|
build_time_t Xm;
|
|
|
|
/** alpha exponent for pareto dist. */
|
|
|
|
double alpha;
|
|
|
|
/** Have we computed a timeout? */
|
|
|
|
int have_computed_timeout;
|
|
|
|
/** The exact value for that timeout in milliseconds. Stored as a double
|
|
|
|
* to maintain precision from calculations to and from quantile value. */
|
|
|
|
double timeout_ms;
|
|
|
|
/** How long we wait before actually closing the circuit. */
|
|
|
|
double close_ms;
|
2017-12-07 00:56:03 +01:00
|
|
|
/** Total succeeded counts. Old measurements may be scaled downward if
|
|
|
|
* we've seen a lot of circuits. */
|
|
|
|
uint32_t num_circ_succeeded;
|
|
|
|
/** Total timeout counts. Old measurements may be scaled downward if
|
|
|
|
* we've seen a lot of circuits. */
|
|
|
|
uint32_t num_circ_timeouts;
|
|
|
|
/** Total closed counts. Old measurements may be scaled downward if
|
|
|
|
* we've seen a lot of circuits.*/
|
|
|
|
uint32_t num_circ_closed;
|
|
|
|
|
2013-08-21 18:37:35 +02:00
|
|
|
};
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* defined(CIRCUITSTATS_PRIVATE) */
|
2013-08-21 18:37:35 +02:00
|
|
|
|
2017-09-15 22:24:44 +02:00
|
|
|
#endif /* !defined(TOR_CIRCUITSTATS_H) */
|
2012-10-15 20:48:34 +02:00
|
|
|
|