aboutsummaryrefslogtreecommitdiff
path: root/src/lib/testing/testing_api_cmd_send_peer_ready.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/testing/testing_api_cmd_send_peer_ready.c')
-rw-r--r--src/lib/testing/testing_api_cmd_send_peer_ready.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/lib/testing/testing_api_cmd_send_peer_ready.c b/src/lib/testing/testing_api_cmd_send_peer_ready.c
new file mode 100644
index 000000000..f615a1cee
--- /dev/null
+++ b/src/lib/testing/testing_api_cmd_send_peer_ready.c
@@ -0,0 +1,123 @@
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 "gnunet_testing_plugin.h"
30#include "gnunet_testing_barrier.h"
31#include "gnunet_testing_netjail_lib.h"
32#include "testing_cmds.h"
33
34
35/**
36 * Struct to hold information for callbacks.
37 *
38 */
39struct SendPeerReadyState
40{
41 /**
42 * Callback to write messages to the master loop.
43 *
44 */
45 GNUNET_TESTING_cmd_helper_write_cb write_message;
46
47 /**
48 * The message send back to the master loop.
49 *
50 */
51 struct GNUNET_TESTING_CommandPeerStarted *reply;
52};
53
54
55/**
56 * Trait function of this cmd does nothing.
57 *
58 */
59static enum GNUNET_GenericReturnValue
60send_peer_ready_traits (void *cls,
61 const void **ret,
62 const char *trait,
63 unsigned int index)
64{
65 return GNUNET_NO;
66}
67
68
69/**
70 * The cleanup function of this cmd frees resources the cmd allocated.
71 *
72 */
73static void
74send_peer_ready_cleanup (void *cls)
75{
76 struct SendPeerReadyState *sprs = cls;
77
78 GNUNET_free (sprs);
79}
80
81
82/**
83 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
84 *
85 */
86static void
87send_peer_ready_run (void *cls,
88 struct GNUNET_TESTING_Interpreter *is)
89{
90 struct SendPeerReadyState *sprs = cls;
91 struct GNUNET_TESTING_CommandPeerStarted *reply;
92 size_t msg_length;
93
94 msg_length = sizeof(struct GNUNET_TESTING_CommandPeerStarted);
95 reply = GNUNET_new (struct GNUNET_TESTING_CommandPeerStarted);
96 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED);
97 reply->header.size = htons ((uint16_t) msg_length);
98 sprs->reply = reply;
99 sprs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
100}
101
102
103/**
104 * Create command.
105 *
106 * @param label name for command.
107 * @param write_message Callback to write messages to the master loop.
108 * @return command.
109 */
110struct GNUNET_TESTING_Command
111GNUNET_TESTING_cmd_send_peer_ready (const char *label,
112 GNUNET_TESTING_cmd_helper_write_cb
113 write_message)
114{
115 struct SendPeerReadyState *sprs;
116
117 sprs = GNUNET_new (struct SendPeerReadyState);
118 sprs->write_message = write_message;
119 return GNUNET_TESTING_command_new (sprs, label,
120 &send_peer_ready_run,
121 &send_peer_ready_cleanup,
122 &send_peer_ready_traits, NULL);
123}