GNUnet 0.24.1-15-gab6ed22f1
plugin_testing_transport_simple_send_dv.c
Go to the documentation of this file.
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
26#include "platform.h"
27#include "gnunet_testing_barrier.h"
28#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_util_lib.h"
31#include "transport-testing2.h"
33#include "gnunet_testing_barrier.h"
34
38#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
39
40#define BASE_DIR "testdir"
41
42#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
43
44#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 600)
45
49static unsigned int number_received;
50
52
54
56
58
60
62
68static int
69check_test (void *cls,
70 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
71{
72 GNUNET_assert (NULL != cls);
73 return GNUNET_OK;
74}
75
76
82static void
83handle_test (void *cls,
84 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
85{
86 struct GNUNET_PeerIdentity *peer = cls;
87 struct GNUNET_TESTING_AsyncContext *ac_block;
88 const struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
89 unsigned int connected;
90 struct GNUNET_TESTING_BlockState *bs;
92 const struct GNUNET_TESTING_StartPeerState *sps;
93
95 &sps);
96 ch = sps->th;
99
100 if (NULL != connected_peers_map)
101 {
104
107 "Received %u test message(s) from %s, %u connected peer(s)\n",
110 connected);
111
112 GNUNET_TESTING_get_trait_async_context (&block_receive,
113 &ac_block);
114
115 if (connected == number_received)
116 {
117 if (NULL != ac_block->is)
118 {
119 GNUNET_assert (NULL != ac_block);
120 if (NULL == ac_block->cont)
122 GNUNET_TESTING_AsyncContext *) ac_block);
123 else
125 GNUNET_TESTING_AsyncContext *) ac_block);
126 }
127 else
128 {
129 GNUNET_TESTING_get_trait_block_state (
131 &bs);
132 bs->asynchronous_finish = GNUNET_YES;
133 }
134
135 }
136 }
137 GNUNET_TRANSPORT_core_receive_continue (ch, peer);
138}
139
140
141struct GNUNET_TESTING_BarrierList *
143{
144 // No Barrier
145 return GNUNET_new (struct GNUNET_TESTING_BarrierList);
146}
147
148
153static void
155{
157
159 "Received message\n");
160 GNUNET_TESTING_get_trait_async_context (&block_send,
161 &ac);
162 GNUNET_assert (NULL != ac);
163 if (NULL == ac->cont)
165 else
167}
168
169
176static void
177handle_result (void *cls,
179{
180 struct TestState *ts = cls;
181
183 "Local test exits with status %d\n",
184 rv);
185 ts->finished_cb (rv);
186 GNUNET_free (ts->testdir);
187 GNUNET_free (ts->cfgname);
189 GNUNET_free (ts);
190}
191
192
197static void *
199 const struct GNUNET_PeerIdentity *peer)
200{
201 const struct ConnectPeersState *cps;
202 const struct GNUNET_TESTING_Command *cmd;
203
205 "notify_connect peer %s\n",
206 GNUNET_i2s (peer));
207 // FIXME: modifying future is a bit unclean, not easy to follow logic;
208 // might be better to when reaching the future command to look into
209 // the past...
210 cmd = GNUNET_TESTING_interpreter_lookup_command_all (is,
211 "connect-peers");
212 // FIXME: check return value!
213 GNUNET_TRANSPORT_TESTING_get_trait_connect_peer_state (cmd,
214 &cps);
215 cps->notify_connect (is,
216 peer);
217 return NULL;
218}
219
220
224static void
226{
227 const struct GNUNET_TESTING_LocalPreparedState *lfs;
228
229 GNUNET_TESTING_get_trait_local_prepared_state (&local_prepared,
230 &lfs);
231 GNUNET_assert (NULL != &lfs->ac);
232 if (NULL == lfs->ac.cont)
234 else
236 GNUNET_TESTING_AsyncContext *) &lfs->ac);
237}
238
239
250static struct GNUNET_TESTING_Interpreter *
252 const char *router_ip,
253 const char *node_ip,
254 const char *m,
255 const char *n,
256 const char *local_m,
257 const char *topology_data,
258 unsigned int *read_file,
259 GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
260{
261 unsigned int n_int;
262 unsigned int m_int;
263 unsigned int local_m_int;
264 unsigned int num;
265 struct TestState *ts = GNUNET_new (struct TestState);
266 struct GNUNET_TESTING_NetjailTopology *topology;
271 ts),
273 };
274 unsigned int sscanf_ret = 0;
275
276 ts->finished_cb = finished_cb;
278 "n %s m %s\n",
279 n,
280 m);
281
282 if (GNUNET_YES == *read_file)
283 {
285 "read from file\n");
286 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
287 }
288 else
289 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
290
291 ts->topology = topology;
292
293 errno = 0;
294 sscanf_ret = sscanf (m, "%u", &m_int);
295 if (errno != 0)
296 {
298 }
299 GNUNET_assert (0 < sscanf_ret);
300 errno = 0;
301 sscanf_ret = sscanf (n, "%u", &n_int);
302 if (errno != 0)
303 {
305 }
306 GNUNET_assert (0 < sscanf_ret);
307 errno = 0;
308 sscanf_ret = sscanf (local_m, "%u", &local_m_int);
309 if (errno != 0)
310 {
312 }
313 GNUNET_assert (0 < sscanf_ret);
314
315 if (0 == n_int)
316 num = m_int;
317 else
318 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
319
320 block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
321 block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
322 "block-receive");
324 "connect-peers",
325 "start-peer",
326 "system-create",
327 num,
328 topology,
329 topology->additional_connects,
330 GNUNET_YES);
331 local_prepared = GNUNET_TESTING_cmd_local_test_prepared (
332 "local-test-prepared",
334
335
337 "test_transport_api_tcp_node1.conf");
338
340 "plugin cfgname: %s\n",
341 ts->cfgname);
342
344 "node ip: %s\n",
345 node_ip);
346
348 "%s%s%s",
349 BASE_DIR,
350 m,
351 n);
352
354 "system-create",
355 num,
356 node_ip,
357 handlers,
358 ts->cfgname,
360 GNUNET_NO);
362 GNUNET_TESTING_cmd_system_create ("system-create",
363 ts->testdir),
365 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
370 "start-peer",
371 "system-create",
372 num,
373 topology),
377 "start-peer"),
378 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
379 "system-create"),
381 };
382
383 ts->write_message = write_message;
384
386 TIMEOUT,
388 ts);
389 return is;
390}
391
392
399void *
401{
403
404 GNUNET_log_setup ("simple-send",
405 "DEBUG",
406 NULL);
407
410 api->all_peers_started = &all_peers_started;
411 api->all_local_tests_prepared = all_local_tests_prepared;
412 api->get_waiting_for_barriers = get_waiting_for_barriers;
413 return api;
414}
415
416
423void *
425{
427
428 GNUNET_free (api);
429 return NULL;
430}
431
432
433/* end of plugin_cmd_simple_send_broadcast.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static void write_message(const struct GNUNET_MessageHeader *message)
Callback to write a message to the parent process.
static void finished_cb(void *cls, enum GNUNET_GenericReturnValue rv)
static struct VoipCommand commands[]
List of supported commands.
void GNUNET_TESTING_async_finish(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has finished.
void GNUNET_TESTING_async_fail(struct GNUNET_TESTING_AsyncContext *ac)
The asynchronous command of ac has failed.
struct GNUNET_TESTING_Interpreter * GNUNET_TESTING_run(const struct GNUNET_TESTING_Command *commands, struct GNUNET_TIME_Relative timeout, GNUNET_TESTING_ResultCallback rc, void *rc_cls)
Run the testsuite.
struct GNUNET_TESTING_Command GNUNET_TESTING_cmd_end(void)
Create command array terminator.
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_TESTING_get_trait_state(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_TESTING_StartPeerState **ret)
enum GNUNET_GenericReturnValue GNUNET_TRANSPORT_TESTING_get_trait_connected_peers_map(const struct GNUNET_TESTING_Command *cmd, const struct GNUNET_CONTAINER_MultiShortmap **ret)
Bandwidth allocation API for applications to interact with.
unsigned int GNUNET_CONTAINER_multishortmap_size(const struct GNUNET_CONTAINER_MultiShortmap *map)
Get the number of key-value pairs in the map.
#define GNUNET_log(kind,...)
GNUNET_GenericReturnValue
Named constants for return values.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
enum GNUNET_GenericReturnValue read_file(char const *const filename, char **buffer)
Definition: pabc_helper.c:71
static struct GNUNET_TESTING_Command block_receive
void * libgnunet_test_transport_plugin_cmd_simple_send_dv_init(void *cls)
Entry point for the plugin.
static struct GNUNET_TESTING_Command block_send
static void handle_result(void *cls, enum GNUNET_GenericReturnValue rv)
Function called with the final result of the test.
static struct GNUNET_TESTING_Command local_prepared
static struct GNUNET_TESTING_Command connect_peers
void * libgnunet_test_transport_plugin_cmd_simple_send_dv_done(void *cls)
Exit point from the plugin.
static void all_local_tests_prepared()
Callback to set the flag indicating all peers are prepared to finish.
static unsigned int number_received
The number of messages received.
static void * notify_connect(struct GNUNET_TESTING_Interpreter *is, const struct GNUNET_PeerIdentity *peer)
Callback from start peer cmd for signaling a peer got connected.
struct GNUNET_TESTING_BarrierList * get_waiting_for_barriers()
static struct GNUNET_TESTING_Command start_peer
static int check_test(void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.
static void handle_test(void *cls, const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being received.
static struct GNUNET_TESTING_Interpreter * is
#define LOG(kind,...)
Generic logging shortcut.
static void all_peers_started()
Callback to set the flag indicating all peers started.
static struct GNUNET_TESTING_Interpreter * start_testcase(GNUNET_TESTING_cmd_helper_write_cb write_message, const char *router_ip, const char *node_ip, const char *m, const char *n, const char *local_m, const char *topology_data, unsigned int *read_file, GNUNET_TESTING_cmd_helper_finish_cb finished_cb)
Function to start a local test case.
Struct to store information needed in callbacks.
GNUNET_TESTING_notify_connect_cb notify_connect
Internal representation of the hash map.
Message handler for a specific message type.
The identity of the host (wraps the signing key of the peer).
State each asynchronous command must have in its closure.
struct GNUNET_TESTING_Interpreter * is
Interpreter we are part of.
A command to be run by the interpreter.
void * cls
Closure for all commands with command-specific context information.
Global state of the interpreter, used by a command to access information about other commands.
Topology of our netjail setup.
unsigned int nodes_x
Number of global known nodes.
unsigned int additional_connects
Additional connects we do expect, beside the connects which are configured in the topology.
The plugin API every test case plugin has to implement.
void * cls
Closure to pass to start_testcase.
struct GNUNET_TESTING_Interpreter *(* start_testcase)(void *cls, const char *topology_data, uint32_t barrier_count, const struct GNUNET_ShortHashCode *barriers, GNUNET_TESTING_cmd_helper_write_cb write_message, GNUNET_TESTING_ResultCallback finish_cb, void *finish_cb_cls)
Function to be implemented for each test case plugin which starts the test case on a netjail node.
Handle for a peer controlled via ARM.
struct GNUNET_CONTAINER_MultiShortmap * connected_peers_map
A map with struct GNUNET_MQ_Handle values for each peer this peer is connected to.
struct GNUNET_TESTING_Peer * peer
struct GNUNET_TESTING_Peer returned by GNUNET_TESTING_peer_configure.
struct GNUNET_TRANSPORT_CoreHandle * th
Peer's transport service handle.
Handle for the transport service (includes all of the state for the transport service).
char * cfgname
The name for the configuration file of the specific node.
char * testdir
The name for a specific test environment directory.
struct GNUNET_TESTING_NetjailTopology * topology
The complete topology information.
void(* GNUNET_TESTING_cmd_helper_write_cb)(const struct GNUNET_MessageHeader *message)
Callback function to write messages from the helper process running on a netjail node to the master p...
void GNUNET_TESTING_free_topology(struct GNUNET_TESTING_NetjailTopology *topology)
Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_send_simple(const char *label, const char *start_peer_label, const char *create_label, uint32_t num)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_stop_peer(const char *label, const char *start_label)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_connect_peers(const char *label, const char *start_peer_label, const char *create_label, uint32_t num, struct GNUNET_TESTING_NetjailTopology *topology, unsigned int additional_connects, unsigned int wait_for_connect)
Create command.
struct GNUNET_TESTING_Command GNUNET_TRANSPORT_cmd_start_peer(const char *label, const char *system_label, uint32_t no, const char *node_ip, struct GNUNET_MQ_MessageHandler *handlers, const char *cfgname, GNUNET_TRANSPORT_notify_connect_cb notify_connect, unsigned int broadcast)
Create command.
#define GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
Message type used by GNUNET_TRANSPORT_TESTING_simple_send().