aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-07-02 20:31:52 +0200
committert3sserakt <t3ss@posteo.de>2021-07-02 20:31:52 +0200
commitc4240e04b4cd3956f88c3b1da988345fcd4414fc (patch)
tree3fbba7dc63f729eb55b778846ccaf1cda2c6f81d /src
parent13dbe5418c1e61bb3c433efa7c2dc412e08b356d (diff)
downloadgnunet-c4240e04b4cd3956f88c3b1da988345fcd4414fc.tar.gz
gnunet-c4240e04b4cd3956f88c3b1da988345fcd4414fc.zip
- stopping testbed, starting testbed for every node, fixing bugs, implement traits to start peers on nodes
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testbed_ng_service.h31
-rw-r--r--src/include/gnunet_testing_ng_lib.h2
-rw-r--r--src/testbed/Makefile.am1
-rwxr-xr-xsrc/testbed/netjail_core.sh4
-rwxr-xr-xsrc/testbed/netjail_exec.sh11
-rw-r--r--src/testbed/test_testbed_api_cmd_netjail.c35
-rw-r--r--src/testbed/testbed_api_cmd_controller.c104
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start_testbed.c327
-rw-r--r--src/testbed/testbed_api_cmd_netjail_stop_testbed.c143
-rw-r--r--src/testbed/testbed_api_hosts.c57
-rw-r--r--src/testbed/testbed_api_hosts.h4
-rw-r--r--src/testing/testing_api_loop.c25
-rw-r--r--src/util/child_management.c3
13 files changed, 474 insertions, 273 deletions
diff --git a/src/include/gnunet_testbed_ng_service.h b/src/include/gnunet_testbed_ng_service.h
index b19a6e958..9845b3be6 100644
--- a/src/include/gnunet_testbed_ng_service.h
+++ b/src/include/gnunet_testbed_ng_service.h
@@ -197,11 +197,7 @@ GNUNET_TESTBED_get_trait_controller (const struct GNUNET_TESTING_Command *cmd,
197 197
198struct GNUNET_TESTING_Command 198struct GNUNET_TESTING_Command
199GNUNET_TESTBED_cmd_controller (const char *label, 199GNUNET_TESTBED_cmd_controller (const char *label,
200 const char *trusted_ip, 200 const char *host,
201 const char *hostname,
202 const char *username,
203 uint16_t port,
204 struct GNUNET_CONFIGURATION_Handle *cfg,
205 uint64_t event_mask); 201 uint64_t event_mask);
206 202
207void 203void
@@ -225,6 +221,7 @@ GNUNET_TESTBED_cmd_netjail_start (const char *label,
225 char *local_m, 221 char *local_m,
226 char *global_n); 222 char *global_n);
227 223
224
228/** 225/**
229 * Create command. 226 * Create command.
230 * 227 *
@@ -234,11 +231,9 @@ GNUNET_TESTBED_cmd_netjail_start (const char *label,
234 */ 231 */
235struct GNUNET_TESTING_Command 232struct GNUNET_TESTING_Command
236GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label, 233GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label,
237 char *const binary_argv[],
238 char *local_m, 234 char *local_m,
239 char *global_n, 235 char *global_n);
240 GNUNET_MessageTokenizerCallback cb, 236
241 GNUNET_HELPER_ExceptionCallback exp_cb);
242 237
243/** 238/**
244 * Create command. 239 * Create command.
@@ -252,4 +247,22 @@ GNUNET_TESTBED_cmd_netjail_stop (const char *label,
252 char *local_m, 247 char *local_m,
253 char *global_n); 248 char *global_n);
254 249
250
251struct GNUNET_TESTING_Command
252GNUNET_TESTBED_cmd_stop_testbed (const char *label,
253 const char *helper_start_label,
254 char *local_m,
255 char *global_n);
256
257
258int
259GNUNET_TESTBED_get_trait_helper_handles (const struct
260 GNUNET_TESTING_Command *cmd,
261 struct GNUNET_HELPER_Handle ***helper);
262
263
264int
265GNUNET_TESTBED_get_trait_hosts (const struct
266 GNUNET_TESTING_Command *cmd,
267 struct GNUNET_TESTBED_Host ***hosts);
255#endif 268#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index dd83bbe82..a794562a9 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -240,7 +240,7 @@ GNUNET_TESTING_interpreter_get_current_label (
240 * @param is interpreter state. 240 * @param is interpreter state.
241 */ 241 */
242void 242void
243GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is); 243GNUNET_TESTING_interpreter_fail ();
244 244
245 245
246/** 246/**
diff --git a/src/testbed/Makefile.am b/src/testbed/Makefile.am
index 486c4a4f8..79989bae7 100644
--- a/src/testbed/Makefile.am
+++ b/src/testbed/Makefile.am
@@ -94,6 +94,7 @@ lib_LTLIBRARIES = \
94libgnunettestbed_la_SOURCES = \ 94libgnunettestbed_la_SOURCES = \
95 testbed_api_cmd_netjail_start.c \ 95 testbed_api_cmd_netjail_start.c \
96 testbed_api_cmd_netjail_start_testbed.c \ 96 testbed_api_cmd_netjail_start_testbed.c \
97 testbed_api_cmd_netjail_stop_testbed.c \
97 testbed_api_cmd_netjail_stop.c \ 98 testbed_api_cmd_netjail_stop.c \
98 testbed_api.c testbed_api.h testbed.h \ 99 testbed_api.c testbed_api.h testbed.h \
99 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \ 100 testbed_api_hosts.c testbed_api_hosts.h testbed_helper.h \
diff --git a/src/testbed/netjail_core.sh b/src/testbed/netjail_core.sh
index d25948bc7..792b1df24 100755
--- a/src/testbed/netjail_core.sh
+++ b/src/testbed/netjail_core.sh
@@ -99,8 +99,8 @@ netjail_node_exec() {
99} 99}
100 100
101netjail_node_exec_without_fds() { 101netjail_node_exec_without_fds() {
102 local NODE=$1 102 NODE=$1
103 shift 3 103 shift 1
104 104
105 unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@ 105 unshare -fp --kill-child -- ip netns exec $NODE sudo -u $JAILOR -- $@
106} 106}
diff --git a/src/testbed/netjail_exec.sh b/src/testbed/netjail_exec.sh
index 274a8b037..3e5d39c1c 100755
--- a/src/testbed/netjail_exec.sh
+++ b/src/testbed/netjail_exec.sh
@@ -6,14 +6,11 @@ set -x
6 6
7export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 7export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
8 8
9LOCAL_M=$1 9M=$1
10M=$2 10N=$2
11N=$3
12 11
13NODE=$(netjail_print_name "N" $N $M) 12NODE=$(netjail_print_name "N" $N $M)
14INDEX=$(($LOCAL_M * ($N - 1) + $M - 1))
15 13
16FD_X=$(($INDEX * 2 + 3 + 0))
17FD_Y=$(($INDEX * 2 + 3 + 1))
18 14
19netjail_node_exec_without_fds $NODE $@ 15
16netjail_node_exec_without_fds $NODE $3
diff --git a/src/testbed/test_testbed_api_cmd_netjail.c b/src/testbed/test_testbed_api_cmd_netjail.c
index d29ebdcb4..e5fc0877e 100644
--- a/src/testbed/test_testbed_api_cmd_netjail.c
+++ b/src/testbed/test_testbed_api_cmd_netjail.c
@@ -28,22 +28,6 @@
28#include "gnunet_testbed_ng_service.h" 28#include "gnunet_testbed_ng_service.h"
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30
31#define HELPER_TESTBED_BINARY "../testbed/gnunet-helper-testbed"
32
33static int
34tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
35{
36 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called tokenizer.\n");
37 return GNUNET_OK;
38}
39
40
41static void
42exp_cb (void *cls)
43{
44 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
45}
46
47 31
48/** 32/**
49 * Main function to run the test cases. 33 * Main function to run the test cases.
@@ -54,20 +38,19 @@ exp_cb (void *cls)
54static void 38static void
55run (void *cls) 39run (void *cls)
56{ 40{
57 char *const binary_argv[3] = {HELPER_TESTBED_BINARY, NULL};
58
59 struct GNUNET_TESTING_Command commands[] = { 41 struct GNUNET_TESTING_Command commands[] = {
60 GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1", 42 GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1",
61 "1", 43 "2",
62 "2"), 44 "2"),
63 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-exec-1", 45 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1",
64 binary_argv,
65 "1",
66 "2", 46 "2",
67 &tokenizer_cb, 47 "2"),
68 &exp_cb), 48 GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed",
49 "netjail-start-testbed-1",
50 "2",
51 "2"),
69 GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1", 52 GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1",
70 "1", 53 "2",
71 "2"), 54 "2"),
72 GNUNET_TESTING_cmd_end () 55 GNUNET_TESTING_cmd_end ()
73 }; 56 };
@@ -90,5 +73,7 @@ main (int argc,
90 GNUNET_SCHEDULER_run (&run, 73 GNUNET_SCHEDULER_run (&run,
91 NULL); 74 NULL);
92 75
76 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
77 "Test finished!\n");
93 return rv; 78 return rv;
94} 79}
diff --git a/src/testbed/testbed_api_cmd_controller.c b/src/testbed/testbed_api_cmd_controller.c
index e3044eaa7..794b1ccf3 100644
--- a/src/testbed/testbed_api_cmd_controller.c
+++ b/src/testbed/testbed_api_cmd_controller.c
@@ -39,26 +39,6 @@
39 39
40 40
41/** 41/**
42 * abort task to run on test timed out
43 *
44 * @param cls NULL
45 * @param tc the task context
46 */
47static void
48do_abort (void *cls)
49{
50 struct ControllerState *cs = cls;
51
52 if (GNUNET_NO == cs->host_ready)
53 {
54 LOG (GNUNET_ERROR_TYPE_WARNING, "Test timedout -- Aborting\n");
55 cs->abort_task = NULL;
56 GNUNET_TESTBED_shutdown_controller (cs);
57 }
58}
59
60
61/**
62* 42*
63* 43*
64* @param cls closure 44* @param cls closure
@@ -98,83 +78,20 @@ controller_cb (void *cls,
98} 78}
99 79
100 80
101/**
102 * Callback which will be called to after a host registration succeeded or failed
103 *
104 * @param cls the host which has been registered
105 * @param emsg the error message; NULL if host registration is successful
106 */
107static void 81static void
108registration_comp (void *cls, 82controller_run (void *cls,
109 const char *emsg) 83 const struct GNUNET_TESTING_Command *cmd,
110{ 84 struct GNUNET_TESTING_Interpreter *is)
111 struct ControllerState *cs = cls;
112
113 if (NULL != emsg)
114 {
115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "There was an error during host registration: %s\n",
117 emsg);
118 GNUNET_TESTBED_shutdown_controller (cs);
119 }
120 else
121 {
122 cs->reg_handle = NULL;
123 cs->host_ready = GNUNET_YES;
124 }
125}
126
127
128/**
129 * Callback to signal successful startup of the controller process
130 *
131 * @param cls the closure from GNUNET_TESTBED_controller_start()
132 * @param cfg the configuration with which the controller has been started;
133 * NULL if status is not #GNUNET_OK
134 * @param status #GNUNET_OK if the startup is successful; #GNUNET_SYSERR if not,
135 * GNUNET_TESTBED_controller_stop() shouldn't be called in this case
136 */
137static void
138controller_status_cb (void *cls,
139 const struct GNUNET_CONFIGURATION_Handle *cfg_,
140 int status)
141{ 85{
142 struct ControllerState *cs = cls; 86 struct ControllerState *cs = cls;
143 87
144 if (GNUNET_OK != status) 88 cs->is = is;
145 {
146 cs->cp = NULL;
147 return;
148 }
149 89
150 cs->controller = 90 cs->controller =
151 GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb, 91 GNUNET_TESTBED_controller_connect (cs->host, cs->event_mask, &controller_cb,
152 cs); 92 cs);
153 cs->reg_handle =
154 GNUNET_TESTBED_register_host (cs->controller, cs->host, &registration_comp,
155 cs);
156}
157 93
158 94
159static void
160controller_run (void *cls,
161 const struct GNUNET_TESTING_Command *cmd,
162 struct GNUNET_TESTING_Interpreter *is)
163{
164 struct ControllerState *cs = cls;
165
166 cs->is = is;
167 cs->host = GNUNET_TESTBED_host_create (cs->hostname, cs->username, cs->cfg,
168 cs->port);
169 cs->cp = GNUNET_TESTBED_controller_start (cs->trusted_ip,
170 cs->host,
171 &controller_status_cb,
172 cs);
173 cs->abort_task =
174 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
175 (GNUNET_TIME_UNIT_MINUTES, 5),
176 &do_abort,
177 cs);
178} 95}
179 96
180/** 97/**
@@ -264,22 +181,15 @@ GNUNET_TESTBED_shutdown_controller (struct ControllerState *cs)
264 181
265struct GNUNET_TESTING_Command 182struct GNUNET_TESTING_Command
266GNUNET_TESTBED_cmd_controller (const char *label, 183GNUNET_TESTBED_cmd_controller (const char *label,
267 const char *trusted_ip, 184 const char *host,
268 const char *hostname,
269 const char *username,
270 uint16_t port,
271 struct GNUNET_CONFIGURATION_Handle *cfg,
272 uint64_t event_mask) 185 uint64_t event_mask)
273{ 186{
274 struct ControllerState *cs; 187 struct ControllerState *cs;
275 188
276 cs = GNUNET_new (struct ControllerState); 189 cs = GNUNET_new (struct ControllerState);
277 cs->event_mask = event_mask; 190 cs->event_mask = event_mask;
278 cs->trusted_ip = trusted_ip; 191 cs->hostname = host;
279 cs->hostname = hostname; 192
280 cs->username = username;
281 cs->port = port;
282 cs->cfg = cfg;
283 193
284 struct GNUNET_TESTING_Command cmd = { 194 struct GNUNET_TESTING_Command cmd = {
285 .cls = cs, 195 .cls = cs,
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
index da51350a1..786084917 100644
--- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c
+++ b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
@@ -27,20 +27,20 @@
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h" 28#include "gnunet_testbed_ng_service.h"
29#include "testbed_api.h" 29#include "testbed_api.h"
30#include "testbed_api_hosts.h"
30 31
31#define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh" 32#define NETJAIL_EXEC_SCRIPT "./netjail_exec.sh"
32 33
34
33struct NetJailState 35struct NetJailState
34{ 36{
35 37
36 /** 38 /**
37 * The process handle 39 * The process handle
38 */ 40 */
39 struct GNUNET_HELPER_Handle *helper; 41 struct GNUNET_HELPER_Handle **helper;
40
41 GNUNET_MessageTokenizerCallback cb;
42 42
43 GNUNET_HELPER_ExceptionCallback exp_cb; 43 unsigned int n_helper;
44 44
45 char *binary_name; 45 char *binary_name;
46 46
@@ -48,19 +48,36 @@ struct NetJailState
48 48
49 char *global_n; 49 char *global_n;
50 50
51 char **binary_argv;
52
53 /** 51 /**
54 * The send handle for the helper 52 * The send handle for the helper
55 */ 53 */
56 struct GNUNET_HELPER_SendHandle *shandle; 54 struct GNUNET_HELPER_SendHandle **shandle;
55
56 unsigned int n_shandle;
57 57
58 /** 58 /**
59 * The message corresponding to send handle 59 * The message corresponding to send handle
60 */ 60 */
61 struct GNUNET_MessageHeader *msg; 61 struct GNUNET_MessageHeader **msg;
62
63 unsigned int n_msg;
64
65 unsigned int number_of_testbeds_started;
66
67 /**
68 * The host where the controller is running
69 */
70 struct GNUNET_TESTBED_Host **host;
71
72 unsigned int n_host;
62}; 73};
63 74
75struct TestbedCount
76{
77 unsigned int count;
78
79 struct NetJailState *ns;
80};
64 81
65/** 82/**
66* 83*
@@ -93,40 +110,66 @@ netjail_exec_traits (void *cls,
93 const char *trait, 110 const char *trait,
94 unsigned int index) 111 unsigned int index)
95{ 112{
96 return GNUNET_OK; 113 struct NetJailState *ns = cls;
114 struct GNUNET_HELPER_Handle **helper = ns->helper;
115 struct GNUNET_TESTBED_Host **hosts = ns->host;
116
117
118 struct GNUNET_TESTING_Trait traits[] = {
119 {
120 .index = 0,
121 .trait_name = "helper_handles",
122 .ptr = (const void *) helper,
123 },
124 {
125 .index = 1,
126 .trait_name = "hosts",
127 .ptr = (const void *) hosts,
128 },
129 GNUNET_TESTING_trait_end ()
130 };
131
132 return GNUNET_TESTING_get_trait (traits,
133 ret,
134 trait,
135 index);
97} 136}
98 137
99 138
100// TODO This would be a useful macro.
101/** 139/**
102 * Function to join NULL terminated list of arguments 140 * Offer handles to testbed helper from trait
103 * 141 *
104 * @param argv1 the NULL terminated list of arguments. Cannot be NULL. 142 * @param cmd command to extract the message from.
105 * @param argv2 the NULL terminated list of arguments. Cannot be NULL. 143 * @param pt pointer to message.
106 * @return the joined NULL terminated arguments 144 * @return #GNUNET_OK on success.
107 */ 145 */
108static char ** 146int
109join_argv (const char *const *argv1, const char *const *argv2) 147GNUNET_TESTBED_get_trait_helper_handles (const struct
148 GNUNET_TESTING_Command *cmd,
149 struct GNUNET_HELPER_Handle ***helper)
110{ 150{
111 char **argvj; 151 return cmd->traits (cmd->cls,
112 char *argv; 152 (const void **) helper,
113 unsigned int carg = 0; 153 "helper_handles",
114 unsigned int cnt; 154 (unsigned int) 0);
115 155}
116 carg = 0; 156
117 argvj = NULL; 157/**
118 for (cnt = 0; NULL != argv1[cnt]; cnt++) 158 * Offer handles to testbed helper from trait
119 { 159 *
120 argv = GNUNET_strdup (argv1[cnt]); 160 * @param cmd command to extract the message from.
121 GNUNET_array_append (argvj, carg, argv); 161 * @param pt pointer to message.
122 } 162 * @return #GNUNET_OK on success.
123 for (cnt = 0; NULL != argv2[cnt]; cnt++) 163 */
124 { 164int
125 argv = GNUNET_strdup (argv2[cnt]); 165GNUNET_TESTBED_get_trait_hosts (const struct
126 GNUNET_array_append (argvj, carg, argv); 166 GNUNET_TESTING_Command *cmd,
127 } 167 struct GNUNET_TESTBED_Host ***hosts)
128 GNUNET_array_append (argvj, carg, NULL); 168{
129 return argvj; 169 return cmd->traits (cmd->cls,
170 (const void **) hosts,
171 "hosts",
172 (unsigned int) 1);
130} 173}
131 174
132 175
@@ -141,41 +184,95 @@ join_argv (const char *const *argv1, const char *const *argv2)
141static void 184static void
142clear_msg (void *cls, int result) 185clear_msg (void *cls, int result)
143{ 186{
144 struct NetJailState *ns = cls; 187 struct TestbedCount *tbc = cls;
145 188 struct NetJailState *ns = tbc->ns;
146 GNUNET_assert (NULL != ns->shandle); 189
147 ns->shandle = NULL; 190 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
148 GNUNET_free (ns->msg); 191 "clear_msg tbc->count: %d\n",
149 ns->msg = NULL; 192 tbc->count);
193 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
194 ns->shandle[tbc->count - 1] = NULL;
195 GNUNET_free (ns->msg[tbc->count - 1]);
196 ns->msg[tbc->count - 1] = NULL;
150} 197}
151 198
152 199
153/** 200/**
154* Run the "hello world" CMD. 201 * Functions with this signature are called whenever a
155* 202 * complete message is received by the tokenizer.
156* @param cls closure. 203 *
157* @param cmd CMD being run. 204 * Do not call GNUNET_SERVER_mst_destroy in callback
158* @param is interpreter state. 205 *
159*/ 206 * @param cls closure
207 * @param client identification of the client
208 * @param message the actual message
209 *
210 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
211 */
212static int
213helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
214{
215 struct TestbedCount *tbc = cls;
216 struct NetJailState *ns = tbc->ns;
217 struct GNUNET_TESTBED_Host *host = ns->host[tbc->count - 1];
218
219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
220 "helper_mst tbc->count: %d\n",
221 tbc->count);
222 GNUNET_TESTBED_extract_cfg (host, message);
223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Received message from helper.\n");
225 ns->number_of_testbeds_started++;
226 return GNUNET_OK;
227}
228
229
160static void 230static void
161netjail_exec_run (void *cls, 231exp_cb (void *cls)
162 const struct GNUNET_TESTING_Command *cmd,
163 struct GNUNET_TESTING_Interpreter *is)
164{ 232{
165 struct NetJailState *ns = cls; 233 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
166 char **helper_argv; 234 GNUNET_TESTING_interpreter_fail ();
235}
236
237
238static void
239start_testbed (struct NetJailState *ns, struct
240 GNUNET_CONFIGURATION_Handle *config,
241 char *n_char,
242 char *m_char)
243{
244 struct GNUNET_CONFIGURATION_Handle *cfg;
167 struct GNUNET_TESTBED_HelperInit *msg; 245 struct GNUNET_TESTBED_HelperInit *msg;
168 struct GNUNET_CONFIGURATION_Handle *cfg = GNUNET_CONFIGURATION_create (); 246 struct TestbedCount *tbc;
169 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, 247 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
170 ns->local_m, 248 m_char,
171 "1", 249 n_char,
172 "1", 250 GNUNET_OS_get_libexec_binary_path (
251 HELPER_TESTBED_BINARY),
173 NULL}; 252 NULL};
174 GNUNET_MessageTokenizerCallback cb = ns->cb; 253 unsigned int m = atoi (m_char);
175 GNUNET_HELPER_ExceptionCallback exp_cb = ns->exp_cb; 254 unsigned int n = atoi (n_char);
255
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
257 "m: %d n: %d\n",
258 m,
259 n);
260
261 tbc = GNUNET_new (struct TestbedCount);
262 tbc->ns = ns;
263 tbc->count = (n - 1) * atoi (ns->local_m) + m;
264
265 cfg = GNUNET_CONFIGURATION_dup (config);
266
267 GNUNET_array_append (ns->host, ns->n_host,
268 GNUNET_TESTBED_host_create_with_id (tbc->count - 1,
269 NULL,
270 NULL,
271 cfg,
272 0));
176 273
177 if ((GNUNET_YES != GNUNET_DISK_file_test ("test_testbed_api.conf")) || 274 if ((GNUNET_YES != GNUNET_DISK_file_test ("test_testbed_api.conf")) ||
178 (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, 275 (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (config,
179 "test_testbed_api.conf"))) 276 "test_testbed_api.conf")))
180 { 277 {
181 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 278 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -184,30 +281,88 @@ netjail_exec_run (void *cls,
184 "test_testbed_api.conf"); 281 "test_testbed_api.conf");
185 } 282 }
186 283
187 helper_argv = join_argv ((const char **) script_argv, 284 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
188 (const char **) ns->binary_argv); 285 GNUNET_YES,
189 286 NETJAIL_EXEC_SCRIPT,
190 ns->helper = GNUNET_HELPER_start (GNUNET_YES, 287 script_argv,
191 NETJAIL_EXEC_SCRIPT, 288 &
192 helper_argv, 289 helper_mst,
193 cb, 290 exp_cb,
194 exp_cb, 291 tbc));
195 ns); 292
196 293 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
197 msg = GNUNET_TESTBED_create_helper_init_msg_ ("127.0.0.1", NULL, cfg); 294
198 ns->msg = &msg->header; 295 msg = GNUNET_TESTBED_create_helper_init_msg_ ("127.0.0.1", NULL, config);
199 ns->shandle = GNUNET_HELPER_send (ns->helper, &msg->header, GNUNET_NO, 296 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
200 &clear_msg, ns); 297
201 if (NULL == ns->shandle) 298 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
299 helper,
300 &msg->header,
301 GNUNET_NO,
302 &clear_msg,
303 tbc));
304 if (NULL == ns->shandle[tbc->count - 1])
202 { 305 {
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 306 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
204 "Send handle is NULL!\n"); 307 "Send handle is NULL!\n");
205 GNUNET_free (msg); 308 GNUNET_free (msg);
309 GNUNET_TESTING_interpreter_fail ();
206 } 310 }
207} 311}
208 312
209 313
210/** 314/**
315* Run the "hello world" CMD.
316*
317* @param cls closure.
318* @param cmd CMD being run.
319* @param is interpreter state.
320*/
321static void
322netjail_exec_run (void *cls,
323 const struct GNUNET_TESTING_Command *cmd,
324 struct GNUNET_TESTING_Interpreter *is)
325{
326 char str_m[12];
327 char str_n[12];
328 struct NetJailState *ns = cls;
329 struct GNUNET_CONFIGURATION_Handle *config =
330 GNUNET_CONFIGURATION_create ();
331
332 for (int i = 1; i <= atoi (ns->global_n); i++) {
333 for (int j = 1; j <= atoi (ns->local_m); j++)
334 {
335 sprintf (str_n, "%d", i);
336 sprintf (str_m, "%d", j);
337 start_testbed (ns, config,
338 str_n,
339 str_m);
340 }
341 }
342}
343
344
345static int
346netjail_start_finish (void *cls,
347 GNUNET_SCHEDULER_TaskCallback cont,
348 void *cont_cls)
349{
350 unsigned int ret = GNUNET_NO;
351 struct NetJailState *ns = cls;
352
353 if (ns->number_of_testbeds_started == atoi (ns->local_m) * atoi (
354 ns->global_n))
355 {
356 ret = GNUNET_YES;
357 cont (cont_cls);
358 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
359 "All helper started!\n");
360 }
361 return ret;
362}
363
364
365/**
211 * Create command. 366 * Create command.
212 * 367 *
213 * @param label name for command. 368 * @param label name for command.
@@ -216,40 +371,20 @@ netjail_exec_run (void *cls,
216 */ 371 */
217struct GNUNET_TESTING_Command 372struct GNUNET_TESTING_Command
218GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label, 373GNUNET_TESTBED_cmd_netjail_start_testbed (const char *label,
219 char *const binary_argv[],
220 char *local_m, 374 char *local_m,
221 char *global_n, 375 char *global_n)
222 GNUNET_MessageTokenizerCallback cb,
223 GNUNET_HELPER_ExceptionCallback exp_cb)
224{ 376{
225 struct NetJailState *ns; 377 struct NetJailState *ns;
226 unsigned int append_cnt;
227 char **argvj;
228 char *argv;
229 unsigned int carg = 0;
230 378
231 ns = GNUNET_new (struct NetJailState); 379 ns = GNUNET_new (struct NetJailState);
232 argvj = NULL;
233 for (append_cnt = 0; NULL != binary_argv[append_cnt]; append_cnt++)
234 {
235 argv = GNUNET_strdup (binary_argv[append_cnt]);
236 GNUNET_array_append (argvj,
237 carg,
238 argv);
239 }
240 GNUNET_array_append (argvj, carg, NULL);
241
242 ns->binary_argv = argvj;
243
244 ns->local_m = local_m; 380 ns->local_m = local_m;
245 ns->global_n = global_n; 381 ns->global_n = global_n;
246 ns->cb = cb;
247 ns->exp_cb = exp_cb;
248 382
249 struct GNUNET_TESTING_Command cmd = { 383 struct GNUNET_TESTING_Command cmd = {
250 .cls = ns, 384 .cls = ns,
251 .label = label, 385 .label = label,
252 .run = &netjail_exec_run, 386 .run = &netjail_exec_run,
387 .finish = &netjail_start_finish,
253 .cleanup = &netjail_exec_cleanup, 388 .cleanup = &netjail_exec_cleanup,
254 .traits = &netjail_exec_traits 389 .traits = &netjail_exec_traits
255 }; 390 };
diff --git a/src/testbed/testbed_api_cmd_netjail_stop_testbed.c b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c
new file mode 100644
index 000000000..9a9d489a7
--- /dev/null
+++ b/src/testbed/testbed_api_cmd_netjail_stop_testbed.c
@@ -0,0 +1,143 @@
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/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h"
29#include "testbed_api.h"
30#include "testbed_api_hosts.h"
31
32
33struct StopHelperState
34{
35
36 const char *helper_start_label;
37
38 /**
39 * The process handle
40 */
41 struct GNUNET_HELPER_Handle **helper;
42
43 char *local_m;
44
45 char *global_n;
46};
47
48
49/**
50*
51*
52* @param cls closure
53* @param cmd current CMD being cleaned up.
54*/
55static void
56stop_testbed_cleanup (void *cls,
57 const struct GNUNET_TESTING_Command *cmd)
58{
59
60}
61
62
63/**
64*
65*
66* @param cls closure.
67* @param[out] ret result
68* @param trait name of the trait.
69* @param index index number of the object to offer.
70* @return #GNUNET_OK on success.
71*/
72static int
73stop_testbed_traits (void *cls,
74 const void **ret,
75 const char *trait,
76 unsigned int index)
77{
78 return GNUNET_OK;
79}
80
81
82/**
83* Run the "hello world" CMD.
84*
85* @param cls closure.
86* @param cmd CMD being run.
87* @param is interpreter state.
88*/
89static void
90stop_testbed_run (void *cls,
91 const struct GNUNET_TESTING_Command *cmd,
92 struct GNUNET_TESTING_Interpreter *is)
93{
94 struct StopHelperState *shs = cls;
95 struct GNUNET_HELPER_Handle **helper;
96 const struct GNUNET_TESTING_Command *start_helper_cmd;
97
98 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
99 shs->helper_start_label);
100 GNUNET_TESTBED_get_trait_helper_handles (start_helper_cmd,
101 &helper);
102
103 for (int i = 1; i <= atoi (shs->global_n); i++) {
104 for (int j = 1; j <= atoi (shs->local_m); j++)
105 {
106 GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1],
107 GNUNET_YES);
108 }
109 }
110}
111
112
113/**
114 * Create command.
115 *
116 * @param label name for command.
117 * @param binaryname to exec.
118 * @return command.
119 */
120struct GNUNET_TESTING_Command
121GNUNET_TESTBED_cmd_stop_testbed (const char *label,
122 const char *helper_start_label,
123 char *local_m,
124 char *global_n
125 )
126{
127 struct StopHelperState *shs;
128
129 shs = GNUNET_new (struct StopHelperState);
130 shs->helper_start_label = helper_start_label;
131 shs->local_m = local_m;
132 shs->global_n = global_n;
133
134 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs,
136 .label = label,
137 .run = &stop_testbed_run,
138 .cleanup = &stop_testbed_cleanup,
139 .traits = &stop_testbed_traits
140 };
141
142 return cmd;
143}
diff --git a/src/testbed/testbed_api_hosts.c b/src/testbed/testbed_api_hosts.c
index 26d2553e0..d0a460fe6 100644
--- a/src/testbed/testbed_api_hosts.c
+++ b/src/testbed/testbed_api_hosts.c
@@ -56,7 +56,7 @@
56 do \ 56 do \
57 { \ 57 { \
58 if (cond) \ 58 if (cond) \
59 break; \ 59 break; \
60 LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \ 60 LOG (GNUNET_ERROR_TYPE_ERROR, "API violation detected: %s\n", errstr); \
61 GNUNET_assert (0); \ 61 GNUNET_assert (0); \
62 } while (0) 62 } while (0)
@@ -964,22 +964,10 @@ gen_rsh_suffix_args (const char *const *append_args)
964} 964}
965 965
966 966
967/** 967void
968 * Functions with this signature are called whenever a 968GNUNET_TESTBED_extract_cfg (struct GNUNET_TESTBED_Host *host, const struct
969 * complete message is received by the tokenizer. 969 GNUNET_MessageHeader *message)
970 *
971 * Do not call GNUNET_SERVER_mst_destroy in callback
972 *
973 * @param cls closure
974 * @param client identification of the client
975 * @param message the actual message
976 *
977 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
978 */
979static int
980helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
981{ 970{
982 struct GNUNET_TESTBED_ControllerProc *cp = cls;
983 const struct GNUNET_TESTBED_HelperReply *msg; 971 const struct GNUNET_TESTBED_HelperReply *msg;
984 const char *hostname; 972 const char *hostname;
985 char *config; 973 char *config;
@@ -1001,22 +989,43 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
1001 xconfig_size)); 989 xconfig_size));
1002 /* Replace the configuration template present in the host with the 990 /* Replace the configuration template present in the host with the
1003 controller's running configuration */ 991 controller's running configuration */
1004 GNUNET_CONFIGURATION_destroy (cp->host->cfg); 992 GNUNET_CONFIGURATION_destroy (host->cfg);
1005 cp->host->cfg = GNUNET_CONFIGURATION_create (); 993 host->cfg = GNUNET_CONFIGURATION_create ();
1006 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (cp->host->cfg, 994 GNUNET_assert (GNUNET_CONFIGURATION_deserialize (host->cfg,
1007 config, 995 config,
1008 config_size, 996 config_size,
1009 NULL)); 997 NULL));
1010 GNUNET_free (config); 998 GNUNET_free (config);
1011 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (cp->host))) 999 if (NULL == (hostname = GNUNET_TESTBED_host_get_hostname (host)))
1012 hostname = "localhost"; 1000 hostname = "localhost";
1013 /* Change the hostname so that we can connect to it */ 1001 /* Change the hostname so that we can connect to it */
1014 GNUNET_CONFIGURATION_set_value_string (cp->host->cfg, 1002 GNUNET_CONFIGURATION_set_value_string (host->cfg,
1015 "testbed", 1003 "testbed",
1016 "hostname", 1004 "hostname",
1017 hostname); 1005 hostname);
1018 cp->host->locked = GNUNET_NO; 1006 host->locked = GNUNET_NO;
1019 cp->host->controller_started = GNUNET_YES; 1007}
1008
1009/**
1010 * Functions with this signature are called whenever a
1011 * complete message is received by the tokenizer.
1012 *
1013 * Do not call GNUNET_SERVER_mst_destroy in callback
1014 *
1015 * @param cls closure
1016 * @param client identification of the client
1017 * @param message the actual message
1018 *
1019 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
1020 */
1021static int
1022helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
1023{
1024 struct GNUNET_TESTBED_ControllerProc *cp = cls;
1025 struct GNUNET_TESTBED_Host *host = cp->host;
1026
1027 GNUNET_TESTBED_extract_cfg (host, message);
1028
1020 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK); 1029 cp->cb (cp->cls, cp->host->cfg, GNUNET_OK);
1021 return GNUNET_OK; 1030 return GNUNET_OK;
1022} 1031}
@@ -1323,7 +1332,7 @@ habitability_check (void *cls)
1323 h->auxp = NULL; 1332 h->auxp = NULL;
1324 ret = (0 != code) ? GNUNET_NO : GNUNET_YES; 1333 ret = (0 != code) ? GNUNET_NO : GNUNET_YES;
1325 1334
1326call_cb: 1335 call_cb:
1327 if (NULL != h->auxp) 1336 if (NULL != h->auxp)
1328 GNUNET_OS_process_destroy (h->auxp); 1337 GNUNET_OS_process_destroy (h->auxp);
1329 cb = h->cb; 1338 cb = h->cb;
diff --git a/src/testbed/testbed_api_hosts.h b/src/testbed/testbed_api_hosts.h
index 291cab859..ab7dd8808 100644
--- a/src/testbed/testbed_api_hosts.h
+++ b/src/testbed/testbed_api_hosts.h
@@ -218,6 +218,10 @@ GNUNET_TESTBED_controller_destroy_ (struct GNUNET_TESTBED_ControllerProc
218void 218void
219GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host); 219GNUNET_TESTBED_host_resolve_ (struct GNUNET_TESTBED_Host *host);
220 220
221void
222GNUNET_TESTBED_extract_cfg (struct GNUNET_TESTBED_Host *host, const struct
223 GNUNET_MessageHeader *message);
224
221 225
222#endif 226#endif
223/* end of testbed_api_hosts.h */ 227/* end of testbed_api_hosts.h */
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index ccee76898..82f6d0cab 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -204,7 +204,7 @@ run_finish_task_next (void *cls)
204 } 204 }
205 else 205 else
206 { 206 {
207 GNUNET_TESTING_interpreter_fail (is); 207 GNUNET_TESTING_interpreter_fail ();
208 } 208 }
209 209
210} 210}
@@ -232,7 +232,7 @@ run_finish_task_sync (void *cls)
232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 232 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
233 "The command with label %s did not finish its asynchronous task in time.\n", 233 "The command with label %s did not finish its asynchronous task in time.\n",
234 cmd->label); 234 cmd->label);
235 GNUNET_TESTING_interpreter_fail (is); 235 GNUNET_TESTING_interpreter_fail ();
236 } 236 }
237 237
238 if (GNUNET_YES == finished) 238 if (GNUNET_YES == finished)
@@ -246,7 +246,7 @@ run_finish_task_sync (void *cls)
246 } 246 }
247 else 247 else
248 { 248 {
249 GNUNET_TESTING_interpreter_fail (is); 249 GNUNET_TESTING_interpreter_fail ();
250 } 250 }
251} 251}
252 252
@@ -321,7 +321,7 @@ GNUNET_TESTING_cmd_make_unblocking (const struct GNUNET_TESTING_Command cmd)
321 * @param is interpreter of the test 321 * @param is interpreter of the test
322 */ 322 */
323void 323void
324GNUNET_TESTING_interpreter_fail (struct GNUNET_TESTING_Interpreter *is) 324GNUNET_TESTING_interpreter_fail ()
325{ 325{
326 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip]; 326 struct GNUNET_TESTING_Command *cmd = &is->commands[is->ip];
327 327
@@ -411,9 +411,9 @@ interpreter_run (void *cls)
411 ftc = GNUNET_new (struct FinishTaskClosure); 411 ftc = GNUNET_new (struct FinishTaskClosure);
412 ftc->cmd = cmd; 412 ftc->cmd = cmd;
413 ftc->is = is; 413 ftc->is = is;
414 cmd->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD, 414 is->finish_task = GNUNET_SCHEDULER_add_delayed (CHECK_FINISHED_PERIOD,
415 &run_finish_task_next, 415 &run_finish_task_next,
416 ftc); 416 ftc);
417 } 417 }
418 else 418 else
419 { 419 {
@@ -448,11 +448,12 @@ do_shutdown (void *cls)
448 j++) { 448 j++) {
449 cmd->cleanup (cmd->cls, 449 cmd->cleanup (cmd->cls,
450 cmd); 450 cmd);
451 if (NULL != cmd->finish_task) 451 }
452 { 452
453 GNUNET_SCHEDULER_cancel (cmd->finish_task); 453 if (NULL != is->finish_task)
454 cmd->finish_task = NULL; 454 {
455 } 455 GNUNET_SCHEDULER_cancel (is->finish_task);
456 cmd->finish_task = NULL;
456 } 457 }
457 458
458 if (NULL != is->task) 459 if (NULL != is->task)
diff --git a/src/util/child_management.c b/src/util/child_management.c
index 7775bfc3d..11fde4a61 100644
--- a/src/util/child_management.c
+++ b/src/util/child_management.c
@@ -222,6 +222,9 @@ GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
222 if (NULL == cwh_head) 222 if (NULL == cwh_head)
223 { 223 {
224 child_management_done (); 224 child_management_done ();
225 }
226 if (NULL != sig_task)
227 {
225 GNUNET_SCHEDULER_cancel (sig_task); 228 GNUNET_SCHEDULER_cancel (sig_task);
226 sig_task = NULL; 229 sig_task = NULL;
227 } 230 }