Tor  0.4.8.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_note_conn_opened(bool initiated, unsigned int type, int af);
45 void rep_hist_note_conn_closed(bool initiated, unsigned int type, int af);
46 void rep_hist_note_conn_rejected(unsigned int type, int af);
47 uint64_t rep_hist_get_conn_created(bool initiated, unsigned int type, int af);
48 uint64_t rep_hist_get_conn_opened(bool initiated, unsigned int type, int af);
49 uint64_t rep_hist_get_conn_rejected(unsigned int type, int af);
50 
51 void rep_hist_note_exit_stream(unsigned int cmd);
52 uint64_t rep_hist_get_exit_stream_seen(unsigned int cmd);
53 
54 void rep_hist_buffer_stats_init(time_t now);
56  time_t end_of_interval);
57 time_t rep_hist_buffer_stats_write(time_t now);
59 void rep_hist_add_buffer_stats(double mean_num_cells_in_queue,
60  double mean_time_cells_in_queue, uint32_t processed_cells);
61 char *rep_hist_format_buffer_stats(time_t now);
62 void rep_hist_reset_buffer_stats(time_t now);
63 
64 void rep_hist_desc_stats_init(time_t now);
65 void rep_hist_note_desc_served(const char * desc);
66 void rep_hist_desc_stats_term(void);
67 time_t rep_hist_desc_stats_write(time_t now);
68 
71 void rep_hist_note_circuit_handshake_dropped(uint16_t type);
73 
76 
78  (uint16_t type));
80  (uint16_t type));
81 
82 void rep_hist_hs_stats_init(time_t now);
83 void rep_hist_hs_stats_term(void);
84 time_t rep_hist_hs_stats_write(time_t now, bool is_v3);
85 
86 void rep_hist_seen_new_rp_cell(bool is_v2);
87 
88 char *rep_hist_get_hs_v3_stats_string(void);
89 void rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key);
90 
91 void rep_hist_free_all(void);
92 
93 void rep_hist_note_negotiated_link_proto(unsigned link_proto,
94  int started_here);
96 
97 uint64_t rep_hist_get_n_dns_error(int type, uint8_t error);
98 uint64_t rep_hist_get_n_dns_request(int type);
99 void rep_hist_note_dns_request(int type);
100 void rep_hist_note_dns_error(int type, uint8_t error);
101 
103 
104 /** We combine ntor and ntorv3 stats, so we have 3 stat types:
105  * tap, fast, and ntor. The max type is ntor (2) */
106 #define MAX_ONION_STAT_TYPE ONION_HANDSHAKE_TYPE_NTOR
107 
108 extern uint64_t rephist_total_alloc;
109 extern uint32_t rephist_total_num;
110 #ifdef TOR_UNIT_TESTS
112 extern int onion_handshakes_assigned[MAX_ONION_STAT_TYPE+1];
113 #endif
114 
115 #ifdef REPHIST_PRIVATE
116 /** Carries the various hidden service statistics, and any other
117  * information needed. */
118 typedef struct hs_v2_stats_t {
119  /** How many v2 relay cells have we seen as rendezvous points? */
120  uint64_t rp_v2_relay_cells_seen;
121 } hs_v2_stats_t;
122 
123 /** Structure that contains the various statistics we keep about v3
124  * services.
125  *
126  * Because of the time period logic of v3 services, v3 statistics are more
127  * sensitive to time than v2 stats. For this reason, we collect v3
128  * statistics strictly from 12:00UTC to 12:00UTC as dictated by
129  * 'start_of_hs_v3_stats_interval'.
130  **/
131 typedef struct hs_v3_stats_t {
132  /** How many v3 relay cells have we seen as a rendezvous point? */
133  uint64_t rp_v3_relay_cells_seen;
134 
135  /* The number of unique v3 onion descriptors (actually, unique v3 blind keys)
136  * we've seen during the measurement period */
137  digest256map_t *v3_onions_seen_this_period;
138 } hs_v3_stats_t;
139 
141 
142 STATIC char *rep_hist_format_hs_stats(time_t now, bool is_v3);
143 #endif /* defined(REPHIST_PRIVATE) */
144 
145 /**
146  * Represents the type of a cell for padding accounting
147  */
148 typedef enum padding_type_t {
149  /** A RELAY_DROP cell */
151  /** A CELL_PADDING cell */
153  /** Total counts of padding and non-padding together */
155  /** Total cell counts for all padding-enabled channels */
157  /** CELL_PADDING counts for all padding-enabled channels */
160 
161 /** The amount of time over which the padding cell counts were counted */
162 #define REPHIST_CELL_PADDING_COUNTS_INTERVAL (24*60*60)
167 void rep_hist_prep_published_padding_counts(time_t now);
168 void rep_hist_padding_count_timers(uint64_t num_timers);
169 
170 /**
171  * Represents the various types of overload we keep track of and expose in our
172  * extra-info descriptor.
173 */
174 typedef enum {
175  /* A general overload -- can have many different causes. */
176  OVERLOAD_GENERAL,
177  /* We went over our configured read rate/burst bandwidth limit */
178  OVERLOAD_READ,
179  /* We went over our configured write rate/burst bandwidth limit */
180  OVERLOAD_WRITE,
181  /* We exhausted the file descriptors in this system */
182  OVERLOAD_FD_EXHAUSTED,
184 
188 
190 uint64_t rep_hist_get_n_tcp_exhaustion(void);
191 
192 uint64_t rep_hist_get_n_read_limit_reached(void);
194 
195 #ifdef TOR_UNIT_TESTS
196 struct hs_v2_stats_t;
197 const struct hs_v2_stats_t *rep_hist_get_hs_v2_stats(void);
198 struct hs_v3_stats_t;
199 const struct hs_v3_stats_t *rep_hist_get_hs_v3_stats(void);
200 #endif /* defined(TOR_UNIT_TESTS) */
201 
202 #endif /* !defined(TOR_REPHIST_H) */
STATIC int onion_handshakes_requested[MAX_ONION_STAT_TYPE+1]
Definition: rephist.c:2234
STATIC char * rep_hist_format_hs_stats(time_t now, bool is_v3)
Definition: rephist.c:2690
STATIC bool should_collect_v3_stats(void)
Definition: rephist.c:2585
void rep_hist_note_dns_error(int type, uint8_t error)
Definition: rephist.c:372
void rep_hist_note_desc_served(const char *desc)
Definition: rephist.c:2212
void rep_hist_consensus_has_changed(const networkstatus_t *ns)
Definition: rephist.c:3010
void rep_hist_buffer_stats_term(void)
Definition: rephist.c:1919
time_t rep_hist_downrate_old_runs(time_t now)
Definition: rephist.c:771
void rep_hist_note_exit_bytes(uint16_t port, size_t num_written, size_t num_read)
Definition: rephist.c:1620
void rep_hist_note_negotiated_link_proto(unsigned link_proto, int started_here)
Definition: rephist.c:2784
padding_type_t
Definition: rephist.h:148
@ PADDING_TYPE_DROP
Definition: rephist.h:150
@ PADDING_TYPE_ENABLED_CELL
Definition: rephist.h:158
@ PADDING_TYPE_TOTAL
Definition: rephist.h:154
@ PADDING_TYPE_ENABLED_TOTAL
Definition: rephist.h:156
@ PADDING_TYPE_CELL
Definition: rephist.h:152
overload_type_t
Definition: rephist.h:174
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:630
uint64_t rephist_total_alloc
Definition: rephist.c:95
void rep_hist_seen_new_rp_cell(bool is_v2)
Definition: rephist.c:2619
void rep_hist_desc_stats_term(void)
Definition: rephist.c:2114
uint64_t rep_hist_get_n_dns_request(int type)
Definition: rephist.c:355
void rep_hist_hs_stats_term(void)
Definition: rephist.c:2654
void rep_hist_reset_padding_counts(void)
Definition: rephist.c:2867
void rep_hist_note_conn_closed(bool initiated, unsigned int type, int af)
Definition: rephist.c:1730
double rep_hist_get_stability(const char *id, time_t when)
Definition: rephist.c:892
int rep_hist_load_mtbf_data(time_t now)
Definition: rephist.c:1178
void rep_hist_note_circuit_handshake_dropped(uint16_t type)
Definition: rephist.c:2394
void rep_hist_note_conn_opened(bool initiated, unsigned int type, int af)
Definition: rephist.c:1707
void rep_hist_free_all(void)
Definition: rephist.c:2982
void rep_hist_init(void)
Definition: rephist.c:622
int rep_hist_get_circuit_handshake_assigned(uint16_t type)
Definition: rephist.c:2416
time_t rep_hist_desc_stats_write(time_t now)
Definition: rephist.c:2181
char * rep_hist_get_overload_stats_lines(void)
Definition: rephist.c:491
void rep_hist_note_exit_stream(unsigned int cmd)
Definition: rephist.c:1653
void rep_hist_buffer_stats_init(time_t now)
Definition: rephist.c:1827
uint64_t rep_hist_get_conn_rejected(unsigned int type, int af)
Definition: rephist.c:1806
void rep_hist_exit_stats_init(time_t now)
Definition: rephist.c:1393
uint64_t rep_hist_get_conn_opened(bool initiated, unsigned int type, int af)
Definition: rephist.c:1790
void rep_hist_note_exit_stream_opened(uint16_t port)
Definition: rephist.c:1634
double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when)
Definition: rephist.c:904
void rep_hist_buffer_stats_add_circ(circuit_t *circ, time_t end_of_interval)
Definition: rephist.c:1869
uint64_t rep_hist_get_circuit_n_handshake_assigned(uint16_t type)
Definition: rephist.c:2423
void rep_hist_note_dns_request(int type)
Definition: rephist.c:431
void rep_hist_padding_count_write(padding_type_t type)
Definition: rephist.c:2814
char * rep_hist_get_overload_general_line(void)
Definition: rephist.c:473
long rep_hist_get_uptime(const char *id, time_t when)
Definition: rephist.c:879
long rep_hist_get_weighted_time_known(const char *id, time_t when)
Definition: rephist.c:920
void rep_hist_note_conn_rejected(unsigned int type, int af)
Definition: rephist.c:1755
void rep_hist_dump_stats(time_t now, int severity)
Definition: rephist.c:943
void rep_hist_reset_buffer_stats(time_t now)
Definition: rephist.c:1927
uint64_t rep_hist_get_conn_created(bool initiated, unsigned int type, int af)
Definition: rephist.c:1774
void rep_hist_note_router_unreachable(const char *id, time_t when)
Definition: rephist.c:703
void rep_hist_hs_stats_init(time_t now)
Definition: rephist.c:2634
void rep_hist_hsdir_stored_maybe_new_v3_onion(const uint8_t *blinded_key)
Definition: rephist.c:2593
char * rep_hist_format_exit_stats(time_t now)
Definition: rephist.c:1435
void rep_hist_log_link_protocol_counts(void)
Definition: rephist.c:2958
uint32_t rephist_total_num
Definition: rephist.c:97
char * rep_hist_get_padding_count_lines(void)
Definition: rephist.c:2912
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:1850
void rep_hist_note_circuit_handshake_requested(uint16_t type)
Definition: rephist.c:2367
int rep_hist_get_circuit_handshake_requested(uint16_t type)
Definition: rephist.c:2409
void rep_history_clean(time_t before)
Definition: rephist.c:982
void rep_hist_desc_stats_init(time_t now)
Definition: rephist.c:2091
uint64_t rep_hist_get_n_dns_error(int type, uint8_t error)
Definition: rephist.c:314
uint64_t rep_hist_get_n_read_limit_reached(void)
Definition: rephist.c:458
uint64_t rep_hist_get_n_tcp_exhaustion(void)
Definition: rephist.c:583
int rep_hist_record_mtbf_data(time_t now, int missing_means_down)
Definition: rephist.c:1015
char * rep_hist_format_buffer_stats(time_t now)
Definition: rephist.c:1941
void rep_hist_reset_exit_stats(time_t now)
Definition: rephist.c:1403
void rep_hist_padding_count_timers(uint64_t num_timers)
Definition: rephist.c:2800
time_t rep_hist_hs_stats_write(time_t now, bool is_v3)
Definition: rephist.c:2741
time_t rep_hist_buffer_stats_write(time_t now)
Definition: rephist.c:2044
uint64_t rep_hist_get_circuit_n_handshake_dropped(uint16_t type)
Definition: rephist.c:2430
void rep_hist_make_router_pessimal(const char *id, time_t when)
Definition: rephist.c:757
void rep_hist_exit_stats_term(void)
Definition: rephist.c:1414
void rep_hist_note_overload(overload_type_t overload)
Definition: rephist.c:538
uint64_t rep_hist_get_exit_stream_seen(unsigned int cmd)
Definition: rephist.c:1673
void rep_hist_log_circuit_handshake_stats(time_t now)
Definition: rephist.c:2437
void rep_hist_note_circuit_handshake_assigned(uint16_t type)
Definition: rephist.c:2385
#define MAX_ONION_STAT_TYPE
Definition: rephist.h:106
void rep_hist_note_tcp_exhaustion(void)
Definition: rephist.c:575
void rep_hist_padding_count_read(padding_type_t type)
Definition: rephist.c:2842
int rep_hist_have_measured_enough_stability(void)
Definition: rephist.c:932
uint64_t rep_hist_get_n_write_limit_reached(void)
Definition: rephist.c:465
time_t rep_hist_exit_stats_write(time_t now)
Definition: rephist.c:1590
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127