diff options
Diffstat (limited to 'src/include/gnunet_testing_barrier.h')
-rw-r--r-- | src/include/gnunet_testing_barrier.h | 272 |
1 files changed, 272 insertions, 0 deletions
diff --git a/src/include/gnunet_testing_barrier.h b/src/include/gnunet_testing_barrier.h new file mode 100644 index 000000000..4a3d87ec7 --- /dev/null +++ b/src/include/gnunet_testing_barrier.h | |||
@@ -0,0 +1,272 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2022 GNUnet e.V. | ||
4 | |||
5 | GNUnet is free software: you can redistribute it and/or modify it | ||
6 | under the terms of the GNU Affero General Public License as published | ||
7 | by the Free Software Foundation, either version 3 of the License, | ||
8 | or (at your option) any later version. | ||
9 | |||
10 | GNUnet is distributed in the hope that it will be useful, but | ||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file include/gnunet_testing_barrier.h | ||
23 | * @brief API to manage barriers. | ||
24 | * @author t3sserakt | ||
25 | */ | ||
26 | |||
27 | #ifndef GNUNET_TESTING_BARRIER_LIB_H | ||
28 | #define GNUNET_TESTING_BARRIER_LIB_H | ||
29 | |||
30 | #include "gnunet_testing_lib.h" | ||
31 | #include "gnunet_testing_netjail_lib.h" | ||
32 | |||
33 | struct GNUNET_TESTING_Barrier | ||
34 | { | ||
35 | /** | ||
36 | * Pointer to the previous prefix in the DLL. | ||
37 | */ | ||
38 | struct GNUNET_TESTING_Barrier *prev; | ||
39 | |||
40 | /** | ||
41 | * Pointer to the next prefix in the DLL. | ||
42 | */ | ||
43 | struct GNUNET_TESTING_Barrier *next; | ||
44 | |||
45 | /** | ||
46 | * Head of the DLL with local commands the barrier is attached too. | ||
47 | */ | ||
48 | struct GNUNET_TESTING_Command *cmds_head; | ||
49 | |||
50 | /** | ||
51 | * Tail of the DLL with local commands the barrier is attached too. | ||
52 | */ | ||
53 | struct GNUNET_TESTING_Command *cmds_tail; | ||
54 | |||
55 | /** | ||
56 | * Hash map containing the global known nodes which are not natted. | ||
57 | */ | ||
58 | struct GNUNET_CONTAINER_MultiShortmap *nodes; | ||
59 | |||
60 | /** | ||
61 | * Name of the barrier. | ||
62 | */ | ||
63 | const char *name; | ||
64 | |||
65 | /** | ||
66 | * Is this barrier running on the master. | ||
67 | */ | ||
68 | unsigned int running_on_master; | ||
69 | |||
70 | /** | ||
71 | * Number of commands attached to this barrier. | ||
72 | */ | ||
73 | unsigned int expected_reaches; | ||
74 | |||
75 | /** | ||
76 | * Number of commands which reached this barrier. | ||
77 | */ | ||
78 | unsigned int reached; | ||
79 | |||
80 | /** | ||
81 | * Percentage of of commands which need to reach the barrier to change state. | ||
82 | * Can not be used together with to_be_reached; | ||
83 | */ | ||
84 | double percentage_to_be_reached; | ||
85 | |||
86 | /** | ||
87 | * Number of commands which need to reach the barrier to change state. | ||
88 | * Can not be used together with percentage_to_be_reached; | ||
89 | */ | ||
90 | unsigned int number_to_be_reached; | ||
91 | |||
92 | /* | ||
93 | * No barrier locally. Shadow created. Real barrier created elsewhere. | ||
94 | */ | ||
95 | unsigned int shadow; | ||
96 | }; | ||
97 | |||
98 | /** | ||
99 | * Message send to a child loop to inform the child loop about a barrier being advanced. | ||
100 | */ | ||
101 | struct GNUNET_TESTING_CommandBarrierAdvanced | ||
102 | { | ||
103 | /** | ||
104 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ADVANCED | ||
105 | */ | ||
106 | struct GNUNET_MessageHeader header; | ||
107 | |||
108 | /** | ||
109 | * The name of the barrier. | ||
110 | */ | ||
111 | const char *barrier_name; | ||
112 | }; | ||
113 | |||
114 | /** | ||
115 | * Message send by a child loop to inform the master loop how much | ||
116 | * GNUNET_CMDS_BARRIER_REACHED messages the child will send. | ||
117 | */ | ||
118 | struct GNUNET_TESTING_CommandBarrierAttached | ||
119 | { | ||
120 | /** | ||
121 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_ATTACHED | ||
122 | */ | ||
123 | struct GNUNET_MessageHeader header; | ||
124 | |||
125 | /** | ||
126 | * The name of the barrier. | ||
127 | */ | ||
128 | const char *barrier_name; | ||
129 | |||
130 | /** | ||
131 | * How often the child loop will reach the barrier. | ||
132 | */ | ||
133 | unsigned int expected_reaches; | ||
134 | |||
135 | /** | ||
136 | * The number of the node the barrier is running on. | ||
137 | */ | ||
138 | unsigned int node_number; | ||
139 | }; | ||
140 | |||
141 | |||
142 | struct GNUNET_TESTING_CommandBarrierReached | ||
143 | { | ||
144 | /** | ||
145 | * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_BARRIER_REACHED | ||
146 | */ | ||
147 | struct GNUNET_MessageHeader header; | ||
148 | |||
149 | /** | ||
150 | * The name of the barrier. | ||
151 | */ | ||
152 | const char *barrier_name; | ||
153 | |||
154 | /** | ||
155 | * The number of the node the barrier is reached. | ||
156 | */ | ||
157 | unsigned int node_number; | ||
158 | |||
159 | /** | ||
160 | * The number of reach messages which most likely will send. | ||
161 | */ | ||
162 | unsigned int expected_number_of_reached_messages; | ||
163 | }; | ||
164 | |||
165 | |||
166 | /** | ||
167 | * Adding a node to the map of nodes of a barrier. | ||
168 | * | ||
169 | * @param nodes Map of nodes. | ||
170 | * @param node The node to add. | ||
171 | */ | ||
172 | void | ||
173 | GNUNET_TESTING_barrier_add_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, | ||
174 | struct GNUNET_TESTING_NetjailNode *node); | ||
175 | |||
176 | |||
177 | struct GNUNET_TESTING_Command | ||
178 | GNUNET_TESTING_cmd_barrier_create ( | ||
179 | const char *label, | ||
180 | double percentage_to_be_reached, | ||
181 | unsigned int number_to_be_reached); | ||
182 | |||
183 | |||
184 | // Wait for barrier to be reached by all; | ||
185 | // async version implies reached but does not | ||
186 | // wait on other peers to reach it. | ||
187 | /** | ||
188 | * Create command. | ||
189 | * | ||
190 | * @param label name for command. | ||
191 | * @param barrier_label The name of the barrier we wait for and which will be reached. | ||
192 | * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL. | ||
193 | * @param asynchronous_finish If GNUNET_YES this command will not block. Can be NULL. | ||
194 | * @param node_number The global numer of the node the cmd runs on. | ||
195 | * @param running_on_master Is this cmd running on the master loop. | ||
196 | * @param write_message Callback to write messages to the master loop. | ||
197 | * @return command. | ||
198 | */ | ||
199 | struct GNUNET_TESTING_Command | ||
200 | GNUNET_TESTING_cmd_barrier_reached ( | ||
201 | const char *label, | ||
202 | const char *barrier_label, | ||
203 | unsigned int asynchronous_finish, | ||
204 | unsigned int node_number, | ||
205 | unsigned int running_on_master, | ||
206 | TESTING_CMD_HELPER_write_cb write_message); | ||
207 | |||
208 | |||
209 | /** | ||
210 | * Can we advance the barrier? | ||
211 | * | ||
212 | * @param barrier The barrier in question. | ||
213 | * @return GNUNET_YES if we can advance the barrier, GNUNET_NO if not. | ||
214 | */ | ||
215 | unsigned int | ||
216 | GNUNET_TESTING_can_barrier_advance (struct GNUNET_TESTING_Barrier *barrier); | ||
217 | |||
218 | |||
219 | /** | ||
220 | * Send Message to netjail nodes that a barrier can be advanced. | ||
221 | * | ||
222 | * @param is The interpreter loop. | ||
223 | * @param barrier_name The name of the barrier to advance. | ||
224 | * @param global_node_number The global number of the node to inform. | ||
225 | */ | ||
226 | void | ||
227 | GNUNET_TESTING_send_barrier_advance (struct GNUNET_TESTING_Interpreter *is, | ||
228 | const char *barrier_name, | ||
229 | unsigned int global_node_number); | ||
230 | |||
231 | |||
232 | /** | ||
233 | * Finish all "barrier reached" comands attached to this barrier. | ||
234 | * | ||
235 | * @param barrier The barrier in question. | ||
236 | */ | ||
237 | void | ||
238 | GNUNET_TESTING_finish_attached_cmds (struct GNUNET_TESTING_Interpreter *is, | ||
239 | struct GNUNET_TESTING_Barrier *barrier); | ||
240 | |||
241 | |||
242 | /** | ||
243 | * Send Message to master loop that cmds being attached to a barrier. | ||
244 | * | ||
245 | * @param is The interpreter loop. | ||
246 | * @param barrier_name The name of the barrier to advance. | ||
247 | * @param subnet_number The number of the subnet. | ||
248 | * @param node_number The node to inform. | ||
249 | * @param write_message Callback to write messages to the master loop. | ||
250 | */ | ||
251 | void | ||
252 | GNUNET_TESTING_send_barrier_attach (struct GNUNET_TESTING_Interpreter *is, | ||
253 | char *barrier_name, | ||
254 | unsigned int global_node_number, | ||
255 | unsigned int expected_reaches, | ||
256 | TESTING_CMD_HELPER_write_cb write_message); | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Getting a node from a map by global node number. | ||
261 | * | ||
262 | * @param nodes The map. | ||
263 | * @param node_number The global node number. | ||
264 | * @return The node. | ||
265 | */ | ||
266 | struct GNUNET_TESTING_NetjailNode * | ||
267 | GNUNET_TESTING_barrier_get_node (struct GNUNET_CONTAINER_MultiShortmap *nodes, | ||
268 | unsigned int node_number); | ||
269 | |||
270 | |||
271 | #endif | ||
272 | /* end of testing_barrier.h */ | ||