diff options
Diffstat (limited to 'src/transport/transport-testing-cmds.h')
-rw-r--r-- | src/transport/transport-testing-cmds.h | 390 |
1 files changed, 0 insertions, 390 deletions
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h deleted file mode 100644 index 46f6045dc..000000000 --- a/src/transport/transport-testing-cmds.h +++ /dev/null | |||
@@ -1,390 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2021 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 transport-testing.h | ||
23 | * @brief testing lib for transport service | ||
24 | * @author Matthias Wachs | ||
25 | * @author Christian Grothoff | ||
26 | */ | ||
27 | #ifndef TRANSPORT_TESTING_CMDS_H | ||
28 | #define TRANSPORT_TESTING_CMDS_H | ||
29 | #include "gnunet_testing_ng_lib.h" | ||
30 | #include "gnunet_testing_plugin.h" | ||
31 | |||
32 | typedef void * | ||
33 | (*GNUNET_TRANSPORT_notify_connect_cb) (struct GNUNET_TESTING_Interpreter *is, | ||
34 | const struct GNUNET_PeerIdentity *peer); | ||
35 | |||
36 | /** | ||
37 | * Struct to store information needed in callbacks. | ||
38 | * | ||
39 | */ | ||
40 | struct ConnectPeersState | ||
41 | { | ||
42 | /** | ||
43 | * Context for our asynchronous completion. | ||
44 | */ | ||
45 | struct GNUNET_TESTING_AsyncContext ac; | ||
46 | |||
47 | GNUNET_TRANSPORT_notify_connect_cb notify_connect; | ||
48 | |||
49 | /** | ||
50 | * The testing system of this node. | ||
51 | */ | ||
52 | const struct GNUNET_TESTING_System *tl_system; | ||
53 | |||
54 | // Label of the cmd which started the test system. | ||
55 | const char *create_label; | ||
56 | |||
57 | /** | ||
58 | * Number globally identifying the node. | ||
59 | * | ||
60 | */ | ||
61 | uint32_t num; | ||
62 | |||
63 | /** | ||
64 | * Label of the cmd to start a peer. | ||
65 | * | ||
66 | */ | ||
67 | const char *start_peer_label; | ||
68 | |||
69 | /** | ||
70 | * The topology of the test setup. | ||
71 | */ | ||
72 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
73 | |||
74 | /** | ||
75 | * Connections to other peers. | ||
76 | */ | ||
77 | struct GNUNET_TESTING_NodeConnection *node_connections_head; | ||
78 | |||
79 | struct GNUNET_TESTING_Interpreter *is; | ||
80 | |||
81 | /** | ||
82 | * Number of connections. | ||
83 | */ | ||
84 | unsigned int con_num; | ||
85 | |||
86 | /** | ||
87 | * Number of additional connects this cmd will wait for not triggered by this cmd. | ||
88 | */ | ||
89 | unsigned int additional_connects; | ||
90 | |||
91 | /** | ||
92 | * Number of connections we already have a notification for. | ||
93 | */ | ||
94 | unsigned int con_num_notified; | ||
95 | |||
96 | /** | ||
97 | * Number of additional connects this cmd will wait for not triggered by this cmd we already have a notification for. | ||
98 | */ | ||
99 | unsigned int additional_connects_notified; | ||
100 | }; | ||
101 | |||
102 | struct StartPeerState | ||
103 | { | ||
104 | /** | ||
105 | * Context for our asynchronous completion. | ||
106 | */ | ||
107 | struct GNUNET_TESTING_AsyncContext ac; | ||
108 | |||
109 | /** | ||
110 | * The ip of a node. | ||
111 | */ | ||
112 | char *node_ip; | ||
113 | |||
114 | /** | ||
115 | * Receive callback | ||
116 | */ | ||
117 | struct GNUNET_MQ_MessageHandler *handlers; | ||
118 | |||
119 | /** | ||
120 | * GNUnet configuration file used to start a peer. | ||
121 | */ | ||
122 | char *cfgname; | ||
123 | |||
124 | /** | ||
125 | * Peer's configuration | ||
126 | */ | ||
127 | struct GNUNET_CONFIGURATION_Handle *cfg; | ||
128 | |||
129 | /** | ||
130 | * struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure. | ||
131 | */ | ||
132 | struct GNUNET_TESTING_Peer *peer; | ||
133 | |||
134 | /** | ||
135 | * Peer identity | ||
136 | */ | ||
137 | struct GNUNET_PeerIdentity id; | ||
138 | |||
139 | /** | ||
140 | * Peer's transport service handle | ||
141 | */ | ||
142 | struct GNUNET_TRANSPORT_CoreHandle *th; | ||
143 | |||
144 | /** | ||
145 | * Application handle | ||
146 | */ | ||
147 | struct GNUNET_TRANSPORT_ApplicationHandle *ah; | ||
148 | |||
149 | /** | ||
150 | * Peer's PEERSTORE Handle | ||
151 | */ | ||
152 | struct GNUNET_PEERSTORE_Handle *ph; | ||
153 | |||
154 | /** | ||
155 | * Hello get task | ||
156 | */ | ||
157 | struct GNUNET_SCHEDULER_Task *rh_task; | ||
158 | |||
159 | /** | ||
160 | * Peer's transport get hello handle to retrieve peer's HELLO message | ||
161 | */ | ||
162 | struct GNUNET_PEERSTORE_IterateContext *pic; | ||
163 | |||
164 | /** | ||
165 | * Hello | ||
166 | */ | ||
167 | char *hello; | ||
168 | |||
169 | /** | ||
170 | * Hello size | ||
171 | */ | ||
172 | size_t hello_size; | ||
173 | |||
174 | /** | ||
175 | * The label of the command which was started by calling GNUNET_TESTING_cmd_system_create. | ||
176 | */ | ||
177 | char *system_label; | ||
178 | |||
179 | /** | ||
180 | * An unique number to identify the peer | ||
181 | */ | ||
182 | unsigned int no; | ||
183 | |||
184 | /** | ||
185 | * A map with struct GNUNET_MQ_Handle values for each peer this peer | ||
186 | * is connected to. | ||
187 | */ | ||
188 | struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; | ||
189 | |||
190 | /** | ||
191 | * Test setup for this peer. | ||
192 | */ | ||
193 | const struct GNUNET_TESTING_System *tl_system; | ||
194 | |||
195 | /** | ||
196 | * Callback which is called on neighbour connect events. | ||
197 | */ | ||
198 | GNUNET_TRANSPORT_notify_connect_cb notify_connect; | ||
199 | |||
200 | /** | ||
201 | * Flag indicating, if udp broadcast should be switched on. | ||
202 | */ | ||
203 | enum GNUNET_GenericReturnValue broadcast; | ||
204 | }; | ||
205 | |||
206 | struct TestState | ||
207 | { | ||
208 | /** | ||
209 | * Callback to write messages to the master loop. | ||
210 | * | ||
211 | */ | ||
212 | GNUNET_TESTING_cmd_helper_write_cb write_message; | ||
213 | |||
214 | /** | ||
215 | * Callback to notify the helper test case has finished. | ||
216 | */ | ||
217 | GNUNET_TESTING_cmd_helper_finish_cb finished_cb; | ||
218 | |||
219 | /** | ||
220 | * The name for a specific test environment directory. | ||
221 | * | ||
222 | */ | ||
223 | char *testdir; | ||
224 | |||
225 | /** | ||
226 | * The name for the configuration file of the specific node. | ||
227 | * | ||
228 | */ | ||
229 | char *cfgname; | ||
230 | |||
231 | /** | ||
232 | * The complete topology information. | ||
233 | */ | ||
234 | struct GNUNET_TESTING_NetjailTopology *topology; | ||
235 | }; | ||
236 | |||
237 | |||
238 | /** | ||
239 | * Create command. | ||
240 | * | ||
241 | * @param label name for command. | ||
242 | * @param system_label Label of the cmd to setup a test environment. | ||
243 | * @param no Decimal number representing the last byte of the IP address of this peer. | ||
244 | * @param node_ip The IP address of this node. | ||
245 | * @param handlers Handler for messages received by this peer. | ||
246 | * @param cfgname Configuration file name for this peer. | ||
247 | * @param notify_connect Method which will be called, when a peer connects. | ||
248 | * @param broadcast Flag indicating, if broadcast should be switched on. | ||
249 | * @return command. | ||
250 | */ | ||
251 | struct GNUNET_TESTING_Command | ||
252 | GNUNET_TRANSPORT_cmd_start_peer (const char *label, | ||
253 | const char *system_label, | ||
254 | uint32_t no, | ||
255 | const char *node_ip, | ||
256 | struct GNUNET_MQ_MessageHandler *handlers, | ||
257 | const char *cfgname, | ||
258 | GNUNET_TRANSPORT_notify_connect_cb | ||
259 | notify_connect, | ||
260 | unsigned int broadcast); | ||
261 | |||
262 | |||
263 | struct GNUNET_TESTING_Command | ||
264 | GNUNET_TRANSPORT_cmd_stop_peer (const char *label, | ||
265 | const char *start_label); | ||
266 | |||
267 | |||
268 | /** | ||
269 | * Create command | ||
270 | * | ||
271 | * @param label name for command | ||
272 | * @param start_peer_label Label of the cmd to start a peer. | ||
273 | * @param create_label Label of the cmd which started the test system. | ||
274 | * @param num Number globally identifying the node. | ||
275 | * @param topology The topology for the test setup. | ||
276 | * @param additional_connects Number of additional connects this cmd will wait for not triggered by this cmd. | ||
277 | * @return command. | ||
278 | */ | ||
279 | struct GNUNET_TESTING_Command | ||
280 | GNUNET_TRANSPORT_cmd_connect_peers ( | ||
281 | const char *label, | ||
282 | const char *start_peer_label, | ||
283 | const char *create_label, | ||
284 | uint32_t num, | ||
285 | struct GNUNET_TESTING_NetjailTopology *topology, | ||
286 | unsigned int additional_connects); | ||
287 | |||
288 | |||
289 | /** | ||
290 | * Create command. | ||
291 | * | ||
292 | * @param label name for command. | ||
293 | * @param start_peer_label Label of the cmd to start a peer. | ||
294 | * @param create_label Label of the cmd which started the test system. | ||
295 | * @param num Number globally identifying the node. | ||
296 | * @param topology The topology for the test setup. | ||
297 | * @return command. | ||
298 | */ | ||
299 | struct GNUNET_TESTING_Command | ||
300 | GNUNET_TRANSPORT_cmd_send_simple (const char *label, | ||
301 | const char *start_peer_label, | ||
302 | const char *create_label, | ||
303 | uint32_t num, | ||
304 | struct GNUNET_TESTING_NetjailTopology * | ||
305 | topology); | ||
306 | |||
307 | |||
308 | /** | ||
309 | * Create command. | ||
310 | * | ||
311 | * @param label name for command. | ||
312 | * @param start_peer_label Label of the cmd to start a peer. | ||
313 | * @param create_label Label of the cmd to create the testing system. | ||
314 | * @param num Number globally identifying the node. | ||
315 | * @param node_n The number of the node in a network namespace. | ||
316 | * @param namespace_n The number of the network namespace. | ||
317 | * @param topology The topology for the test setup. | ||
318 | * @return command. | ||
319 | */ | ||
320 | struct GNUNET_TESTING_Command | ||
321 | GNUNET_TRANSPORT_cmd_backchannel_check (const char *label, | ||
322 | const char *start_peer_label, | ||
323 | const char *create_label, | ||
324 | uint32_t num, | ||
325 | unsigned int node_n, | ||
326 | unsigned int namespace_n, | ||
327 | struct GNUNET_TESTING_NetjailTopology * | ||
328 | topology); | ||
329 | |||
330 | |||
331 | /** | ||
332 | * Create headers for a trait with name @a name for | ||
333 | * statically allocated data of type @a type. | ||
334 | */ | ||
335 | #define GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT(name,type) \ | ||
336 | enum GNUNET_GenericReturnValue \ | ||
337 | GNUNET_TRANSPORT_get_trait_ ## name ( \ | ||
338 | const struct GNUNET_TESTING_Command *cmd, \ | ||
339 | type **ret); \ | ||
340 | struct GNUNET_TESTING_Trait \ | ||
341 | GNUNET_TRANSPORT_make_trait_ ## name ( \ | ||
342 | type * value); | ||
343 | |||
344 | |||
345 | /** | ||
346 | * Create C implementation for a trait with name @a name for statically | ||
347 | * allocated data of type @a type. | ||
348 | */ | ||
349 | #define GNUNET_TRANSPORT_MAKE_IMPL_SIMPLE_TRAIT(name,type) \ | ||
350 | enum GNUNET_GenericReturnValue \ | ||
351 | GNUNET_TRANSPORT_get_trait_ ## name ( \ | ||
352 | const struct GNUNET_TESTING_Command *cmd, \ | ||
353 | type **ret) \ | ||
354 | { \ | ||
355 | if (NULL == cmd->traits) return GNUNET_SYSERR; \ | ||
356 | return cmd->traits (cmd->cls, \ | ||
357 | (const void **) ret, \ | ||
358 | GNUNET_S (name), \ | ||
359 | 0); \ | ||
360 | } \ | ||
361 | struct GNUNET_TESTING_Trait \ | ||
362 | GNUNET_TRANSPORT_make_trait_ ## name ( \ | ||
363 | type * value) \ | ||
364 | { \ | ||
365 | struct GNUNET_TESTING_Trait ret = { \ | ||
366 | .trait_name = GNUNET_S (name), \ | ||
367 | .ptr = (const void *) value \ | ||
368 | }; \ | ||
369 | return ret; \ | ||
370 | } | ||
371 | |||
372 | |||
373 | /** | ||
374 | * Call #op on all simple traits. | ||
375 | */ | ||
376 | #define GNUNET_TRANSPORT_SIMPLE_TRAITS(op) \ | ||
377 | op (peer_id, const struct GNUNET_PeerIdentity) \ | ||
378 | op (connected_peers_map, const struct GNUNET_CONTAINER_MultiShortmap) \ | ||
379 | op (hello_size, const size_t) \ | ||
380 | op (hello, const char) \ | ||
381 | op (application_handle, const struct GNUNET_TRANSPORT_ApplicationHandle) \ | ||
382 | op (connect_peer_state, const struct ConnectPeersState) \ | ||
383 | op (state, const struct StartPeerState) \ | ||
384 | op (broadcast, const enum GNUNET_GenericReturnValue) | ||
385 | |||
386 | GNUNET_TRANSPORT_SIMPLE_TRAITS (GNUNET_TRANSPORT_MAKE_DECL_SIMPLE_TRAIT) | ||
387 | |||
388 | |||
389 | #endif | ||
390 | /* end of transport_testing.h */ | ||