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 */
9 * \brief Types used for messages in the dispatcher code.
12 #ifndef TOR_DISPATCH_MSGTYPES_H
13 #define TOR_DISPATCH_MSGTYPES_H
17 #include "ext/tor_queue.h"
20 * These types are aliases for subsystems, channels, and message IDs.
22 typedef uint16_t subsys_id_t
;
23 typedef uint16_t channel_id_t
;
24 typedef uint16_t message_id_t
;
27 * This identifies a C type that can be sent along with a message.
29 typedef uint16_t msg_type_id_t
;
32 * An ID value returned for *_type_t when none exists.
34 #define ERROR_ID 65535
37 * Auxiliary (untyped) data sent along with a message.
39 * We define this as a union of a pointer and a u64, so that the integer
40 * types will have the same range across platforms.
48 * Structure of a received message.
50 typedef struct msg_t
{
51 TOR_SIMPLEQ_ENTRY(msg_t
) next
;
55 /** We could omit this field, since it is implicit in the message type, but
56 * IMO let's leave it in for safety. */
58 /** Untyped auxiliary data. You shouldn't have to mess with this
60 msg_aux_data_t aux_data__
;
64 * A function that a subscriber uses to receive a message.
66 typedef void (*recv_fn_t
)(const msg_t
*m
);
69 * Table of functions to use for a given C type. Any omitted (NULL) functions
70 * will be treated as no-ops.
72 typedef struct dispatch_typefns_t
{
73 /** Release storage held for the auxiliary data of this type. */
74 void (*free_fn
)(msg_aux_data_t
);
75 /** Format and return a newly allocated string describing the contents
76 * of this data element. */
77 char *(*fmt_fn
)(msg_aux_data_t
);
80 #endif /* !defined(TOR_DISPATCH_MSGTYPES_H) */