Add Coccinelle patch for replacing NULL/non-NULL tt_assert().
[tor.git] / src / or / rephist.h
blob8f6d46616d6204dfe6aeb36c29a16e74fc088ec9
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-2017, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
7 /**
8 * \file rephist.h
9 * \brief Header file for rephist.c.
10 **/
12 #ifndef TOR_REPHIST_H
13 #define TOR_REPHIST_H
15 void rep_hist_init(void);
16 void rep_hist_note_connect_failed(const char* nickname, time_t when);
17 void rep_hist_note_connect_succeeded(const char* nickname, time_t when);
18 void rep_hist_note_disconnect(const char* nickname, time_t when);
19 void rep_hist_note_connection_died(const char* nickname, time_t when);
20 void rep_hist_note_extend_succeeded(const char *from_name,
21 const char *to_name);
22 void rep_hist_note_extend_failed(const char *from_name, const char *to_name);
23 void rep_hist_dump_stats(time_t now, int severity);
24 void rep_hist_note_bytes_read(size_t num_bytes, time_t when);
25 void rep_hist_note_bytes_written(size_t num_bytes, time_t when);
27 void rep_hist_make_router_pessimal(const char *id, time_t when);
29 void rep_hist_note_dir_bytes_read(size_t num_bytes, time_t when);
30 void rep_hist_note_dir_bytes_written(size_t num_bytes, time_t when);
32 int rep_hist_bandwidth_assess(void);
33 char *rep_hist_get_bandwidth_lines(void);
34 void rep_hist_update_state(or_state_t *state);
35 int rep_hist_load_state(or_state_t *state, char **err);
36 void rep_history_clean(time_t before);
38 void rep_hist_note_router_reachable(const char *id, const tor_addr_t *at_addr,
39 const uint16_t at_port, time_t when);
40 void rep_hist_note_router_unreachable(const char *id, time_t when);
41 int rep_hist_record_mtbf_data(time_t now, int missing_means_down);
42 int rep_hist_load_mtbf_data(time_t now);
44 time_t rep_hist_downrate_old_runs(time_t now);
45 long rep_hist_get_uptime(const char *id, time_t when);
46 double rep_hist_get_stability(const char *id, time_t when);
47 double rep_hist_get_weighted_fractional_uptime(const char *id, time_t when);
48 long rep_hist_get_weighted_time_known(const char *id, time_t when);
49 int rep_hist_have_measured_enough_stability(void);
51 void predicted_ports_init(void);
52 void rep_hist_note_used_port(time_t now, uint16_t port);
53 smartlist_t *rep_hist_get_predicted_ports(time_t now);
54 void rep_hist_remove_predicted_ports(const smartlist_t *rmv_ports);
55 void rep_hist_note_used_resolve(time_t now);
56 void rep_hist_note_used_internal(time_t now, int need_uptime,
57 int need_capacity);
58 int rep_hist_get_predicted_internal(time_t now, int *need_uptime,
59 int *need_capacity);
61 int any_predicted_circuits(time_t now);
62 int rep_hist_circbuilding_dormant(time_t now);
63 int predicted_ports_prediction_time_remaining(time_t now);
65 void rep_hist_exit_stats_init(time_t now);
66 void rep_hist_reset_exit_stats(time_t now);
67 void rep_hist_exit_stats_term(void);
68 char *rep_hist_format_exit_stats(time_t now);
69 time_t rep_hist_exit_stats_write(time_t now);
70 void rep_hist_note_exit_bytes(uint16_t port, size_t num_written,
71 size_t num_read);
72 void rep_hist_note_exit_stream_opened(uint16_t port);
74 void rep_hist_buffer_stats_init(time_t now);
75 void rep_hist_buffer_stats_add_circ(circuit_t *circ,
76 time_t end_of_interval);
77 time_t rep_hist_buffer_stats_write(time_t now);
78 void rep_hist_buffer_stats_term(void);
79 void rep_hist_add_buffer_stats(double mean_num_cells_in_queue,
80 double mean_time_cells_in_queue, uint32_t processed_cells);
81 char *rep_hist_format_buffer_stats(time_t now);
82 void rep_hist_reset_buffer_stats(time_t now);
84 void rep_hist_desc_stats_init(time_t now);
85 void rep_hist_note_desc_served(const char * desc);
86 void rep_hist_desc_stats_term(void);
87 time_t rep_hist_desc_stats_write(time_t now);
89 void rep_hist_conn_stats_init(time_t now);
90 void rep_hist_note_or_conn_bytes(uint64_t conn_id, size_t num_read,
91 size_t num_written, time_t when);
92 void rep_hist_reset_conn_stats(time_t now);
93 char *rep_hist_format_conn_stats(time_t now);
94 time_t rep_hist_conn_stats_write(time_t now);
95 void rep_hist_conn_stats_term(void);
97 void rep_hist_note_circuit_handshake_requested(uint16_t type);
98 void rep_hist_note_circuit_handshake_assigned(uint16_t type);
99 void rep_hist_log_circuit_handshake_stats(time_t now);
101 void rep_hist_hs_stats_init(time_t now);
102 void rep_hist_hs_stats_term(void);
103 time_t rep_hist_hs_stats_write(time_t now);
104 char *rep_hist_get_hs_stats_string(void);
105 void rep_hist_seen_new_rp_cell(void);
106 void rep_hist_stored_maybe_new_hs(const crypto_pk_t *pubkey);
108 void rep_hist_free_all(void);
110 void rep_hist_note_negotiated_link_proto(unsigned link_proto,
111 int started_here);
112 void rep_hist_log_link_protocol_counts(void);
114 extern uint64_t rephist_total_alloc;
115 extern uint32_t rephist_total_num;
116 #ifdef TOR_UNIT_TESTS
117 extern int onion_handshakes_requested[MAX_ONION_HANDSHAKE_TYPE+1];
118 extern int onion_handshakes_assigned[MAX_ONION_HANDSHAKE_TYPE+1];
119 #endif
122 * Represents the type of a cell for padding accounting
124 typedef enum padding_type_t {
125 /** A RELAY_DROP cell */
126 PADDING_TYPE_DROP,
127 /** A CELL_PADDING cell */
128 PADDING_TYPE_CELL,
129 /** Total counts of padding and non-padding together */
130 PADDING_TYPE_TOTAL,
131 /** Total cell counts for all padding-enabled channels */
132 PADDING_TYPE_ENABLED_TOTAL,
133 /** CELL_PADDING counts for all padding-enabled channels */
134 PADDING_TYPE_ENABLED_CELL
135 } padding_type_t;
137 /** The amount of time over which the padding cell counts were counted */
138 #define REPHIST_CELL_PADDING_COUNTS_INTERVAL (24*60*60)
139 void rep_hist_padding_count_read(padding_type_t type);
140 void rep_hist_padding_count_write(padding_type_t type);
141 char *rep_hist_get_padding_count_lines(void);
142 void rep_hist_reset_padding_counts(void);
143 void rep_hist_prep_published_padding_counts(time_t now);
144 void rep_hist_padding_count_timers(uint64_t num_timers);
146 #endif