tor  0.4.2.1-alpha-dev
control_events.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-2019, The Tor Project, Inc. */
5 /* See LICENSE for licensing information */
6 
12 #ifndef TOR_CONTROL_EVENTS_H
13 #define TOR_CONTROL_EVENTS_H
14 
15 #include "core/or/ocirc_event.h"
16 
20  CIRC_MINOR_EVENT_PURPOSE_CHANGED,
21  CIRC_MINOR_EVENT_CANNIBALIZED,
23 
24 #include "core/or/orconn_event.h"
25 
28 typedef enum stream_status_event_t {
29  STREAM_EVENT_SENT_CONNECT = 0,
30  STREAM_EVENT_SENT_RESOLVE = 1,
31  STREAM_EVENT_SUCCEEDED = 2,
32  STREAM_EVENT_FAILED = 3,
33  STREAM_EVENT_CLOSED = 4,
34  STREAM_EVENT_NEW = 5,
35  STREAM_EVENT_NEW_RESOLVE = 6,
36  STREAM_EVENT_FAILED_RETRIABLE = 7,
37  STREAM_EVENT_REMAP = 8
39 
42  BUILDTIMEOUT_SET_EVENT_COMPUTED = 0,
43  BUILDTIMEOUT_SET_EVENT_RESET = 1,
44  BUILDTIMEOUT_SET_EVENT_SUSPENDED = 2,
45  BUILDTIMEOUT_SET_EVENT_DISCARD = 3,
46  BUILDTIMEOUT_SET_EVENT_RESUME = 4
48 
51 typedef enum {
52  BOOTSTRAP_STATUS_UNDEF=-1,
53  BOOTSTRAP_STATUS_STARTING=0,
54 
55  /* Initial connection to any relay */
56 
57  BOOTSTRAP_STATUS_CONN_PT=1,
58  BOOTSTRAP_STATUS_CONN_DONE_PT=2,
59  BOOTSTRAP_STATUS_CONN_PROXY=3,
60  BOOTSTRAP_STATUS_CONN_DONE_PROXY=4,
61  BOOTSTRAP_STATUS_CONN=5,
62  BOOTSTRAP_STATUS_CONN_DONE=10,
63  BOOTSTRAP_STATUS_HANDSHAKE=14,
64  BOOTSTRAP_STATUS_HANDSHAKE_DONE=15,
65 
66  /* Loading directory info */
67 
68  BOOTSTRAP_STATUS_ONEHOP_CREATE=20,
69  BOOTSTRAP_STATUS_REQUESTING_STATUS=25,
70  BOOTSTRAP_STATUS_LOADING_STATUS=30,
71  BOOTSTRAP_STATUS_LOADING_KEYS=40,
72  BOOTSTRAP_STATUS_REQUESTING_DESCRIPTORS=45,
73  BOOTSTRAP_STATUS_LOADING_DESCRIPTORS=50,
74  BOOTSTRAP_STATUS_ENOUGH_DIRINFO=75,
75 
76  /* Connecting to a relay for AP circuits */
77 
78  BOOTSTRAP_STATUS_AP_CONN_PT=76,
79  BOOTSTRAP_STATUS_AP_CONN_DONE_PT=77,
80  BOOTSTRAP_STATUS_AP_CONN_PROXY=78,
81  BOOTSTRAP_STATUS_AP_CONN_DONE_PROXY=79,
82  BOOTSTRAP_STATUS_AP_CONN=80,
83  BOOTSTRAP_STATUS_AP_CONN_DONE=85,
84  BOOTSTRAP_STATUS_AP_HANDSHAKE=89,
85  BOOTSTRAP_STATUS_AP_HANDSHAKE_DONE=90,
86 
87  /* Creating AP circuits */
88 
89  BOOTSTRAP_STATUS_CIRCUIT_CREATE=95,
90  BOOTSTRAP_STATUS_DONE=100
92 
95 #define REMAP_STREAM_SOURCE_CACHE 1
96 
98 #define REMAP_STREAM_SOURCE_EXIT 2
99 
100 void control_initialize_event_queue(void);
101 
104 
105 #define EVENT_NS 0x000F
106 int control_event_is_interesting(int event);
107 
108 void control_per_second_events(void);
110 
112  circuit_status_event_t e, int reason);
114  int old_purpose);
116  int old_purpose,
117  const struct timeval *old_tv_created);
120  int reason);
122  or_conn_status_event_t e, int reason);
123 int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written);
131 void control_event_logmsg(int severity, log_domain_mask_t domain,
132  const char *msg);
135 int control_event_address_mapped(const char *from, const char *to,
136  time_t expires, const char *error,
137  const int cached);
139 int control_event_network_liveness_update(int liveness);
141 
142 int control_event_newconsensus(const networkstatus_t *consensus);
144 int control_event_general_status(int severity, const char *format, ...)
145  CHECK_PRINTF(2,3);
146 int control_event_client_status(int severity, const char *format, ...)
147  CHECK_PRINTF(2,3);
148 int control_event_server_status(int severity, const char *format, ...)
149  CHECK_PRINTF(2,3);
150 
151 int control_event_general_error(const char *format, ...)
152  CHECK_PRINTF(1,2);
153 int control_event_client_error(const char *format, ...)
154  CHECK_PRINTF(1,2);
155 int control_event_server_error(const char *format, ...)
156  CHECK_PRINTF(1,2);
157 
158 int control_event_guard(const char *nickname, const char *digest,
159  const char *status);
160 int control_event_conf_changed(const smartlist_t *elements);
162  const char *args);
163 int control_event_signal(uintptr_t signal);
164 
165 void control_event_bootstrap(bootstrap_status_t status, int progress);
166 MOCK_DECL(void, control_event_bootstrap_prob_or,(const char *warn,
167  int reason,
168  or_connection_t *or_conn));
169 void control_event_boot_dir(bootstrap_status_t status, int progress);
171 void control_event_bootstrap_problem(const char *warn, const char *reason,
172  const connection_t *conn, int dowarn);
173 char *control_event_boot_last_msg(void);
175 
176 void control_event_clients_seen(const char *controller_str);
177 void control_event_transport_launched(const char *mode,
178  const char *transport_name,
179  tor_addr_t *addr, uint16_t port);
180 void control_event_pt_log(const char *log);
181 void control_event_pt_status(const char *status);
182 
183 void control_event_hs_descriptor_requested(const char *onion_address,
184  rend_auth_type_t auth_type,
185  const char *id_digest,
186  const char *desc_id,
187  const char *hsdir_index);
188 void control_event_hs_descriptor_created(const char *onion_address,
189  const char *desc_id,
190  int replica);
191 void control_event_hs_descriptor_upload(const char *onion_address,
192  const char *desc_id,
193  const char *hs_dir,
194  const char *hsdir_index);
195 void control_event_hs_descriptor_upload_end(const char *action,
196  const char *onion_address,
197  const char *hs_dir,
198  const char *reason);
199 void control_event_hs_descriptor_uploaded(const char *hs_dir,
200  const char *onion_address);
201 /* Hidden service v2 HS_DESC specific. */
203  const char *id_digest,
204  const char *reason);
205 void control_event_hsv2_descriptor_received(const char *onion_address,
206  const rend_data_t *rend_data,
207  const char *id_digest);
208 /* Hidden service v3 HS_DESC specific. */
209 void control_event_hsv3_descriptor_failed(const char *onion_address,
210  const char *desc_id,
211  const char *hsdir_id_digest,
212  const char *reason);
213 void control_event_hsv3_descriptor_received(const char *onion_address,
214  const char *desc_id,
215  const char *hsdir_id_digest);
216 void control_event_hs_descriptor_upload_failed(const char *hs_dir,
217  const char *onion_address,
218  const char *reason);
219 void control_event_hs_descriptor_content(const char *onion_address,
220  const char *desc_id,
221  const char *hsdir_fp,
222  const char *content);
223 
224 void control_events_free_all(void);
225 
226 #ifdef CONTROL_MODULE_PRIVATE
227 char *get_bw_samples(void);
228 #endif /* defined(CONTROL_MODULE_PRIVATE) */
229 
230 #ifdef CONTROL_EVENTS_PRIVATE
231 
237 typedef uint64_t event_mask_t;
238 
239 /* Recognized asynchronous event types. It's okay to expand this list
240  * because it is used both as a list of v0 event types, and as indices
241  * into the bitfield to determine which controllers want which events.
242  */
243 /* This bitfield has no event zero 0x0000 */
244 #define EVENT_MIN_ 0x0001
245 #define EVENT_CIRCUIT_STATUS 0x0001
246 #define EVENT_STREAM_STATUS 0x0002
247 #define EVENT_OR_CONN_STATUS 0x0003
248 #define EVENT_BANDWIDTH_USED 0x0004
249 #define EVENT_CIRCUIT_STATUS_MINOR 0x0005
250 #define EVENT_NEW_DESC 0x0006
251 #define EVENT_DEBUG_MSG 0x0007
252 #define EVENT_INFO_MSG 0x0008
253 #define EVENT_NOTICE_MSG 0x0009
254 #define EVENT_WARN_MSG 0x000A
255 #define EVENT_ERR_MSG 0x000B
256 #define EVENT_ADDRMAP 0x000C
257 /* There was an AUTHDIR_NEWDESCS event, but it no longer exists. We
258  can reclaim 0x000D. */
259 #define EVENT_DESCCHANGED 0x000E
260 /* Exposed above */
261 // #define EVENT_NS 0x000F
262 #define EVENT_STATUS_CLIENT 0x0010
263 #define EVENT_STATUS_SERVER 0x0011
264 #define EVENT_STATUS_GENERAL 0x0012
265 #define EVENT_GUARD 0x0013
266 #define EVENT_STREAM_BANDWIDTH_USED 0x0014
267 #define EVENT_CLIENTS_SEEN 0x0015
268 #define EVENT_NEWCONSENSUS 0x0016
269 #define EVENT_BUILDTIMEOUT_SET 0x0017
270 #define EVENT_GOT_SIGNAL 0x0018
271 #define EVENT_CONF_CHANGED 0x0019
272 #define EVENT_CONN_BW 0x001A
273 #define EVENT_CELL_STATS 0x001B
274 /* UNUSED : 0x001C */
275 #define EVENT_CIRC_BANDWIDTH_USED 0x001D
276 #define EVENT_TRANSPORT_LAUNCHED 0x0020
277 #define EVENT_HS_DESC 0x0021
278 #define EVENT_HS_DESC_CONTENT 0x0022
279 #define EVENT_NETWORK_LIVENESS 0x0023
280 #define EVENT_PT_LOG 0x0024
281 #define EVENT_PT_STATUS 0x0025
282 #define EVENT_MAX_ 0x0025
283 
284 /* sizeof(control_connection_t.event_mask) in bits, currently a uint64_t */
285 #define EVENT_CAPACITY_ 0x0040
286 
287 /* If EVENT_MAX_ ever hits 0x0040, we need to make the mask into a
288  * different structure, as it can only handle a maximum left shift of 1<<63. */
289 
290 #if EVENT_MAX_ >= EVENT_CAPACITY_
291 #error control_connection_t.event_mask has an event greater than its capacity
292 #endif
293 
294 #define EVENT_MASK_(e) (((uint64_t)1)<<(e))
295 
296 #define EVENT_MASK_NONE_ ((uint64_t)0x0)
297 
298 #define EVENT_MASK_ABOVE_MIN_ ((~((uint64_t)0x0)) << EVENT_MIN_)
299 #define EVENT_MASK_BELOW_MAX_ ((~((uint64_t)0x0)) \
300  >> (EVENT_CAPACITY_ - EVENT_MAX_ \
301  - EVENT_MIN_))
302 
303 #define EVENT_MASK_ALL_ (EVENT_MASK_ABOVE_MIN_ \
304  & EVENT_MASK_BELOW_MAX_)
305 
307 typedef struct cell_stats_t {
309  uint64_t added_cells_appward[CELL_COMMAND_MAX_ + 1];
311  uint64_t added_cells_exitward[CELL_COMMAND_MAX_ + 1];
313  uint64_t removed_cells_appward[CELL_COMMAND_MAX_ + 1];
315  uint64_t removed_cells_exitward[CELL_COMMAND_MAX_ + 1];
317  uint64_t total_time_appward[CELL_COMMAND_MAX_ + 1];
319  uint64_t total_time_exitward[CELL_COMMAND_MAX_ + 1];
320 } cell_stats_t;
321 
323  cell_stats_t *cell_stats);
324 void append_cell_stats_by_command(smartlist_t *event_parts,
325  const char *key,
326  const uint64_t *include_if_non_zero,
327  const uint64_t *number_to_include);
328 void format_cell_stats(char **event_string, circuit_t *circ,
329  cell_stats_t *cell_stats);
330 
332 struct control_event_t {
333  uint16_t event_code;
334  const char *event_name;
335 };
336 
337 extern const struct control_event_t control_event_table[];
338 
339 #ifdef TOR_UNIT_TESTS
340 MOCK_DECL(STATIC void,
341  send_control_event_string,(uint16_t event, const char *msg));
342 
343 MOCK_DECL(STATIC void,
344  queue_control_event_string,(uint16_t event, char *msg));
345 
346 void control_testing_set_global_event_mask(uint64_t mask);
347 
348 #endif /* defined(TOR_UNIT_TESTS) */
349 
350 #endif /* defined(CONTROL_EVENTS_PRIVATE) */
351 
352 #endif /* !defined(TOR_CONTROL_EVENTS_H) */
void control_event_hs_descriptor_content(const char *onion_address, const char *desc_id, const char *hsdir_fp, const char *content)
void control_event_boot_dir(bootstrap_status_t status, int progress)
void control_event_hsv2_descriptor_received(const char *onion_address, const rend_data_t *rend_data, const char *id_digest)
int control_event_address_mapped(const char *from, const char *to, time_t expires, const char *error, const int cached)
void control_event_bootstrap_problem(const char *warn, const char *reason, const connection_t *conn, int dowarn)
static void static int static void const struct control_event_t control_event_table[]
void control_event_boot_first_orconn(void)
int control_event_networkstatus_changed(smartlist_t *statuses)
void format_cell_stats(char **event_string, circuit_t *circ, cell_stats_t *cell_stats)
int control_event_stream_bandwidth(edge_connection_t *edge_conn)
int control_event_signal(uintptr_t signal)
void control_event_hs_descriptor_upload(const char *onion_address, const char *desc_id, const char *hs_dir, const char *hsdir_index)
stream_status_event_t
int control_event_descriptors_changed(smartlist_t *routers)
int control_event_client_error(const char *format,...)
int control_event_circuit_cell_stats(void)
void control_event_hs_descriptor_created(const char *onion_address, const char *desc_id, int replica)
Header file for orconn_event.c.
rend_auth_type_t
Definition: or.h:402
void control_event_hs_descriptor_upload_failed(const char *hs_dir, const char *onion_address, const char *reason)
int control_event_my_descriptor_changed(void)
int control_event_buildtimeout_set(buildtimeout_set_event_t type, const char *args)
buildtimeout_set_event_t
int control_event_general_status(int severity, const char *format,...)
void control_event_bootstrap_reset(void)
void sum_up_cell_stats_by_command(circuit_t *circ, cell_stats_t *cell_stats)
int control_event_or_conn_status(or_connection_t *conn, or_conn_status_event_t e, int reason)
void control_event_transport_launched(const char *mode, const char *transport_name, tor_addr_t *addr, uint16_t port)
int control_event_general_error(const char *format,...)
bootstrap_status_t
char * control_event_boot_last_msg(void)
int control_event_circuit_purpose_changed(origin_circuit_t *circ, int old_purpose)
int control_event_circ_bandwidth_used_for_circ(origin_circuit_t *ocirc)
int control_event_circuit_status(origin_circuit_t *circ, circuit_status_event_t e, int reason)
int control_event_stream_status(entry_connection_t *conn, stream_status_event_t e, int reason)
void control_event_hsv3_descriptor_failed(const char *onion_address, const char *desc_id, const char *hsdir_id_digest, const char *reason)
int control_event_circ_bandwidth_used(void)
int control_event_client_status(int severity, const char *format,...)
int control_any_per_second_event_enabled(void)
void control_event_hs_descriptor_uploaded(const char *hs_dir, const char *onion_address)
void control_event_hs_descriptor_upload_end(const char *action, const char *onion_address, const char *hs_dir, const char *reason)
void control_update_global_event_mask(void)
int control_event_is_interesting(int event)
uint64_t log_domain_mask_t
Definition: logging_types.h:21
int control_event_stream_bandwidth_used(void)
int control_event_circuit_cannibalized(origin_circuit_t *circ, int old_purpose, const struct timeval *old_tv_created)
void control_event_bootstrap(bootstrap_status_t status, int progress)
void control_event_clients_seen(const char *controller_str)
int control_event_network_liveness_update(int liveness)
int control_event_networkstatus_changed_single(const routerstatus_t *rs)
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:94
void append_cell_stats_by_command(smartlist_t *event_parts, const char *key, const uint64_t *include_if_non_zero, const uint64_t *number_to_include)
int control_event_server_error(const char *format,...)
Header file for ocirc_event.c.
int control_event_conn_bandwidth(connection_t *conn)
void control_event_pt_status(const char *status)
int control_event_server_status(int severity, const char *format,...)
int control_event_conf_changed(const smartlist_t *elements)
void control_per_second_events(void)
void control_event_hsv2_descriptor_failed(const rend_data_t *rend_data, const char *id_digest, const char *reason)
void control_event_logmsg(int severity, log_domain_mask_t domain, const char *msg)
void control_adjust_event_log_severity(void)
or_conn_status_event_t
Definition: orconn_event.h:59
void control_event_pt_log(const char *log)
void control_event_hs_descriptor_requested(const char *onion_address, rend_auth_type_t auth_type, const char *id_digest, const char *desc_id, const char *hsdir_index)
void control_event_logmsg_pending(void)
int control_event_newconsensus(const networkstatus_t *consensus)
int int int int int int int control_event_guard(const char *nickname, const char *digest, const char *status)
circuit_status_minor_event_t
int control_event_conn_bandwidth_used(void)
int control_event_bandwidth_used(uint32_t n_read, uint32_t n_written)
circuit_status_event_t
Definition: ocirc_event.h:19