1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
/* Copyright (c) 2001, Matej Pfajfar.
* Copyright (c) 2001-2004, Roger Dingledine.
* Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
* Copyright (c) 2007-2020, The Tor Project, Inc. */
/* See LICENSE for licensing information */
/**
* \file dispatch_st.h
*
* \brief private structures used for the dispatcher module
*/
#ifndef TOR_DISPATCH_ST_H
#define TOR_DISPATCH_ST_H
#ifdef DISPATCH_PRIVATE
#include "lib/container/smartlist.h"
/**
* Information about the recipient of a message.
**/
typedef struct dispatch_rcv_t {
/** The subsystem receiving a message. */
subsys_id_t sys;
/** True iff this recipient is enabled. */
bool enabled;
/** The function that will handle the message. */
recv_fn_t fn;
} dispatch_rcv_t;
/**
* Information used by a dispatcher to handle and dispatch a single message
* ID. It maps that message ID to its type, channel, and list of receiver
* functions.
*
* This structure is used when the dispatcher is running.
**/
typedef struct dtbl_entry_t {
/** The number of enabled non-stub subscribers for this message.
*
* Note that for now, this will be the same as <b>n_fns</b>, since there is
* no way to turn these subscribers on an off yet. */
uint16_t n_enabled;
/** The channel that handles this message. */
channel_id_t channel;
/** The associated C type for this message. */
msg_type_id_t type;
/**
* The number of functions pointers for subscribers that receive this
* message, in rcv. */
uint16_t n_fns;
/**
* The recipients for this message.
*/
dispatch_rcv_t rcv[FLEXIBLE_ARRAY_MEMBER];
} dtbl_entry_t;
/**
* A queue of messages for a given channel, used by a live dispatcher.
*/
typedef struct dqueue_t {
/** The queue of messages itself. */
TOR_SIMPLEQ_HEAD( , msg_t) queue;
/** A function to be called when the queue becomes nonempty. */
dispatch_alertfn_t alert_fn;
/** An argument for the alert_fn. */
void *alert_fn_arg;
} dqueue_t ;
/**
* A single dispatcher for cross-module messages.
*/
struct dispatch_t {
/**
* The length of <b>table</b>: the number of message IDs that this
* dispatcher can handle.
*/
size_t n_msgs;
/**
* The length of <b>queues</b>: the number of channels that this dispatcher
* has configured.
*/
size_t n_queues;
/**
* The length of <b>typefns</b>: the number of C type IDs that this
* dispatcher has configured.
*/
size_t n_types;
/**
* An array of message queues, indexed by channel ID.
*/
dqueue_t *queues;
/**
* An array of entries about how to handle particular message types, indexed
* by message ID.
*/
dtbl_entry_t **table;
/**
* An array of function tables for manipulating types, index by message
* type ID.
**/
dispatch_typefns_t *typefns;
};
#endif /* defined(DISPATCH_PRIVATE) */
#endif /* !defined(TOR_DISPATCH_ST_H) */
|