aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/testbed/Makefile.am16
-rw-r--r--src/testbed/gnunet-testbed-helper.c207
-rw-r--r--src/testbed/testbed_helper.h55
3 files changed, 275 insertions, 3 deletions
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index b6e42276e..39be05223 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -15,7 +15,8 @@ pkgcfg_DATA = \
15 testbed.conf 15 testbed.conf
16 16
17bin_PROGRAMS = \ 17bin_PROGRAMS = \
18 gnunet-service-testbed 18 gnunet-service-testbed \
19 gnunet-testbed-helper
19 20
20gnunet_service_testbed_SOURCES = \ 21gnunet_service_testbed_SOURCES = \
21 gnunet-service-testbed.c 22 gnunet-service-testbed.c
@@ -27,12 +28,21 @@ gnunet_service_testbed_LDADD = $(XLIB) \
27gnunet_service_testbed_DEPENDENCIES = \ 28gnunet_service_testbed_DEPENDENCIES = \
28 libgnunettestbed.la 29 libgnunettestbed.la
29 30
31gnunet_testbed_helper_SOURCES = \
32 gnunet-testbed-helper.c
33gnunet_testbed_helper_LDADD = $(XLIB) \
34 $(top_builddir)/src/util/libgnunetutil.la \
35 $(top_builddir)/src/testing/libgnunettesting.la \
36 $(LTLIBINTL) -lz
37gnunet_testbed_helper_DEPENDENCIES = \
38 gnunet-service-testbed.$(OBJEXT)
39
30lib_LTLIBRARIES = \ 40lib_LTLIBRARIES = \
31 libgnunettestbed.la 41 libgnunettestbed.la
32 42
33libgnunettestbed_la_SOURCES = \ 43libgnunettestbed_la_SOURCES = \
34 testbed_api.c testbed.h \ 44 testbed_api.c testbed_api.h testbed.h \
35 testbed_api_hosts.c testbed_api_hosts.h \ 45 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \
36 testbed_api_operations.c testbed_api_operations.h \ 46 testbed_api_operations.c testbed_api_operations.h \
37 testbed_api_peers.c testbed_api_peers.h \ 47 testbed_api_peers.c testbed_api_peers.h \
38 testbed_api_services.c \ 48 testbed_api_services.c \
diff --git a/src/testbed/gnunet-testbed-helper.c b/src/testbed/gnunet-testbed-helper.c
new file mode 100644
index 000000000..0b590daa1
--- /dev/null
+++ b/src/testbed/gnunet-testbed-helper.c
@@ -0,0 +1,207 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testbed/gnunet-testbed-helper.c
23 * @brief Helper binary that is started from a remote controller to start
24 * gnunet-service-testbed. This binary also receives configuration
25 * from the remove controller which is put in a temporary location
26 * with ports and paths fixed so that gnunet-service-testbed runs
27 * without any hurdels. This binary also kills the testbed service
28 * should the connection from the remote controller is dropped
29 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
30 */
31
32
33#include "platform.h"
34#include "gnunet_util_lib.h"
35#include "gnunet_testing_lib-new.h"
36
37#include "testbed_helper.h"
38
39
40/**
41 * Generic debug logging shortcut
42 */
43#define LOG_DEBUG(...) \
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
45
46
47/**
48 * Handle to the testing system
49 */
50static struct GNUNET_TESTING_System *test_system;
51
52/**
53 * Our message stream tokenizer
54 */
55struct GNUNET_SERVER_MessageStreamTokenizer *tokenizer;
56
57/**
58 * Disk handle from stdin
59 */
60static struct GNUNET_DISK_FileHandle *stdin_fd;
61
62/**
63 * Message receive buffer
64 */
65static void *buf;
66
67/**
68 * The size of the above buffer
69 */
70static size_t buf_size;
71
72/**
73 * Task identifier for the read task
74 */
75static GNUNET_SCHEDULER_TaskIdentifier read_task_id;
76
77/**
78 * Task identifier for the shutdown task
79 */
80static GNUNET_SCHEDULER_TaskIdentifier shutdown_task_id;
81
82/**
83 * Task to shutting down nicely
84 *
85 * @param cls NULL
86 * @return tc the task context
87 */
88static void
89shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
90{
91 if (GNUNET_SCHEDULER_NO_TASK != read_task_id)
92 GNUNET_SCHEDULER_cancel (read_task_id);
93 (void) GNUNET_DISK_file_close (stdin_fd);
94 GNUNET_free_non_null (buf);
95 GNUNET_SERVER_mst_destroy (tokenizer);
96 if (NULL != test_system)
97 GNUNET_TESTING_system_destroy (test_system, GNUNET_YES);
98}
99
100
101/**
102 * Functions with this signature are called whenever a
103 * complete message is received by the tokenizer.
104 *
105 * Do not call GNUNET_SERVER_mst_destroy in callback
106 *
107 * @param cls closure
108 * @param client identification of the client
109 * @param message the actual message
110 *
111 * @return GNUNET_OK on success, GNUNET_SYSERR to stop further processing
112 */
113static int
114tokenizer_cb (void *cls, void *client,
115 const struct GNUNET_MessageHeader *message)
116{
117 GNUNET_break (0);
118 return GNUNET_OK;
119}
120
121
122/**
123 * Task to read from stdin
124 *
125 * @param cls NULL
126 * @return tc the task context
127 */
128static void
129read_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
130{
131 ssize_t sread;
132 static int ignore_reading = GNUNET_NO;
133 int ret;
134
135 read_task_id = GNUNET_SCHEDULER_NO_TASK;
136 if (GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason)
137 return;
138 sread = GNUNET_DISK_file_read (stdin_fd, buf, buf_size);
139 if (GNUNET_SYSERR == sread)
140 {
141 GNUNET_break (0); /* FIXME: stdin closed - kill child */
142 GNUNET_SCHEDULER_cancel (shutdown_task_id);
143 shutdown_task_id = GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
144 return;
145 }
146 LOG_DEBUG ("Read %u bytes\n", sread);
147 read_task_id = /* No timeout while reading */
148 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
149 stdin_fd, &read_task, NULL);
150 if (GNUNET_YES == ignore_reading)
151 return;
152 ret = GNUNET_SERVER_mst_receive (tokenizer, NULL, buf, sread,
153 GNUNET_YES, GNUNET_YES);
154 GNUNET_assert (GNUNET_SYSERR != ret);
155 if (GNUNET_NO == ret)
156 {
157 LOG_DEBUG ("We only listen for 1 message -- ignoring others\n");
158 ignore_reading = GNUNET_YES;
159 }
160}
161
162
163/**
164 * Main function that will be run.
165 *
166 * @param cls closure
167 * @param args remaining command-line arguments
168 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
169 * @param cfg configuration
170 */
171static void
172run (void *cls, char *const *args, const char *cfgfile,
173 const struct GNUNET_CONFIGURATION_Handle * cfg)
174{
175 tokenizer = GNUNET_SERVER_mst_create (&tokenizer_cb, NULL);
176 stdin_fd = GNUNET_DISK_get_handle_from_native (stdin);
177 buf_size = sizeof (struct GNUNET_TESTBED_HelperInit) + 8 * 1024;
178 buf = GNUNET_malloc (buf_size);
179 read_task_id = /* No timeout while reading */
180 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
181 stdin_fd, &read_task, NULL);
182 shutdown_task_id =
183 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
184 &shutdown_task, NULL);
185}
186
187
188/**
189 * Main function
190 *
191 * @param argc the number of command line arguments
192 * @param argv command line arg array
193 * @return return code
194 */
195int main (int argc, char **argv)
196{
197 struct GNUNET_GETOPT_CommandLineOption options[] = {
198 GNUNET_GETOPT_OPTION_END
199 };
200
201 if (GNUNET_OK !=
202 GNUNET_PROGRAM_run ( argc, argv, "gnunet-testbed-helper",
203 "Helper for starting gnunet-service-testbed",
204 options, &run, NULL))
205 return 1;
206 else return 0;
207}
diff --git a/src/testbed/testbed_helper.h b/src/testbed/testbed_helper.h
new file mode 100644
index 000000000..f4f8abd39
--- /dev/null
+++ b/src/testbed/testbed_helper.h
@@ -0,0 +1,55 @@
1/*
2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21/**
22 * @file testbed/testbed_helper.c
23 * @brief Message formats for communication between testbed api and
24 * gnunet-testbed-helper process
25 * @author Sree Harsha Totakura <sreeharsha@totakura.in>
26 */
27
28#ifndef TESTBED_HELPER_H
29#define TESTBED_HELPER_H
30
31struct GNUNET_TESTBED_HelperInit
32{
33 /**
34 * Type is GNUNET_MESSAGE_TYPE_TESTBED_HELPER_INIT
35 */
36 struct GNUNET_MessageHeader header;
37
38 /**
39 * The controller hostname size excluding the NULL termination character -
40 * strlen (hostname); cannot be zero
41 */
42 uint16_t cname_size GNUNET_PACKED;
43
44 /**
45 * The sizeof the configuration following
46 */
47 uint16_t config_size GNUNET_PACKED;
48
49 /* Followed by NULL terminated controller hostname */
50
51 /* Followed by serialized and compressed configuration which should be
52 config_size long */
53};
54
55#endif