summaryrefslogtreecommitdiff
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
parent9d5a8c05f3a33c49fd97e5b8ef99d58b96704c6d (diff)
- fixed mem leaks, added code doc, formatting, removed trace logs
-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 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to start the netjail peers.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_testbed_ng_service.h"
-#include "testbed_api.h"
-#include "testbed_api_hosts.h"
-#include "testbed_helper.h"
-
-#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
-
-struct HelperMessage;
-
-struct HelperMessage
-{
-
- struct HelperMessage *next;
-
- struct HelperMessage *prev;
-
- /**
- * Size of the original message.
- */
- uint16_t bytes_msg;
-
- /* Followed by @e bytes_msg of msg.*/
-};
-
-
-
-struct NetJailState
-{
-
- unsigned int *rv;
-
- struct HelperMessage *hp_messages_head;
-
- struct HelperMessage *hp_messages_tail;
-
- /**
- * The process handle
- */
- struct GNUNET_HELPER_Handle **helper;
-
- unsigned int n_helper;
-
- char *binary_name;
-
- char *local_m;
-
- char *global_n;
-
- /**
- * The send handle for the helper
- */
- struct GNUNET_HELPER_SendHandle **shandle;
-
- unsigned int n_shandle;
-
- /**
- * The message corresponding to send handle
- */
- struct GNUNET_MessageHeader **msg;
-
- unsigned int n_msg;
-
- unsigned int number_of_testsystems_started;
-
- unsigned int number_of_peers_started;
-
- unsigned int number_of_local_test_finished;
-
- char *plugin_name;
-};
-
-struct TestingSystemCount
-{
- unsigned int count;
-
- struct NetJailState *ns;
-};
-
-/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-netjail_exec_cleanup (void *cls,
- const struct GNUNET_TESTING_Command *cmd)
-{
- struct NetJailState *ns = cls;
-
- GNUNET_free (ns->binary_name);
-}
-
-
-/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
-static int
-netjail_exec_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct NetJailState *ns = cls;
- struct GNUNET_HELPER_Handle **helper = ns->helper;
- struct HelperMessage *hp_messages_head = ns->hp_messages_head;
-
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "helper_handles",
- .ptr = (const void *) helper,
- },
- {
- .index = 1,
- .trait_name = "hp_msgs_head",
- .ptr = (const void *) hp_messages_head,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
- * Offer handles to testing cmd helper from trait
- *
- * @param cmd command to extract the message from.
- * @param pt pointer to message.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_helper_handles (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***helper)
-{
- return cmd->traits (cmd->cls,
- (const void **) helper,
- "helper_handles",
- (unsigned int) 0);
-}
-
-/**
- * Offer messages received via testing cmd helper from trait
- *
- * @param cmd command to extract the message from.
- * @param pt pointer to message.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_helper_messages (const struct
- GNUNET_TESTING_Command *cmd,
- struct HelperMessage ***
- hp_messages_head)
-{
- return cmd->traits (cmd->cls,
- (const void **) hp_messages_head,
- "hp_msgs_head",
- (unsigned int) 1);
-}
-
-
-/**
- * Continuation function from GNUNET_HELPER_send()
- *
- * @param cls closure
- * @param result GNUNET_OK on success,
- * GNUNET_NO if helper process died
- * GNUNET_SYSERR during GNUNET_HELPER_stop
- */
-static void
-clear_msg (void *cls, int result)
-{
- struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "clear_msg tbc->count: %d\n",
- tbc->count);
- GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
- ns->shandle[tbc->count - 1] = NULL;
- GNUNET_free (ns->msg[tbc->count - 1]);
- ns->msg[tbc->count - 1] = NULL;
-}
-
-
-/**
- * Functions with this signature are called whenever a
- * complete message is received by the tokenizer.
- *
- * Do not call GNUNET_SERVER_mst_destroy in callback
- *
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
- */
-static int
-helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
-{
- struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
- struct HelperMessage *hp_msg;
-
- if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "helper_mst tbc->count: %d\n",
- tbc->count);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message from helper.\n");
- ns->number_of_testsystems_started++;
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
- message->type))
- {
- ns->number_of_peers_started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "number_of_peers_started: %d\n",
- ns->number_of_peers_started);
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
- message->type))
- {
- ns->number_of_local_test_finished++;
- }
- else
- {
- hp_msg = GNUNET_new (struct HelperMessage);
- hp_msg->bytes_msg = message->size;
- memcpy (&hp_msg[1], message, message->size);
- GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
- hp_msg);
- }
-
- return GNUNET_OK;
-}
-
-
-static void
-exp_cb (void *cls)
-{
- struct NetJailState *ns = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
- *ns->rv = 1;
-}
-
-
-static struct GNUNET_CMDS_HelperInit *
-create_helper_init_msg_ (char *m_char,
- char *n_char,
- const char *plugin_name)
-{
- struct GNUNET_CMDS_HelperInit *msg;
- uint16_t plugin_name_len;
- uint16_t msg_size;
-
- GNUNET_assert (NULL != plugin_name);
- plugin_name_len = strlen (plugin_name);
- msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "msg_size: %d \n",
- msg_size);
- msg = GNUNET_malloc (msg_size);
- msg->header.size = htons (msg_size);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
- msg->plugin_name_size = htons (plugin_name_len);
- GNUNET_memcpy ((char *) &msg[1],
- plugin_name,
- plugin_name_len);
- return msg;
-}
-
-
-static void
-start_helper (struct NetJailState *ns, struct
- GNUNET_CONFIGURATION_Handle *config,
- char *m_char,
- char *n_char)
-{
- // struct GNUNET_CONFIGURATION_Handle *cfg;
- struct GNUNET_CMDS_HelperInit *msg;
- struct TestingSystemCount *tbc;
- char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
- m_char,
- n_char,
- GNUNET_OS_get_libexec_binary_path (
- HELPER_CMDS_BINARY),
- ns->global_n,
- ns->local_m,
- NULL};
- unsigned int m = atoi (m_char);
- unsigned int n = atoi (n_char);
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_EXEC_SCRIPT,
- GNUNET_YES,
- NULL);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "m: %d n: %d\n",
- m,
- n);
-
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- tbc->count = (n - 1) * atoi (ns->local_m) + m;
-
-
- if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No SUID for %s!\n",
- NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
- }
- else if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
- }
-
- GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
- GNUNET_YES,
- NETJAIL_EXEC_SCRIPT,
- script_argv,
- &helper_mst,
- &exp_cb,
- tbc));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "First using helper %d %d\n",
- tbc->count - 1,
- ns->n_helper);
- struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "First using helper %d %d %p\n",
- tbc->count - 1,
- ns->n_helper,
- helper);
-
- msg = create_helper_init_msg_ (m_char,
- n_char,
- ns->plugin_name);
- GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
-
- GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
- helper,
- &msg->header,
- GNUNET_NO,
- &clear_msg,
- tbc));
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Message %d send!\n",
- tbc->count);
-
- if (NULL == ns->shandle[tbc->count - 1])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Send handle is NULL!\n");
- GNUNET_free (msg);
- *ns->rv = 1;
- }
-}
-
-
-/**
-* Run the "hello world" CMD.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-netjail_exec_run (void *cls,
- const struct GNUNET_TESTING_Command *cmd,
- struct GNUNET_TESTING_Interpreter *is)
-{
- char str_m[12];
- char str_n[12];
- struct NetJailState *ns = cls;
- struct GNUNET_CONFIGURATION_Handle *config =
- GNUNET_CONFIGURATION_create ();
-
- for (int i = 1; i <= atoi (ns->global_n); i++) {
- for (int j = 1; j <= atoi (ns->local_m); j++)
- {
- sprintf (str_n, "%d", i);
- sprintf (str_m, "%d", j);
- start_helper (ns, config,
- str_m,
- str_n);
- }
- }
-}
-
-
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- unsigned int ret = GNUNET_NO;
- struct NetJailState *ns = cls;
- unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
- struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
- size_t msg_length;
- struct GNUNET_HELPER_Handle *helper;
- struct TestingSystemCount *tbc;
-
- if (ns->number_of_local_test_finished == total_number)
- {
- ret = GNUNET_YES;
- cont (cont_cls);
- }
-
- if (ns->number_of_testsystems_started == total_number)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All helpers started!\n");
- ns->number_of_testsystems_started = 0;
- }
-
- if (ns->number_of_peers_started == total_number)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started!\n");
-
- for (int i = 1; i <= atoi (ns->global_n); i++) {
- for (int j = 1; j <= atoi (ns->local_m); j++)
- {
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- // 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.
- tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Second using helper %d %d %d\n",
- tbc->count - 1 - total_number,
- i,
- j);
- helper = ns->helper[tbc->count - 1 - total_number];
- msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
-
- GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
-
- struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
- helper,
- &reply->header,
- GNUNET_NO,
- &clear_msg,
- tbc);
-
- GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started message %d send!\n",
- tbc->count);
- }
- }
- ns->number_of_peers_started = 0;
- }
- return ret;
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param binaryname to exec.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- char *local_m,
- char *global_n,
- char *plugin_name,
- unsigned int *rv)
-{
- struct NetJailState *ns;
-
- ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
- ns->plugin_name = plugin_name;
- ns->rv = rv;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_exec_run,
- .finish = &netjail_start_finish,
- .cleanup = &netjail_exec_cleanup,
- .traits = &netjail_exec_traits
- };
-
- return cmd;
-}
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 @@
/**
* Generic logging shortcut
- */
+testing_api_cmd_block_until_all_peers_started.c */
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
/**
@@ -74,27 +74,71 @@ struct Plugin
*/
struct GNUNET_TESTING_PluginFunctions *api;
+ /**
+ * IP address of the specific node the helper is running for.
+ *
+ */
char *node_ip;
+ /**
+ * Name of the test case plugin.
+ *
+ */
char *plugin_name;
+ /**
+ * The number of namespaces
+ *
+ */
char *global_n;
+ /**
+ * The number of local nodes per namespace.
+ *
+ */
char *local_m;
+ /**
+ * The number of the namespace this node is in.
+ *
+ */
char *n;
+ /**
+ * The number of the node in the namespace.
+ *
+ */
char *m;
};
+/**
+ * Struct with information about a specific node and the whole network namespace setup.
+ *
+ */
struct NodeIdentifier
{
+ /**
+ * The number of the namespace this node is in.
+ *
+ */
char *n;
+ /**
+ * The number of the node in the namespace.
+ *
+ */
char *m;
+ /**
+ * The number of namespaces
+ *
+ */
char *global_n;
+ /**
+ * The number of local nodes per namespace.
+ *
+ */
char *local_m;
};
@@ -162,11 +206,6 @@ static struct GNUNET_SCHEDULER_Task *read_task_id;
static struct GNUNET_SCHEDULER_Task *write_task_id;
/**
- * Task to kill the child
- */
-static struct GNUNET_SCHEDULER_Task *child_death_task_id;
-
-/**
* Are we done reading messages from stdin?
*/
static int done_reading;
@@ -187,8 +226,6 @@ shutdown_task (void *cls)
{
LOG_DEBUG ("Shutting down.\n");
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Shutting down tokenizer!\n");
if (NULL != read_task_id)
{
@@ -204,11 +241,6 @@ shutdown_task (void *cls)
GNUNET_free (wc->data);
GNUNET_free (wc);
}
- if (NULL != child_death_task_id)
- {
- GNUNET_SCHEDULER_cancel (child_death_task_id);
- child_death_task_id = NULL;
- }
if (NULL != stdin_fd)
(void) GNUNET_DISK_file_close (stdin_fd);
if (NULL != stdout_fd)
@@ -235,9 +267,6 @@ write_task (void *cls)
struct WriteContext *wc = cls;
ssize_t bytes_wrote;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Writing data!\n");
-
GNUNET_assert (NULL != wc);
write_task_id = NULL;
bytes_wrote = GNUNET_DISK_file_write (stdout_fd,
@@ -256,12 +285,8 @@ write_task (void *cls)
{
GNUNET_free (wc->data);
GNUNET_free (wc);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Written successfully!\n");
return;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Written data!\n");
write_task_id = GNUNET_SCHEDULER_add_write_file (GNUNET_TIME_UNIT_FOREVER_REL,
stdout_fd,
&write_task,
@@ -270,39 +295,14 @@ write_task (void *cls)
/**
- * Task triggered whenever we receive a SIGCHLD (child
- * process died).
+ * Callback to write a message to the master loop.
*
- * @param cls closure, NULL if we need to self-restart
*/
-/*static void
-child_death_task (void *cls)
-{
- const struct GNUNET_DISK_FileHandle *pr;
- char c[16];
-
- pr = GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ);
- child_death_task_id = NULL;
- // consume the signal
- GNUNET_break (0 < GNUNET_DISK_file_read (pr, &c, sizeof(c)));
- LOG_DEBUG ("Got SIGCHLD\n");
-
- LOG_DEBUG ("Child hasn't died. Resuming to monitor its status\n");
- child_death_task_id =
- GNUNET_SCHEDULER_add_read_file (GNUNET_TIME_UNIT_FOREVER_REL,
- pr,
- &child_death_task,
- NULL);
-}*/
-
-
static void
write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
{
struct WriteContext *wc;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "enter write_message!\n");
wc = GNUNET_new (struct WriteContext);
wc->length = msg_length;
wc->data = message;
@@ -311,38 +311,10 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
stdout_fd,
&write_task,
wc);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "leave write_message!\n");
}
/**
- * Function to run the test cases.
- *
- * @param cls plugin to use.
- *
- */
-/*static void
-run_plugin (void *cls)
-{
- struct Plugin *plugin = cls;
- char *router_ip;
- char *node_ip;
-
- router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) + 1);
- strcpy (router_ip, ROUTER_BASE_IP);
- strcat (router_ip, plugin->m);
-
- node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1);
- strcat (node_ip, NODE_BASE_IP);
- strcat (node_ip, plugin->n);
-
- plugin->api->start_testcase (&write_message, router_ip, node_ip);
-
-}*/
-
-
-/**
* Functions with this signature are called whenever a
* complete message is received by the tokenizer.
*
@@ -368,9 +340,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
char *router_ip;
char *node_ip;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "tokenizer \n");
-
msize = ntohs (message->size);
if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT == ntohs (message->type))
{
@@ -390,23 +359,6 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
binary = GNUNET_OS_get_libexec_binary_path ("gnunet-cmd");
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin_name: %s \n",
- plugin_name);
-
- // cmd_binary_process = GNUNET_OS_start_process (
- /*GNUNET_OS_INHERIT_STD_ERR verbose? ,
- NULL,
- NULL,
- NULL,
- binary,
- plugin_name,
- ni->global_n,
- ni->local_m,
- ni->n,
- ni->m,
- NULL);*/
-
plugin = GNUNET_new (struct Plugin);
plugin->api = GNUNET_PLUGIN_load (plugin_name,
NULL);
@@ -429,51 +381,15 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
plugin->n, plugin->local_m);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here!\n");
-
- /*if (NULL == cmd_binary_process)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Starting plugin failed!\n");
- return GNUNET_SYSERR;
- }*/
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 2!\n");
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "global_n: %s local_n: %s n: %s m: %s.\n",
- ni->global_n,
- ni->local_m,
- ni->n,
- ni->m);
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 3!\n");
-
GNUNET_free (binary);
- // done_reading = GNUNET_YES;
-
msg_length = sizeof(struct GNUNET_CMDS_HelperReply);
reply = GNUNET_new (struct GNUNET_CMDS_HelperReply);
reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY);
reply->header.size = htons ((uint16_t) msg_length);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 4!\n");
-
write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 5!\n");
-
- /*child_death_task_id = GNUNET_SCHEDULER_add_read_file (
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_DISK_pipe_handle (sigpipe, GNUNET_DISK_PIPE_END_READ),
- &child_death_task,
- NULL);*/
return GNUNET_OK;
}
else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED == ntohs (
@@ -514,8 +430,6 @@ read_task (void *cls)
if ((GNUNET_SYSERR == sread) || (0 == sread))
{
LOG_DEBUG ("STDIN closed\n");
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "tokenizer shutting down during reading!\n");
GNUNET_SCHEDULER_shutdown ();
return;
}
@@ -529,8 +443,6 @@ read_task (void *cls)
return;
}
LOG_DEBUG ("Read %u bytes\n", (unsigned int) sread);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Read %u bytes\n", (unsigned int) sread);
/* FIXME: could introduce a GNUNET_MST_read2 to read
directly from 'stdin_fd' and save a memcpy() here */
if (GNUNET_OK !=
@@ -624,13 +536,6 @@ main (int argc, char **argv)
ni->n = argv[3];
ni->m = argv[4];
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "global_n: %s local_n: %s n: %s m: %s.\n",
- ni->global_n,
- ni->local_m,
- ni->n,
- ni->m);
-
status = GNUNET_OK;
if (NULL ==
(sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
@@ -647,8 +552,7 @@ main (int argc, char **argv)
options,
&run,
ni);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "run finished\n");
+
GNUNET_SIGNAL_handler_uninstall (shc_chld);
shc_chld = NULL;
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 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+/**
+ * Struct with information for callbacks.
+ *
+ */
struct BlockState
{
+ /**
+ * Flag to indicate if all peers have started.
+ *
+ */
unsigned int *all_peers_started;
};
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
block_until_all_peers_started_traits (void *cls,
const void **ret,
@@ -48,6 +60,10 @@ block_until_all_peers_started_traits (void *cls,
}
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
block_until_all_peers_started_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
@@ -58,16 +74,24 @@ block_until_all_peers_started_cleanup (void *cls,
}
+/**
+ * This function does nothing but to start the cmd.
+ *
+ */
static void
block_until_all_peers_started_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_TESTING_Interpreter *is)
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"block_until_all_peers_started_run!\n");
}
+/**
+ * Function to check if BlockState#all_peers_started is GNUNET_YES. In that case interpreter_next will be called.
+ *
+ */
static int
block_until_all_peers_started_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -76,20 +100,10 @@ block_until_all_peers_started_finish (void *cls,
struct BlockState *bs = cls;
unsigned int *ret = bs->all_peers_started;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 10\n");
-
if (GNUNET_YES == *ret)
{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We do not need to block anymore!\n");
cont (cont_cls);
}
- else
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "You shall not pass!\n");
- }
return *ret;
}
@@ -99,6 +113,7 @@ block_until_all_peers_started_finish (void *cls,
* Create command.
*
* @param label name for command.
+ * @param all_peers_started Flag which will be set from outside.
* @return command.
*/
struct GNUNET_TESTING_Command
@@ -108,10 +123,6 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
{
struct BlockState *bs;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "we have all_peers_started: %u\n",
- *all_peers_started);
-
bs = GNUNET_new (struct BlockState);
bs->all_peers_started = all_peers_started;
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 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
struct LocalFinishedState
{
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
TESTING_CMD_HELPER_write_cb write_message;
+ /**
+ * The message send back to the master loop.
+ *
+ */
struct GNUNET_CMDS_LOCAL_FINISHED *reply;
};
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
local_test_finished_traits (void *cls,
const void **ret,
@@ -51,6 +68,10 @@ local_test_finished_traits (void *cls,
}
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
local_test_finished_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
@@ -62,6 +83,10 @@ local_test_finished_cleanup (void *cls,
}
+/**
+ * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED message to the master loop.
+ *
+ */
static void
local_test_finished_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -72,28 +97,25 @@ local_test_finished_run (void *cls,
struct GNUNET_CMDS_LOCAL_FINISHED *reply;
size_t msg_length;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 12!\n");
-
msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
reply->header.size = htons ((uint16_t) msg_length);
lfs->reply = reply;
lfs->write_message ((struct GNUNET_MessageHeader *) reply, msg_length);
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 13!\n");
}
+/**
+ * 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.
+ *
+ */
static int
local_test_finished_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
void *cont_cls)
{
- // This will stop the local loop without shutting down the scheduler, because we do not call the continuation, which is the interpreter_next method.
- LOG (GNUNET_ERROR_TYPE_ERROR,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Stopping local loop\n");
return GNUNET_YES;
}
@@ -103,6 +125,7 @@ local_test_finished_finish (void *cls,
* Create command.
*
* @param label name for command.
+ * @param write_message Callback to write messages to the master loop.
* @return command.
*/
struct GNUNET_TESTING_Command
@@ -112,9 +135,6 @@ GNUNET_TESTING_cmd_local_test_finished (const char *label,
{
struct LocalFinishedState *lfs;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 11!\n");
-
lfs = GNUNET_new (struct LocalFinishedState);
lfs->write_message = write_message;
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 @@
#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh"
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
struct NetJailState
{
+ // Child Wait handle
struct GNUNET_ChildWaitHandle *cwh;
+ // Number of local nodes in each namespace.
char *local_m;
+ // The number of namespaces.
char *global_n;
/**
@@ -42,16 +49,15 @@ struct NetJailState
*/
struct GNUNET_OS_Process *start_proc;
+ // Flag indication if the script finished.
unsigned int finished;
};
/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
netjail_start_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
@@ -81,14 +87,9 @@ netjail_start_cleanup (void *cls,
/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
netjail_start_traits (void *cls,
const void **ret,
@@ -98,6 +99,11 @@ netjail_start_traits (void *cls,
return GNUNET_OK;
}
+
+/**
+ * Callback which will be called if the setup script finished.
+ *
+ */
static void
child_completed_callback (void *cls,
enum GNUNET_OS_ProcessStatusType type,
@@ -122,7 +128,7 @@ child_completed_callback (void *cls,
/**
-* Run the "hello world" CMD.
+* The run method starts the script which setup the network namespaces.
*
* @param cls closure.
* @param cmd CMD being run.
@@ -171,6 +177,11 @@ netjail_start_run (void *cls,
GNUNET_break (NULL != ns->cwh);
}
+
+/**
+ * This function checks the flag NetJailState#finished, if this cmd finished.
+ *
+ */
static int
netjail_start_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -189,7 +200,8 @@ netjail_start_finish (void *cls,
* Create command.
*
* @param label name for command.
- * @param binaryname to start.
+ * @param local_m Number of local nodes in each namespace.
+ * @param global_n The number of namespaces.
* @return command.
*/
struct 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 @@
#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
-struct HelperMessage;
-
+/**
+ * Struct to store messages send/received by the helper into a DLL
+ *
+ */
struct HelperMessage
{
+ /**
+ * Kept in a DLL.
+ */
struct HelperMessage *next;
+ /**
+ * Kept in a DLL.
+ */
struct HelperMessage *prev;
/**
@@ -47,27 +55,51 @@ struct HelperMessage
};
-
+/**
+ * Struct to store information handed over to callbacks.
+ *
+ */
struct NetJailState
{
-
+ /**
+ * Pointer to the return value of the test.
+ *
+ */
unsigned int *rv;
+ /**
+ * Head of the DLL which stores messages received by the helper.
+ *
+ */
struct HelperMessage *hp_messages_head;
+ /**
+ * Tail of the DLL which stores messages received by the helper.
+ *
+ */
struct HelperMessage *hp_messages_tail;
/**
- * The process handle
+ * Array with handles of helper processes.
*/
struct GNUNET_HELPER_Handle **helper;
+ /**
+ * Size of the array NetJailState#helper.
+ *
+ */
unsigned int n_helper;
- char *binary_name;
-
+ /**
+ * Number of nodes in a network namespace. //TODO make this a unsigned int
+ *
+ */
char *local_m;
+ /**
+ * Number of network namespaces. //TODO make this a unsigned int
+ *
+ */
char *global_n;
/**
@@ -75,33 +107,91 @@ struct NetJailState
*/
struct GNUNET_HELPER_SendHandle **shandle;
+ /**
+ * Size of the array NetJailState#shandle.
+ *
+ */
unsigned int n_shandle;
/**
- * The message corresponding to send handle
+ * The messages send to the helper.
*/
struct GNUNET_MessageHeader **msg;
+ /**
+ * Size of the array NetJailState#msg.
+ *
+ */
unsigned int n_msg;
+ /**
+ * Number of test environments started.
+ *
+ */
unsigned int number_of_testsystems_started;
+ /**
+ * Number of peers started.
+ *
+ */
unsigned int number_of_peers_started;
+ /**
+ * Number of local tests finished.
+ *
+ */
unsigned int number_of_local_test_finished;
+ /**
+ * Name of the test case plugin the helper will load.
+ *
+ */
char *plugin_name;
+
+ /**
+ * HEAD of the DLL containing TestingSystemCount.
+ *
+ */
+ struct TestingSystemCount *tbcs_head;
+
+ /**
+ * TAIL of the DLL containing TestingSystemCount.
+ *
+ */
+ struct TestingSystemCount *tbcs_tail;
};
+/**
+ * Struct containing the number of the test environment and the NetJailState which
+ * will be handed to callbacks specific to a test environment.
+ */
struct TestingSystemCount
{
+ /**
+ * Kept in a DLL.
+ */
+ struct TestingSystemCount *next;
+
+ /**
+ * Kept in a DLL.
+ */
+ struct TestingSystemCount *prev;
+
+ /**
+ * The number of the test environment.
+ *
+ */
unsigned int count;
+ /**
+ * Struct to store information handed over to callbacks.
+ *
+ */
struct NetJailState *ns;
};
/**
-*
+* Code to clean up ressource this cmd used.
*
* @param cls closure
* @param cmd current CMD being cleaned up.
@@ -111,20 +201,31 @@ netjail_exec_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
{
struct NetJailState *ns = cls;
+ struct HelperMessage *message_pos;
+ struct TestingSystemCount *tbc_pos;
- GNUNET_free (ns->binary_name);
+ while (NULL != (message_pos = ns->hp_messages_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
+ ns->hp_messages_tail,
+ message_pos);
+ GNUNET_free (message_pos);
+ }
+ while (NULL != (tbc_pos = ns->tbcs_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
+ ns->tbcs_tail,
+ tbc_pos);
+ GNUNET_free (tbc_pos);
+ }
+ GNUNET_free (ns);
}
/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
+ * This function prepares an array with traits.
+ *
+ */
static int
netjail_exec_traits (void *cls,
const void **ret,
@@ -209,9 +310,6 @@ clear_msg (void *cls, int result)
struct TestingSystemCount *tbc = cls;
struct NetJailState *ns = tbc->ns;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "clear_msg tbc->count: %d\n",
- tbc->count);
GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
ns->shandle[tbc->count - 1] = NULL;
GNUNET_free (ns->msg[tbc->count - 1]);
@@ -240,20 +338,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "helper_mst tbc->count: %d\n",
- tbc->count);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message from helper.\n");
ns->number_of_testsystems_started++;
}
else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
message->type))
{
ns->number_of_peers_started++;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "number_of_peers_started: %d\n",
- ns->number_of_peers_started);
}
else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
message->type))
@@ -272,7 +362,10 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
return GNUNET_OK;
}
-
+/**
+ * Callback called if there was an exception during execution of the helper.
+ *
+ */
static void
exp_cb (void *cls)
{
@@ -281,7 +374,14 @@ exp_cb (void *cls)
*ns->rv = 1;
}
-
+/**
+ * Function to initialize a init message for the helper.
+ *
+ * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
+ * @param n_char The actual namespace. //TODO Change this to unsigned int
+ * @param plugin_name Name of the test case plugin the helper will load.
+ *
+ */
static struct GNUNET_CMDS_HelperInit *
create_helper_init_msg_ (char *m_char,
char *n_char,
@@ -294,9 +394,6 @@ create_helper_init_msg_ (char *m_char,
GNUNET_assert (NULL != plugin_name);
plugin_name_len = strlen (plugin_name);
msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "msg_size: %d \n",
- msg_size);
msg = GNUNET_malloc (msg_size);
msg->header.size = htons (msg_size);
msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
@@ -308,13 +405,17 @@ create_helper_init_msg_ (char *m_char,
}
+/**
+ * Function which start a single helper process.
+ *
+ */
static void
start_helper (struct NetJailState *ns, struct
GNUNET_CONFIGURATION_Handle *config,
char *m_char,
char *n_char)
{
- // struct GNUNET_CONFIGURATION_Handle *cfg;
+ struct GNUNET_HELPER_Handle *helper;
struct GNUNET_CMDS_HelperInit *msg;
struct TestingSystemCount *tbc;
char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
@@ -332,15 +433,13 @@ start_helper (struct NetJailState *ns, struct
GNUNET_YES,
NULL);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "m: %d n: %d\n",
- m,
- n);
-
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
tbc->count = (n - 1) * atoi (ns->local_m) + m;
+ GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
+ tbc);
+
if (GNUNET_NO == helper_check)
{
@@ -365,17 +464,7 @@ start_helper (struct NetJailState *ns, struct
&exp_cb,
tbc));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "First using helper %d %d\n",
- tbc->count - 1,
- ns->n_helper);
- struct GNUNET_HELPER_Handle *helper = ns->helper[tbc->count - 1];
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "First using helper %d %d %p\n",
- tbc->count - 1,
- ns->n_helper,
- helper);
+ helper = ns->helper[tbc->count - 1];
msg = create_helper_init_msg_ (m_char,
n_char,
@@ -389,10 +478,6 @@ start_helper (struct NetJailState *ns, struct
&clear_msg,
tbc));
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Message %d send!\n",
- tbc->count);
-
if (NULL == ns->shandle[tbc->count - 1])
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -404,7 +489,7 @@ start_helper (struct NetJailState *ns, struct
/**
-* Run the "hello world" CMD.
+* This function starts a helper process for each node.
*
* @param cls closure.
* @param cmd CMD being run.
@@ -434,6 +519,15 @@ netjail_exec_run (void *cls,
}
+/**
+ * This function checks on three different information.
+ *
+ * 1. Did all helpers start. This is only logged.
+ * 2. Did all peer start.
+ * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
+ * 3. Did all peers finished the test case. In this case interpreter_next will be called.
+ *
+ */
static int
netjail_start_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -455,16 +549,11 @@ netjail_start_finish (void *cls,
if (ns->number_of_testsystems_started == total_number)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All helpers started!\n");
ns->number_of_testsystems_started = 0;
}
if (ns->number_of_peers_started == total_number)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started!\n");
-
for (int i = 1; i <= atoi (ns->global_n); i++) {
for (int j = 1; j <= atoi (ns->local_m); j++)
{
@@ -472,11 +561,7 @@ netjail_start_finish (void *cls,
tbc->ns = ns;
// 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.
tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Second using helper %d %d %d\n",
- tbc->count - 1 - total_number,
- i,
- j);
+
helper = ns->helper[tbc->count - 1 - total_number];
msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
@@ -494,10 +579,6 @@ netjail_start_finish (void *cls,
tbc);
GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "All peers started message %d send!\n",
- tbc->count);
}
}
ns->number_of_peers_started = 0;
@@ -509,8 +590,11 @@ netjail_start_finish (void *cls,
/**
* Create command.
*
- * @param label name for command.
- * @param binaryname to exec.
+ * @param label Name for the command.
+ * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
+ * @param global_n Number of network namespaces. //TODO make this a unsigned int
+ * @param plugin_name Name of the test case plugin the helper will load.
+ * @param rv Pointer to the return value of the test.
* @return command.
*/
struct 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 @@
#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
+// Child Wait handle
struct GNUNET_ChildWaitHandle *cwh;
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
struct NetJailState
{
+ // Number of local nodes in each namespace.
char *local_m;
+ // The number of namespaces.
char *global_n;
/**
@@ -43,16 +50,15 @@ struct NetJailState
*/
struct GNUNET_OS_Process *stop_proc;
+ // Flag indication if the script finished.
unsigned int finished;
};
/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
netjail_stop_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
@@ -78,14 +84,9 @@ netjail_stop_cleanup (void *cls,
/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
netjail_stop_traits (void *cls,
const void **ret,
@@ -96,6 +97,10 @@ netjail_stop_traits (void *cls,
}
+/**
+ * Callback which will be called if the setup script finished.
+ *
+ */
static void
child_completed_callback (void *cls,
enum GNUNET_OS_ProcessStatusType type,
@@ -118,7 +123,7 @@ child_completed_callback (void *cls,
/**
-* Run the "hello world" CMD.
+* The run method starts the script which deletes the network namespaces.
*
* @param cls closure.
* @param cmd CMD being run.
@@ -169,6 +174,10 @@ netjail_stop_run (void *cls,
}
+/**
+ * This function checks the flag NetJailState#finished, if this cmd finished.
+ *
+ */
static int
netjail_stop_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -188,7 +197,8 @@ netjail_stop_finish (void *cls,
* Create command.
*
* @param label name for command.
- * @param binaryname to stop.
+ * @param local_m Number of local nodes in each namespace.
+ * @param global_n The number of namespaces.
* @return command.
*/
struct 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 @@
#include "testing_cmds.h"
+/**
+ * Struct to store information handed over to callbacks.
+ *
+ */
struct StopHelperState
{
@@ -45,7 +49,7 @@ struct StopHelperState
/**
-*
+* Code to clean up ressource this cmd used.
*
* @param cls closure
* @param cmd current CMD being cleaned up.
@@ -59,14 +63,9 @@ stop_testing_system_cleanup (void *cls,
/**
-*
-*
-* @param cls closure.
-* @param[out] ret result
-* @param trait name of the trait.
-* @param index index number of the object to offer.
-* @return #GNUNET_OK on success.
-*/
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
stop_testing_system_traits (void *cls,
const void **ret,
@@ -78,7 +77,7 @@ stop_testing_system_traits (void *cls,
/**
-* Run the "hello world" CMD.
+* This function stops the helper process for each node.
*
* @param cls closure.
* @param cmd CMD being run.
@@ -110,9 +109,11 @@ stop_testing_system_run (void *cls,
/**
* Create command.
- *
+ * @param helper_start_label label of the cmd to start the test system.
* @param label name for command.
- * @param binaryname to exec.
+ * @param .
+ * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
+ * @param global_n Number of network namespaces. //TODO make this a unsigned int
* @return command.
*/
struct 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 @@
#include "testing_cmds.h"
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
struct SendPeerReadyState
{
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
TESTING_CMD_HELPER_write_cb write_message;
+ /**
+ * The message send back to the master loop.
+ *
+ */
struct GNUNET_CMDS_PEER_STARTED *reply;
};
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
send_peer_ready_traits (void *cls,
const void **ret,
@@ -47,6 +63,10 @@ send_peer_ready_traits (void *cls,
}
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
send_peer_ready_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
@@ -58,6 +78,10 @@ send_peer_ready_cleanup (void *cls,
}
+/**
+ * This function sends a GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED message to the master loop.
+ *
+ */
static void
send_peer_ready_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -80,6 +104,7 @@ send_peer_ready_run (void *cls,
* Create command.
*
* @param label name for command.
+ * @param write_message Callback to write messages to the master loop.
* @return command.
*/
struct 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 @@
#include "gnunet_testing_ng_lib.h"
#include "gnunet_testing_lib.h"
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
struct TestSystemState
{
struct GNUNET_TESTING_System *test_system;
@@ -36,6 +40,10 @@ struct TestSystemState
};
+/**
+ * The run method of this cmd will setup a test environment for a node.
+ *
+ */
static void
system_create_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -54,6 +62,11 @@ system_create_run (void *cls,
"system created\n");
}
+
+/**
+ * This function prepares an array with traits.
+ *
+ */
static int
system_create_traits (void *cls,
const void **ret,
@@ -79,6 +92,12 @@ system_create_traits (void *cls,
}
+/**
+ * Function to get the trait with struct GNUNET_TESTING_System
+ *
+ * @param[out] test_system The struct GNUNET_TESTING_System.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ */
int
GNUNET_TESTING_get_trait_test_system (const struct
GNUNET_TESTING_Command *cmd,
@@ -91,13 +110,16 @@ GNUNET_TESTING_get_trait_test_system (const struct
}
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
system_create_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
{
struct TestSystemState *tss = cls;
- GNUNET_free (tss->test_system);
GNUNET_free (tss);
}
@@ -106,6 +128,7 @@ system_create_cleanup (void *cls,
* Create command.
*
* @param label name for command.
+ * @param label name for the test environment directory.
* @return command.
*/
struct 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,
const struct GNUNET_TESTING_Command *system_cmd;
struct GNUNET_TESTING_System *tl_system;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "system destroy\n");
-
system_cmd = GNUNET_TESTING_interpreter_lookup_command (tss->create_label);
GNUNET_TESTING_get_trait_test_system (system_cmd,
&tl_system);
GNUNET_TESTING_system_destroy (tl_system, GNUNET_YES);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "system destroyed\n");
}
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 @@
struct GNUNET_TESTING_Interpreter *is;
+
/**
* Closure used to sync an asynchronous with an synchronous command.
*/
@@ -57,6 +58,7 @@ struct SyncTaskClosure
struct GNUNET_TESTING_Interpreter *is;
};
+
/**
* Closure used to run the finish task.
*/
@@ -74,6 +76,7 @@ struct FinishTaskClosure
struct GNUNET_TESTING_Interpreter *is;
};
+
/**
* Lookup command by label.
*
@@ -185,6 +188,10 @@ interpreter_next (void *cls)
}
+/**
+ * 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.
+ *
+ */
static void
run_finish_task_next (void *cls)
{
@@ -212,6 +219,12 @@ run_finish_task_next (void *cls)
}
+/**
+ * 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.
+ *
+ * //TODO run_finish_task_next and this function can be merged.
+ *
+ */
static void
run_finish_task_sync (void *cls)
{
@@ -248,13 +261,17 @@ run_finish_task_sync (void *cls)
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Sync task finished with an error.\n");
GNUNET_TESTING_interpreter_fail ();
}
}
+/**
+ * run method of the command created by the interpreter to wait for another command to finish.
+ *
+ */
static void
start_finish_on_ref (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -277,6 +294,17 @@ start_finish_on_ref (void *cls,
}
+/**
+ * Create (synchronous) command that waits for another command to finish.
+ * If @a cmd_ref did not finish after @a timeout, this command will fail
+ * the test case.
+ *
+ * @param finish_label label for this command
+ * @param cmd_ref reference to a previous command which we should
+ * wait for (call `finish()` on)
+ * @param timeout how long to wait at most for @a cmd_ref to finish
+ * @return a finish-command.
+ */
const struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_finish (const char *finish_label,
const char *cmd_ref,
@@ -340,7 +368,7 @@ GNUNET_TESTING_interpreter_fail ()
while (GNUNET_TESTING_cmd_is_batch (cmd))
{
cmd = GNUNET_TESTING_cmd_batch_get_current (cmd);
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Batch is at command `%s'\n",
cmd->label);
}
@@ -354,7 +382,7 @@ GNUNET_TESTING_interpreter_fail ()
if (NULL == cmd->label)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Failed at command `%s'\n",
cmd->label);
@@ -415,7 +443,7 @@ interpreter_run (void *cls)
if (NULL == cmd->label)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Running command END %p\n",
is);
is->result = GNUNET_OK;
@@ -424,7 +452,7 @@ interpreter_run (void *cls)
}
else if (NULL != cmd)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Running command `%s' %p\n",
cmd->label,
is);
@@ -478,8 +506,14 @@ do_shutdown (void *cls)
for (unsigned int j = 0;
NULL != (cmd = &is->commands[j])->label;
j++) {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cleaning up cmd %s\n",
+ cmd->label);
cmd->cleanup (cmd->cls,
cmd);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cleaned up cmd %s\n",
+ cmd->label);
}
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)
struct GNUNET_HashCode h_sock;
int sockfd;
- sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
- GNUNET_CRYPTO_hash (&sockfd,
- sizeof(int),
- &h_sock);
+ if (NULL != queue->listen_sock)
+ {
+ sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
+ GNUNET_CRYPTO_hash (&sockfd,
+ sizeof(int),
+ &h_sock);
- lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
+ lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Disconnecting queue for peer `%s'\n",
@@ -1900,9 +1903,9 @@ queue_read (void *cls)
BUF_SIZE - queue->cread_off);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %lu bytes from TCP queue\n", rcvd);
- GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
"transport",
- "Received %lu bytes from TCP queue\n", rcvd);
+ "Received %lu bytes from TCP queue\n", rcvd);
if (-1 == rcvd)
{
if ((EAGAIN != errno) && (EINTR != errno))
@@ -2678,9 +2681,9 @@ proto_read_kx (void *cls)
sizeof(pq->ibuf) - pq->ibuf_off);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %lu bytes for KX\n", rcvd);
- GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
"transport",
- "Received %lu bytes for KX\n", rcvd);
+ "Received %lu bytes for KX\n", rcvd);
if (-1 == rcvd)
{
if ((EAGAIN != errno) && (EINTR != errno))
@@ -2830,10 +2833,10 @@ queue_read_kx (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received %lu bytes for KX\n",
rcvd);
- GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
+ GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
"transport",
- "Received %lu bytes for KX\n",
- rcvd);
+ "Received %lu bytes for KX\n",
+ rcvd);
if (-1 == rcvd)
{
if ((EAGAIN != errno) && (EINTR != errno))
@@ -3082,9 +3085,9 @@ do_shutdown (void *cls)
GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL);
GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
GNUNET_CONTAINER_multipeermap_destroy (queue_map);
- GNUNET_TRANSPORT_communicator_address_remove_all (ch);
if (NULL != ch)
{
+ GNUNET_TRANSPORT_communicator_address_remove_all (ch);
GNUNET_TRANSPORT_communicator_disconnect (ch);
ch = NULL;
}
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 @@
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+/**
+ * Return value of the test.
+ *
+ */
static unsigned int rv = 0;
@@ -42,19 +46,19 @@ static void
run (void *cls)
{
struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_netjail_start ("netjail-start-1",
+ GNUNET_TESTING_cmd_netjail_start ("netjail-start",
"2",
"1"),
- GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1",
+ GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed ",
"2",
"1",
"libgnunet_test_transport_plugin_cmd_simple_send",
&rv),
GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
- "netjail-start-testbed-1",
+ "netjail-start-testbed ",
"2",
"1"),
- GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1",
+ GNUNET_TESTING_cmd_netjail_stop ("netjail-stop ",
"2",
"1"),
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,
m,
n);
- /*testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
- + 1);
-
- strcpy (testdir, BASE_DIR);
- strcat (testdir, m);
- strcat (testdir, n);*/
-
struct GNUNET_MQ_MessageHandler handlers[] = {
GNUNET_MQ_hd_var_size (test,
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,
const char *cfgname);
struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
+ const char *start_label);
+
+struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
- const char *peer1_label,
- const char *peer2_label);
+ const char *start_peer_label);
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_send_simple (const char *label,
char *m,
char *n,
uint32_t num,
- const char *peer1_label,
- const char *peer2_label);
+ const char *start_peer_label);
int
GNUNET_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 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+/**
+ * Struct to store information needed in callbacks.
+ *
+ */
struct ConnectPeersState
{
- const char *peer1_label;
-
- const char *peer2_label;
-
+ /**
+ * Label of the cmd to start a peer.
+ *
+ */
+ const char *start_peer_label;
+
+ /**
+ * The peer identity of this peer.
+ *
+ */
struct GNUNET_PeerIdentity *id;
};
+/**
+ * The run method of this cmd will connect to peers.
+ *
+ */
static void
connect_peers_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -53,47 +67,38 @@ connect_peers_run (void *cls,
{
struct ConnectPeersState *cps = cls;
const struct GNUNET_TESTING_Command *peer1_cmd;
- //const struct GNUNET_TESTING_Command *peer2_cmd;
+ // const struct GNUNET_TESTING_Command *peer2_cmd;
struct GNUNET_TRANSPORT_ApplicationHandle *ah;
struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
char *addr;
- //struct GNUNET_TIME_Absolute t;
+ // struct GNUNET_TIME_Absolute t;
char *hello;
- //size_t *hello_size;
+ // size_t *hello_size;
enum GNUNET_NetworkType nt = 0;
char *peer_id;
struct GNUNET_PeerIdentity *id;
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
&ah);
GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
&hello);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "hello: %s\n",
- hello);
-
GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
- &id);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "pid %s\n",
- GNUNET_i2s_full(id));
+ &id);
- if(strstr(hello, "60002") != NULL)
- {
+ if (strstr (hello, "60002") != NULL)
+ {
addr = "tcp-192.168.15.2:60003";
peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
- }
+ }
else
- {
+ {
addr = "tcp-192.168.15.1:60002";
peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
- }
+ }
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "get pub key\n");
GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
strlen (peer_id),
&peer->public_key);
@@ -116,10 +121,9 @@ connect_peers_run (void *cls,
&nt,
&t);*/
- //----------------------------------------------
+ // ----------------------------------------------
+
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "application validate\n");
GNUNET_TRANSPORT_application_validate (ah,
peer,
nt,
@@ -127,6 +131,10 @@ connect_peers_run (void *cls,
}
+/**
+ * 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.
+ *
+ */
static int
connect_peers_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -140,36 +148,34 @@ connect_peers_finish (void *cls,
struct GNUNET_HashCode hc;
int node_number;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "Connect finished?\n");
-
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label);
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
- &connected_peers_map);
+ &connected_peers_map);
node_number = 1;
- GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
-
+ GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
+
// TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
memcpy (key,
&hc,
sizeof (*key));
ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
- key);
+ key);
if (GNUNET_YES == ret)
{
cont (cont_cls);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "connect peer finish\n");
}
+ GNUNET_free (key);
return ret;
- /*cont (cont_cls);
- return GNUNET_OK;*/
}
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
connect_peers_traits (void *cls,
const void **ret,
@@ -180,12 +186,17 @@ connect_peers_traits (void *cls,
}
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
connect_peers_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
{
struct ConnectPeersState *cps = cls;
+ GNUNET_free (cps->id);
GNUNET_free (cps);
}
@@ -194,18 +205,17 @@ connect_peers_cleanup (void *cls,
* Create command.
*
* @param label name for command.
+ * @param start_peer_label Label of the cmd to start a peer.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
- const char *peer1_label,
- const char *peer2_label)
+ const char *start_peer_label)
{
struct ConnectPeersState *cps;
cps = GNUNET_new (struct ConnectPeersState);
- cps->peer1_label = peer1_label;
- cps->peer2_label = peer2_label;
+ cps->start_peer_label = start_peer_label;
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 @@
#include "transport-testing2.h"
#include "transport-testing-cmds.h"
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
struct SendSimpleState
{
+ /**
+ * The number of the local node of the actual network namespace.
+ *
+ */
char *m;
+ /**
+ * The number of the actual namespace.
+ *
+ */
char *n;
+ /**
+ * Number globally identifying the node.
+ *
+ */
uint32_t num;
- const char *peer1_label;
-
- const char *peer2_label;
+ /**
+ * Label of the cmd to start a peer.
+ *
+ */
+ const char *start_peer_label;
};
+
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
static int
send_simple_traits (void *cls,
const void **ret,
@@ -52,6 +75,10 @@ send_simple_traits (void *cls,
}
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
send_simple_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
@@ -62,6 +89,10 @@ send_simple_cleanup (void *cls,
}
+/**
+ * The run method of this cmd will send a simple message to the connected peer.
+ *
+ */
static void
send_simple_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -72,14 +103,12 @@ send_simple_run (void *cls,
struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
struct GNUNET_MQ_Handle *mq;
struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
- //struct GNUNET_PeerIdentity *id;
const struct GNUNET_TESTING_Command *peer1_cmd;
- //const struct GNUNET_TESTING_Command *peer2_cmd;
struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
struct GNUNET_HashCode hc;
int node_number;
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label);
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
&connected_peers_map);
@@ -88,9 +117,9 @@ send_simple_run (void *cls,
memcpy (key,
&hc,
sizeof (*key));
-
+
mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
- key);
+ key);
env = GNUNET_MQ_msg_extra (test,
2600 - sizeof(*test),
@@ -99,12 +128,9 @@ send_simple_run (void *cls,
memset (&test[1],
sss->num,
2600 - sizeof(*test));
- /*GNUNET_MQ_notify_sent (env,
- cont,
- cont_cls);*/
GNUNET_MQ_send (mq,
env);
-
+ GNUNET_free (key);
}
@@ -113,15 +139,18 @@ send_simple_run (void *cls,
* Create command.
*
* @param label name for command.
+ * @param m The number of the local node of the actual network namespace.
+ * @param n The number of the actual namespace.
+ * @param num Number globally identifying the node.
+ * @param start_peer_label Label of the cmd to start a peer.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_send_simple (const char *label,
- char *m,
- char *n,
- uint32_t num,
- const char *peer1_label,
- const char *peer2_label)
+ char *m,
+ char *n,
+ uint32_t num,
+ const char *start_peer_label)
{
struct SendSimpleState *sss;
@@ -129,7 +158,7 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
sss->m = m;
sss->n = n;
sss->num = num;
- sss->peer1_label = peer1_label;
+ sss->start_peer_label = start_peer_label;
struct GNUNET_TESTING_Command cmd = {
.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 @@
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"
+#include "transport-testing-ng.h"
/**
* Generic logging shortcut
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-struct StartPeerState
-{
- /**
- * Receive callback
- */
- struct GNUNET_MQ_MessageHandler *handlers;
-
- const char *cfgname;
-
- /**
- * Peer's configuration
- */
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- struct GNUNET_TESTING_Peer *peer;
-
- /**
- * Peer identity
- */
- struct GNUNET_PeerIdentity id;
-
- /**
- * Peer's transport service handle
- */
- struct GNUNET_TRANSPORT_CoreHandle *th;
-
- /**
- * Application handle
- */
- struct GNUNET_TRANSPORT_ApplicationHandle *ah;
-
- /**
- * Peer's PEERSTORE Handle
- */
- struct GNUNET_PEERSTORE_Handle *ph;
-
- /**
- * Hello get task
- */
- struct GNUNET_SCHEDULER_Task *rh_task;
-
- /**
- * Peer's transport get hello handle to retrieve peer's HELLO message
- */
- struct GNUNET_PEERSTORE_IterateContext *pic;
-
- /**
- * Hello
- */
- char *hello;
-
- /**
- * Hello size
- */
- size_t hello_size;
-
- char *m;
-
- char *n;
-
- char *local_m;
-
- unsigned int finished;
-
- const char *system_label;
-
- /**
- * An unique number to identify the peer
- */
- unsigned int no;
-
- struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
-
- struct GNUNET_TESTING_System *tl_system;
-
-};
-
static void
retrieve_hello (void *cls);
+
+/**
+ * Callback delivering the hello of this peer from peerstore.
+ *
+ */
static void
hello_iter_cb (void *cb_cls,
const struct GNUNET_PEERSTORE_Record *record,
@@ -140,6 +69,11 @@ hello_iter_cb (void *cb_cls,
}
+
+/**
+ * Function to start the retrival task to retrieve the hello of this peer from the peerstore.
+ *
+ */
static void
retrieve_hello (void *cls)
{
@@ -154,6 +88,11 @@ retrieve_hello (void *cls)
}
+
+/**
+ * This function checks StartPeerState#finished, which is set when the hello was retrieved.
+ *
+ */
static int
start_peer_finish (void *cls,
GNUNET_SCHEDULER_TaskCallback cont,
@@ -170,6 +109,10 @@ start_peer_finish (void *cls,
}
+/**
+ * Disconnect callback for the connection to the core service.
+ *
+ */
static void
notify_disconnect (void *cls,
const struct GNUNET_PeerIdentity *peer,
@@ -186,6 +129,10 @@ notify_disconnect (void *cls,
}
+/**
+ * Connect callback for the connection to the core service.
+ *
+ */
static void *
notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
@@ -206,23 +153,27 @@ notify_connect (void *cls,
GNUNET_i2s (&sps->id));
// TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
- node_number = 1;
- GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
-
+ node_number = 1;
+ GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
+
memcpy (key,
&hc,
sizeof (*key));
GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
- key,
- mq,
- GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ key,
+ mq,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+ GNUNET_free (key);
// TODO what does the handler function need?
return ret;
}
-
+/**
+ * The run method of this cmd will start all services of a peer to test the transport service.
+ *
+ */
static void
start_peer_run (void *cls,
const struct GNUNET_TESTING_Command *cmd,
@@ -234,9 +185,6 @@ start_peer_run (void *cls,
const struct GNUNET_TESTING_Command *system_cmd;
struct GNUNET_TESTING_System *tl_system;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 1\n");
-
if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -269,8 +217,6 @@ start_peer_run (void *cls,
return;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 2\n");
sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
sps->cfg,
sps->no,
@@ -287,8 +233,6 @@ start_peer_run (void *cls,
return;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 3\n");
if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
{
LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -298,17 +242,14 @@ start_peer_run (void *cls,
GNUNET_TESTING_interpreter_fail ();
return;
}
-LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 4\n");
+
memset (&dummy,
'\0',
sizeof(dummy));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 4.1\n");
+
GNUNET_TESTING_peer_get_identity (sps->peer,
&sps->id);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 4.2\n");
+
if (0 == memcmp (&dummy,
&sps->id,
sizeof(struct GNUNET_PeerIdentity)))
@@ -324,8 +265,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
"Peer %u configured with identity `%s'\n",
sps->no,
GNUNET_i2s_full (&sps->id));
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 4.3\n");
+
sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
NULL,
sps->handlers,
@@ -342,8 +282,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
GNUNET_TESTING_interpreter_fail ();
return;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 5\n");
+
sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
if (NULL == sps->th)
{
@@ -355,8 +294,7 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
GNUNET_TESTING_interpreter_fail ();
return;
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 6\n");
+
sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
if (NULL == sps->ah)
{
@@ -371,28 +309,16 @@ LOG (GNUNET_ERROR_TYPE_ERROR,
sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
}
-
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
static void
start_peer_cleanup (void *cls,
const struct GNUNET_TESTING_Command *cmd)
{
struct StartPeerState *sps = cls;
- if (NULL != sps->rh_task)
- GNUNET_SCHEDULER_cancel (sps->rh_task);
- sps->rh_task = NULL;
- if (NULL != sps->ah)
- {
- GNUNET_TRANSPORT_application_done (sps->ah);
- sps->ah = NULL;
- }
- if (NULL != sps->ph)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Disconnecting from PEERSTORE service\n");
- GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
- sps->ph = NULL;
- }
if (NULL != sps->handlers)
{
GNUNET_free (sps->handlers);
@@ -403,34 +329,16 @@ start_peer_cleanup (void *cls,
GNUNET_CONFIGURATION_destroy (sps->cfg);
sps->cfg = NULL;
}
- if (NULL != sps->peer)
- {
- if (GNUNET_OK !=
- GNUNET_TESTING_peer_stop (sps->peer))
- {
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Testing lib failed to stop peer %u (`%s')\n",
- sps->no,
- GNUNET_i2s (&sps->id));
- }
- GNUNET_TESTING_peer_destroy (sps->peer);
- sps->peer = NULL;
- }
- if (NULL != sps->th)
- {
- GNUNET_TRANSPORT_core_disconnect (sps->th);
- sps->th = NULL;
- }
- if (NULL != sps->tl_system)
- {
- GNUNET_free (sps->tl_system);
- }
GNUNET_free (sps->hello);
GNUNET_free (sps->connected_peers_map);
GNUNET_free (sps);
}
+/**
+ * This function prepares an array with traits.
+ *
+ */
static int
start_peer_traits (void *cls,
const void **ret,
@@ -472,6 +380,11 @@ start_peer_traits (void *cls,
.trait_name = "hello_size",
.ptr = (const void *) hello_size,
},
+ {
+ .index = 5,
+ .trait_name = "state",
+ .ptr = (const void *) sps,
+ },
GNUNET_TESTING_trait_end ()
};
@@ -481,6 +394,34 @@ start_peer_traits (void *cls,
index);
}
+
+/**
+ * Function to get the trait with the struct StartPeerState.
+ *
+ * @param[out] sps struct StartPeerState.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
+int
+GNUNET_TRANSPORT_get_trait_state (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ struct StartPeerState **sps)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) sps,
+ "state",
+ (unsigned int) 5);
+}
+
+
+/**
+ * Function to get the trait with the size of the hello.
+ *
+ * @param[out] hello_size size of hello.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
int
GNUNET_TRANSPORT_get_trait_hello_size (const struct
GNUNET_TESTING_Command
@@ -493,6 +434,13 @@ GNUNET_TRANSPORT_get_trait_hello_size (const struct
(unsigned int) 4);
}
+/**
+ * Function to get the trait with the hello.
+ *
+ * @param[out] hello The hello for the peer.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
int
GNUNET_TRANSPORT_get_trait_hello (const struct
GNUNET_TESTING_Command
@@ -505,12 +453,21 @@ GNUNET_TRANSPORT_get_trait_hello (const struct
(unsigned int) 3);
}
+
+/**
+ * Function to get the trait with the map of connected peers.
+ *
+ * @param[out] connected_peers_map The map with connected peers.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
int
GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
GNUNET_TESTING_Command
*cmd,
struct
- GNUNET_CONTAINER_MultiShortmap **
+ GNUNET_CONTAINER_MultiShortmap *
+ *
connected_peers_map)
{
return cmd->traits (cmd->cls,
@@ -520,6 +477,12 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
}
+/**
+ * Function to get the trait with the transport application handle.
+ *
+ * @param[out] ah The application handle.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ */
int
GNUNET_TRANSPORT_get_trait_application_handle (const struct
GNUNET_TESTING_Command *cmd,
@@ -534,6 +497,12 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct
}
+/**
+ * Function to get the trait with the peer id.
+ *
+ * @param[out] id The peer id.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ */
int
GNUNET_TRANSPORT_get_trait_peer_id (const struct
GNUNET_TESTING_Command *cmd,
@@ -550,6 +519,12 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
* Create command.
*
* @param label name for command.
+ * @param system_label Label of the cmd to setup a test environment.
+ * @param m The number of the local node of the actual network namespace.
+ * @param n The number of the actual namespace.
+ * @param local_m Number of local nodes in each namespace.
+ * @param handlers Handler for messages received by this peer.
+ * @param cfgname Configuration file name for this peer.
* @return command.
*/
struct GNUNET_TESTING_Command
@@ -566,10 +541,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
unsigned int i;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 0.1 with cfg: %s\n",
- cfgname);
-
sps = GNUNET_new (struct StartPeerState);
sps->m = m;
sps->n = n;
@@ -579,9 +550,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
sps->connected_peers_map = connected_peers_map;
sps->cfgname = cfgname;
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 0.2\n");
-
if (NULL != handlers)
{
for (i = 0; NULL != handlers[i].cb; i++)
@@ -593,8 +561,6 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
i * sizeof(struct GNUNET_MQ_MessageHandler));
}
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "start peer 0.3\n");
struct GNUNET_TESTING_Command cmd = {
.cls = sps,
.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,
if (GNUNET_OK !=
GNUNET_TESTING_peer_stop (sps->peer))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_ERROR,
"Testing lib failed to stop peer %u (`%s')\n",
sps->no,
GNUNET_i2s (&sps->id));