aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-08-24 11:56:13 +0200
committert3sserakt <t3ss@posteo.de>2021-08-24 11:56:13 +0200
commit5ddaa3f8eb5e01882540f21ddf237f3a41311e8a (patch)
tree765617baebf4366c9584d71863c3077f5d107d49 /src
parent9d5a8c05f3a33c49fd97e5b8ef99d58b96704c6d (diff)
downloadgnunet-5ddaa3f8eb5e01882540f21ddf237f3a41311e8a.tar.gz
gnunet-5ddaa3f8eb5e01882540f21ddf237f3a41311e8a.zip
- fixed mem leaks, added code doc, formatting, removed trace logs
Diffstat (limited to 'src')
-rw-r--r--src/testbed/testbed_api_cmd_netjail_start_testbed.c544
-rw-r--r--src/testing/gnunet-cmds-helper.c190
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c41
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c42
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c42
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c228
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c40
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c25
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c25
-rw-r--r--src/testing/testing_api_cmd_system_create.c25
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c6
-rw-r--r--src/testing/testing_api_loop.c44
-rw-r--r--src/transport/gnunet-communicator-tcp.c29
-rw-r--r--src/transport/test_transport_api_cmd_simple_send.c12
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c7
-rw-r--r--src/transport/transport-testing-cmds.h10
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c94
-rw-r--r--src/transport/transport_api_cmd_send_simple.c65
-rw-r--r--src/transport/transport_api_cmd_start_peer.c268
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c2
20 files changed, 660 insertions, 1079 deletions
diff --git a/src/testbed/testbed_api_cmd_netjail_start_testbed.c b/src/testbed/testbed_api_cmd_netjail_start_testbed.c
deleted file mode 100644
index 3d1a1d893..000000000
--- a/src/testbed/testbed_api_cmd_netjail_start_testbed.c
+++ /dev/null
@@ -1,544 +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/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#include "testbed_helper.h"
32
33#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
34
35struct HelperMessage;
36
37struct HelperMessage
38{
39
40 struct HelperMessage *next;
41
42 struct HelperMessage *prev;
43
44 /**
45 * Size of the original message.
46 */
47 uint16_t bytes_msg;
48
49 /* Followed by @e bytes_msg of msg.*/
50};
51
52
53
54struct NetJailState
55{
56
57 unsigned int *rv;
58
59 struct HelperMessage *hp_messages_head;
60
61 struct HelperMessage *hp_messages_tail;
62
63 /**
64 * The process handle
65 */
66 struct GNUNET_HELPER_Handle **helper;
67
68 unsigned int n_helper;
69
70 char *binary_name;
71
72 char *local_m;
73
74 char *global_n;
75
76 /**
77 * The send handle for the helper
78 */
79 struct GNUNET_HELPER_SendHandle **shandle;
80
81 unsigned int n_shandle;
82
83 /**
84 * The message corresponding to send handle
85 */
86 struct GNUNET_MessageHeader **msg;
87
88 unsigned int n_msg;
89
90 unsigned int number_of_testsystems_started;
91
92 unsigned int number_of_peers_started;
93
94 unsigned int number_of_local_test_finished;
95
96 char *plugin_name;
97};
98
99struct TestingSystemCount
100{
101 unsigned int count;
102
103 struct NetJailState *ns;
104};
105
106/**
107*
108*
109* @param cls closure
110* @param cmd current CMD being cleaned up.
111*/
112static void
113netjail_exec_cleanup (void *cls,
114 const struct GNUNET_TESTING_Command *cmd)
115{
116 struct NetJailState *ns = cls;
117
118 GNUNET_free (ns->binary_name);
119}
120
121
122/**
123*
124*
125* @param cls closure.
126* @param[out] ret result
127* @param trait name of the trait.
128* @param index index number of the object to offer.
129* @return #GNUNET_OK on success.
130*/
131static int
132netjail_exec_traits (void *cls,
133 const void **ret,
134 const char *trait,
135 unsigned int index)
136{
137 struct NetJailState *ns = cls;
138 struct GNUNET_HELPER_Handle **helper = ns->helper;
139 struct HelperMessage *hp_messages_head = ns->hp_messages_head;
140
141
142 struct GNUNET_TESTING_Trait traits[] = {
143 {
144 .index = 0,
145 .trait_name = "helper_handles",
146 .ptr = (const void *) helper,
147 },
148 {
149 .index = 1,
150 .trait_name = "hp_msgs_head",
151 .ptr = (const void *) hp_messages_head,
152 },
153 GNUNET_TESTING_trait_end ()
154 };
155
156 return GNUNET_TESTING_get_trait (traits,
157 ret,
158 trait,
159 index);
160}
161
162
163/**
164 * Offer handles to testing cmd helper from trait
165 *
166 * @param cmd command to extract the message from.
167 * @param pt pointer to message.
168 * @return #GNUNET_OK on success.
169 */
170int
171GNUNET_TESTING_get_trait_helper_handles (const struct
172 GNUNET_TESTING_Command *cmd,
173 struct GNUNET_HELPER_Handle ***helper)
174{
175 return cmd->traits (cmd->cls,
176 (const void **) helper,
177 "helper_handles",
178 (unsigned int) 0);
179}
180
181/**
182 * Offer messages received via testing cmd helper from trait
183 *
184 * @param cmd command to extract the message from.
185 * @param pt pointer to message.
186 * @return #GNUNET_OK on success.
187 */
188int
189GNUNET_TESTING_get_trait_helper_messages (const struct
190 GNUNET_TESTING_Command *cmd,
191 struct HelperMessage ***
192 hp_messages_head)
193{
194 return cmd->traits (cmd->cls,
195 (const void **) hp_messages_head,
196 "hp_msgs_head",
197 (unsigned int) 1);
198}
199
200
201/**
202 * Continuation function from GNUNET_HELPER_send()
203 *
204 * @param cls closure
205 * @param result GNUNET_OK on success,
206 * GNUNET_NO if helper process died
207 * GNUNET_SYSERR during GNUNET_HELPER_stop
208 */
209static void
210clear_msg (void *cls, int result)
211{
212 struct TestingSystemCount *tbc = cls;
213 struct NetJailState *ns = tbc->ns;
214
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
216 "clear_msg tbc->count: %d\n",
217 tbc->count);
218 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
219 ns->shandle[tbc->count - 1] = NULL;
220 GNUNET_free (ns->msg[tbc->count - 1]);
221 ns->msg[tbc->count - 1] = NULL;
222}
223
224
225/**
226 * Functions with this signature are called whenever a
227 * complete message is received by the tokenizer.
228 *
229 * Do not call GNUNET_SERVER_mst_destroy in callback
230 *
231 * @param cls closure
232 * @param client identification of the client
233 * @param message the actual message
234 *
235 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
236 */
237static int
238helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
239{
240 struct TestingSystemCount *tbc = cls;
241 struct NetJailState *ns = tbc->ns;
242 struct HelperMessage *hp_msg;
243
244 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
245 {
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "helper_mst tbc->count: %d\n",
248 tbc->count);
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
250 "Received message from helper.\n");
251 ns->number_of_testsystems_started++;
252 }
253 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
254 message->type))
255 {
256 ns->number_of_peers_started++;
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
258 "number_of_peers_started: %d\n",
259 ns->number_of_peers_started);
260 }
261 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
262 message->type))
263 {
264 ns->number_of_local_test_finished++;
265 }
266 else
267 {
268 hp_msg = GNUNET_new (struct HelperMessage);
269 hp_msg->bytes_msg = message->size;
270 memcpy (&hp_msg[1], message, message->size);
271 GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
272 hp_msg);
273 }
274
275 return GNUNET_OK;
276}
277
278
279static void
280exp_cb (void *cls)
281{
282 struct NetJailState *ns = cls;
283 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
284 *ns->rv = 1;
285}
286
287
288static struct GNUNET_CMDS_HelperInit *
289create_helper_init_msg_ (char *m_char,
290 char *n_char,
291 const char *plugin_name)
292{
293 struct GNUNET_CMDS_HelperInit *msg;
294 uint16_t plugin_name_len;
295 uint16_t msg_size;
296
297 GNUNET_assert (NULL != plugin_name);
298 plugin_name_len = strlen (plugin_name);
299 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
301 "msg_size: %d \n",
302 msg_size);
303 msg = GNUNET_malloc (msg_size);
304 msg->header.size = htons (msg_size);
305 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
306 msg->plugin_name_size = htons (plugin_name_len);
307 GNUNET_memcpy ((char *) &msg[1],
308 plugin_name,
309 plugin_name_len);
310 return msg;
311}
312
313
314static void
315start_helper (struct NetJailState *ns, struct
316 GNUNET_CONFIGURATION_Handle *config,
317 char *m_char,
318 char *n_char)
319{
320 // struct GNUNET_CONFIGURATION_Handle *cfg;
321 struct GNUNET_CMDS_HelperInit *msg;
322 struct TestingSystemCount *tbc;
323 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
324 m_char,
325 n_char,
326 GNUNET_OS_get_libexec_binary_path (
327 HELPER_CMDS_BINARY),
328 ns->global_n,
329 ns->local_m,
330 NULL};
331 unsigned int m = atoi (m_char);
332 unsigned int n = atoi (n_char);
333 unsigned int helper_check = GNUNET_OS_check_helper_binary (
334 NETJAIL_EXEC_SCRIPT,
335 GNUNET_YES,
336 NULL);
337
338 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
339 "m: %d n: %d\n",
340 m,
341 n);
342
343 tbc = GNUNET_new (struct TestingSystemCount);
344 tbc->ns = ns;
345 tbc->count = (n - 1) * atoi (ns->local_m) + m;
346
347
348 if (GNUNET_NO == helper_check)
349 {
350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
351 "No SUID for %s!\n",
352 NETJAIL_EXEC_SCRIPT);
353 *ns->rv = 1;
354 }
355 else if (GNUNET_NO == helper_check)
356 {
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
358 "%s not found!\n",
359 NETJAIL_EXEC_SCRIPT);
360 *ns->rv = 1;
361 }
362
363 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
364 GNUNET_YES,
365 NETJAIL_EXEC_SCRIPT,
366 script_argv,
367 &helper_mst,
368 &exp_cb,
369 tbc));
370
371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
372 "First using helper %d %d\n",
373 tbc->count - 1,
374 ns->n_helper);
375 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
376
377 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
378 "First using helper %d %d %p\n",
379 tbc->count - 1,
380 ns->n_helper,
381 helper);
382
383 msg = create_helper_init_msg_ (m_char,
384 n_char,
385 ns->plugin_name);
386 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
387
388 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
389 helper,
390 &msg->header,
391 GNUNET_NO,
392 &clear_msg,
393 tbc));
394
395 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
396 "Message %d send!\n",
397 tbc->count);
398
399 if (NULL == ns->shandle[tbc->count - 1])
400 {
401 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
402 "Send handle is NULL!\n");
403 GNUNET_free (msg);
404 *ns->rv = 1;
405 }
406}
407
408
409/**
410* Run the "hello world" CMD.
411*
412* @param cls closure.
413* @param cmd CMD being run.
414* @param is interpreter state.
415*/
416static void
417netjail_exec_run (void *cls,
418 const struct GNUNET_TESTING_Command *cmd,
419 struct GNUNET_TESTING_Interpreter *is)
420{
421 char str_m[12];
422 char str_n[12];
423 struct NetJailState *ns = cls;
424 struct GNUNET_CONFIGURATION_Handle *config =
425 GNUNET_CONFIGURATION_create ();
426
427 for (int i = 1; i <= atoi (ns->global_n); i++) {
428 for (int j = 1; j <= atoi (ns->local_m); j++)
429 {
430 sprintf (str_n, "%d", i);
431 sprintf (str_m, "%d", j);
432 start_helper (ns, config,
433 str_m,
434 str_n);
435 }
436 }
437}
438
439
440static int
441netjail_start_finish (void *cls,
442 GNUNET_SCHEDULER_TaskCallback cont,
443 void *cont_cls)
444{
445 unsigned int ret = GNUNET_NO;
446 struct NetJailState *ns = cls;
447 unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
448 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
449 size_t msg_length;
450 struct GNUNET_HELPER_Handle *helper;
451 struct TestingSystemCount *tbc;
452
453 if (ns->number_of_local_test_finished == total_number)
454 {
455 ret = GNUNET_YES;
456 cont (cont_cls);
457 }
458
459 if (ns->number_of_testsystems_started == total_number)
460 {
461 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
462 "All helpers started!\n");
463 ns->number_of_testsystems_started = 0;
464 }
465
466 if (ns->number_of_peers_started == total_number)
467 {
468 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
469 "All peers started!\n");
470
471 for (int i = 1; i <= atoi (ns->global_n); i++) {
472 for (int j = 1; j <= atoi (ns->local_m); j++)
473 {
474 tbc = GNUNET_new (struct TestingSystemCount);
475 tbc->ns = ns;
476 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
477 tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
478 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
479 "Second using helper %d %d %d\n",
480 tbc->count - 1 - total_number,
481 i,
482 j);
483 helper = ns->helper[tbc->count - 1 - total_number];
484 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
485 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
486 reply->header.type = htons (
487 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
488 reply->header.size = htons ((uint16_t) msg_length);
489
490 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
491
492 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
493 helper,
494 &reply->header,
495 GNUNET_NO,
496 &clear_msg,
497 tbc);
498
499 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
500
501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
502 "All peers started message %d send!\n",
503 tbc->count);
504 }
505 }
506 ns->number_of_peers_started = 0;
507 }
508 return ret;
509}
510
511
512/**
513 * Create command.
514 *
515 * @param label name for command.
516 * @param binaryname to exec.
517 * @return command.
518 */
519struct GNUNET_TESTING_Command
520GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
521 char *local_m,
522 char *global_n,
523 char *plugin_name,
524 unsigned int *rv)
525{
526 struct NetJailState *ns;
527
528 ns = GNUNET_new (struct NetJailState);
529 ns->local_m = local_m;
530 ns->global_n = global_n;
531 ns->plugin_name = plugin_name;
532 ns->rv = rv;
533
534 struct GNUNET_TESTING_Command cmd = {
535 .cls = ns,
536 .label = label,
537 .run = &netjail_exec_run,
538 .finish = &netjail_start_finish,
539 .cleanup = &netjail_exec_cleanup,
540 .traits = &netjail_exec_traits
541 };
542
543 return cmd;
544}
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 5705f46c2..21ea33888 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -47,7 +47,7 @@
47 47
48/** 48/**
49 * Generic logging shortcut 49 * Generic logging shortcut
50 */ 50testing_api_cmd_block_until_all_peers_started.c */
51#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 51#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
52 52
53/** 53/**
@@ -74,27 +74,71 @@ struct Plugin
74 */ 74 */
75 struct GNUNET_TESTING_PluginFunctions *api; 75 struct GNUNET_TESTING_PluginFunctions *api;
76 76
77 /**
78 * IP address of the specific node the helper is running for.
79 *
80 */
77 char *node_ip; 81 char *node_ip;
78 82
83 /**
84 * Name of the test case plugin.
85 *
86 */
79 char *plugin_name; 87 char *plugin_name;
80 88
89 /**
90 * The number of namespaces
91 *
92 */
81 char *global_n; 93 char *global_n;
82 94
95 /**
96 * The number of local nodes per namespace.
97 *
98 */
83 char *local_m; 99 char *local_m;
84 100
101 /**
102 * The number of the namespace this node is in.
103 *
104 */
85 char *n; 105 char *n;
86 106
107 /**
108 * The number of the node in the namespace.
109 *
110 */
87 char *m; 111 char *m;
88}; 112};
89 113
114/**
115 * Struct with information about a specific node and the whole network namespace setup.
116 *
117 */
90struct NodeIdentifier 118struct NodeIdentifier
91{ 119{
120 /**
121 * The number of the namespace this node is in.
122 *
123 */
92 char *n; 124 char *n;
93 125
126 /**
127 * The number of the node in the namespace.
128 *
129 */
94 char *m; 130 char *m;
95 131
132 /**
133 * The number of namespaces
134 *
135 */
96 char *global_n; 136 char *global_n;
97 137
138 /**
139 * The number of local nodes per namespace.
140 *
141 */
98 char *local_m; 142 char *local_m;
99}; 143};
100 144
@@ -162,11 +206,6 @@ static struct GNUNET_SCHEDULER_Task *read_task_id;
162static struct GNUNET_SCHEDULER_Task *write_task_id; 206static struct GNUNET_SCHEDULER_Task *write_task_id;
163 207
164/** 208/**
165 * Task to kill the child
166 */
167static struct GNUNET_SCHEDULER_Task *child_death_task_id;
168
169/**
170 * Are we done reading messages from stdin? 209 * Are we done reading messages from stdin?
171 */ 210 */
172static int done_reading; 211static int done_reading;
@@ -187,8 +226,6 @@ shutdown_task (void *cls)
187{ 226{
188 227
189 LOG_DEBUG ("Shutting down.\n"); 228 LOG_DEBUG ("Shutting down.\n");
190 LOG (GNUNET_ERROR_TYPE_ERROR,
191 "Shutting down tokenizer!\n");
192 229
193 if (NULL != read_task_id) 230 if (NULL != read_task_id)
194 { 231 {
@@ -204,11 +241,6 @@ shutdown_task (void *cls)
204 GNUNET_free (wc->data); 241 GNUNET_free (wc->data);
205 GNUNET_free (wc); 242 GNUNET_free (wc);
206 } 243 }
207 if (NULL != child_death_task_id)
208 {
209 GNUNET_SCHEDULER_cancel (child_death_task_id);
210 child_death_task_id = NULL;
211 }
212 if (NULL != stdin_fd) 244 if (NULL != stdin_fd)
213 (void) GNUNET_DISK_file_close (stdin_fd); 245 (void) GNUNET_DISK_file_close (stdin_fd);
214 if (NULL != stdout_fd) 246 if (NULL != stdout_fd)
@@ -235,9 +267,6 @@ write_task (void *cls)
235 struct WriteContext *wc = cls; 267 struct WriteContext *wc = cls;
236 ssize_t bytes_wrote; 268 ssize_t bytes_wrote;
237 269
238 LOG (GNUNET_ERROR_TYPE_ERROR,
239 "Writing data!\n");
240
241 GNUNET_assert (NULL != wc); 270 GNUNET_assert (NULL != wc);
242 write_task_id = NULL; 271 write_task_id = NULL;
243 bytes_wrote = GNUNET_DISK_file_write (stdout_fd, 272 bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
@@ -256,12 +285,8 @@ write_task (void *cls)
256 { 285 {
257 GNUNET_free (wc->data); 286 GNUNET_free (wc->data);
258 GNUNET_free (wc); 287 GNUNET_free (wc);
259 LOG (GNUNET_ERROR_TYPE_ERROR,
260 "Written successfully!\n");
261 return; 288 return;
262 } 289 }
263 LOG (GNUNET_ERROR_TYPE_ERROR,
264 "Written data!\n");
265 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL, 290 write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
266 stdout_fd, 291 stdout_fd,
267 &write_task, 292 &write_task,
@@ -270,39 +295,14 @@ write_task (void *cls)
270 295
271 296
272/** 297/**
273 * Task triggered whenever we receive a SIGCHLD (child 298 * Callback to write a message to the master loop.
274 * process died).
275 * 299 *
276 * @param cls closure, NULL if we need to self-restart
277 */ 300 */
278/*static void
279child_death_task (void *cls)
280{
281 const struct GNUNET_DISK_FileHandle *pr;
282 char c[16];
283
284 pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
285 child_death_task_id = NULL;
286 // consume the signal
287 GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
288 LOG_DEBUG ("Got SIGCHLD\n");
289
290 LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
291 child_death_task_id =
292 GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
293 pr,
294 &child_death_task,
295 NULL);
296}*/
297
298
299static void 301static void
300write_message (struct GNUNET_MessageHeader *message, size_t msg_length) 302write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
301{ 303{
302 struct WriteContext *wc; 304 struct WriteContext *wc;
303 305
304 LOG (GNUNET_ERROR_TYPE_ERROR,
305 "enter write_message!\n");
306 wc = GNUNET_new (struct WriteContext); 306 wc = GNUNET_new (struct WriteContext);
307 wc->length = msg_length; 307 wc->length = msg_length;
308 wc->data = message; 308 wc->data = message;
@@ -311,38 +311,10 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
311 stdout_fd, 311 stdout_fd,
312 &write_task, 312 &write_task,
313 wc); 313 wc);
314 LOG (GNUNET_ERROR_TYPE_ERROR,
315 "leave write_message!\n");
316} 314}
317 315
318 316
319/** 317/**
320 * Function to run the test cases.
321 *
322 * @param cls plugin to use.
323 *
324 */
325/*static void
326run_plugin (void *cls)
327{
328 struct Plugin *plugin = cls;
329 char *router_ip;
330 char *node_ip;
331
332 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
333 strcpy (router_ip, ROUTER_BASE_IP);
334 strcat (router_ip, plugin->m);
335
336 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
337 strcat (node_ip, NODE_BASE_IP);
338 strcat (node_ip, plugin->n);
339
340 plugin->api->start_testcase (&write_message, router_ip, node_ip);
341
342}*/
343
344
345/**
346 * Functions with this signature are called whenever a 318 * Functions with this signature are called whenever a
347 * complete message is received by the tokenizer. 319 * complete message is received by the tokenizer.
348 * 320 *
@@ -368,9 +340,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
368 char *router_ip; 340 char *router_ip;
369 char *node_ip; 341 char *node_ip;
370 342
371 LOG (GNUNET_ERROR_TYPE_ERROR,
372 "tokenizer \n");
373
374 msize = ntohs (message->size); 343 msize = ntohs (message->size);
375 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type)) 344 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
376 { 345 {
@@ -390,23 +359,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
390 359
391 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd"); 360 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
392 361
393 LOG (GNUNET_ERROR_TYPE_ERROR,
394 "plugin_name: %s \n",
395 plugin_name);
396
397 // cmd_binary_process = GNUNET_OS_start_process (
398 /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
399 NULL,
400 NULL,
401 NULL,
402 binary,
403 plugin_name,
404 ni->global_n,
405 ni->local_m,
406 ni->n,
407 ni->m,
408 NULL);*/
409
410 plugin = GNUNET_new (struct Plugin); 362 plugin = GNUNET_new (struct Plugin);
411 plugin->api = GNUNET_PLUGIN_load (plugin_name, 363 plugin->api = GNUNET_PLUGIN_load (plugin_name,
412 NULL); 364 NULL);
@@ -429,51 +381,15 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
429 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, 381 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
430 plugin->n, plugin->local_m); 382 plugin->n, plugin->local_m);
431 383
432 LOG (GNUNET_ERROR_TYPE_ERROR,
433 "We got here!\n");
434
435 /*if (NULL == cmd_binary_process)
436 {
437 LOG (GNUNET_ERROR_TYPE_ERROR,
438 "Starting plugin failed!\n");
439 return GNUNET_SYSERR;
440 }*/
441
442 LOG (GNUNET_ERROR_TYPE_ERROR,
443 "We got here 2!\n");
444
445 LOG (GNUNET_ERROR_TYPE_ERROR,
446 "global_n: %s local_n: %s n: %s m: %s.\n",
447 ni->global_n,
448 ni->local_m,
449 ni->n,
450 ni->m);
451
452 LOG (GNUNET_ERROR_TYPE_ERROR,
453 "We got here 3!\n");
454
455 GNUNET_free (binary); 384 GNUNET_free (binary);
456 385
457 // done_reading = GNUNET_YES;
458
459 msg_length = sizeof(struct GNUNET_CMDS_HelperReply); 386 msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
460 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply); 387 reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
461 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY); 388 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
462 reply->header.size = htons ((uint16_t) msg_length); 389 reply->header.size = htons ((uint16_t) msg_length);
463 390
464 LOG (GNUNET_ERROR_TYPE_ERROR,
465 "We got here 4!\n");
466
467 write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 391 write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
468 392
469 LOG (GNUNET_ERROR_TYPE_ERROR,
470 "We got here 5!\n");
471
472 /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
473 GNUNET_TIME_UNIT_FOREVER_REL,
474 GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
475 &child_death_task,
476 NULL);*/
477 return GNUNET_OK; 393 return GNUNET_OK;
478 } 394 }
479 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs ( 395 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
@@ -514,8 +430,6 @@ read_task (void *cls)
514 if ((GNUNET_SYSERR == sread) || (0 == sread)) 430 if ((GNUNET_SYSERR == sread) || (0 == sread))
515 { 431 {
516 LOG_DEBUG ("STDIN closed\n"); 432 LOG_DEBUG ("STDIN closed\n");
517 LOG (GNUNET_ERROR_TYPE_ERROR,
518 "tokenizer shutting down during reading!\n");
519 GNUNET_SCHEDULER_shutdown (); 433 GNUNET_SCHEDULER_shutdown ();
520 return; 434 return;
521 } 435 }
@@ -529,8 +443,6 @@ read_task (void *cls)
529 return; 443 return;
530 } 444 }
531 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread); 445 LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
532 LOG (GNUNET_ERROR_TYPE_ERROR,
533 "Read %u bytes\n", (unsigned int) sread);
534 /* FIXME: could introduce a GNUNET_MST_read2 to read 446 /* FIXME: could introduce a GNUNET_MST_read2 to read
535 directly from 'stdin_fd' and save a memcpy() here */ 447 directly from 'stdin_fd' and save a memcpy() here */
536 if (GNUNET_OK != 448 if (GNUNET_OK !=
@@ -624,13 +536,6 @@ main (int argc, char **argv)
624 ni->n = argv[3]; 536 ni->n = argv[3];
625 ni->m = argv[4]; 537 ni->m = argv[4];
626 538
627 LOG (GNUNET_ERROR_TYPE_ERROR,
628 "global_n: %s local_n: %s n: %s m: %s.\n",
629 ni->global_n,
630 ni->local_m,
631 ni->n,
632 ni->m);
633
634 status = GNUNET_OK; 539 status = GNUNET_OK;
635 if (NULL == 540 if (NULL ==
636 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) 541 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
@@ -647,8 +552,7 @@ main (int argc, char **argv)
647 options, 552 options,
648 &run, 553 &run,
649 ni); 554 ni);
650 LOG (GNUNET_ERROR_TYPE_ERROR, 555
651 "run finished\n");
652 GNUNET_SIGNAL_handler_uninstall (shc_chld); 556 GNUNET_SIGNAL_handler_uninstall (shc_chld);
653 shc_chld = NULL; 557 shc_chld = NULL;
654 GNUNET_DISK_pipe_close (sigpipe); 558 GNUNET_DISK_pipe_close (sigpipe);
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c
index 8659fbb46..e9d3f0ed3 100644
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c
@@ -32,12 +32,24 @@
32 */ 32 */
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
34 34
35/**
36 * Struct with information for callbacks.
37 *
38 */
35struct BlockState 39struct BlockState
36{ 40{
41 /**
42 * Flag to indicate if all peers have started.
43 *
44 */
37 unsigned int *all_peers_started; 45 unsigned int *all_peers_started;
38}; 46};
39 47
40 48
49/**
50 * Trait function of this cmd does nothing.
51 *
52 */
41static int 53static int
42block_until_all_peers_started_traits (void *cls, 54block_until_all_peers_started_traits (void *cls,
43 const void **ret, 55 const void **ret,
@@ -48,6 +60,10 @@ block_until_all_peers_started_traits (void *cls,
48} 60}
49 61
50 62
63/**
64 * The cleanup function of this cmd frees resources the cmd allocated.
65 *
66 */
51static void 67static void
52block_until_all_peers_started_cleanup (void *cls, 68block_until_all_peers_started_cleanup (void *cls,
53 const struct GNUNET_TESTING_Command *cmd) 69 const struct GNUNET_TESTING_Command *cmd)
@@ -58,16 +74,24 @@ block_until_all_peers_started_cleanup (void *cls,
58} 74}
59 75
60 76
77/**
78 * This function does nothing but to start the cmd.
79 *
80 */
61static void 81static void
62block_until_all_peers_started_run (void *cls, 82block_until_all_peers_started_run (void *cls,
63 const struct GNUNET_TESTING_Command *cmd, 83 const struct GNUNET_TESTING_Command *cmd,
64 struct GNUNET_TESTING_Interpreter *is) 84 struct GNUNET_TESTING_Interpreter *is)
65{ 85{
66 LOG (GNUNET_ERROR_TYPE_ERROR, 86 LOG (GNUNET_ERROR_TYPE_DEBUG,
67 "block_until_all_peers_started_run!\n"); 87 "block_until_all_peers_started_run!\n");
68} 88}
69 89
70 90
91/**
92 * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
93 *
94 */
71static int 95static int
72block_until_all_peers_started_finish (void *cls, 96block_until_all_peers_started_finish (void *cls,
73 GNUNET_SCHEDULER_TaskCallback cont, 97 GNUNET_SCHEDULER_TaskCallback cont,
@@ -76,20 +100,10 @@ block_until_all_peers_started_finish (void *cls,
76 struct BlockState *bs = cls; 100 struct BlockState *bs = cls;
77 unsigned int *ret = bs->all_peers_started; 101 unsigned int *ret = bs->all_peers_started;
78 102
79 LOG (GNUNET_ERROR_TYPE_ERROR,
80 "We got here 10\n");
81
82 if (GNUNET_YES == *ret) 103 if (GNUNET_YES == *ret)
83 { 104 {
84 LOG (GNUNET_ERROR_TYPE_ERROR,
85 "We do not need to block anymore!\n");
86 cont (cont_cls); 105 cont (cont_cls);
87 } 106 }
88 else
89 {
90 LOG (GNUNET_ERROR_TYPE_ERROR,
91 "You shall not pass!\n");
92 }
93 107
94 return *ret; 108 return *ret;
95} 109}
@@ -99,6 +113,7 @@ block_until_all_peers_started_finish (void *cls,
99 * Create command. 113 * Create command.
100 * 114 *
101 * @param label name for command. 115 * @param label name for command.
116 * @param all_peers_started Flag which will be set from outside.
102 * @return command. 117 * @return command.
103 */ 118 */
104struct GNUNET_TESTING_Command 119struct GNUNET_TESTING_Command
@@ -108,10 +123,6 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
108{ 123{
109 struct BlockState *bs; 124 struct BlockState *bs;
110 125
111 LOG (GNUNET_ERROR_TYPE_ERROR,
112 "we have all_peers_started: %u\n",
113 *all_peers_started);
114
115 bs = GNUNET_new (struct BlockState); 126 bs = GNUNET_new (struct BlockState);
116 bs->all_peers_started = all_peers_started; 127 bs->all_peers_started = all_peers_started;
117 128
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 5b74d4e04..383de4c10 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -33,14 +33,31 @@
33 */ 33 */
34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 34#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
35 35
36
37/**
38 * Struct to hold information for callbacks.
39 *
40 */
36struct LocalFinishedState 41struct LocalFinishedState
37{ 42{
43 /**
44 * Callback to write messages to the master loop.
45 *
46 */
38 TESTING_CMD_HELPER_write_cb write_message; 47 TESTING_CMD_HELPER_write_cb write_message;
39 48
49 /**
50 * The message send back to the master loop.
51 *
52 */
40 struct GNUNET_CMDS_LOCAL_FINISHED *reply; 53 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
41}; 54};
42 55
43 56
57/**
58 * Trait function of this cmd does nothing.
59 *
60 */
44static int 61static int
45local_test_finished_traits (void *cls, 62local_test_finished_traits (void *cls,
46 const void **ret, 63 const void **ret,
@@ -51,6 +68,10 @@ local_test_finished_traits (void *cls,
51} 68}
52 69
53 70
71/**
72 * The cleanup function of this cmd frees resources the cmd allocated.
73 *
74 */
54static void 75static void
55local_test_finished_cleanup (void *cls, 76local_test_finished_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd) 77 const struct GNUNET_TESTING_Command *cmd)
@@ -62,6 +83,10 @@ local_test_finished_cleanup (void *cls,
62} 83}
63 84
64 85
86/**
87 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED message to the master loop.
88 *
89 */
65static void 90static void
66local_test_finished_run (void *cls, 91local_test_finished_run (void *cls,
67 const struct GNUNET_TESTING_Command *cmd, 92 const struct GNUNET_TESTING_Command *cmd,
@@ -72,28 +97,25 @@ local_test_finished_run (void *cls,
72 struct GNUNET_CMDS_LOCAL_FINISHED *reply; 97 struct GNUNET_CMDS_LOCAL_FINISHED *reply;
73 size_t msg_length; 98 size_t msg_length;
74 99
75 LOG (GNUNET_ERROR_TYPE_ERROR,
76 "We got here 12!\n");
77
78 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED); 100 msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
79 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED); 101 reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
80 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED); 102 reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
81 reply->header.size = htons ((uint16_t) msg_length); 103 reply->header.size = htons ((uint16_t) msg_length);
82 lfs->reply = reply; 104 lfs->reply = reply;
83 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length); 105 lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
84
85 LOG (GNUNET_ERROR_TYPE_ERROR,
86 "We got here 13!\n");
87} 106}
88 107
89 108
109/**
110 * This finish function will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
111 *
112 */
90static int 113static int
91local_test_finished_finish (void *cls, 114local_test_finished_finish (void *cls,
92 GNUNET_SCHEDULER_TaskCallback cont, 115 GNUNET_SCHEDULER_TaskCallback cont,
93 void *cont_cls) 116 void *cont_cls)
94{ 117{
95 // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method. 118 LOG (GNUNET_ERROR_TYPE_DEBUG,
96 LOG (GNUNET_ERROR_TYPE_ERROR,
97 "Stopping local loop\n"); 119 "Stopping local loop\n");
98 return GNUNET_YES; 120 return GNUNET_YES;
99} 121}
@@ -103,6 +125,7 @@ local_test_finished_finish (void *cls,
103 * Create command. 125 * Create command.
104 * 126 *
105 * @param label name for command. 127 * @param label name for command.
128 * @param write_message Callback to write messages to the master loop.
106 * @return command. 129 * @return command.
107 */ 130 */
108struct GNUNET_TESTING_Command 131struct GNUNET_TESTING_Command
@@ -112,9 +135,6 @@ GNUNET_TESTING_cmd_local_test_finished (const char *label,
112{ 135{
113 struct LocalFinishedState *lfs; 136 struct LocalFinishedState *lfs;
114 137
115 LOG (GNUNET_ERROR_TYPE_ERROR,
116 "We got here 11!\n");
117
118 lfs = GNUNET_new (struct LocalFinishedState); 138 lfs = GNUNET_new (struct LocalFinishedState);
119 lfs->write_message = write_message; 139 lfs->write_message = write_message;
120 140
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index c82392a08..536b356a6 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -29,12 +29,19 @@
29 29
30#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh" 30#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh"
31 31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
32struct NetJailState 36struct NetJailState
33{ 37{
38 // Child Wait handle
34 struct GNUNET_ChildWaitHandle *cwh; 39 struct GNUNET_ChildWaitHandle *cwh;
35 40
41 // Number of local nodes in each namespace.
36 char *local_m; 42 char *local_m;
37 43
44 // The number of namespaces.
38 char *global_n; 45 char *global_n;
39 46
40 /** 47 /**
@@ -42,16 +49,15 @@ struct NetJailState
42 */ 49 */
43 struct GNUNET_OS_Process *start_proc; 50 struct GNUNET_OS_Process *start_proc;
44 51
52 // Flag indication if the script finished.
45 unsigned int finished; 53 unsigned int finished;
46}; 54};
47 55
48 56
49/** 57/**
50* 58 * The cleanup function of this cmd frees resources the cmd allocated.
51* 59 *
52* @param cls closure 60 */
53* @param cmd current CMD being cleaned up.
54*/
55static void 61static void
56netjail_start_cleanup (void *cls, 62netjail_start_cleanup (void *cls,
57 const struct GNUNET_TESTING_Command *cmd) 63 const struct GNUNET_TESTING_Command *cmd)
@@ -81,14 +87,9 @@ netjail_start_cleanup (void *cls,
81 87
82 88
83/** 89/**
84* 90 * Trait function of this cmd does nothing.
85* 91 *
86* @param cls closure. 92 */
87* @param[out] ret result
88* @param trait name of the trait.
89* @param index index number of the object to offer.
90* @return #GNUNET_OK on success.
91*/
92static int 93static int
93netjail_start_traits (void *cls, 94netjail_start_traits (void *cls,
94 const void **ret, 95 const void **ret,
@@ -98,6 +99,11 @@ netjail_start_traits (void *cls,
98 return GNUNET_OK; 99 return GNUNET_OK;
99} 100}
100 101
102
103/**
104 * Callback which will be called if the setup script finished.
105 *
106 */
101static void 107static void
102child_completed_callback (void *cls, 108child_completed_callback (void *cls,
103 enum GNUNET_OS_ProcessStatusType type, 109 enum GNUNET_OS_ProcessStatusType type,
@@ -122,7 +128,7 @@ child_completed_callback (void *cls,
122 128
123 129
124/** 130/**
125* Run the "hello world" CMD. 131* The run method starts the script which setup the network namespaces.
126* 132*
127* @param cls closure. 133* @param cls closure.
128* @param cmd CMD being run. 134* @param cmd CMD being run.
@@ -171,6 +177,11 @@ netjail_start_run (void *cls,
171 GNUNET_break (NULL != ns->cwh); 177 GNUNET_break (NULL != ns->cwh);
172} 178}
173 179
180
181/**
182 * This function checks the flag NetJailState#finished, if this cmd finished.
183 *
184 */
174static int 185static int
175netjail_start_finish (void *cls, 186netjail_start_finish (void *cls,
176 GNUNET_SCHEDULER_TaskCallback cont, 187 GNUNET_SCHEDULER_TaskCallback cont,
@@ -189,7 +200,8 @@ netjail_start_finish (void *cls,
189 * Create command. 200 * Create command.
190 * 201 *
191 * @param label name for command. 202 * @param label name for command.
192 * @param binaryname to start. 203 * @param local_m Number of local nodes in each namespace.
204 * @param global_n The number of namespaces.
193 * @return command. 205 * @return command.
194 */ 206 */
195struct GNUNET_TESTING_Command 207struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 5c2f71168..01bac9b05 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -29,13 +29,21 @@
29 29
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" 30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
31 31
32struct HelperMessage; 32/**
33 33 * Struct to store messages send/received by the helper into a DLL
34 *
35 */
34struct HelperMessage 36struct HelperMessage
35{ 37{
36 38
39 /**
40 * Kept in a DLL.
41 */
37 struct HelperMessage *next; 42 struct HelperMessage *next;
38 43
44 /**
45 * Kept in a DLL.
46 */
39 struct HelperMessage *prev; 47 struct HelperMessage *prev;
40 48
41 /** 49 /**
@@ -47,27 +55,51 @@ struct HelperMessage
47}; 55};
48 56
49 57
50 58/**
59 * Struct to store information handed over to callbacks.
60 *
61 */
51struct NetJailState 62struct NetJailState
52{ 63{
53 64 /**
65 * Pointer to the return value of the test.
66 *
67 */
54 unsigned int *rv; 68 unsigned int *rv;
55 69
70 /**
71 * Head of the DLL which stores messages received by the helper.
72 *
73 */
56 struct HelperMessage *hp_messages_head; 74 struct HelperMessage *hp_messages_head;
57 75
76 /**
77 * Tail of the DLL which stores messages received by the helper.
78 *
79 */
58 struct HelperMessage *hp_messages_tail; 80 struct HelperMessage *hp_messages_tail;
59 81
60 /** 82 /**
61 * The process handle 83 * Array with handles of helper processes.
62 */ 84 */
63 struct GNUNET_HELPER_Handle **helper; 85 struct GNUNET_HELPER_Handle **helper;
64 86
87 /**
88 * Size of the array NetJailState#helper.
89 *
90 */
65 unsigned int n_helper; 91 unsigned int n_helper;
66 92
67 char *binary_name; 93 /**
68 94 * Number of nodes in a network namespace. //TODO make this a unsigned int
95 *
96 */
69 char *local_m; 97 char *local_m;
70 98
99 /**
100 * Number of network namespaces. //TODO make this a unsigned int
101 *
102 */
71 char *global_n; 103 char *global_n;
72 104
73 /** 105 /**
@@ -75,33 +107,91 @@ struct NetJailState
75 */ 107 */
76 struct GNUNET_HELPER_SendHandle **shandle; 108 struct GNUNET_HELPER_SendHandle **shandle;
77 109
110 /**
111 * Size of the array NetJailState#shandle.
112 *
113 */
78 unsigned int n_shandle; 114 unsigned int n_shandle;
79 115
80 /** 116 /**
81 * The message corresponding to send handle 117 * The messages send to the helper.
82 */ 118 */
83 struct GNUNET_MessageHeader **msg; 119 struct GNUNET_MessageHeader **msg;
84 120
121 /**
122 * Size of the array NetJailState#msg.
123 *
124 */
85 unsigned int n_msg; 125 unsigned int n_msg;
86 126
127 /**
128 * Number of test environments started.
129 *
130 */
87 unsigned int number_of_testsystems_started; 131 unsigned int number_of_testsystems_started;
88 132
133 /**
134 * Number of peers started.
135 *
136 */
89 unsigned int number_of_peers_started; 137 unsigned int number_of_peers_started;
90 138
139 /**
140 * Number of local tests finished.
141 *
142 */
91 unsigned int number_of_local_test_finished; 143 unsigned int number_of_local_test_finished;
92 144
145 /**
146 * Name of the test case plugin the helper will load.
147 *
148 */
93 char *plugin_name; 149 char *plugin_name;
150
151 /**
152 * HEAD of the DLL containing TestingSystemCount.
153 *
154 */
155 struct TestingSystemCount *tbcs_head;
156
157 /**
158 * TAIL of the DLL containing TestingSystemCount.
159 *
160 */
161 struct TestingSystemCount *tbcs_tail;
94}; 162};
95 163
164/**
165 * Struct containing the number of the test environment and the NetJailState which
166 * will be handed to callbacks specific to a test environment.
167 */
96struct TestingSystemCount 168struct TestingSystemCount
97{ 169{
170 /**
171 * Kept in a DLL.
172 */
173 struct TestingSystemCount *next;
174
175 /**
176 * Kept in a DLL.
177 */
178 struct TestingSystemCount *prev;
179
180 /**
181 * The number of the test environment.
182 *
183 */
98 unsigned int count; 184 unsigned int count;
99 185
186 /**
187 * Struct to store information handed over to callbacks.
188 *
189 */
100 struct NetJailState *ns; 190 struct NetJailState *ns;
101}; 191};
102 192
103/** 193/**
104* 194* Code to clean up ressource this cmd used.
105* 195*
106* @param cls closure 196* @param cls closure
107* @param cmd current CMD being cleaned up. 197* @param cmd current CMD being cleaned up.
@@ -111,20 +201,31 @@ netjail_exec_cleanup (void *cls,
111 const struct GNUNET_TESTING_Command *cmd) 201 const struct GNUNET_TESTING_Command *cmd)
112{ 202{
113 struct NetJailState *ns = cls; 203 struct NetJailState *ns = cls;
204 struct HelperMessage *message_pos;
205 struct TestingSystemCount *tbc_pos;
114 206
115 GNUNET_free (ns->binary_name); 207 while (NULL != (message_pos = ns->hp_messages_head))
208 {
209 GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
210 ns->hp_messages_tail,
211 message_pos);
212 GNUNET_free (message_pos);
213 }
214 while (NULL != (tbc_pos = ns->tbcs_head))
215 {
216 GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
217 ns->tbcs_tail,
218 tbc_pos);
219 GNUNET_free (tbc_pos);
220 }
221 GNUNET_free (ns);
116} 222}
117 223
118 224
119/** 225/**
120* 226 * This function prepares an array with traits.
121* 227 *
122* @param cls closure. 228 */
123* @param[out] ret result
124* @param trait name of the trait.
125* @param index index number of the object to offer.
126* @return #GNUNET_OK on success.
127*/
128static int 229static int
129netjail_exec_traits (void *cls, 230netjail_exec_traits (void *cls,
130 const void **ret, 231 const void **ret,
@@ -209,9 +310,6 @@ clear_msg (void *cls, int result)
209 struct TestingSystemCount *tbc = cls; 310 struct TestingSystemCount *tbc = cls;
210 struct NetJailState *ns = tbc->ns; 311 struct NetJailState *ns = tbc->ns;
211 312
212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
213 "clear_msg tbc->count: %d\n",
214 tbc->count);
215 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]); 313 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
216 ns->shandle[tbc->count - 1] = NULL; 314 ns->shandle[tbc->count - 1] = NULL;
217 GNUNET_free (ns->msg[tbc->count - 1]); 315 GNUNET_free (ns->msg[tbc->count - 1]);
@@ -240,20 +338,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
240 338
241 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type)) 339 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
242 { 340 {
243 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
244 "helper_mst tbc->count: %d\n",
245 tbc->count);
246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
247 "Received message from helper.\n");
248 ns->number_of_testsystems_started++; 341 ns->number_of_testsystems_started++;
249 } 342 }
250 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs ( 343 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
251 message->type)) 344 message->type))
252 { 345 {
253 ns->number_of_peers_started++; 346 ns->number_of_peers_started++;
254 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
255 "number_of_peers_started: %d\n",
256 ns->number_of_peers_started);
257 } 347 }
258 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs ( 348 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
259 message->type)) 349 message->type))
@@ -272,7 +362,10 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
272 return GNUNET_OK; 362 return GNUNET_OK;
273} 363}
274 364
275 365/**
366 * Callback called if there was an exception during execution of the helper.
367 *
368 */
276static void 369static void
277exp_cb (void *cls) 370exp_cb (void *cls)
278{ 371{
@@ -281,7 +374,14 @@ exp_cb (void *cls)
281 *ns->rv = 1; 374 *ns->rv = 1;
282} 375}
283 376
284 377/**
378 * Function to initialize a init message for the helper.
379 *
380 * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
381 * @param n_char The actual namespace. //TODO Change this to unsigned int
382 * @param plugin_name Name of the test case plugin the helper will load.
383 *
384 */
285static struct GNUNET_CMDS_HelperInit * 385static struct GNUNET_CMDS_HelperInit *
286create_helper_init_msg_ (char *m_char, 386create_helper_init_msg_ (char *m_char,
287 char *n_char, 387 char *n_char,
@@ -294,9 +394,6 @@ create_helper_init_msg_ (char *m_char,
294 GNUNET_assert (NULL != plugin_name); 394 GNUNET_assert (NULL != plugin_name);
295 plugin_name_len = strlen (plugin_name); 395 plugin_name_len = strlen (plugin_name);
296 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len; 396 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
297 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
298 "msg_size: %d \n",
299 msg_size);
300 msg = GNUNET_malloc (msg_size); 397 msg = GNUNET_malloc (msg_size);
301 msg->header.size = htons (msg_size); 398 msg->header.size = htons (msg_size);
302 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT); 399 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
@@ -308,13 +405,17 @@ create_helper_init_msg_ (char *m_char,
308} 405}
309 406
310 407
408/**
409 * Function which start a single helper process.
410 *
411 */
311static void 412static void
312start_helper (struct NetJailState *ns, struct 413start_helper (struct NetJailState *ns, struct
313 GNUNET_CONFIGURATION_Handle *config, 414 GNUNET_CONFIGURATION_Handle *config,
314 char *m_char, 415 char *m_char,
315 char *n_char) 416 char *n_char)
316{ 417{
317 // struct GNUNET_CONFIGURATION_Handle *cfg; 418 struct GNUNET_HELPER_Handle *helper;
318 struct GNUNET_CMDS_HelperInit *msg; 419 struct GNUNET_CMDS_HelperInit *msg;
319 struct TestingSystemCount *tbc; 420 struct TestingSystemCount *tbc;
320 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, 421 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
@@ -332,15 +433,13 @@ start_helper (struct NetJailState *ns, struct
332 GNUNET_YES, 433 GNUNET_YES,
333 NULL); 434 NULL);
334 435
335 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
336 "m: %d n: %d\n",
337 m,
338 n);
339
340 tbc = GNUNET_new (struct TestingSystemCount); 436 tbc = GNUNET_new (struct TestingSystemCount);
341 tbc->ns = ns; 437 tbc->ns = ns;
342 tbc->count = (n - 1) * atoi (ns->local_m) + m; 438 tbc->count = (n - 1) * atoi (ns->local_m) + m;
343 439
440 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
441 tbc);
442
344 443
345 if (GNUNET_NO == helper_check) 444 if (GNUNET_NO == helper_check)
346 { 445 {
@@ -365,17 +464,7 @@ start_helper (struct NetJailState *ns, struct
365 &exp_cb, 464 &exp_cb,
366 tbc)); 465 tbc));
367 466
368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 467 helper = ns->helper[tbc->count - 1];
369 "First using helper %d %d\n",
370 tbc->count - 1,
371 ns->n_helper);
372 struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
373
374 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
375 "First using helper %d %d %p\n",
376 tbc->count - 1,
377 ns->n_helper,
378 helper);
379 468
380 msg = create_helper_init_msg_ (m_char, 469 msg = create_helper_init_msg_ (m_char,
381 n_char, 470 n_char,
@@ -389,10 +478,6 @@ start_helper (struct NetJailState *ns, struct
389 &clear_msg, 478 &clear_msg,
390 tbc)); 479 tbc));
391 480
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
393 "Message %d send!\n",
394 tbc->count);
395
396 if (NULL == ns->shandle[tbc->count - 1]) 481 if (NULL == ns->shandle[tbc->count - 1])
397 { 482 {
398 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 483 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -404,7 +489,7 @@ start_helper (struct NetJailState *ns, struct
404 489
405 490
406/** 491/**
407* Run the "hello world" CMD. 492* This function starts a helper process for each node.
408* 493*
409* @param cls closure. 494* @param cls closure.
410* @param cmd CMD being run. 495* @param cmd CMD being run.
@@ -434,6 +519,15 @@ netjail_exec_run (void *cls,
434} 519}
435 520
436 521
522/**
523 * This function checks on three different information.
524 *
525 * 1. Did all helpers start. This is only logged.
526 * 2. Did all peer start.
527 * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
528 * 3. Did all peers finished the test case. In this case interpreter_next will be called.
529 *
530 */
437static int 531static int
438netjail_start_finish (void *cls, 532netjail_start_finish (void *cls,
439 GNUNET_SCHEDULER_TaskCallback cont, 533 GNUNET_SCHEDULER_TaskCallback cont,
@@ -455,16 +549,11 @@ netjail_start_finish (void *cls,
455 549
456 if (ns->number_of_testsystems_started == total_number) 550 if (ns->number_of_testsystems_started == total_number)
457 { 551 {
458 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
459 "All helpers started!\n");
460 ns->number_of_testsystems_started = 0; 552 ns->number_of_testsystems_started = 0;
461 } 553 }
462 554
463 if (ns->number_of_peers_started == total_number) 555 if (ns->number_of_peers_started == total_number)
464 { 556 {
465 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
466 "All peers started!\n");
467
468 for (int i = 1; i <= atoi (ns->global_n); i++) { 557 for (int i = 1; i <= atoi (ns->global_n); i++) {
469 for (int j = 1; j <= atoi (ns->local_m); j++) 558 for (int j = 1; j <= atoi (ns->local_m); j++)
470 { 559 {
@@ -472,11 +561,7 @@ netjail_start_finish (void *cls,
472 tbc->ns = ns; 561 tbc->ns = ns;
473 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone. 562 // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
474 tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number; 563 tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
475 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 564
476 "Second using helper %d %d %d\n",
477 tbc->count - 1 - total_number,
478 i,
479 j);
480 helper = ns->helper[tbc->count - 1 - total_number]; 565 helper = ns->helper[tbc->count - 1 - total_number];
481 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED); 566 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
482 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED); 567 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
@@ -494,10 +579,6 @@ netjail_start_finish (void *cls,
494 tbc); 579 tbc);
495 580
496 GNUNET_array_append (ns->shandle, ns->n_shandle, sh); 581 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
497
498 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
499 "All peers started message %d send!\n",
500 tbc->count);
501 } 582 }
502 } 583 }
503 ns->number_of_peers_started = 0; 584 ns->number_of_peers_started = 0;
@@ -509,8 +590,11 @@ netjail_start_finish (void *cls,
509/** 590/**
510 * Create command. 591 * Create command.
511 * 592 *
512 * @param label name for command. 593 * @param label Name for the command.
513 * @param binaryname to exec. 594 * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
595 * @param global_n Number of network namespaces. //TODO make this a unsigned int
596 * @param plugin_name Name of the test case plugin the helper will load.
597 * @param rv Pointer to the return value of the test.
514 * @return command. 598 * @return command.
515 */ 599 */
516struct GNUNET_TESTING_Command 600struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 710b4fbf4..99084d9af 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -30,12 +30,19 @@
30 30
31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" 31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
32 32
33// Child Wait handle
33struct GNUNET_ChildWaitHandle *cwh; 34struct GNUNET_ChildWaitHandle *cwh;
34 35
36/**
37 * Struct to hold information for callbacks.
38 *
39 */
35struct NetJailState 40struct NetJailState
36{ 41{
42 // Number of local nodes in each namespace.
37 char *local_m; 43 char *local_m;
38 44
45 // The number of namespaces.
39 char *global_n; 46 char *global_n;
40 47
41 /** 48 /**
@@ -43,16 +50,15 @@ struct NetJailState
43 */ 50 */
44 struct GNUNET_OS_Process *stop_proc; 51 struct GNUNET_OS_Process *stop_proc;
45 52
53 // Flag indication if the script finished.
46 unsigned int finished; 54 unsigned int finished;
47}; 55};
48 56
49 57
50/** 58/**
51* 59 * The cleanup function of this cmd frees resources the cmd allocated.
52* 60 *
53* @param cls closure 61 */
54* @param cmd current CMD being cleaned up.
55*/
56static void 62static void
57netjail_stop_cleanup (void *cls, 63netjail_stop_cleanup (void *cls,
58 const struct GNUNET_TESTING_Command *cmd) 64 const struct GNUNET_TESTING_Command *cmd)
@@ -78,14 +84,9 @@ netjail_stop_cleanup (void *cls,
78 84
79 85
80/** 86/**
81* 87 * Trait function of this cmd does nothing.
82* 88 *
83* @param cls closure. 89 */
84* @param[out] ret result
85* @param trait name of the trait.
86* @param index index number of the object to offer.
87* @return #GNUNET_OK on success.
88*/
89static int 90static int
90netjail_stop_traits (void *cls, 91netjail_stop_traits (void *cls,
91 const void **ret, 92 const void **ret,
@@ -96,6 +97,10 @@ netjail_stop_traits (void *cls,
96} 97}
97 98
98 99
100/**
101 * Callback which will be called if the setup script finished.
102 *
103 */
99static void 104static void
100child_completed_callback (void *cls, 105child_completed_callback (void *cls,
101 enum GNUNET_OS_ProcessStatusType type, 106 enum GNUNET_OS_ProcessStatusType type,
@@ -118,7 +123,7 @@ child_completed_callback (void *cls,
118 123
119 124
120/** 125/**
121* Run the "hello world" CMD. 126* The run method starts the script which deletes the network namespaces.
122* 127*
123* @param cls closure. 128* @param cls closure.
124* @param cmd CMD being run. 129* @param cmd CMD being run.
@@ -169,6 +174,10 @@ netjail_stop_run (void *cls,
169} 174}
170 175
171 176
177/**
178 * This function checks the flag NetJailState#finished, if this cmd finished.
179 *
180 */
172static int 181static int
173netjail_stop_finish (void *cls, 182netjail_stop_finish (void *cls,
174 GNUNET_SCHEDULER_TaskCallback cont, 183 GNUNET_SCHEDULER_TaskCallback cont,
@@ -188,7 +197,8 @@ netjail_stop_finish (void *cls,
188 * Create command. 197 * Create command.
189 * 198 *
190 * @param label name for command. 199 * @param label name for command.
191 * @param binaryname to stop. 200 * @param local_m Number of local nodes in each namespace.
201 * @param global_n The number of namespaces.
192 * @return command. 202 * @return command.
193 */ 203 */
194struct GNUNET_TESTING_Command 204struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index bed9f3ebf..d6e733e05 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -28,6 +28,10 @@
28#include "testing_cmds.h" 28#include "testing_cmds.h"
29 29
30 30
31/**
32 * Struct to store information handed over to callbacks.
33 *
34 */
31struct StopHelperState 35struct StopHelperState
32{ 36{
33 37
@@ -45,7 +49,7 @@ struct StopHelperState
45 49
46 50
47/** 51/**
48* 52* Code to clean up ressource this cmd used.
49* 53*
50* @param cls closure 54* @param cls closure
51* @param cmd current CMD being cleaned up. 55* @param cmd current CMD being cleaned up.
@@ -59,14 +63,9 @@ stop_testing_system_cleanup (void *cls,
59 63
60 64
61/** 65/**
62* 66 * Trait function of this cmd does nothing.
63* 67 *
64* @param cls closure. 68 */
65* @param[out] ret result
66* @param trait name of the trait.
67* @param index index number of the object to offer.
68* @return #GNUNET_OK on success.
69*/
70static int 69static int
71stop_testing_system_traits (void *cls, 70stop_testing_system_traits (void *cls,
72 const void **ret, 71 const void **ret,
@@ -78,7 +77,7 @@ stop_testing_system_traits (void *cls,
78 77
79 78
80/** 79/**
81* Run the "hello world" CMD. 80* This function stops the helper process for each node.
82* 81*
83* @param cls closure. 82* @param cls closure.
84* @param cmd CMD being run. 83* @param cmd CMD being run.
@@ -110,9 +109,11 @@ stop_testing_system_run (void *cls,
110 109
111/** 110/**
112 * Create command. 111 * Create command.
113 * 112 * @param helper_start_label label of the cmd to start the test system.
114 * @param label name for command. 113 * @param label name for command.
115 * @param binaryname to exec. 114 * @param .
115 * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
116 * @param global_n Number of network namespaces. //TODO make this a unsigned int
116 * @return command. 117 * @return command.
117 */ 118 */
118struct GNUNET_TESTING_Command 119struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index afe28de77..016837214 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -29,14 +29,30 @@
29#include "testing_cmds.h" 29#include "testing_cmds.h"
30 30
31 31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
32struct SendPeerReadyState 36struct SendPeerReadyState
33{ 37{
38 /**
39 * Callback to write messages to the master loop.
40 *
41 */
34 TESTING_CMD_HELPER_write_cb write_message; 42 TESTING_CMD_HELPER_write_cb write_message;
35 43
44 /**
45 * The message send back to the master loop.
46 *
47 */
36 struct GNUNET_CMDS_PEER_STARTED *reply; 48 struct GNUNET_CMDS_PEER_STARTED *reply;
37}; 49};
38 50
39 51
52/**
53 * Trait function of this cmd does nothing.
54 *
55 */
40static int 56static int
41send_peer_ready_traits (void *cls, 57send_peer_ready_traits (void *cls,
42 const void **ret, 58 const void **ret,
@@ -47,6 +63,10 @@ send_peer_ready_traits (void *cls,
47} 63}
48 64
49 65
66/**
67 * The cleanup function of this cmd frees resources the cmd allocated.
68 *
69 */
50static void 70static void
51send_peer_ready_cleanup (void *cls, 71send_peer_ready_cleanup (void *cls,
52 const struct GNUNET_TESTING_Command *cmd) 72 const struct GNUNET_TESTING_Command *cmd)
@@ -58,6 +78,10 @@ send_peer_ready_cleanup (void *cls,
58} 78}
59 79
60 80
81/**
82 * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
83 *
84 */
61static void 85static void
62send_peer_ready_run (void *cls, 86send_peer_ready_run (void *cls,
63 const struct GNUNET_TESTING_Command *cmd, 87 const struct GNUNET_TESTING_Command *cmd,
@@ -80,6 +104,7 @@ send_peer_ready_run (void *cls,
80 * Create command. 104 * Create command.
81 * 105 *
82 * @param label name for command. 106 * @param label name for command.
107 * @param write_message Callback to write messages to the master loop.
83 * @return command. 108 * @return command.
84 */ 109 */
85struct GNUNET_TESTING_Command 110struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 2007b4ef3..f3a0b1a4c 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -28,6 +28,10 @@
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31/**
32 * Struct to hold information for callbacks.
33 *
34 */
31struct TestSystemState 35struct TestSystemState
32{ 36{
33 struct GNUNET_TESTING_System *test_system; 37 struct GNUNET_TESTING_System *test_system;
@@ -36,6 +40,10 @@ struct TestSystemState
36}; 40};
37 41
38 42
43/**
44 * The run method of this cmd will setup a test environment for a node.
45 *
46 */
39static void 47static void
40system_create_run (void *cls, 48system_create_run (void *cls,
41 const struct GNUNET_TESTING_Command *cmd, 49 const struct GNUNET_TESTING_Command *cmd,
@@ -54,6 +62,11 @@ system_create_run (void *cls,
54 "system created\n"); 62 "system created\n");
55} 63}
56 64
65
66/**
67 * This function prepares an array with traits.
68 *
69 */
57static int 70static int
58system_create_traits (void *cls, 71system_create_traits (void *cls,
59 const void **ret, 72 const void **ret,
@@ -79,6 +92,12 @@ system_create_traits (void *cls,
79} 92}
80 93
81 94
95/**
96 * Function to get the trait with struct GNUNET_TESTING_System
97 *
98 * @param[out] test_system The struct GNUNET_TESTING_System.
99 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
100 */
82int 101int
83GNUNET_TESTING_get_trait_test_system (const struct 102GNUNET_TESTING_get_trait_test_system (const struct
84 GNUNET_TESTING_Command *cmd, 103 GNUNET_TESTING_Command *cmd,
@@ -91,13 +110,16 @@ GNUNET_TESTING_get_trait_test_system (const struct
91} 110}
92 111
93 112
113/**
114 * The cleanup function of this cmd frees resources the cmd allocated.
115 *
116 */
94static void 117static void
95system_create_cleanup (void *cls, 118system_create_cleanup (void *cls,
96 const struct GNUNET_TESTING_Command *cmd) 119 const struct GNUNET_TESTING_Command *cmd)
97{ 120{
98 struct TestSystemState *tss = cls; 121 struct TestSystemState *tss = cls;
99 122
100 GNUNET_free (tss->test_system);
101 GNUNET_free (tss); 123 GNUNET_free (tss);
102} 124}
103 125
@@ -106,6 +128,7 @@ system_create_cleanup (void *cls,
106 * Create command. 128 * Create command.
107 * 129 *
108 * @param label name for command. 130 * @param label name for command.
131 * @param label name for the test environment directory.
109 * @return command. 132 * @return command.
110 */ 133 */
111struct GNUNET_TESTING_Command 134struct GNUNET_TESTING_Command
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index e94d8dad0..5ed0c2fd2 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -53,16 +53,10 @@ system_destroy_run (void *cls,
53 const struct GNUNET_TESTING_Command *system_cmd; 53 const struct GNUNET_TESTING_Command *system_cmd;
54 struct GNUNET_TESTING_System *tl_system; 54 struct GNUNET_TESTING_System *tl_system;
55 55
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "system destroy\n");
58
59 system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label); 56 system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label);
60 GNUNET_TESTING_get_trait_test_system (system_cmd, 57 GNUNET_TESTING_get_trait_test_system (system_cmd,
61 &tl_system); 58 &tl_system);
62 GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES); 59 GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES);
63
64 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
65 "system destroyed\n");
66} 60}
67 61
68 62
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index f4fa4e17e..0c24c0e26 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -35,6 +35,7 @@
35 35
36struct GNUNET_TESTING_Interpreter *is; 36struct GNUNET_TESTING_Interpreter *is;
37 37
38
38/** 39/**
39 * Closure used to sync an asynchronous with an synchronous command. 40 * Closure used to sync an asynchronous with an synchronous command.
40 */ 41 */
@@ -57,6 +58,7 @@ struct SyncTaskClosure
57 struct GNUNET_TESTING_Interpreter *is; 58 struct GNUNET_TESTING_Interpreter *is;
58}; 59};
59 60
61
60/** 62/**
61* Closure used to run the finish task. 63* Closure used to run the finish task.
62*/ 64*/
@@ -74,6 +76,7 @@ struct FinishTaskClosure
74 struct GNUNET_TESTING_Interpreter *is; 76 struct GNUNET_TESTING_Interpreter *is;
75}; 77};
76 78
79
77/** 80/**
78 * Lookup command by label. 81 * Lookup command by label.
79 * 82 *
@@ -185,6 +188,10 @@ interpreter_next (void *cls)
185} 188}
186 189
187 190
191/**
192 * This function checks if the finish function of a command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called.
193 *
194 */
188static void 195static void
189run_finish_task_next (void *cls) 196run_finish_task_next (void *cls)
190{ 197{
@@ -212,6 +219,12 @@ run_finish_task_next (void *cls)
212} 219}
213 220
214 221
222/**
223 * This function checks if the finish function of an asynchronous command returns GNUNET_YES, when the command is finished. In this case the finish function might have called interpreter_next. IF GNUNET_NO was returned this function is added to the scheduler again. In case of an error interpreter_fail is called.
224 *
225 * //TODO run_finish_task_next and this function can be merged.
226 *
227 */
215static void 228static void
216run_finish_task_sync (void *cls) 229run_finish_task_sync (void *cls)
217{ 230{
@@ -248,13 +261,17 @@ run_finish_task_sync (void *cls)
248 } 261 }
249 else 262 else
250 { 263 {
251 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 264 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
252 "Sync task finished with an error.\n"); 265 "Sync task finished with an error.\n");
253 GNUNET_TESTING_interpreter_fail (); 266 GNUNET_TESTING_interpreter_fail ();
254 } 267 }
255} 268}
256 269
257 270
271/**
272 * run method of the command created by the interpreter to wait for another command to finish.
273 *
274 */
258static void 275static void
259start_finish_on_ref (void *cls, 276start_finish_on_ref (void *cls,
260 const struct GNUNET_TESTING_Command *cmd, 277 const struct GNUNET_TESTING_Command *cmd,
@@ -277,6 +294,17 @@ start_finish_on_ref (void *cls,
277} 294}
278 295
279 296
297/**
298 * Create (synchronous) command that waits for another command to finish.
299 * If @a cmd_ref did not finish after @a timeout, this command will fail
300 * the test case.
301 *
302 * @param finish_label label for this command
303 * @param cmd_ref reference to a previous command which we should
304 * wait for (call `finish()` on)
305 * @param timeout how long to wait at most for @a cmd_ref to finish
306 * @return a finish-command.
307 */
280const struct GNUNET_TESTING_Command 308const struct GNUNET_TESTING_Command
281GNUNET_TESTING_cmd_finish (const char *finish_label, 309GNUNET_TESTING_cmd_finish (const char *finish_label,
282 const char *cmd_ref, 310 const char *cmd_ref,
@@ -340,7 +368,7 @@ GNUNET_TESTING_interpreter_fail ()
340 while (GNUNET_TESTING_cmd_is_batch (cmd)) 368 while (GNUNET_TESTING_cmd_is_batch (cmd))
341 { 369 {
342 cmd = GNUNET_TESTING_cmd_batch_get_current (cmd); 370 cmd = GNUNET_TESTING_cmd_batch_get_current (cmd);
343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 371 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
344 "Batch is at command `%s'\n", 372 "Batch is at command `%s'\n",
345 cmd->label); 373 cmd->label);
346 } 374 }
@@ -354,7 +382,7 @@ GNUNET_TESTING_interpreter_fail ()
354 382
355 if (NULL == cmd->label) 383 if (NULL == cmd->label)
356 { 384 {
357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
358 "Failed at command `%s'\n", 386 "Failed at command `%s'\n",
359 cmd->label); 387 cmd->label);
360 388
@@ -415,7 +443,7 @@ interpreter_run (void *cls)
415 if (NULL == cmd->label) 443 if (NULL == cmd->label)
416 { 444 {
417 445
418 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Running command END %p\n", 447 "Running command END %p\n",
420 is); 448 is);
421 is->result = GNUNET_OK; 449 is->result = GNUNET_OK;
@@ -424,7 +452,7 @@ interpreter_run (void *cls)
424 } 452 }
425 else if (NULL != cmd) 453 else if (NULL != cmd)
426 { 454 {
427 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 455 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
428 "Running command `%s' %p\n", 456 "Running command `%s' %p\n",
429 cmd->label, 457 cmd->label,
430 is); 458 is);
@@ -478,8 +506,14 @@ do_shutdown (void *cls)
478 for (unsigned int j = 0; 506 for (unsigned int j = 0;
479 NULL != (cmd = &is->commands[j])->label; 507 NULL != (cmd = &is->commands[j])->label;
480 j++) { 508 j++) {
509 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
510 "Cleaning up cmd %s\n",
511 cmd->label);
481 cmd->cleanup (cmd->cls, 512 cmd->cleanup (cmd->cls,
482 cmd); 513 cmd);
514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
515 "Cleaned up cmd %s\n",
516 cmd->label);
483 } 517 }
484 518
485 if (NULL != is->finish_task) 519 if (NULL != is->finish_task)
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 10e2f7d40..d8bf7c1a8 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -879,12 +879,15 @@ queue_destroy (struct Queue *queue)
879 struct GNUNET_HashCode h_sock; 879 struct GNUNET_HashCode h_sock;
880 int sockfd; 880 int sockfd;
881 881
882 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock); 882 if (NULL != queue->listen_sock)
883 GNUNET_CRYPTO_hash (&sockfd, 883 {
884 sizeof(int), 884 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
885 &h_sock); 885 GNUNET_CRYPTO_hash (&sockfd,
886 sizeof(int),
887 &h_sock);
886 888
887 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock); 889 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
890 }
888 891
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 "Disconnecting queue for peer `%s'\n", 893 "Disconnecting queue for peer `%s'\n",
@@ -1900,9 +1903,9 @@ queue_read (void *cls)
1900 BUF_SIZE - queue->cread_off); 1903 BUF_SIZE - queue->cread_off);
1901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1902 "Received %lu bytes from TCP queue\n", rcvd); 1905 "Received %lu bytes from TCP queue\n", rcvd);
1903 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, 1906 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
1904 "transport", 1907 "transport",
1905 "Received %lu bytes from TCP queue\n", rcvd); 1908 "Received %lu bytes from TCP queue\n", rcvd);
1906 if (-1 == rcvd) 1909 if (-1 == rcvd)
1907 { 1910 {
1908 if ((EAGAIN != errno) && (EINTR != errno)) 1911 if ((EAGAIN != errno) && (EINTR != errno))
@@ -2678,9 +2681,9 @@ proto_read_kx (void *cls)
2678 sizeof(pq->ibuf) - pq->ibuf_off); 2681 sizeof(pq->ibuf) - pq->ibuf_off);
2679 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2680 "Received %lu bytes for KX\n", rcvd); 2683 "Received %lu bytes for KX\n", rcvd);
2681 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, 2684 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
2682 "transport", 2685 "transport",
2683 "Received %lu bytes for KX\n", rcvd); 2686 "Received %lu bytes for KX\n", rcvd);
2684 if (-1 == rcvd) 2687 if (-1 == rcvd)
2685 { 2688 {
2686 if ((EAGAIN != errno) && (EINTR != errno)) 2689 if ((EAGAIN != errno) && (EINTR != errno))
@@ -2830,10 +2833,10 @@ queue_read_kx (void *cls)
2830 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2831 "Received %lu bytes for KX\n", 2834 "Received %lu bytes for KX\n",
2832 rcvd); 2835 rcvd);
2833 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG, 2836 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
2834 "transport", 2837 "transport",
2835 "Received %lu bytes for KX\n", 2838 "Received %lu bytes for KX\n",
2836 rcvd); 2839 rcvd);
2837 if (-1 == rcvd) 2840 if (-1 == rcvd)
2838 { 2841 {
2839 if ((EAGAIN != errno) && (EINTR != errno)) 2842 if ((EAGAIN != errno) && (EINTR != errno))
@@ -3082,9 +3085,9 @@ do_shutdown (void *cls)
3082 GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL); 3085 GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL);
3083 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); 3086 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
3084 GNUNET_CONTAINER_multipeermap_destroy (queue_map); 3087 GNUNET_CONTAINER_multipeermap_destroy (queue_map);
3085 GNUNET_TRANSPORT_communicator_address_remove_all (ch);
3086 if (NULL != ch) 3088 if (NULL != ch)
3087 { 3089 {
3090 GNUNET_TRANSPORT_communicator_address_remove_all (ch);
3088 GNUNET_TRANSPORT_communicator_disconnect (ch); 3091 GNUNET_TRANSPORT_communicator_disconnect (ch);
3089 ch = NULL; 3092 ch = NULL;
3090 } 3093 }
diff --git a/src/transport/test_transport_api_cmd_simple_send.c b/src/transport/test_transport_api_cmd_simple_send.c
index 13497366e..27b9f95de 100644
--- a/src/transport/test_transport_api_cmd_simple_send.c
+++ b/src/transport/test_transport_api_cmd_simple_send.c
@@ -29,6 +29,10 @@
29 29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31 31
32/**
33 * Return value of the test.
34 *
35 */
32static unsigned int rv = 0; 36static unsigned int rv = 0;
33 37
34 38
@@ -42,19 +46,19 @@ static void
42run (void *cls) 46run (void *cls)
43{ 47{
44 struct GNUNET_TESTING_Command commands[] = { 48 struct GNUNET_TESTING_Command commands[] = {
45 GNUNET_TESTING_cmd_netjail_start ("netjail-start-1", 49 GNUNET_TESTING_cmd_netjail_start ("netjail-start",
46 "2", 50 "2",
47 "1"), 51 "1"),
48 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1", 52 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed ",
49 "2", 53 "2",
50 "1", 54 "1",
51 "libgnunet_test_transport_plugin_cmd_simple_send", 55 "libgnunet_test_transport_plugin_cmd_simple_send",
52 &rv), 56 &rv),
53 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", 57 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
54 "netjail-start-testbed-1", 58 "netjail-start-testbed ",
55 "2", 59 "2",
56 "1"), 60 "1"),
57 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1", 61 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop ",
58 "2", 62 "2",
59 "1"), 63 "1"),
60 GNUNET_TESTING_cmd_end () 64 GNUNET_TESTING_cmd_end ()
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index ac5c01075..4b5018b60 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -160,13 +160,6 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
160 m, 160 m,
161 n); 161 n);
162 162
163 /*testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
164 + 1);
165
166 strcpy (testdir, BASE_DIR);
167 strcat (testdir, m);
168 strcat (testdir, n);*/
169
170 struct GNUNET_MQ_MessageHandler handlers[] = { 163 struct GNUNET_MQ_MessageHandler handlers[] = {
171 GNUNET_MQ_hd_var_size (test, 164 GNUNET_MQ_hd_var_size (test,
172 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE, 165 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index ece3b09a2..1461a3d4d 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -38,17 +38,19 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
38 const char *cfgname); 38 const char *cfgname);
39 39
40struct GNUNET_TESTING_Command 40struct GNUNET_TESTING_Command
41GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
42 const char *start_label);
43
44struct GNUNET_TESTING_Command
41GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 45GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
42 const char *peer1_label, 46 const char *start_peer_label);
43 const char *peer2_label);
44 47
45struct GNUNET_TESTING_Command 48struct GNUNET_TESTING_Command
46GNUNET_TRANSPORT_cmd_send_simple (const char *label, 49GNUNET_TRANSPORT_cmd_send_simple (const char *label,
47 char *m, 50 char *m,
48 char *n, 51 char *n,
49 uint32_t num, 52 uint32_t num,
50 const char *peer1_label, 53 const char *start_peer_label);
51 const char *peer2_label);
52 54
53int 55int
54GNUNET_TRANSPORT_get_trait_peer_id (const struct 56GNUNET_TRANSPORT_get_trait_peer_id (const struct
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index d5c4a5d48..34b3d5925 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -36,16 +36,30 @@
36 */ 36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38 38
39/**
40 * Struct to store information needed in callbacks.
41 *
42 */
39struct ConnectPeersState 43struct ConnectPeersState
40{ 44{
41 const char *peer1_label; 45 /**
42 46 * Label of the cmd to start a peer.
43 const char *peer2_label; 47 *
44 48 */
49 const char *start_peer_label;
50
51 /**
52 * The peer identity of this peer.
53 *
54 */
45 struct GNUNET_PeerIdentity *id; 55 struct GNUNET_PeerIdentity *id;
46}; 56};
47 57
48 58
59/**
60 * The run method of this cmd will connect to peers.
61 *
62 */
49static void 63static void
50connect_peers_run (void *cls, 64connect_peers_run (void *cls,
51 const struct GNUNET_TESTING_Command *cmd, 65 const struct GNUNET_TESTING_Command *cmd,
@@ -53,47 +67,38 @@ connect_peers_run (void *cls,
53{ 67{
54 struct ConnectPeersState *cps = cls; 68 struct ConnectPeersState *cps = cls;
55 const struct GNUNET_TESTING_Command *peer1_cmd; 69 const struct GNUNET_TESTING_Command *peer1_cmd;
56 //const struct GNUNET_TESTING_Command *peer2_cmd; 70 // const struct GNUNET_TESTING_Command *peer2_cmd;
57 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 71 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
58 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity); 72 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
59 char *addr; 73 char *addr;
60 //struct GNUNET_TIME_Absolute t; 74 // struct GNUNET_TIME_Absolute t;
61 char *hello; 75 char *hello;
62 //size_t *hello_size; 76 // size_t *hello_size;
63 enum GNUNET_NetworkType nt = 0; 77 enum GNUNET_NetworkType nt = 0;
64 char *peer_id; 78 char *peer_id;
65 struct GNUNET_PeerIdentity *id; 79 struct GNUNET_PeerIdentity *id;
66 80
67 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); 81 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
68 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 82 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
69 &ah); 83 &ah);
70 84
71 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, 85 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
72 &hello); 86 &hello);
73 87
74 LOG (GNUNET_ERROR_TYPE_ERROR,
75 "hello: %s\n",
76 hello);
77
78 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, 88 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
79 &id); 89 &id);
80 LOG (GNUNET_ERROR_TYPE_ERROR,
81 "pid %s\n",
82 GNUNET_i2s_full(id));
83 90
84 if(strstr(hello, "60002") != NULL) 91 if (strstr (hello, "60002") != NULL)
85 { 92 {
86 addr = "tcp-192.168.15.2:60003"; 93 addr = "tcp-192.168.15.2:60003";
87 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; 94 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
88 } 95 }
89 else 96 else
90 { 97 {
91 addr = "tcp-192.168.15.1:60002"; 98 addr = "tcp-192.168.15.1:60002";
92 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; 99 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
93 } 100 }
94 101
95 LOG (GNUNET_ERROR_TYPE_ERROR,
96 "get pub key\n");
97 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 102 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
98 strlen (peer_id), 103 strlen (peer_id),
99 &peer->public_key); 104 &peer->public_key);
@@ -116,10 +121,9 @@ connect_peers_run (void *cls,
116 &nt, 121 &nt,
117 &t);*/ 122 &t);*/
118 123
119 //---------------------------------------------- 124 // ----------------------------------------------
125
120 126
121 LOG (GNUNET_ERROR_TYPE_ERROR,
122 "application validate\n");
123 GNUNET_TRANSPORT_application_validate (ah, 127 GNUNET_TRANSPORT_application_validate (ah,
124 peer, 128 peer,
125 nt, 129 nt,
@@ -127,6 +131,10 @@ connect_peers_run (void *cls,
127} 131}
128 132
129 133
134/**
135 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.
136 *
137 */
130static int 138static int
131connect_peers_finish (void *cls, 139connect_peers_finish (void *cls,
132 GNUNET_SCHEDULER_TaskCallback cont, 140 GNUNET_SCHEDULER_TaskCallback cont,
@@ -140,36 +148,34 @@ connect_peers_finish (void *cls,
140 struct GNUNET_HashCode hc; 148 struct GNUNET_HashCode hc;
141 int node_number; 149 int node_number;
142 150
143 LOG (GNUNET_ERROR_TYPE_ERROR, 151 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
144 "Connect finished?\n");
145
146 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
147 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 152 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
148 &connected_peers_map); 153 &connected_peers_map);
149 154
150 node_number = 1; 155 node_number = 1;
151 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); 156 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
152 157
153 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. 158 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
154 memcpy (key, 159 memcpy (key,
155 &hc, 160 &hc,
156 sizeof (*key)); 161 sizeof (*key));
157 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map, 162 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
158 key); 163 key);
159 164
160 if (GNUNET_YES == ret) 165 if (GNUNET_YES == ret)
161 { 166 {
162 cont (cont_cls); 167 cont (cont_cls);
163 LOG (GNUNET_ERROR_TYPE_ERROR,
164 "connect peer finish\n");
165 } 168 }
166 169
170 GNUNET_free (key);
167 return ret; 171 return ret;
168 /*cont (cont_cls);
169 return GNUNET_OK;*/
170} 172}
171 173
172 174
175/**
176 * Trait function of this cmd does nothing.
177 *
178 */
173static int 179static int
174connect_peers_traits (void *cls, 180connect_peers_traits (void *cls,
175 const void **ret, 181 const void **ret,
@@ -180,12 +186,17 @@ connect_peers_traits (void *cls,
180} 186}
181 187
182 188
189/**
190 * The cleanup function of this cmd frees resources the cmd allocated.
191 *
192 */
183static void 193static void
184connect_peers_cleanup (void *cls, 194connect_peers_cleanup (void *cls,
185 const struct GNUNET_TESTING_Command *cmd) 195 const struct GNUNET_TESTING_Command *cmd)
186{ 196{
187 struct ConnectPeersState *cps = cls; 197 struct ConnectPeersState *cps = cls;
188 198
199 GNUNET_free (cps->id);
189 GNUNET_free (cps); 200 GNUNET_free (cps);
190} 201}
191 202
@@ -194,18 +205,17 @@ connect_peers_cleanup (void *cls,
194 * Create command. 205 * Create command.
195 * 206 *
196 * @param label name for command. 207 * @param label name for command.
208 * @param start_peer_label Label of the cmd to start a peer.
197 * @return command. 209 * @return command.
198 */ 210 */
199struct GNUNET_TESTING_Command 211struct GNUNET_TESTING_Command
200GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 212GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
201 const char *peer1_label, 213 const char *start_peer_label)
202 const char *peer2_label)
203{ 214{
204 struct ConnectPeersState *cps; 215 struct ConnectPeersState *cps;
205 216
206 cps = GNUNET_new (struct ConnectPeersState); 217 cps = GNUNET_new (struct ConnectPeersState);
207 cps->peer1_label = peer1_label; 218 cps->start_peer_label = start_peer_label;
208 cps->peer2_label = peer2_label;
209 219
210 220
211 struct GNUNET_TESTING_Command cmd = { 221 struct GNUNET_TESTING_Command cmd = {
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 6c4b76f48..f9e515c0f 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -29,19 +29,42 @@
29#include "transport-testing2.h" 29#include "transport-testing2.h"
30#include "transport-testing-cmds.h" 30#include "transport-testing-cmds.h"
31 31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
32struct SendSimpleState 36struct SendSimpleState
33{ 37{
38 /**
39 * The number of the local node of the actual network namespace.
40 *
41 */
34 char *m; 42 char *m;
35 43
44 /**
45 * The number of the actual namespace.
46 *
47 */
36 char *n; 48 char *n;
37 49
50 /**
51 * Number globally identifying the node.
52 *
53 */
38 uint32_t num; 54 uint32_t num;
39 55
40 const char *peer1_label; 56 /**
41 57 * Label of the cmd to start a peer.
42 const char *peer2_label; 58 *
59 */
60 const char *start_peer_label;
43}; 61};
44 62
63
64/**
65 * Trait function of this cmd does nothing.
66 *
67 */
45static int 68static int
46send_simple_traits (void *cls, 69send_simple_traits (void *cls,
47 const void **ret, 70 const void **ret,
@@ -52,6 +75,10 @@ send_simple_traits (void *cls,
52} 75}
53 76
54 77
78/**
79 * The cleanup function of this cmd frees resources the cmd allocated.
80 *
81 */
55static void 82static void
56send_simple_cleanup (void *cls, 83send_simple_cleanup (void *cls,
57 const struct GNUNET_TESTING_Command *cmd) 84 const struct GNUNET_TESTING_Command *cmd)
@@ -62,6 +89,10 @@ send_simple_cleanup (void *cls,
62} 89}
63 90
64 91
92/**
93 * The run method of this cmd will send a simple message to the connected peer.
94 *
95 */
65static void 96static void
66send_simple_run (void *cls, 97send_simple_run (void *cls,
67 const struct GNUNET_TESTING_Command *cmd, 98 const struct GNUNET_TESTING_Command *cmd,
@@ -72,14 +103,12 @@ send_simple_run (void *cls,
72 struct GNUNET_TRANSPORT_TESTING_TestMessage *test; 103 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
73 struct GNUNET_MQ_Handle *mq; 104 struct GNUNET_MQ_Handle *mq;
74 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map; 105 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
75 //struct GNUNET_PeerIdentity *id;
76 const struct GNUNET_TESTING_Command *peer1_cmd; 106 const struct GNUNET_TESTING_Command *peer1_cmd;
77 //const struct GNUNET_TESTING_Command *peer2_cmd;
78 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode); 107 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
79 struct GNUNET_HashCode hc; 108 struct GNUNET_HashCode hc;
80 int node_number; 109 int node_number;
81 110
82 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label); 111 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
83 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 112 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
84 &connected_peers_map); 113 &connected_peers_map);
85 114
@@ -88,9 +117,9 @@ send_simple_run (void *cls,
88 memcpy (key, 117 memcpy (key,
89 &hc, 118 &hc,
90 sizeof (*key)); 119 sizeof (*key));
91 120
92 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map, 121 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
93 key); 122 key);
94 123
95 env = GNUNET_MQ_msg_extra (test, 124 env = GNUNET_MQ_msg_extra (test,
96 2600 - sizeof(*test), 125 2600 - sizeof(*test),
@@ -99,12 +128,9 @@ send_simple_run (void *cls,
99 memset (&test[1], 128 memset (&test[1],
100 sss->num, 129 sss->num,
101 2600 - sizeof(*test)); 130 2600 - sizeof(*test));
102 /*GNUNET_MQ_notify_sent (env,
103 cont,
104 cont_cls);*/
105 GNUNET_MQ_send (mq, 131 GNUNET_MQ_send (mq,
106 env); 132 env);
107 133 GNUNET_free (key);
108 134
109} 135}
110 136
@@ -113,15 +139,18 @@ send_simple_run (void *cls,
113 * Create command. 139 * Create command.
114 * 140 *
115 * @param label name for command. 141 * @param label name for command.
142 * @param m The number of the local node of the actual network namespace.
143 * @param n The number of the actual namespace.
144 * @param num Number globally identifying the node.
145 * @param start_peer_label Label of the cmd to start a peer.
116 * @return command. 146 * @return command.
117 */ 147 */
118struct GNUNET_TESTING_Command 148struct GNUNET_TESTING_Command
119GNUNET_TRANSPORT_cmd_send_simple (const char *label, 149GNUNET_TRANSPORT_cmd_send_simple (const char *label,
120 char *m, 150 char *m,
121 char *n, 151 char *n,
122 uint32_t num, 152 uint32_t num,
123 const char *peer1_label, 153 const char *start_peer_label)
124 const char *peer2_label)
125{ 154{
126 struct SendSimpleState *sss; 155 struct SendSimpleState *sss;
127 156
@@ -129,7 +158,7 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
129 sss->m = m; 158 sss->m = m;
130 sss->n = n; 159 sss->n = n;
131 sss->num = num; 160 sss->num = num;
132 sss->peer1_label = peer1_label; 161 sss->start_peer_label = start_peer_label;
133 162
134 struct GNUNET_TESTING_Command cmd = { 163 struct GNUNET_TESTING_Command cmd = {
135 .cls = sss, 164 .cls = sss,
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 8696a99dc..9277bc346 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -29,93 +29,22 @@
29#include "gnunet_peerstore_service.h" 29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h" 30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h" 31#include "gnunet_transport_application_service.h"
32#include "transport-testing-ng.h"
32 33
33/** 34/**
34 * Generic logging shortcut 35 * Generic logging shortcut
35 */ 36 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37 38
38struct StartPeerState
39{
40 /**
41 * Receive callback
42 */
43 struct GNUNET_MQ_MessageHandler *handlers;
44
45 const char *cfgname;
46
47 /**
48 * Peer's configuration
49 */
50 struct GNUNET_CONFIGURATION_Handle *cfg;
51
52 struct GNUNET_TESTING_Peer *peer;
53
54 /**
55 * Peer identity
56 */
57 struct GNUNET_PeerIdentity id;
58
59 /**
60 * Peer's transport service handle
61 */
62 struct GNUNET_TRANSPORT_CoreHandle *th;
63
64 /**
65 * Application handle
66 */
67 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
68
69 /**
70 * Peer's PEERSTORE Handle
71 */
72 struct GNUNET_PEERSTORE_Handle *ph;
73
74 /**
75 * Hello get task
76 */
77 struct GNUNET_SCHEDULER_Task *rh_task;
78
79 /**
80 * Peer's transport get hello handle to retrieve peer's HELLO message
81 */
82 struct GNUNET_PEERSTORE_IterateContext *pic;
83
84 /**
85 * Hello
86 */
87 char *hello;
88
89 /**
90 * Hello size
91 */
92 size_t hello_size;
93
94 char *m;
95
96 char *n;
97
98 char *local_m;
99
100 unsigned int finished;
101
102 const char *system_label;
103
104 /**
105 * An unique number to identify the peer
106 */
107 unsigned int no;
108
109 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
110
111 struct GNUNET_TESTING_System *tl_system;
112
113};
114
115 39
116static void 40static void
117retrieve_hello (void *cls); 41retrieve_hello (void *cls);
118 42
43
44/**
45 * Callback delivering the hello of this peer from peerstore.
46 *
47 */
119static void 48static void
120hello_iter_cb (void *cb_cls, 49hello_iter_cb (void *cb_cls,
121 const struct GNUNET_PEERSTORE_Record *record, 50 const struct GNUNET_PEERSTORE_Record *record,
@@ -140,6 +69,11 @@ hello_iter_cb (void *cb_cls,
140} 69}
141 70
142 71
72
73/**
74 * Function to start the retrival task to retrieve the hello of this peer from the peerstore.
75 *
76 */
143static void 77static void
144retrieve_hello (void *cls) 78retrieve_hello (void *cls)
145{ 79{
@@ -154,6 +88,11 @@ retrieve_hello (void *cls)
154 88
155} 89}
156 90
91
92/**
93 * This function checks StartPeerState#finished, which is set when the hello was retrieved.
94 *
95 */
157static int 96static int
158start_peer_finish (void *cls, 97start_peer_finish (void *cls,
159 GNUNET_SCHEDULER_TaskCallback cont, 98 GNUNET_SCHEDULER_TaskCallback cont,
@@ -170,6 +109,10 @@ start_peer_finish (void *cls,
170} 109}
171 110
172 111
112/**
113 * Disconnect callback for the connection to the core service.
114 *
115 */
173static void 116static void
174notify_disconnect (void *cls, 117notify_disconnect (void *cls,
175 const struct GNUNET_PeerIdentity *peer, 118 const struct GNUNET_PeerIdentity *peer,
@@ -186,6 +129,10 @@ notify_disconnect (void *cls,
186} 129}
187 130
188 131
132/**
133 * Connect callback for the connection to the core service.
134 *
135 */
189static void * 136static void *
190notify_connect (void *cls, 137notify_connect (void *cls,
191 const struct GNUNET_PeerIdentity *peer, 138 const struct GNUNET_PeerIdentity *peer,
@@ -206,23 +153,27 @@ notify_connect (void *cls,
206 GNUNET_i2s (&sps->id)); 153 GNUNET_i2s (&sps->id));
207 154
208 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node. 155 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
209 node_number = 1; 156 node_number = 1;
210 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc); 157 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
211 158
212 159
213 memcpy (key, 160 memcpy (key,
214 &hc, 161 &hc,
215 sizeof (*key)); 162 sizeof (*key));
216 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map, 163 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
217 key, 164 key,
218 mq, 165 mq,
219 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
220 167
168 GNUNET_free (key);
221 // TODO what does the handler function need? 169 // TODO what does the handler function need?
222 return ret; 170 return ret;
223} 171}
224 172
225 173/**
174 * The run method of this cmd will start all services of a peer to test the transport service.
175 *
176 */
226static void 177static void
227start_peer_run (void *cls, 178start_peer_run (void *cls,
228 const struct GNUNET_TESTING_Command *cmd, 179 const struct GNUNET_TESTING_Command *cmd,
@@ -234,9 +185,6 @@ start_peer_run (void *cls,
234 const struct GNUNET_TESTING_Command *system_cmd; 185 const struct GNUNET_TESTING_Command *system_cmd;
235 struct GNUNET_TESTING_System *tl_system; 186 struct GNUNET_TESTING_System *tl_system;
236 187
237 LOG (GNUNET_ERROR_TYPE_ERROR,
238 "start peer 1\n");
239
240 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) 188 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
241 { 189 {
242 LOG (GNUNET_ERROR_TYPE_ERROR, 190 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -269,8 +217,6 @@ start_peer_run (void *cls,
269 return; 217 return;
270 } 218 }
271 219
272 LOG (GNUNET_ERROR_TYPE_ERROR,
273 "start peer 2\n");
274 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, 220 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
275 sps->cfg, 221 sps->cfg,
276 sps->no, 222 sps->no,
@@ -287,8 +233,6 @@ start_peer_run (void *cls,
287 return; 233 return;
288 } 234 }
289 235
290 LOG (GNUNET_ERROR_TYPE_ERROR,
291 "start peer 3\n");
292 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) 236 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
293 { 237 {
294 LOG (GNUNET_ERROR_TYPE_ERROR, 238 LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -298,17 +242,14 @@ start_peer_run (void *cls,
298 GNUNET_TESTING_interpreter_fail (); 242 GNUNET_TESTING_interpreter_fail ();
299 return; 243 return;
300 } 244 }
301LOG (GNUNET_ERROR_TYPE_ERROR, 245
302 "start peer 4\n");
303 memset (&dummy, 246 memset (&dummy,
304 '\0', 247 '\0',
305 sizeof(dummy)); 248 sizeof(dummy));
306 LOG (GNUNET_ERROR_TYPE_ERROR, 249
307 "start peer 4.1\n");
308 GNUNET_TESTING_peer_get_identity (sps->peer, 250 GNUNET_TESTING_peer_get_identity (sps->peer,
309 &sps->id); 251 &sps->id);
310 LOG (GNUNET_ERROR_TYPE_ERROR, 252
311 "start peer 4.2\n");
312 if (0 == memcmp (&dummy, 253 if (0 == memcmp (&dummy,
313 &sps->id, 254 &sps->id,
314 sizeof(struct GNUNET_PeerIdentity))) 255 sizeof(struct GNUNET_PeerIdentity)))
@@ -324,8 +265,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
324 "Peer %u configured with identity `%s'\n", 265 "Peer %u configured with identity `%s'\n",
325 sps->no, 266 sps->no,
326 GNUNET_i2s_full (&sps->id)); 267 GNUNET_i2s_full (&sps->id));
327 LOG (GNUNET_ERROR_TYPE_ERROR, 268
328 "start peer 4.3\n");
329 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, 269 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
330 NULL, 270 NULL,
331 sps->handlers, 271 sps->handlers,
@@ -342,8 +282,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
342 GNUNET_TESTING_interpreter_fail (); 282 GNUNET_TESTING_interpreter_fail ();
343 return; 283 return;
344 } 284 }
345 LOG (GNUNET_ERROR_TYPE_ERROR, 285
346 "start peer 5\n");
347 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); 286 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
348 if (NULL == sps->th) 287 if (NULL == sps->th)
349 { 288 {
@@ -355,8 +294,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
355 GNUNET_TESTING_interpreter_fail (); 294 GNUNET_TESTING_interpreter_fail ();
356 return; 295 return;
357 } 296 }
358 LOG (GNUNET_ERROR_TYPE_ERROR, 297
359 "start peer 6\n");
360 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); 298 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
361 if (NULL == sps->ah) 299 if (NULL == sps->ah)
362 { 300 {
@@ -371,28 +309,16 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
371 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); 309 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
372} 310}
373 311
374 312/**
313 * The cleanup function of this cmd frees resources the cmd allocated.
314 *
315 */
375static void 316static void
376start_peer_cleanup (void *cls, 317start_peer_cleanup (void *cls,
377 const struct GNUNET_TESTING_Command *cmd) 318 const struct GNUNET_TESTING_Command *cmd)
378{ 319{
379 struct StartPeerState *sps = cls; 320 struct StartPeerState *sps = cls;
380 321
381 if (NULL != sps->rh_task)
382 GNUNET_SCHEDULER_cancel (sps->rh_task);
383 sps->rh_task = NULL;
384 if (NULL != sps->ah)
385 {
386 GNUNET_TRANSPORT_application_done (sps->ah);
387 sps->ah = NULL;
388 }
389 if (NULL != sps->ph)
390 {
391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
392 "Disconnecting from PEERSTORE service\n");
393 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
394 sps->ph = NULL;
395 }
396 if (NULL != sps->handlers) 322 if (NULL != sps->handlers)
397 { 323 {
398 GNUNET_free (sps->handlers); 324 GNUNET_free (sps->handlers);
@@ -403,34 +329,16 @@ start_peer_cleanup (void *cls,
403 GNUNET_CONFIGURATION_destroy (sps->cfg); 329 GNUNET_CONFIGURATION_destroy (sps->cfg);
404 sps->cfg = NULL; 330 sps->cfg = NULL;
405 } 331 }
406 if (NULL != sps->peer)
407 {
408 if (GNUNET_OK !=
409 GNUNET_TESTING_peer_stop (sps->peer))
410 {
411 LOG (GNUNET_ERROR_TYPE_DEBUG,
412 "Testing lib failed to stop peer %u (`%s')\n",
413 sps->no,
414 GNUNET_i2s (&sps->id));
415 }
416 GNUNET_TESTING_peer_destroy (sps->peer);
417 sps->peer = NULL;
418 }
419 if (NULL != sps->th)
420 {
421 GNUNET_TRANSPORT_core_disconnect (sps->th);
422 sps->th = NULL;
423 }
424 if (NULL != sps->tl_system)
425 {
426 GNUNET_free (sps->tl_system);
427 }
428 GNUNET_free (sps->hello); 332 GNUNET_free (sps->hello);
429 GNUNET_free (sps->connected_peers_map); 333 GNUNET_free (sps->connected_peers_map);
430 GNUNET_free (sps); 334 GNUNET_free (sps);
431} 335}
432 336
433 337
338/**
339 * This function prepares an array with traits.
340 *
341 */
434static int 342static int
435start_peer_traits (void *cls, 343start_peer_traits (void *cls,
436 const void **ret, 344 const void **ret,
@@ -472,6 +380,11 @@ start_peer_traits (void *cls,
472 .trait_name = "hello_size", 380 .trait_name = "hello_size",
473 .ptr = (const void *) hello_size, 381 .ptr = (const void *) hello_size,
474 }, 382 },
383 {
384 .index = 5,
385 .trait_name = "state",
386 .ptr = (const void *) sps,
387 },
475 GNUNET_TESTING_trait_end () 388 GNUNET_TESTING_trait_end ()
476 }; 389 };
477 390
@@ -481,6 +394,34 @@ start_peer_traits (void *cls,
481 index); 394 index);
482} 395}
483 396
397
398/**
399 * Function to get the trait with the struct StartPeerState.
400 *
401 * @param[out] sps struct StartPeerState.
402 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
403 *
404 */
405int
406GNUNET_TRANSPORT_get_trait_state (const struct
407 GNUNET_TESTING_Command
408 *cmd,
409 struct StartPeerState **sps)
410{
411 return cmd->traits (cmd->cls,
412 (const void **) sps,
413 "state",
414 (unsigned int) 5);
415}
416
417
418/**
419 * Function to get the trait with the size of the hello.
420 *
421 * @param[out] hello_size size of hello.
422 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
423 *
424 */
484int 425int
485GNUNET_TRANSPORT_get_trait_hello_size (const struct 426GNUNET_TRANSPORT_get_trait_hello_size (const struct
486 GNUNET_TESTING_Command 427 GNUNET_TESTING_Command
@@ -493,6 +434,13 @@ GNUNET_TRANSPORT_get_trait_hello_size (const struct
493 (unsigned int) 4); 434 (unsigned int) 4);
494} 435}
495 436
437/**
438 * Function to get the trait with the hello.
439 *
440 * @param[out] hello The hello for the peer.
441 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
442 *
443 */
496int 444int
497GNUNET_TRANSPORT_get_trait_hello (const struct 445GNUNET_TRANSPORT_get_trait_hello (const struct
498 GNUNET_TESTING_Command 446 GNUNET_TESTING_Command
@@ -505,12 +453,21 @@ GNUNET_TRANSPORT_get_trait_hello (const struct
505 (unsigned int) 3); 453 (unsigned int) 3);
506} 454}
507 455
456
457/**
458 * Function to get the trait with the map of connected peers.
459 *
460 * @param[out] connected_peers_map The map with connected peers.
461 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
462 *
463 */
508int 464int
509GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct 465GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
510 GNUNET_TESTING_Command 466 GNUNET_TESTING_Command
511 *cmd, 467 *cmd,
512 struct 468 struct
513 GNUNET_CONTAINER_MultiShortmap ** 469 GNUNET_CONTAINER_MultiShortmap *
470 *
514 connected_peers_map) 471 connected_peers_map)
515{ 472{
516 return cmd->traits (cmd->cls, 473 return cmd->traits (cmd->cls,
@@ -520,6 +477,12 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
520} 477}
521 478
522 479
480/**
481 * Function to get the trait with the transport application handle.
482 *
483 * @param[out] ah The application handle.
484 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
485 */
523int 486int
524GNUNET_TRANSPORT_get_trait_application_handle (const struct 487GNUNET_TRANSPORT_get_trait_application_handle (const struct
525 GNUNET_TESTING_Command *cmd, 488 GNUNET_TESTING_Command *cmd,
@@ -534,6 +497,12 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct
534} 497}
535 498
536 499
500/**
501 * Function to get the trait with the peer id.
502 *
503 * @param[out] id The peer id.
504 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
505 */
537int 506int
538GNUNET_TRANSPORT_get_trait_peer_id (const struct 507GNUNET_TRANSPORT_get_trait_peer_id (const struct
539 GNUNET_TESTING_Command *cmd, 508 GNUNET_TESTING_Command *cmd,
@@ -550,6 +519,12 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
550 * Create command. 519 * Create command.
551 * 520 *
552 * @param label name for command. 521 * @param label name for command.
522 * @param system_label Label of the cmd to setup a test environment.
523 * @param m The number of the local node of the actual network namespace.
524 * @param n The number of the actual namespace.
525 * @param local_m Number of local nodes in each namespace.
526 * @param handlers Handler for messages received by this peer.
527 * @param cfgname Configuration file name for this peer.
553 * @return command. 528 * @return command.
554 */ 529 */
555struct GNUNET_TESTING_Command 530struct GNUNET_TESTING_Command
@@ -566,10 +541,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
566 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO); 541 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
567 unsigned int i; 542 unsigned int i;
568 543
569 LOG (GNUNET_ERROR_TYPE_ERROR,
570 "start peer 0.1 with cfg: %s\n",
571 cfgname);
572
573 sps = GNUNET_new (struct StartPeerState); 544 sps = GNUNET_new (struct StartPeerState);
574 sps->m = m; 545 sps->m = m;
575 sps->n = n; 546 sps->n = n;
@@ -579,9 +550,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
579 sps->connected_peers_map = connected_peers_map; 550 sps->connected_peers_map = connected_peers_map;
580 sps->cfgname = cfgname; 551 sps->cfgname = cfgname;
581 552
582 LOG (GNUNET_ERROR_TYPE_ERROR,
583 "start peer 0.2\n");
584
585 if (NULL != handlers) 553 if (NULL != handlers)
586 { 554 {
587 for (i = 0; NULL != handlers[i].cb; i++) 555 for (i = 0; NULL != handlers[i].cb; i++)
@@ -593,8 +561,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
593 i * sizeof(struct GNUNET_MQ_MessageHandler)); 561 i * sizeof(struct GNUNET_MQ_MessageHandler));
594 } 562 }
595 563
596 LOG (GNUNET_ERROR_TYPE_ERROR,
597 "start peer 0.3\n");
598 struct GNUNET_TESTING_Command cmd = { 564 struct GNUNET_TESTING_Command cmd = {
599 .cls = sps, 565 .cls = sps,
600 .label = label, 566 .label = label,
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index 2277520ec..7a0050a63 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -92,7 +92,7 @@ stop_peer_run (void *cls,
92 if (GNUNET_OK != 92 if (GNUNET_OK !=
93 GNUNET_TESTING_peer_stop (sps->peer)) 93 GNUNET_TESTING_peer_stop (sps->peer))
94 { 94 {
95 LOG (GNUNET_ERROR_TYPE_DEBUG, 95 LOG (GNUNET_ERROR_TYPE_ERROR,
96 "Testing lib failed to stop peer %u (`%s')\n", 96 "Testing lib failed to stop peer %u (`%s')\n",
97 sps->no, 97 sps->no,
98 GNUNET_i2s (&sps->id)); 98 GNUNET_i2s (&sps->id));