tor  0.4.0.0-alpha-dev
circuitstats.h
Go to the documentation of this file.
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-2018, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_CIRCUITSTATS_H
13 #define TOR_CIRCUITSTATS_H
14 
15 const circuit_build_times_t *get_circuit_build_times(void);
16 circuit_build_times_t *get_circuit_build_times_mutable(void);
18 double get_circuit_build_timeout_ms(void);
19 
20 int circuit_build_times_disabled(const or_options_t *options);
22  int ignore_consensus);
23 
25 typedef uint32_t build_time_t;
26 
27 int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt);
28 void circuit_build_times_update_state(const circuit_build_times_t *cbt,
29  or_state_t *state);
30 int circuit_build_times_parse_state(circuit_build_times_t *cbt,
31  or_state_t *state);
32 void circuit_build_times_count_timeout(circuit_build_times_t *cbt,
33  int did_onehop);
34 int circuit_build_times_count_close(circuit_build_times_t *cbt,
35  int did_onehop, time_t start_time);
36 void circuit_build_times_set_timeout(circuit_build_times_t *cbt);
37 int circuit_build_times_add_time(circuit_build_times_t *cbt,
38  build_time_t time);
39 int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt);
41 
42 int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt);
43 void circuit_build_times_init(circuit_build_times_t *cbt);
44 void circuit_build_times_free_timeouts(circuit_build_times_t *cbt);
45 void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt,
46  networkstatus_t *ns);
47 double circuit_build_times_timeout_rate(const circuit_build_times_t *cbt);
48 double circuit_build_times_close_rate(const circuit_build_times_t *cbt);
49 
50 void circuit_build_times_update_last_circ(circuit_build_times_t *cbt);
52 
55 #define CBT_NCIRCUITS_TO_OBSERVE 1000
56 
58 #define CBT_BIN_WIDTH ((build_time_t)50)
59 
61 #define CBT_DEFAULT_NUM_XM_MODES 3
62 #define CBT_MIN_NUM_XM_MODES 1
63 #define CBT_MAX_NUM_XM_MODES 20
64 
69 #define CBT_BUILD_ABANDONED ((build_time_t)(INT32_MAX-1))
70 #define CBT_BUILD_TIME_MAX ((build_time_t)(INT32_MAX))
71 
73 #define CBT_SAVE_STATE_EVERY 10
74 
75 /* Circuit build times consensus parameters */
76 
81 #define CBT_DEFAULT_CLOSE_QUANTILE 95
82 #define CBT_MIN_CLOSE_QUANTILE CBT_MIN_QUANTILE_CUTOFF
83 #define CBT_MAX_CLOSE_QUANTILE CBT_MAX_QUANTILE_CUTOFF
84 
89 #define CBT_DEFAULT_RECENT_CIRCUITS 20
90 #define CBT_MIN_RECENT_CIRCUITS 3
91 #define CBT_MAX_RECENT_CIRCUITS 1000
92 
101 #define CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT (CBT_DEFAULT_RECENT_CIRCUITS*9/10)
102 #define CBT_MIN_MAX_RECENT_TIMEOUT_COUNT 3
103 #define CBT_MAX_MAX_RECENT_TIMEOUT_COUNT 10000
104 
106 #define CBT_DEFAULT_MIN_CIRCUITS_TO_OBSERVE 100
107 #define CBT_MIN_MIN_CIRCUITS_TO_OBSERVE 1
108 #define CBT_MAX_MIN_CIRCUITS_TO_OBSERVE 10000
109 
111 #define CBT_DEFAULT_QUANTILE_CUTOFF 80
112 #define CBT_MIN_QUANTILE_CUTOFF 10
113 #define CBT_MAX_QUANTILE_CUTOFF 99
115 
117 #define CBT_DEFAULT_TEST_FREQUENCY 10
118 #define CBT_MIN_TEST_FREQUENCY 1
119 #define CBT_MAX_TEST_FREQUENCY INT32_MAX
120 
122 #define CBT_DEFAULT_TIMEOUT_MIN_VALUE (1500)
123 #define CBT_MIN_TIMEOUT_MIN_VALUE 500
124 #define CBT_MAX_TIMEOUT_MIN_VALUE INT32_MAX
125 
127 #define CBT_DEFAULT_TIMEOUT_INITIAL_VALUE (60*1000)
128 #define CBT_MIN_TIMEOUT_INITIAL_VALUE CBT_MIN_TIMEOUT_MIN_VALUE
129 #define CBT_MAX_TIMEOUT_INITIAL_VALUE INT32_MAX
131 
132 #if CBT_DEFAULT_MAX_RECENT_TIMEOUT_COUNT < CBT_MIN_MAX_RECENT_TIMEOUT_COUNT
133 #error "RECENT_CIRCUITS is set too low."
134 #endif
135 
136 #ifdef CIRCUITSTATS_PRIVATE
137 STATIC double circuit_build_times_calculate_timeout(circuit_build_times_t *cbt,
138  double quantile);
139 STATIC int circuit_build_times_update_alpha(circuit_build_times_t *cbt);
140 STATIC void circuit_build_times_reset(circuit_build_times_t *cbt);
141 
142 /* Network liveness functions */
144  circuit_build_times_t *cbt);
145 #endif /* defined(CIRCUITSTATS_PRIVATE) */
146 
147 #ifdef TOR_UNIT_TESTS
148 build_time_t circuit_build_times_generate_sample(circuit_build_times_t *cbt,
149  double q_lo, double q_hi);
150 double circuit_build_times_cdf(circuit_build_times_t *cbt, double x);
151 void circuit_build_times_initial_alpha(circuit_build_times_t *cbt,
152  double quantile, double time_ms);
153 void circuitbuild_running_unit_tests(void);
154 #endif /* defined(TOR_UNIT_TESTS) */
155 
156 /* Network liveness functions */
157 void circuit_build_times_network_is_live(circuit_build_times_t *cbt);
158 int circuit_build_times_network_check_live(const circuit_build_times_t *cbt);
159 void circuit_build_times_network_circ_success(circuit_build_times_t *cbt);
160 
161 #ifdef CIRCUITSTATS_PRIVATE
162 
163 typedef struct {
165  time_t network_last_live;
167  int nonlive_timeouts;
170  int8_t *timeouts_after_firsthop;
172  int num_recent_circs;
174  int after_firsthop_idx;
175 } network_liveness_t;
176 
178 struct circuit_build_times_s {
180  build_time_t circuit_build_times[CBT_NCIRCUITS_TO_OBSERVE];
182  int build_times_idx;
184  int total_build_times;
186  network_liveness_t liveness;
188  time_t last_circ_at;
190  build_time_t Xm;
192  double alpha;
194  int have_computed_timeout;
197  double timeout_ms;
199  double close_ms;
202  uint32_t num_circ_succeeded;
205  uint32_t num_circ_timeouts;
208  uint32_t num_circ_closed;
209 
210 };
211 #endif /* defined(CIRCUITSTATS_PRIVATE) */
212 
213 #endif /* !defined(TOR_CIRCUITSTATS_H) */
int32_t circuit_build_times_initial_timeout(void)
Definition: circuitstats.c:373
void circuit_build_times_set_timeout(circuit_build_times_t *cbt)
void circuit_build_times_free_timeouts(circuit_build_times_t *cbt)
Definition: circuitstats.c:594
uint32_t build_time_t
Definition: circuitstats.h:25
int circuit_build_times_count_close(circuit_build_times_t *cbt, int did_onehop, time_t start_time)
void circuit_build_times_init(circuit_build_times_t *cbt)
Definition: circuitstats.c:568
double circuit_build_times_close_rate(const circuit_build_times_t *cbt)
const circuit_build_times_t * get_circuit_build_times(void)
Definition: circuitstats.c:81
double circuit_build_times_timeout_rate(const circuit_build_times_t *cbt)
void circuit_build_times_new_consensus_params(circuit_build_times_t *cbt, networkstatus_t *ns)
Definition: circuitstats.c:429
STATIC double circuit_build_times_calculate_timeout(circuit_build_times_t *cbt, double quantile)
double get_circuit_build_close_time_ms(void)
Definition: circuitstats.c:96
double circuit_build_times_quantile_cutoff(void)
Definition: circuitstats.c:270
STATIC int circuit_build_times_network_check_changed(circuit_build_times_t *cbt)
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)
#define CBT_NCIRCUITS_TO_OBSERVE
Definition: circuitstats.h:55
int circuit_build_times_disabled(const or_options_t *options)
Definition: circuitstats.c:120
void circuit_build_times_network_circ_success(circuit_build_times_t *cbt)
void circuit_build_times_mark_circ_as_measurement_only(origin_circuit_t *circ)
Definition: circuitstats.c:640
int circuit_build_times_disabled_(const or_options_t *options, int ignore_consensus)
Definition: circuitstats.c:127
circuit_build_times_t * get_circuit_build_times_mutable(void)
Definition: circuitstats.c:88
int circuit_build_times_enough_to_compute(const circuit_build_times_t *cbt)
Definition: circuitstats.c:258
int circuit_build_times_network_check_live(const circuit_build_times_t *cbt)
double get_circuit_build_timeout_ms(void)
Definition: circuitstats.c:104
int circuit_build_times_add_time(circuit_build_times_t *cbt, build_time_t time)
Definition: circuitstats.c:759
void circuit_build_times_update_state(const circuit_build_times_t *cbt, or_state_t *state)
Definition: circuitstats.c:931
STATIC void circuit_build_times_reset(circuit_build_times_t *cbt)
Definition: circuitstats.c:548
int circuit_build_times_needs_circuits(const circuit_build_times_t *cbt)
STATIC int circuit_build_times_update_alpha(circuit_build_times_t *cbt)
void circuit_build_times_handle_completed_hop(origin_circuit_t *circ)
Definition: circuitstats.c:682
int circuit_build_times_needs_circuits_now(const circuit_build_times_t *cbt)
void circuit_build_times_network_is_live(circuit_build_times_t *cbt)