Tor  0.4.7.0-alpha-dev
rephist.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-2021, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
7 /**
8  * \file rephist.h
9  * \brief Header file for rephist.c.
10  **/
11 
12 #ifndef TOR_REPHIST_H
13 #define TOR_REPHIST_H
14 
15 void rep_hist_init(void);
16 void rep_hist_dump_stats(time_t now, int severity);
17 
18 void rep_hist_make_router_pessimal(const char *id, time_t when);
19 
20 void rep_history_clean(time_t before);
21 
22 void rep_hist_note_router_reachable(const char *id, const tor_addr_t *at_addr,
23  const uint16_t at_port, time_t when);
24 void rep_hist_note_router_unreachable(const char *id, time_t when);
25 int rep_hist_record_mtbf_data(time_t now, int missing_means_down);
26 int rep_hist_load_mtbf_data(time_t now);
27 
28 time_t rep_hist_downrate_old_runs(time_t now);
29 long rep_hist_get_uptime(const char *id, time_t when);
30 double rep_hist_get_stability(const char *id, time_t when);
31 double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when);
32 long rep_hist_get_weighted_time_known(const char *id, time_t when);
34 
35 void rep_hist_exit_stats_init(time_t now);
36 void rep_hist_reset_exit_stats(time_t now);
37 void rep_hist_exit_stats_term(void);
38 char *rep_hist_format_exit_stats(time_t now);
39 time_t rep_hist_exit_stats_write(time_t now);
40 void rep_hist_note_exit_bytes(uint16_t port, size_t num_written,
41  size_t num_read);
42 void rep_hist_note_exit_stream_opened(uint16_t port);
43 
44 void rep_hist_buffer_stats_init(time_t now);
46  time_t end_of_interval);
47 time_t rep_hist_buffer_stats_write(time_t now);
49 void rep_hist_add_buffer_stats(double mean_num_cells_in_queue,
50  double mean_time_cells_in_queue, uint32_t processed_cells);
51 char *rep_hist_format_buffer_stats(time_t now);
52 void rep_hist_reset_buffer_stats(time_t now);
53 
54 void rep_hist_desc_stats_init(time_t now);
55 void rep_hist_note_desc_served(const char * desc);
56 void rep_hist_desc_stats_term(void);
57 time_t rep_hist_desc_stats_write(time_t now);
58 
61 void rep_hist_note_circuit_handshake_dropped(uint16_t type);
63 
66 MOCK_DECL(uint64_t, rep_hist_get_circuit_handshake_dropped, (uint16_t type));
67 
68 void rep_hist_hs_stats_init(time_t now);
69 void rep_hist_hs_stats_term(void);
70 time_t rep_hist_hs_stats_write(time_t now, bool is_v3);
71 
72 void rep_hist_seen_new_rp_cell(bool is_v2);
73 
74 char *rep_hist_get_hs_v3_stats_string(void);
75 void rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key);
76 
77 void rep_hist_free_all(void);
78 
79 void rep_hist_note_negotiated_link_proto(unsigned link_proto,
80  int started_here);
82 
83 uint64_t rep_hist_get_n_dns_error(int type, uint8_t error);
84 uint64_t rep_hist_get_n_dns_request(int type);
85 void rep_hist_note_dns_request(int type);
86 void rep_hist_note_dns_error(int type, uint8_t error);
87 
88 extern uint64_t rephist_total_alloc;
89 extern uint32_t rephist_total_num;
90 #ifdef TOR_UNIT_TESTS
91 extern int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1];
92 extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1];
93 extern uint64_t onion_handshakes_dropped[MAX_ONION_HANDSHAKE_TYPE+1];
94 #endif
95 
96 #ifdef REPHIST_PRIVATE
97 /** Carries the various hidden service statistics, and any other
98  * information needed. */
99 typedef struct hs_v2_stats_t {
100  /** How many v2 relay cells have we seen as rendezvous points? */
101  uint64_t rp_v2_relay_cells_seen;
102 } hs_v2_stats_t;
103 
104 /** Structure that contains the various statistics we keep about v3
105  * services.
106  *
107  * Because of the time period logic of v3 services, v3 statistics are more
108  * sensitive to time than v2 stats. For this reason, we collect v3
109  * statistics strictly from 12:00UTC to 12:00UTC as dictated by
110  * 'start_of_hs_v3_stats_interval'.
111  **/
112 typedef struct hs_v3_stats_t {
113  /** How many v3 relay cells have we seen as a rendezvous point? */
114  uint64_t rp_v3_relay_cells_seen;
115 
116  /* The number of unique v3 onion descriptors (actually, unique v3 blind keys)
117  * we've seen during the measurement period */
118  digest256map_t *v3_onions_seen_this_period;
119 } hs_v3_stats_t;
120 
122 
123 STATIC char *rep_hist_format_hs_stats(time_t now, bool is_v3);
124 #endif /* defined(REPHIST_PRIVATE) */
125 
126 /**
127  * Represents the type of a cell for padding accounting
128  */
129 typedef enum padding_type_t {
130  /** A RELAY_DROP cell */
132  /** A CELL_PADDING cell */
134  /** Total counts of padding and non-padding together */
136  /** Total cell counts for all padding-enabled channels */
138  /** CELL_PADDING counts for all padding-enabled channels */
141 
142 /** The amount of time over which the padding cell counts were counted */
143 #define REPHIST_CELL_PADDING_COUNTS_INTERVAL (24*60*60)
148 void rep_hist_prep_published_padding_counts(time_t now);
149 void rep_hist_padding_count_timers(uint64_t num_timers);
150 
151 /**
152  * Represents the various types of overload we keep track of and expose in our
153  * extra-info descriptor.
154 */
155 typedef enum {
156  /* A general overload -- can have many different causes. */
157  OVERLOAD_GENERAL,
158  /* We went over our configured read rate/burst bandwidth limit */
159  OVERLOAD_READ,
160  /* We went over our configured write rate/burst bandwidth limit */
161  OVERLOAD_WRITE,
162  /* We exhausted the file descriptors in this system */
163  OVERLOAD_FD_EXHAUSTED,
165 
169 
171 uint64_t rep_hist_get_n_tcp_exhaustion(void);
172 
173 uint64_t rep_hist_get_n_read_limit_reached(void);
175 
176 #ifdef TOR_UNIT_TESTS
177 struct hs_v2_stats_t;
178 const struct hs_v2_stats_t *rep_hist_get_hs_v2_stats(void);
179 struct hs_v3_stats_t;
180 const struct hs_v3_stats_t *rep_hist_get_hs_v3_stats(void);
181 #endif /* defined(TOR_UNIT_TESTS) */
182 
183 #endif /* !defined(TOR_REPHIST_H) */
STATIC int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1]
Definition: rephist.c:2002
STATIC char * rep_hist_format_hs_stats(time_t now, bool is_v3)
Definition: rephist.c:2318
STATIC bool should_collect_v3_stats(void)
Definition: rephist.c:2213
void rep_hist_note_dns_error(int type, uint8_t error)
Definition: rephist.c:325
void rep_hist_note_desc_served(const char *desc)
Definition: rephist.c:1982
void rep_hist_buffer_stats_term(void)
Definition: rephist.c:1689
time_t rep_hist_downrate_old_runs(time_t now)
Definition: rephist.c:718
void rep_hist_note_exit_bytes(uint16_t port, size_t num_written, size_t num_read)
Definition: rephist.c:1567
void rep_hist_note_negotiated_link_proto(unsigned link_proto, int started_here)
Definition: rephist.c:2412
padding_type_t
Definition: rephist.h:129
@ PADDING_TYPE_DROP
Definition: rephist.h:131
@ PADDING_TYPE_ENABLED_CELL
Definition: rephist.h:139
@ PADDING_TYPE_TOTAL
Definition: rephist.h:135
@ PADDING_TYPE_ENABLED_TOTAL
Definition: rephist.h:137
@ PADDING_TYPE_CELL
Definition: rephist.h:133
overload_type_t
Definition: rephist.h:155
void rep_hist_note_router_reachable(const char *id, const tor_addr_t *at_addr, const uint16_t at_port, time_t when)
Definition: rephist.c:577
uint64_t rephist_total_alloc
Definition: rephist.c:94
void rep_hist_seen_new_rp_cell(bool is_v2)
Definition: rephist.c:2247
void rep_hist_desc_stats_term(void)
Definition: rephist.c:1884
uint64_t rep_hist_get_n_dns_request(int type)
Definition: rephist.c:313
void rep_hist_hs_stats_term(void)
Definition: rephist.c:2282
uint64_t rep_hist_get_circuit_handshake_dropped(uint16_t type)
Definition: rephist.c:2055
void rep_hist_reset_padding_counts(void)
Definition: rephist.c:2495
double rep_hist_get_stability(const char *id, time_t when)
Definition: rephist.c:839
int rep_hist_load_mtbf_data(time_t now)
Definition: rephist.c:1125
void rep_hist_note_circuit_handshake_dropped(uint16_t type)
Definition: rephist.c:2027
void rep_hist_free_all(void)
Definition: rephist.c:2610
void rep_hist_init(void)
Definition: rephist.c:569
int rep_hist_get_circuit_handshake_assigned(uint16_t type)
Definition: rephist.c:2045
time_t rep_hist_desc_stats_write(time_t now)
Definition: rephist.c:1951
char * rep_hist_get_overload_stats_lines(void)
Definition: rephist.c:438
void rep_hist_buffer_stats_init(time_t now)
Definition: rephist.c:1597
void rep_hist_exit_stats_init(time_t now)
Definition: rephist.c:1340
void rep_hist_note_exit_stream_opened(uint16_t port)
Definition: rephist.c:1581
double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when)
Definition: rephist.c:851
void rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval)
Definition: rephist.c:1639
void rep_hist_note_dns_request(int type)
Definition: rephist.c:378
void rep_hist_padding_count_write(padding_type_t type)
Definition: rephist.c:2442
char * rep_hist_get_overload_general_line(void)
Definition: rephist.c:420
long rep_hist_get_uptime(const char *id, time_t when)
Definition: rephist.c:826
long rep_hist_get_weighted_time_known(const char *id, time_t when)
Definition: rephist.c:867
void rep_hist_dump_stats(time_t now, int severity)
Definition: rephist.c:890
void rep_hist_reset_buffer_stats(time_t now)
Definition: rephist.c:1697
void rep_hist_note_router_unreachable(const char *id, time_t when)
Definition: rephist.c:650
void rep_hist_hs_stats_init(time_t now)
Definition: rephist.c:2262
void rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key)
Definition: rephist.c:2221
char * rep_hist_format_exit_stats(time_t now)
Definition: rephist.c:1382
void rep_hist_log_link_protocol_counts(void)
Definition: rephist.c:2586
uint32_t rephist_total_num
Definition: rephist.c:96
char * rep_hist_get_padding_count_lines(void)
Definition: rephist.c:2540
void rep_hist_add_buffer_stats(double mean_num_cells_in_queue, double mean_time_cells_in_queue, uint32_t processed_cells)
Definition: rephist.c:1620
void rep_hist_note_circuit_handshake_requested(uint16_t type)
Definition: rephist.c:2009
int rep_hist_get_circuit_handshake_requested(uint16_t type)
Definition: rephist.c:2035
void rep_history_clean(time_t before)
Definition: rephist.c:929
void rep_hist_desc_stats_init(time_t now)
Definition: rephist.c:1861
uint64_t rep_hist_get_n_dns_error(int type, uint8_t error)
Definition: rephist.c:272
uint64_t rep_hist_get_n_read_limit_reached(void)
Definition: rephist.c:405
uint64_t rep_hist_get_n_tcp_exhaustion(void)
Definition: rephist.c:530
int rep_hist_record_mtbf_data(time_t now, int missing_means_down)
Definition: rephist.c:962
char * rep_hist_format_buffer_stats(time_t now)
Definition: rephist.c:1711
void rep_hist_reset_exit_stats(time_t now)
Definition: rephist.c:1350
void rep_hist_padding_count_timers(uint64_t num_timers)
Definition: rephist.c:2428
time_t rep_hist_hs_stats_write(time_t now, bool is_v3)
Definition: rephist.c:2369
time_t rep_hist_buffer_stats_write(time_t now)
Definition: rephist.c:1814
void rep_hist_make_router_pessimal(const char *id, time_t when)
Definition: rephist.c:704
void rep_hist_exit_stats_term(void)
Definition: rephist.c:1361
void rep_hist_note_overload(overload_type_t overload)
Definition: rephist.c:485
void rep_hist_log_circuit_handshake_stats(time_t now)
Definition: rephist.c:2065
void rep_hist_note_circuit_handshake_assigned(uint16_t type)
Definition: rephist.c:2018
void rep_hist_note_tcp_exhaustion(void)
Definition: rephist.c:522
void rep_hist_padding_count_read(padding_type_t type)
Definition: rephist.c:2470
int rep_hist_have_measured_enough_stability(void)
Definition: rephist.c:879
uint64_t rep_hist_get_n_write_limit_reached(void)
Definition: rephist.c:412
time_t rep_hist_exit_stats_write(time_t now)
Definition: rephist.c:1537
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127