aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_send_peer_ready.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing_api_cmd_send_peer_ready.c')
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c104
1 files changed, 104 insertions, 0 deletions
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}