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.c128
1 files changed, 0 insertions, 128 deletions
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
deleted file mode 100644
index 016837214..000000000
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ /dev/null
@@ -1,128 +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 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 "testing_cmds.h"
30
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct SendPeerReadyState
37{
38 /**
39 * Callback to write messages to the master loop.
40 *
41 */
42 TESTING_CMD_HELPER_write_cb write_message;
43
44 /**
45 * The message send back to the master loop.
46 *
47 */
48 struct GNUNET_CMDS_PEER_STARTED *reply;
49};
50
51
52/**
53 * Trait function of this cmd does nothing.
54 *
55 */
56static int
57send_peer_ready_traits (void *cls,
58 const void **ret,
59 const char *trait,
60 unsigned int index)
61{
62 return GNUNET_OK;
63}
64
65
66/**
67 * The cleanup function of this cmd frees resources the cmd allocated.
68 *
69 */
70static void
71send_peer_ready_cleanup (void *cls,
72 const struct GNUNET_TESTING_Command *cmd)
73{
74 struct SendPeerReadyState *sprs = cls;
75
76 GNUNET_free (sprs->reply);
77 GNUNET_free (sprs);
78}
79
80
81/**
82 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
83 *
84 */
85static void
86send_peer_ready_run (void *cls,
87 const struct GNUNET_TESTING_Command *cmd,
88 struct GNUNET_TESTING_Interpreter *is)
89{
90 struct SendPeerReadyState *sprs = cls;
91 struct GNUNET_CMDS_PEER_STARTED *reply;
92 size_t msg_length;
93
94 msg_length = sizeof(struct GNUNET_CMDS_PEER_STARTED);
95 reply = GNUNET_new (struct GNUNET_CMDS_PEER_STARTED);
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 TESTING_CMD_HELPER_write_cb write_message)
113{
114 struct SendPeerReadyState *sprs;
115
116 sprs = GNUNET_new (struct SendPeerReadyState);
117 sprs->write_message = write_message;
118
119 struct GNUNET_TESTING_Command cmd = {
120 .cls = sprs,
121 .label = label,
122 .run = &send_peer_ready_run,
123 .cleanup = &send_peer_ready_cleanup,
124 .traits = &send_peer_ready_traits
125 };
126
127 return cmd;
128}