aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_protocols.h2
-rw-r--r--src/include/gnunet_testbed_ng_service.h6
-rw-r--r--src/testbed/Makefile.am1
-rw-r--r--src/testbed/gnunet-cmds-helper.c23
-rw-r--r--src/testbed/plugin_testcmd.c17
-rw-r--r--src/testbed/testbed_api_cmd_block_until_all_peers_started.c26
-rw-r--r--src/testbed/testbed_api_cmd_local_test_finished.c129
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start_testbed.c49
-rw-r--r--src/testbed/testbed_api_cmd_send_peer_ready.c5
-rw-r--r--src/testbed/testbed_helper.h8
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c104
-rw-r--r--src/testing/testing_api_loop.c4
12 files changed, 347 insertions, 27 deletions
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 1d33d986d..715e94c6a 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -3567,6 +3567,8 @@ extern "C" {
3567 3567
3568#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED 1703 3568#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED 1703
3569 3569
3570#define GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED 1704
3571
3570/*********************************************************************************/ 3572/*********************************************************************************/
3571 3573
3572/** 3574/**
diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h
index 2ea5e616c..caaee26b6 100644
--- a/src/include/gnunet_testbed_ng_service.h
+++ b/src/include/gnunet_testbed_ng_service.h
@@ -274,4 +274,10 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
274struct GNUNET_TESTING_Command 274struct GNUNET_TESTING_Command
275GNUNET_TESTING_cmd_send_peer_ready (const char *label, 275GNUNET_TESTING_cmd_send_peer_ready (const char *label,
276 TESTBED_CMD_HELPER_write_cb write_message); 276 TESTBED_CMD_HELPER_write_cb write_message);
277
278struct GNUNET_TESTING_Command
279GNUNET_TESTING_cmd_local_test_finished (const char *label,
280 TESTBED_CMD_HELPER_write_cb
281 write_message);
282
277#endif 283#endif
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index dc24eaf26..8fa3350a2 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -125,6 +125,7 @@ lib_LTLIBRARIES = \
125 libgnunettestbed.la 125 libgnunettestbed.la
126 126
127libgnunettestbed_la_SOURCES = \ 127libgnunettestbed_la_SOURCES = \
128 testbed_api_cmd_local_test_finished.c \
128 testbed_api_cmd_send_peer_ready.c \ 129 testbed_api_cmd_send_peer_ready.c \
129 testbed_api_cmd_block_until_all_peers_started.c \ 130 testbed_api_cmd_block_until_all_peers_started.c \
130 testbed_api_cmd_netjail_start.c \ 131 testbed_api_cmd_netjail_start.c \
diff --git a/src/testbed/gnunet-cmds-helper.c b/src/testbed/gnunet-cmds-helper.c
index 693892a9c..6498d1279 100644
--- a/src/testbed/gnunet-cmds-helper.c
+++ b/src/testbed/gnunet-cmds-helper.c
@@ -383,7 +383,7 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
383 * @param cls plugin to use. 383 * @param cls plugin to use.
384 * 384 *
385 */ 385 */
386static void 386/*static void
387run_plugin (void *cls) 387run_plugin (void *cls)
388{ 388{
389 struct Plugin *plugin = cls; 389 struct Plugin *plugin = cls;
@@ -400,7 +400,7 @@ run_plugin (void *cls)
400 400
401 plugin->api->start_testcase (&write_message, router_ip, node_ip); 401 plugin->api->start_testcase (&write_message, router_ip, node_ip);
402 402
403} 403}*/
404 404
405 405
406/** 406/**
@@ -433,12 +433,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
433 "tokenizer \n"); 433 "tokenizer \n");
434 434
435 msize = ntohs (message->size); 435 msize = ntohs (message->size);
436 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 436 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
437 message->type))
438 {
439 plugin->api->all_peers_started ();
440 }
441 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
442 { 437 {
443 msg = (const struct GNUNET_CMDS_HelperInit *) message; 438 msg = (const struct GNUNET_CMDS_HelperInit *) message;
444 plugin_name_size = ntohs (msg->plugin_name_size); 439 plugin_name_size = ntohs (msg->plugin_name_size);
@@ -519,7 +514,7 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
519 514
520 GNUNET_free (binary); 515 GNUNET_free (binary);
521 516
522 done_reading = GNUNET_YES; 517 // done_reading = GNUNET_YES;
523 518
524 msg_length = sizeof(struct GNUNET_CMDS_HelperReply); 519 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
525 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); 520 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
@@ -541,6 +536,14 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
541 NULL);*/ 536 NULL);*/
542 return GNUNET_OK; 537 return GNUNET_OK;
543 } 538 }
539 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
540 message->type))
541 {
542 LOG (GNUNET_ERROR_TYPE_ERROR,
543 "We got here 8!\n");
544 plugin->api->all_peers_started ();
545 return GNUNET_OK;
546 }
544 else 547 else
545 { 548 {
546 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n"); 549 LOG (GNUNET_ERROR_TYPE_WARNING, "Received unexpected message -- exiting\n");
@@ -588,6 +591,8 @@ read_task (void *cls)
588 return; 591 return;
589 } 592 }
590 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); 593 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
594 LOG (GNUNET_ERROR_TYPE_ERROR,
595 "Read %u bytes\n", (unsigned int) sread);
591 /* FIXME: could introduce a GNUNET_MST_read2 to read 596 /* FIXME: could introduce a GNUNET_MST_read2 to read
592 directly from 'stdin_fd' and save a memcpy() here */ 597 directly from 'stdin_fd' and save a memcpy() here */
593 if (GNUNET_OK != 598 if (GNUNET_OK !=
diff --git a/src/testbed/plugin_testcmd.c b/src/testbed/plugin_testcmd.c
index 6f28e102d..70b6ad3ae 100644
--- a/src/testbed/plugin_testcmd.c
+++ b/src/testbed/plugin_testcmd.c
@@ -28,12 +28,20 @@
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_ng_service.h" 29#include "gnunet_testbed_ng_service.h"
30 30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
31unsigned int are_all_peers_started; 36unsigned int are_all_peers_started;
32 37
33static void 38static void
34all_peers_started () 39all_peers_started ()
35{ 40{
36 are_all_peers_started = GNUNET_YES; 41 are_all_peers_started = GNUNET_YES;
42 LOG (GNUNET_ERROR_TYPE_ERROR,
43 "setting are_all_peers_started: %d\n",
44 are_all_peers_started);
37} 45}
38 46
39static void 47static void
@@ -42,6 +50,9 @@ start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
42{ 50{
43 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); 51 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
44 52
53 LOG (GNUNET_ERROR_TYPE_ERROR,
54 "We got here 6!\n");
55
45 are_all_peers_started = GNUNET_NO; 56 are_all_peers_started = GNUNET_NO;
46 57
47 struct GNUNET_TESTING_Command commands[] = { 58 struct GNUNET_TESTING_Command commands[] = {
@@ -52,12 +63,15 @@ start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
52 write_message), 63 write_message),
53 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1", 64 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
54 &are_all_peers_started), 65 &are_all_peers_started),
55 GNUNET_TESTING_cmd_end () 66 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
67 write_message)
56 }; 68 };
57 69
58 GNUNET_TESTING_run (NULL, 70 GNUNET_TESTING_run (NULL,
59 commands, 71 commands,
60 GNUNET_TIME_UNIT_FOREVER_REL); 72 GNUNET_TIME_UNIT_FOREVER_REL);
73 LOG (GNUNET_ERROR_TYPE_ERROR,
74 "We got here 7!\n");
61 75
62} 76}
63 77
@@ -75,6 +89,7 @@ libgnunet_plugin_testcmd_init (void *cls)
75 89
76 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions); 90 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
77 api->start_testcase = &start_testcase; 91 api->start_testcase = &start_testcase;
92 api->all_peers_started = &all_peers_started;
78 return api; 93 return api;
79} 94}
80 95
diff --git a/src/testbed/testbed_api_cmd_block_until_all_peers_started.c b/src/testbed/testbed_api_cmd_block_until_all_peers_started.c
index fc872311d..8659fbb46 100644
--- a/src/testbed/testbed_api_cmd_block_until_all_peers_started.c
+++ b/src/testbed/testbed_api_cmd_block_until_all_peers_started.c
@@ -27,6 +27,11 @@
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29 29
30/**
31 * Generic logging shortcut
32 */
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
34
30struct BlockState 35struct BlockState
31{ 36{
32 unsigned int *all_peers_started; 37 unsigned int *all_peers_started;
@@ -58,6 +63,8 @@ block_until_all_peers_started_run (void *cls,
58 const struct GNUNET_TESTING_Command *cmd, 63 const struct GNUNET_TESTING_Command *cmd,
59 struct GNUNET_TESTING_Interpreter *is) 64 struct GNUNET_TESTING_Interpreter *is)
60{ 65{
66 LOG (GNUNET_ERROR_TYPE_ERROR,
67 "block_until_all_peers_started_run!\n");
61} 68}
62 69
63 70
@@ -69,6 +76,21 @@ block_until_all_peers_started_finish (void *cls,
69 struct BlockState *bs = cls; 76 struct BlockState *bs = cls;
70 unsigned int *ret = bs->all_peers_started; 77 unsigned int *ret = bs->all_peers_started;
71 78
79 LOG (GNUNET_ERROR_TYPE_ERROR,
80 "We got here 10\n");
81
82 if (GNUNET_YES == *ret)
83 {
84 LOG (GNUNET_ERROR_TYPE_ERROR,
85 "We do not need to block anymore!\n");
86 cont (cont_cls);
87 }
88 else
89 {
90 LOG (GNUNET_ERROR_TYPE_ERROR,
91 "You shall not pass!\n");
92 }
93
72 return *ret; 94 return *ret;
73} 95}
74 96
@@ -86,6 +108,10 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
86{ 108{
87 struct BlockState *bs; 109 struct BlockState *bs;
88 110
111 LOG (GNUNET_ERROR_TYPE_ERROR,
112 "we have all_peers_started: %u\n",
113 *all_peers_started);
114
89 bs = GNUNET_new (struct BlockState); 115 bs = GNUNET_new (struct BlockState);
90 bs->all_peers_started = all_peers_started; 116 bs->all_peers_started = all_peers_started;
91 117
diff --git a/src/testbed/testbed_api_cmd_local_test_finished.c b/src/testbed/testbed_api_cmd_local_test_finished.c
new file mode 100644
index 000000000..8829f1b9a
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_local_test_finished.c
@@ -0,0 +1,129 @@
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 testing_api_cmd_block_until_all_peers_started.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testbed_helper.h"
30
31/**
32 * Generic logging shortcut
33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35
36struct LocalFinishedState
37{
38 TESTBED_CMD_HELPER_write_cb write_message;
39
40 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
41};
42
43
44static int
45local_test_finished_traits (void *cls,
46 const void **ret,
47 const char *trait,
48 unsigned int index)
49{
50 return GNUNET_OK;
51}
52
53
54static void
55local_test_finished_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd)
57{
58 struct LocalFinishedState *lfs = cls;
59
60 GNUNET_free (lfs->reply);
61 GNUNET_free (lfs);
62}
63
64
65static void
66local_test_finished_run (void *cls,
67 const struct GNUNET_TESTING_Command *cmd,
68 struct GNUNET_TESTING_Interpreter *is)
69{
70 struct LocalFinishedState *lfs = cls;
71
72 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
73 size_t msg_length;
74
75 LOG (GNUNET_ERROR_TYPE_ERROR,
76 "We got here 12!\n");
77
78 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
79 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
80 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
81 reply->header.size = htons ((uint16_t) msg_length);
82 lfs->reply = reply;
83 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
84
85 LOG (GNUNET_ERROR_TYPE_ERROR,
86 "We got here 13!\n");
87}
88
89
90static int
91local_test_finished_finish (void *cls,
92 GNUNET_SCHEDULER_TaskCallback cont,
93 void *cont_cls)
94{
95 // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
96 return GNUNET_YES;
97}
98
99
100/**
101 * Create command.
102 *
103 * @param label name for command.
104 * @return command.
105 */
106struct GNUNET_TESTING_Command
107GNUNET_TESTING_cmd_local_test_finished (const char *label,
108 TESTBED_CMD_HELPER_write_cb
109 write_message)
110{
111 struct LocalFinishedState *lfs;
112
113 LOG (GNUNET_ERROR_TYPE_ERROR,
114 "We got here 11!\n");
115
116 lfs = GNUNET_new (struct LocalFinishedState);
117 lfs->write_message = write_message;
118
119 struct GNUNET_TESTING_Command cmd = {
120 .cls = lfs,
121 .label = label,
122 .run = &local_test_finished_run,
123 .finish = &local_test_finished_finish,
124 .cleanup = &local_test_finished_cleanup,
125 .traits = &local_test_finished_traits
126 };
127
128 return cmd;
129}
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
index 585825cbc..bc4674b74 100644
--- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c
+++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
@@ -89,6 +89,8 @@ struct NetJailState
89 89
90 unsigned int number_of_peers_started; 90 unsigned int number_of_peers_started;
91 91
92 unsigned int number_of_local_test_finished;
93
92 /** 94 /**
93 * The host where the controller is running 95 * The host where the controller is running
94 */ 96 */
@@ -256,6 +258,14 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
256 message->type)) 258 message->type))
257 { 259 {
258 ns->number_of_peers_started++; 260 ns->number_of_peers_started++;
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "number_of_peers_started: %d\n",
263 ns->number_of_peers_started);
264 }
265 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
266 message->type))
267 {
268 ns->number_of_local_test_finished++;
259 } 269 }
260 else 270 else
261 { 271 {
@@ -375,7 +385,8 @@ start_testbed (struct NetJailState *ns, struct
375 tbc)); 385 tbc));
376 386
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378 "Message send!\n"); 388 "Message %d send!\n",
389 tbc->count);
379 390
380 if (NULL == ns->shandle[tbc->count - 1]) 391 if (NULL == ns->shandle[tbc->count - 1])
381 { 392 {
@@ -426,17 +437,22 @@ netjail_start_finish (void *cls,
426 unsigned int ret = GNUNET_NO; 437 unsigned int ret = GNUNET_NO;
427 struct NetJailState *ns = cls; 438 struct NetJailState *ns = cls;
428 unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n); 439 unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
429 struct GNUNET_CMDS_PEER_STARTED *reply; 440 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
430 size_t msg_length; 441 size_t msg_length;
431 struct GNUNET_HELPER_Handle *helper; 442 struct GNUNET_HELPER_Handle *helper;
432 struct TestbedCount *tbc; 443 struct TestbedCount *tbc;
433 444
445 if (ns->number_of_local_test_finished == total_number)
446 {
447 ret = GNUNET_YES;
448 cont (cont_cls);
449 }
450
434 if (ns->number_of_testbeds_started == total_number) 451 if (ns->number_of_testbeds_started == total_number)
435 { 452 {
436 /* ret = GNUNET_YES;
437 cont (cont_cls);*/
438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
439 "All helpers started!\n"); 454 "All helpers started!\n");
455 ns->number_of_testbeds_started = 0;
440 } 456 }
441 457
442 if (ns->number_of_peers_started == total_number) 458 if (ns->number_of_peers_started == total_number)
@@ -449,9 +465,9 @@ netjail_start_finish (void *cls,
449 { 465 {
450 tbc = GNUNET_new (struct TestbedCount); 466 tbc = GNUNET_new (struct TestbedCount);
451 tbc->ns = ns; 467 tbc->ns = ns;
452 tbc->count = (j - 1) * atoi (ns->local_m) + i + atoi (ns->global_n) 468 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
453 * atoi (ns->local_m); 469 tbc->count = (j - 1) * atoi (ns->local_m) + i + total_number;
454 helper = ns->helper[tbc->count - 1]; 470 helper = ns->helper[tbc->count - 1 - total_number];
455 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); 471 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
456 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); 472 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
457 reply->header.type = htons ( 473 reply->header.type = htons (
@@ -460,14 +476,21 @@ netjail_start_finish (void *cls,
460 476
461 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header); 477 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
462 478
463 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send ( 479 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
464 helper, 480 helper,
465 &reply->header, 481 &reply->header,
466 GNUNET_NO, 482 GNUNET_NO,
467 &clear_msg, 483 &clear_msg,
468 tbc)); 484 tbc);
485
486 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
487
488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "All peers started message %d send!\n",
490 tbc->count);
469 } 491 }
470 } 492 }
493 ns->number_of_peers_started = 0;
471 } 494 }
472 return ret; 495 return ret;
473} 496}
diff --git a/src/testbed/testbed_api_cmd_send_peer_ready.c b/src/testbed/testbed_api_cmd_send_peer_ready.c
index 8a82b23a8..f175a3e18 100644
--- a/src/testbed/testbed_api_cmd_send_peer_ready.c
+++ b/src/testbed/testbed_api_cmd_send_peer_ready.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "testbed_helper.h"
29 30
30 31
31struct SendPeerReadyState 32struct SendPeerReadyState
@@ -62,7 +63,7 @@ send_peer_ready_run (void *cls,
62 const struct GNUNET_TESTING_Command *cmd, 63 const struct GNUNET_TESTING_Command *cmd,
63 struct GNUNET_TESTING_Interpreter *is) 64 struct GNUNET_TESTING_Interpreter *is)
64{ 65{
65 /*struct SendPeerReadyState *sprs = cls; 66 struct SendPeerReadyState *sprs = cls;
66 struct GNUNET_CMDS_PEER_STARTED *reply; 67 struct GNUNET_CMDS_PEER_STARTED *reply;
67 size_t msg_length; 68 size_t msg_length;
68 69
@@ -71,7 +72,7 @@ send_peer_ready_run (void *cls,
71 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED); 72 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED);
72 reply->header.size = htons ((uint16_t) msg_length); 73 reply->header.size = htons ((uint16_t) msg_length);
73 sprs->reply = reply; 74 sprs->reply = reply;
74 sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);*/ 75 sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
75} 76}
76 77
77 78
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h
index 84059fef2..af90ce85d 100644
--- a/src/testbed/testbed_helper.h
+++ b/src/testbed/testbed_helper.h
@@ -130,6 +130,14 @@ struct GNUNET_CMDS_ALL_PEERS_STARTED
130 struct GNUNET_MessageHeader header; 130 struct GNUNET_MessageHeader header;
131}; 131};
132 132
133struct GNUNET_CMDS_LOCAL_FINISHED
134{
135 /**
136 * Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
137 */
138 struct GNUNET_MessageHeader header;
139};
140
133GNUNET_NETWORK_STRUCT_END 141GNUNET_NETWORK_STRUCT_END
134#endif 142#endif
135/* end of testbed_helper.h */ 143/* end of testbed_helper.h */
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
new file mode 100644
index 000000000..27761c4d5
--- /dev/null
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -0,0 +1,104 @@
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 testing_api_cmd_send_peer_ready.c
23 * @brief cmd to send a helper message if peer is ready.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "testbed_api.h"
30#include "testbed_helper.h"
31
32
33struct SendPeerReadyState
34{
35 TESTBED_CMD_HELPER_write_cb write_message;
36
37 struct GNUNET_CMDS_PEER_STARTED *reply;
38};
39
40
41static int
42send_peer_ready_traits (void *cls,
43 const void **ret,
44 const char *trait,
45 unsigned int index)
46{
47 return GNUNET_OK;
48}
49
50
51static void
52send_peer_ready_cleanup (void *cls,
53 const struct GNUNET_TESTING_Command *cmd)
54{
55 struct SendPeerReadyState *sprs = cls;
56
57 GNUNET_free (sprs->reply);
58 GNUNET_free (sprs);
59}
60
61
62static void
63send_peer_ready_run (void *cls,
64 const struct GNUNET_TESTING_Command *cmd,
65 struct GNUNET_TESTING_Interpreter *is)
66{
67 struct SendPeerReadyState *sprs = cls;
68 struct GNUNET_CMDS_PEER_STARTED *reply;
69 size_t msg_length;
70
71 msg_length = sizeof(struct GNUNET_CMDS_HelperInit);// GNUNET_CMDS_PEER_STARTED);
72 reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED);
73 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED);
74 reply->header.size = htons ((uint16_t) msg_length);
75 sprs->reply = reply;
76 sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
77}
78
79
80/**
81 * Create command.
82 *
83 * @param label name for command.
84 * @return command.
85 */
86struct GNUNET_TESTING_Command
87GNUNET_TESTING_cmd_send_peer_ready (const char *label,
88 TESTBED_CMD_HELPER_write_cb write_message)
89{
90 struct SendPeerReadyState *sprs;
91
92 sprs = GNUNET_new (struct SendPeerReadyState);
93 sprs->write_message = write_message;
94
95 struct GNUNET_TESTING_Command cmd = {
96 .cls = sprs,
97 .label = label,
98 .run = &send_peer_ready_run,
99 .cleanup = &send_peer_ready_cleanup,
100 .traits = &send_peer_ready_traits
101 };
102
103 return cmd;
104}
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 7b7dc010a..f4fa4e17e 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -415,7 +415,7 @@ interpreter_run (void *cls)
415 if (NULL == cmd->label) 415 if (NULL == cmd->label)
416 { 416 {
417 417
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
419 "Running command END %p\n", 419 "Running command END %p\n",
420 is); 420 is);
421 is->result = GNUNET_OK; 421 is->result = GNUNET_OK;
@@ -424,7 +424,7 @@ interpreter_run (void *cls)
424 } 424 }
425 else if (NULL != cmd) 425 else if (NULL != cmd)
426 { 426 {
427 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
428 "Running command `%s' %p\n", 428 "Running command `%s' %p\n",
429 cmd->label, 429 cmd->label,
430 is); 430 is);