aboutsummaryrefslogtreecommitdiff
path: root/src/testbed/test_gnunet_helper_testbed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/test_gnunet_helper_testbed.c')
-rw-r--r--src/testbed/test_gnunet_helper_testbed.c255
1 files changed, 0 insertions, 255 deletions
diff --git a/src/testbed/test_gnunet_helper_testbed.c b/src/testbed/test_gnunet_helper_testbed.c
deleted file mode 100644
index ea303a86c..000000000
--- a/src/testbed/test_gnunet_helper_testbed.c
+++ /dev/null
@@ -1,255 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2008--2013 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 testbed/test_gnunet_helper_testbed.c
23 * @brief Testcase for testing gnunet-helper-testbed.c
24 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
25 */
26
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_testbed_service.h"
30#include <zlib.h>
31
32#include "testbed_api.h"
33#include "testbed_helper.h"
34#include "testbed_api_hosts.h"
35
36/**
37 * Generic logging shortcut
38 */
39#define LOG(kind, ...) \
40 GNUNET_log (kind, __VA_ARGS__)
41
42
43/**
44 * Handle to the helper process
45 */
46static struct GNUNET_HELPER_Handle *helper;
47
48/**
49 * Message to helper
50 */
51static struct GNUNET_TESTBED_HelperInit *msg;
52
53/**
54 * Message send handle
55 */
56static struct GNUNET_HELPER_SendHandle *shandle;
57
58/**
59 * Abort task identifier
60 */
61static struct GNUNET_SCHEDULER_Task *abort_task;
62
63/**
64 * Shutdown task identifier
65 */
66static struct GNUNET_SCHEDULER_Task *shutdown_task;
67
68/**
69 * Configuration handle.
70 */
71static struct GNUNET_CONFIGURATION_Handle *cfg;
72
73/**
74 * Global testing status
75 */
76static int result;
77
78
79/**
80 * Shutdown nicely
81 *
82 * @param cls NULL
83 */
84static void
85do_shutdown (void *cls)
86{
87 if (NULL != abort_task)
88 GNUNET_SCHEDULER_cancel (abort_task);
89 if (NULL != helper)
90 GNUNET_HELPER_stop (helper, GNUNET_NO);
91 GNUNET_free (msg);
92 if (NULL != cfg)
93 GNUNET_CONFIGURATION_destroy (cfg);
94}
95
96
97/**
98 * abort task to run on test timed out
99 *
100 * @param cls NULL
101 */
102static void
103do_abort (void *cls)
104{
105 abort_task = NULL;
106 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
107 result = GNUNET_SYSERR;
108 if (NULL != shandle)
109 GNUNET_HELPER_send_cancel (shandle);
110 if (NULL == shutdown_task)
111 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
112}
113
114
115/**
116 * Continuation function.
117 *
118 * @param cls closure
119 * @param result #GNUNET_OK on success,
120 * #GNUNET_NO if helper process died
121 * #GNUNET_SYSERR during GNUNET_HELPER_stop()
122 */
123static void
124cont_cb (void *cls,
125 int result)
126{
127 shandle = NULL;
128 LOG (GNUNET_ERROR_TYPE_DEBUG,
129 "Message sent\n");
130 GNUNET_assert (GNUNET_OK == result);
131}
132
133
134/**
135 * Functions with this signature are called whenever a
136 * complete message is received by the tokenizer.
137 *
138 * Do not call GNUNET_SERVER_mst_destroy in callback
139 *
140 * @param cls closure
141 * @param client identification of the client
142 * @param message the actual message
143 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
144 */
145static int
146mst_cb (void *cls,
147 const struct GNUNET_MessageHeader *message)
148{
149 const struct GNUNET_TESTBED_HelperReply *msg;
150 char *config;
151 uLongf config_size;
152 uLongf xconfig_size;
153
154 msg = (const struct GNUNET_TESTBED_HelperReply *) message;
155 config_size = 0;
156 xconfig_size = 0;
157 GNUNET_assert (sizeof(struct GNUNET_TESTBED_HelperReply) <
158 ntohs (msg->header.size));
159 GNUNET_assert (GNUNET_MESSAGE_TYPE_TESTBED_HELPER_REPLY ==
160 ntohs (msg->header.type));
161 config_size = (uLongf) ntohs (msg->config_size);
162 xconfig_size =
163 (uLongf) (ntohs (msg->header.size)
164 - sizeof(struct GNUNET_TESTBED_HelperReply));
165 config = GNUNET_malloc (config_size);
166 GNUNET_assert (Z_OK ==
167 uncompress ((Bytef *) config, &config_size,
168 (const Bytef *) &msg[1], xconfig_size));
169 GNUNET_free (config);
170 if (NULL == shutdown_task)
171 shutdown_task =
172 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
173 (GNUNET_TIME_UNIT_SECONDS, 1),
174 &do_shutdown, NULL);
175 return GNUNET_OK;
176}
177
178
179/**
180 * Callback that will be called when the helper process dies. This is not called
181 * when the helper process is stopped using GNUNET_HELPER_stop()
182 *
183 * @param cls the closure from GNUNET_HELPER_start()
184 */
185static void
186exp_cb (void *cls)
187{
188 helper = NULL;
189 result = GNUNET_SYSERR;
190}
191
192
193/**
194 * Main function that will be run.
195 *
196 * @param cls closure
197 * @param args remaining command-line arguments
198 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
199 * @param cfg configuration
200 */
201static void
202run (void *cls, char *const *args, const char *cfgfile,
203 const struct GNUNET_CONFIGURATION_Handle *cfg2)
204{
205 static char *const binary_argv[] = {
206 "gnunet-helper-testbed",
207 NULL
208 };
209 const char *trusted_ip = "127.0.0.1";
210
211 helper =
212 GNUNET_HELPER_start (GNUNET_YES,
213 "gnunet-helper-testbed",
214 binary_argv,
215 &mst_cb,
216 &exp_cb,
217 NULL);
218 GNUNET_assert (NULL != helper);
219 cfg = GNUNET_CONFIGURATION_dup (cfg2);
220 msg = GNUNET_TESTBED_create_helper_init_msg_ (trusted_ip, NULL, cfg);
221 shandle =
222 GNUNET_HELPER_send (helper, &msg->header, GNUNET_NO, &cont_cb, NULL);
223 GNUNET_assert (NULL != shandle);
224 abort_task =
225 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
226 (GNUNET_TIME_UNIT_MINUTES, 1), &do_abort,
227 NULL);
228}
229
230
231/**
232 * Main function
233 *
234 * @param argc the number of command line arguments
235 * @param argv command line arg array
236 * @return return code
237 */
238int
239main (int argc, char **argv)
240{
241 struct GNUNET_GETOPT_CommandLineOption options[] = {
242 GNUNET_GETOPT_OPTION_END
243 };
244
245 result = GNUNET_OK;
246 if (GNUNET_OK !=
247 GNUNET_PROGRAM_run (argc, argv, "test_gnunet_helper_testbed",
248 "Testcase for testing gnunet-helper-testbed.c",
249 options, &run, NULL))
250 return 1;
251 return (GNUNET_OK == result) ? 0 : 1;
252}
253
254
255/* end of test_gnunet_helper_testbed.c */