1 /* Copyright (c) 2001 Matej Pfajfar.
2 * Copyright (c) 2001-2004, Roger Dingledine.
3 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
4 * Copyright (c) 2007-2016, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
9 * \brief Header file for circuitstats.c
12 #ifndef TOR_CIRCUITSTATS_H
13 #define TOR_CIRCUITSTATS_H
15 const circuit_build_times_t
*get_circuit_build_times(void);
16 circuit_build_times_t
*get_circuit_build_times_mutable(void);
17 double get_circuit_build_close_time_ms(void);
18 double get_circuit_build_timeout_ms(void);
20 int circuit_build_times_disabled(void);
21 int circuit_build_times_enough_to_compute(const circuit_build_times_t
*cbt
);
22 void circuit_build_times_update_state(const circuit_build_times_t
*cbt
,
24 int circuit_build_times_parse_state(circuit_build_times_t
*cbt
,
26 void circuit_build_times_count_timeout(circuit_build_times_t
*cbt
,
28 int circuit_build_times_count_close(circuit_build_times_t
*cbt
,
29 int did_onehop
, time_t start_time
);
30 void circuit_build_times_set_timeout(circuit_build_times_t
*cbt
);
31 int circuit_build_times_add_time(circuit_build_times_t
*cbt
,
33 int circuit_build_times_needs_circuits(const circuit_build_times_t
*cbt
);
35 int circuit_build_times_needs_circuits_now(const circuit_build_times_t
*cbt
);
36 void circuit_build_times_init(circuit_build_times_t
*cbt
);
37 void circuit_build_times_free_timeouts(circuit_build_times_t
*cbt
);
38 void circuit_build_times_new_consensus_params(circuit_build_times_t
*cbt
,
40 double circuit_build_times_timeout_rate(const circuit_build_times_t
*cbt
);
41 double circuit_build_times_close_rate(const circuit_build_times_t
*cbt
);
43 void circuit_build_times_update_last_circ(circuit_build_times_t
*cbt
);
45 #ifdef CIRCUITSTATS_PRIVATE
46 STATIC
double circuit_build_times_calculate_timeout(circuit_build_times_t
*cbt
,
48 STATIC
int circuit_build_times_update_alpha(circuit_build_times_t
*cbt
);
49 STATIC
void circuit_build_times_reset(circuit_build_times_t
*cbt
);
51 /* Network liveness functions */
52 STATIC
int circuit_build_times_network_check_changed(
53 circuit_build_times_t
*cbt
);
57 build_time_t
circuit_build_times_generate_sample(circuit_build_times_t
*cbt
,
58 double q_lo
, double q_hi
);
59 double circuit_build_times_cdf(circuit_build_times_t
*cbt
, double x
);
60 void circuit_build_times_initial_alpha(circuit_build_times_t
*cbt
,
61 double quantile
, double time_ms
);
62 void circuitbuild_running_unit_tests(void);
65 /* Network liveness functions */
66 void circuit_build_times_network_is_live(circuit_build_times_t
*cbt
);
67 int circuit_build_times_network_check_live(const circuit_build_times_t
*cbt
);
68 void circuit_build_times_network_circ_success(circuit_build_times_t
*cbt
);
70 #ifdef CIRCUITSTATS_PRIVATE
71 /** Structure for circuit build times history */
72 struct circuit_build_times_s
{
73 /** The circular array of recorded build times in milliseconds */
74 build_time_t circuit_build_times
[CBT_NCIRCUITS_TO_OBSERVE
];
75 /** Current index in the circuit_build_times circular array */
77 /** Total number of build times accumulated. Max CBT_NCIRCUITS_TO_OBSERVE */
78 int total_build_times
;
79 /** Information about the state of our local network connection */
80 network_liveness_t liveness
;
81 /** Last time we built a circuit. Used to decide to build new test circs */
83 /** "Minimum" value of our pareto distribution (actually mode) */
85 /** alpha exponent for pareto dist. */
87 /** Have we computed a timeout? */
88 int have_computed_timeout
;
89 /** The exact value for that timeout in milliseconds. Stored as a double
90 * to maintain precision from calculations to and from quantile value. */
92 /** How long we wait before actually closing the circuit. */