summaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-09-13 18:25:21 +0200
committert3sserakt <t3ss@posteo.de>2021-09-13 18:25:21 +0200
commit72d77af5270ba1dabe6fa8c45009601b44d23b7b (patch)
tree3ea58e04fdaf79befff8925086b2dbf391586d64 /src/transport
parent46e07ed8eb64ff5a7473ac51de2e39c5a8a6ab3d (diff)
- added tng milestone 2 versions with improvements onto version 1 files , fixed smaller issues in milestone 1 versions, added version 1 to buildbot, added new testcase for testing udp backchannel
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am39
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c13
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c262
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c262
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_send.c262
-rw-r--r--src/transport/test_transport_port_forward.c85
-rw-r--r--src/transport/test_transport_simple_send.c86
-rw-r--r--src/transport/test_transport_simple_send_v2.c83
-rwxr-xr-xsrc/transport/test_transport_simple_send_v2.sh2
-rw-r--r--src/transport/transport-testing-cmds.h233
-rw-r--r--src/transport/transport-testing-ng.h107
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c56
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c242
-rw-r--r--src/transport/transport_api_cmd_send_simple_v2.c156
-rw-r--r--src/transport/transport_api_cmd_start_peer.c36
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c607
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c2
17 files changed, 2415 insertions, 118 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 4ea3b58c4..8bd35b5a3 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -161,11 +161,13 @@ libgnunettransporttesting_la_LDFLAGS = \
libgnunettransporttesting2_la_SOURCES = \
transport_api_cmd_connecting_peers.c \
+ transport_api_cmd_connecting_peers_v2.c \
transport_api_cmd_start_peer.c \
+ transport_api_cmd_start_peer_v2.c \
transport_api_cmd_stop_peer.c \
transport_api_cmd_send_simple.c \
+ transport_api_cmd_send_simple_v2.c \
transport-testing2.c transport-testing2.h \
- transport-testing-ng.h \
transport-testing-cmds.h \
transport-testing-filenames2.c \
transport-testing-loggers2.c \
@@ -391,7 +393,8 @@ plugin_LTLIBRARIES = \
$(HTTPS_SERVER_PLUGIN_LA) \
$(WLAN_PLUGIN_LA) \
$(BT_PLUGIN_LA) \
- libgnunet_test_transport_plugin_cmd_simple_send.la
+ libgnunet_test_transport_plugin_cmd_simple_send.la \
+ libgnunet_test_transport_plugin_cmd_simple_send_v2.la
libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \
test_transport_plugin_cmd_simple_send.c
@@ -410,6 +413,23 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
$(GN_PLUGIN_LDFLAGS)
+libgnunet_test_transport_plugin_cmd_simple_send_v2_la_SOURCES = \
+ test_transport_plugin_cmd_simple_send_v2.c
+libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LIBADD = \
+ libgnunettransporttesting2.la \
+ libgnunettransportapplication.la \
+ libgnunettransport.la \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
+ $(top_builddir)/src/statistics/libgnunetstatistics.la \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ $(top_builddir)/src/ats/libgnunetats.la \
+ $(top_builddir)/src/arm/libgnunetarm.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(LTLIBINTL)
+libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LDFLAGS = \
+ $(GN_PLUGIN_LDFLAGS)
+
if HAVE_EXPERIMENTAL
plugin_LTLIBRARIES += \
libgnunet_plugin_transport_udp.la
@@ -557,6 +577,7 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
if HAVE_TESTING
check_PROGRAMS = \
test_transport_simple_send \
+ test_transport_simple_send_v2 \
test_transport_address_switch_tcp \
test_transport_testing_startstop \
test_transport_testing_restart \
@@ -706,6 +727,7 @@ endif
if HAVE_EXPERIMENTAL
TESTS += \
test_transport_simple_send \
+ test_transport_simple_send_v2 \
test_transport_address_switch_udp \
test_plugin_udp \
test_transport_api_udp \
@@ -724,7 +746,8 @@ endif
endif
check_SCRIPTS= \
- test_transport_simple_send.sh
+ test_transport_simple_send.sh \
+ test_transport_simple_send_v2.sh
test_transport_simple_send_SOURCES = \
test_transport_simple_send.c
@@ -736,6 +759,16 @@ test_transport_simple_send_LDADD = \
libgnunettransport.la \
libgnunettransporttesting.la
+test_transport_simple_send_v2_SOURCES = \
+ test_transport_simple_send_v2.c
+test_transport_simple_send_v2_LDADD = \
+ $(top_builddir)/src/testing/libgnunettesting.la \
+ $(top_builddir)/src/util/libgnunetutil.la \
+ $(top_builddir)/src/testbed/libgnunettestbed.la \
+ $(top_builddir)/src/hello/libgnunethello.la \
+ libgnunettransport.la \
+ libgnunettransporttesting.la
+
test_transport_testing_startstop_SOURCES = \
test_transport_testing_startstop.c
test_transport_testing_startstop_LDADD = \
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 4b5018b60..1dc44c945 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -144,7 +144,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
GNUNET_asprintf (&cfgname,
"test_transport_api2_tcp_node%s.conf",
- n);
+ "1");
LOG (GNUNET_ERROR_TYPE_ERROR,
"plugin cfgname: %s\n",
@@ -154,6 +154,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
"node ip: %s\n",
node_ip);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "m: %s n: %s\n",
+ m,
+ n);
+
GNUNET_asprintf (&testdir,
"%s%s%s",
BASE_DIR,
@@ -180,6 +185,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
m,
n,
local_m,
+ node_ip,
handlers,
cfgname),
GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
@@ -187,7 +193,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
&are_all_peers_started),
GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
- "start-peer"),
+ "start-peer",
+ "system-create",
+ (atoi (n) - 1) * atoi (local_m) + atoi (
+ m)),
GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
m,
n,
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
new file mode 100644
index 000000000..ce1245296
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
@@ -0,0 +1,262 @@
+/*
+ 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 testbed/plugin_cmd_simple_send.c
+ * @brief a plugin to provide the API for running test cases.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing2.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define BASE_DIR "testdir"
+
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
+
+/**
+ * The name for a specific test environment directory.
+ *
+ */
+char *testdir;
+
+/**
+ * The name for the configuration file of the specific node.
+ *
+ */
+char *cfgname;
+
+/**
+ * Flag indicating if all peers have been started.
+ *
+ */
+unsigned int are_all_peers_started;
+
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
+ * received.
+ *
+ */
+static int
+check_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
+ * being received.
+ *
+ */
+static void
+handle_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "message received\n");
+}
+
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
+static int
+check_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
+static void
+handle_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "message received\n");
+}
+
+
+/**
+ * Callback to set the flag indicating all peers started. Will be called via the plugin api.
+ *
+ */
+static void
+all_peers_started ()
+{
+ are_all_peers_started = GNUNET_YES;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "setting are_all_peers_started: %d\n",
+ are_all_peers_started);
+}
+
+
+/**
+ * Function to start a local test case.
+ *
+ * @param write_message Callback to send a message to the master loop.
+ * @param router_ip Global address of the network namespace.
+ * @param node_ip Local address of a node i a network namespace.
+ * @param m The number of the node in a network namespace.
+ * @param n The number of the network namespace.
+ * @param local_m The number of nodes in a network namespace.
+ */
+static void
+start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
+ char *node_ip,
+ char *m,
+ char *n,
+ char *local_m)
+{
+
+ unsigned int n_int, m_int, local_m_int, num;
+
+ struct GNUNET_TESTING_NetjailTopology *topology =
+ GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
+
+
+ if (0 == m_int)
+ num = n_int;
+ else
+ num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
+
+ GNUNET_asprintf (&cfgname,
+ "test_transport_api2_tcp_node1.conf");
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "plugin cfgname: %s\n",
+ cfgname);
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "node ip: %s\n",
+ node_ip);
+
+ GNUNET_asprintf (&testdir,
+ "%s%s%s",
+ BASE_DIR,
+ m,
+ n);
+
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (test,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (test2,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_handler_end ()
+ };
+
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_system_create ("system-create",
+ testdir),
+ GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
+ "system-create",
+ num,
+ node_ip,
+ handlers,
+ cfgname),
+ GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
+ write_message),
+ GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
+ &are_all_peers_started),
+ GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
+ "start-peer",
+ "system-create",
+ num),
+ GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
+ "start-peer",
+ num),
+ GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
+ "start-peer"),
+ GNUNET_TESTING_cmd_system_destroy ("system-destroy",
+ "system-create"),
+ GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
+ write_message)
+ };
+
+ GNUNET_TESTING_run (NULL,
+ commands,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+
+}
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls NULL
+ * @return the exported block API
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api;
+
+ api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
+ api->start_testcase = &start_testcase;
+ api->all_peers_started = &all_peers_started;
+ return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
+ * @return NULL
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ GNUNET_free (testdir);
+ GNUNET_free (cfgname);
+ return NULL;
+}
+
+
+/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
new file mode 100644
index 000000000..ce1245296
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
@@ -0,0 +1,262 @@
+/*
+ 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 testbed/plugin_cmd_simple_send.c
+ * @brief a plugin to provide the API for running test cases.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing2.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define BASE_DIR "testdir"
+
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
+
+/**
+ * The name for a specific test environment directory.
+ *
+ */
+char *testdir;
+
+/**
+ * The name for the configuration file of the specific node.
+ *
+ */
+char *cfgname;
+
+/**
+ * Flag indicating if all peers have been started.
+ *
+ */
+unsigned int are_all_peers_started;
+
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
+ * received.
+ *
+ */
+static int
+check_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
+ * being received.
+ *
+ */
+static void
+handle_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "message received\n");
+}
+
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
+static int
+check_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
+static void
+handle_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "message received\n");
+}
+
+
+/**
+ * Callback to set the flag indicating all peers started. Will be called via the plugin api.
+ *
+ */
+static void
+all_peers_started ()
+{
+ are_all_peers_started = GNUNET_YES;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "setting are_all_peers_started: %d\n",
+ are_all_peers_started);
+}
+
+
+/**
+ * Function to start a local test case.
+ *
+ * @param write_message Callback to send a message to the master loop.
+ * @param router_ip Global address of the network namespace.
+ * @param node_ip Local address of a node i a network namespace.
+ * @param m The number of the node in a network namespace.
+ * @param n The number of the network namespace.
+ * @param local_m The number of nodes in a network namespace.
+ */
+static void
+start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
+ char *node_ip,
+ char *m,
+ char *n,
+ char *local_m)
+{
+
+ unsigned int n_int, m_int, local_m_int, num;
+
+ struct GNUNET_TESTING_NetjailTopology *topology =
+ GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
+
+
+ if (0 == m_int)
+ num = n_int;
+ else
+ num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
+
+ GNUNET_asprintf (&cfgname,
+ "test_transport_api2_tcp_node1.conf");
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "plugin cfgname: %s\n",
+ cfgname);
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "node ip: %s\n",
+ node_ip);
+
+ GNUNET_asprintf (&testdir,
+ "%s%s%s",
+ BASE_DIR,
+ m,
+ n);
+
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (test,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (test2,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_handler_end ()
+ };
+
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_system_create ("system-create",
+ testdir),
+ GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
+ "system-create",
+ num,
+ node_ip,
+ handlers,
+ cfgname),
+ GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
+ write_message),
+ GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
+ &are_all_peers_started),
+ GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
+ "start-peer",
+ "system-create",
+ num),
+ GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
+ "start-peer",
+ num),
+ GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
+ "start-peer"),
+ GNUNET_TESTING_cmd_system_destroy ("system-destroy",
+ "system-create"),
+ GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
+ write_message)
+ };
+
+ GNUNET_TESTING_run (NULL,
+ commands,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+
+}
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls NULL
+ * @return the exported block API
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api;
+
+ api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
+ api->start_testcase = &start_testcase;
+ api->all_peers_started = &all_peers_started;
+ return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
+ * @return NULL
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ GNUNET_free (testdir);
+ GNUNET_free (cfgname);
+ return NULL;
+}
+
+
+/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
new file mode 100644
index 000000000..ce1245296
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
@@ -0,0 +1,262 @@
+/*
+ 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 testbed/plugin_cmd_simple_send.c
+ * @brief a plugin to provide the API for running test cases.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing2.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define BASE_DIR "testdir"
+
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
+
+/**
+ * The name for a specific test environment directory.
+ *
+ */
+char *testdir;
+
+/**
+ * The name for the configuration file of the specific node.
+ *
+ */
+char *cfgname;
+
+/**
+ * Flag indicating if all peers have been started.
+ *
+ */
+unsigned int are_all_peers_started;
+
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
+ * received.
+ *
+ */
+static int
+check_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
+ * being received.
+ *
+ */
+static void
+handle_test (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "message received\n");
+}
+
+
+/**
+ * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
+static int
+check_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
+ * being received.
+ *
+ */
+static void
+handle_test2 (void *cls,
+ const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "message received\n");
+}
+
+
+/**
+ * Callback to set the flag indicating all peers started. Will be called via the plugin api.
+ *
+ */
+static void
+all_peers_started ()
+{
+ are_all_peers_started = GNUNET_YES;
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "setting are_all_peers_started: %d\n",
+ are_all_peers_started);
+}
+
+
+/**
+ * Function to start a local test case.
+ *
+ * @param write_message Callback to send a message to the master loop.
+ * @param router_ip Global address of the network namespace.
+ * @param node_ip Local address of a node i a network namespace.
+ * @param m The number of the node in a network namespace.
+ * @param n The number of the network namespace.
+ * @param local_m The number of nodes in a network namespace.
+ */
+static void
+start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
+ char *node_ip,
+ char *m,
+ char *n,
+ char *local_m)
+{
+
+ unsigned int n_int, m_int, local_m_int, num;
+
+ struct GNUNET_TESTING_NetjailTopology *topology =
+ GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
+
+
+ if (0 == m_int)
+ num = n_int;
+ else
+ num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
+
+ GNUNET_asprintf (&cfgname,
+ "test_transport_api2_tcp_node1.conf");
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "plugin cfgname: %s\n",
+ cfgname);
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "node ip: %s\n",
+ node_ip);
+
+ GNUNET_asprintf (&testdir,
+ "%s%s%s",
+ BASE_DIR,
+ m,
+ n);
+
+ struct GNUNET_MQ_MessageHandler handlers[] = {
+ GNUNET_MQ_hd_var_size (test,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_hd_var_size (test2,
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
+ struct GNUNET_TRANSPORT_TESTING_TestMessage,
+ NULL),
+ GNUNET_MQ_handler_end ()
+ };
+
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_system_create ("system-create",
+ testdir),
+ GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
+ "system-create",
+ num,
+ node_ip,
+ handlers,
+ cfgname),
+ GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
+ write_message),
+ GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
+ &are_all_peers_started),
+ GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
+ "start-peer",
+ "system-create",
+ num),
+ GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
+ "start-peer",
+ num),
+ GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
+ "start-peer"),
+ GNUNET_TESTING_cmd_system_destroy ("system-destroy",
+ "system-create"),
+ GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
+ write_message)
+ };
+
+ GNUNET_TESTING_run (NULL,
+ commands,
+ GNUNET_TIME_UNIT_FOREVER_REL);
+
+}
+
+
+/**
+ * Entry point for the plugin.
+ *
+ * @param cls NULL
+ * @return the exported block API
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api;
+
+ api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
+ api->start_testcase = &start_testcase;
+ api->all_peers_started = &all_peers_started;
+ return api;
+}
+
+
+/**
+ * Exit point from the plugin.
+ *
+ * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
+ * @return NULL
+ */
+void *
+libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
+{
+ struct GNUNET_TESTING_PluginFunctions *api = cls;
+
+ GNUNET_free (api);
+ GNUNET_free (testdir);
+ GNUNET_free (cfgname);
+ return NULL;
+}
+
+
+/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_port_forward.c b/src/transport/test_transport_port_forward.c
new file mode 100644
index 000000000..b0f0b113e
--- /dev/null
+++ b/src/transport/test_transport_port_forward.c
@@ -0,0 +1,85 @@
+/*
+ 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 transport/test_transport_port_forward.c
+ * @brief Test case executing a script which sends a test UDP message from a nated peer
+ * to a gloabl known peer. There is a tcp port forwarding in place towards the
+ * natted peer to test the backchannel functionality of the TNG service.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+
+/**
+ * Return value of the test.
+ *
+ */
+static unsigned int rv = 0;
+
+
+/**
+ * Main function to run the test cases.
+ *
+ * @param cls not used.
+ *
+ */
+static void
+run (void *cls)
+{
+ const char *topology_config = "test_topology_port_forward.conf";
+
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
+ topology_config),
+ GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
+ topology_config,
+ &rv),
+ GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
+ "netjail-start-testbed",
+ topology_config),
+ GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
+ topology_config),
+ GNUNET_TESTING_cmd_end ()
+ };
+
+ GNUNET_TESTING_run (NULL,
+ commands,
+ TIMEOUT);
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ GNUNET_log_setup ("test-netjail",
+ "DEBUG",
+ NULL);
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test finished!\n");
+ return rv;
+}
diff --git a/src/transport/test_transport_simple_send.c b/src/transport/test_transport_simple_send.c
new file mode 100644
index 000000000..924990d0a
--- /dev/null
+++ b/src/transport/test_transport_simple_send.c
@@ -0,0 +1,86 @@
+/*
+ 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 transport/test_transport_api_cmd_simple_send.c
+ * @brief Test case executing a script which sends a test message between two peers.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+
+/**
+ * Return value of the test.
+ *
+ */
+static unsigned int rv = 0;
+
+
+/**
+ * Main function to run the test cases.
+ *
+ * @param cls not used.
+ *
+ */
+static void
+run (void *cls)
+{
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_netjail_start ("netjail-start",
+ "2",
+ "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",
+ "2",
+ "1"),
+ GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
+ "2",
+ "1"),
+ GNUNET_TESTING_cmd_end ()
+ };
+
+ GNUNET_TESTING_run (NULL,
+ commands,
+ TIMEOUT);
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ GNUNET_log_setup ("test-netjail",
+ "DEBUG",
+ NULL);
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test finished!\n");
+ return rv;
+}
diff --git a/src/transport/test_transport_simple_send_v2.c b/src/transport/test_transport_simple_send_v2.c
new file mode 100644
index 000000000..aeac1bfb6
--- /dev/null
+++ b/src/transport/test_transport_simple_send_v2.c
@@ -0,0 +1,83 @@
+/*
+ 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 transport/test_transport_api_cmd_simple_send.c
+ * @brief Test case executing a script which sends a test message between two peers.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_util_lib.h"
+
+#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
+
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
+
+/**
+ * Return value of the test.
+ *
+ */
+static unsigned int rv = 0;
+
+
+/**
+ * Main function to run the test cases.
+ *
+ * @param cls not used.
+ *
+ */
+static void
+run (void *cls)
+{
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
+ TOPOLOGY_CONFIG),
+ GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
+ TOPOLOGY_CONFIG,
+ &rv),
+ GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
+ "netjail-start-testbed",
+ TOPOLOGY_CONFIG),
+ GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
+ TOPOLOGY_CONFIG),
+ GNUNET_TESTING_cmd_end ()
+ };
+
+ GNUNET_TESTING_run (NULL,
+ commands,
+ TIMEOUT);
+}
+
+
+int
+main (int argc,
+ char *const *argv)
+{
+ GNUNET_log_setup ("test-netjail",
+ "DEBUG",
+ NULL);
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Test finished!\n");
+ return rv;
+}
diff --git a/src/transport/test_transport_simple_send_v2.sh b/src/transport/test_transport_simple_send_v2.sh
new file mode 100755
index 000000000..8462d1849
--- /dev/null
+++ b/src/transport/test_transport_simple_send_v2.sh
@@ -0,0 +1,2 @@
+#!/bin/bash
+exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send_v2"
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index 1461a3d4d..f9ebafade 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -28,12 +28,195 @@
#define TRANSPORT_TESTING_CMDS_H
#include "gnunet_testing_lib.h"
+
+struct StartPeerState_v2
+{
+ /**
+ * The ip of a node.
+ */
+ char *node_ip;
+
+ /**
+ * 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;
+
+};
+
+
+struct StartPeerState
+{
+ /**
+ * The ip of a node.
+ */
+ char *node_ip;
+
+ /**
+ * 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;
+
+};
+
+
+int
+GNUNET_TRANSPORT_get_trait_state (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ struct StartPeerState **sps);
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
+ const char *system_label,
+ uint32_t no,
+ char *node_ip,
+ struct GNUNET_MQ_MessageHandler *handlers,
+ const char *cfgname);
+
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_start_peer (const char *label,
const char *system_label,
char *m,
char *n,
char *local_m,
+ char *node_ip,
struct GNUNET_MQ_MessageHandler *handlers,
const char *cfgname);
@@ -43,7 +226,15 @@ GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
- const char *start_peer_label);
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num);
+
+struct GNUNET_TESTING_Command
+GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num);
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_send_simple (const char *label,
@@ -52,6 +243,21 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
uint32_t num,
const char *start_peer_label);
+/**
+ * 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_v2 (const char *label,
+ const char *start_peer_label,
+ uint32_t num);
+
int
GNUNET_TRANSPORT_get_trait_peer_id (const struct
GNUNET_TESTING_Command *cmd,
@@ -65,6 +271,16 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
GNUNET_CONTAINER_MultiShortmap *
*
connected_peers_map);
+
+int
+GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ struct
+ GNUNET_CONTAINER_MultiShortmap
+ *
+ *
+ connected_peers_map);
int
GNUNET_TRANSPORT_get_trait_hello_size (const struct
GNUNET_TESTING_Command
@@ -77,5 +293,20 @@ GNUNET_TRANSPORT_get_trait_hello (const struct
*cmd,
char **hello);
+
+int
+GNUNET_TRANSPORT_get_trait_application_handle (const struct
+ GNUNET_TESTING_Command *cmd,
+ struct
+ GNUNET_TRANSPORT_ApplicationHandle
+ **ah);
+
+int
+GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
+ GNUNET_TESTING_Command *cmd,
+ struct
+ GNUNET_TRANSPORT_ApplicationHandle
+ **ah);
+
#endif
/* end of transport_testing.h */
diff --git a/src/transport/transport-testing-ng.h b/src/transport/transport-testing-ng.h
deleted file mode 100644
index cd4e1f3fe..000000000
--- a/src/transport/transport-testing-ng.h
+++ /dev/null
@@ -1,107 +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
- */
-
-/**
- * @author t3sserakt
- */
-
-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;
-
-};
-
-
-int
-GNUNET_TRANSPORT_get_trait_state (const struct
- GNUNET_TESTING_Command
- *cmd,
- struct StartPeerState **sps);
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 34b3d5925..09ca9e54c 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -42,6 +42,15 @@
*/
struct ConnectPeersState
{
+ // Label of the cmd which started the test system.
+ const char *create_label;
+
+ /**
+ * Number globally identifying the node.
+ *
+ */
+ uint32_t num;
+
/**
* Label of the cmd to start a peer.
*
@@ -66,6 +75,13 @@ connect_peers_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct ConnectPeersState *cps = cls;
+ const struct GNUNET_TESTING_Command *system_cmd;
+ struct GNUNET_TESTING_System *tl_system;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
+ GNUNET_CRYPTO_EddsaPrivateKey);
+ struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
+ GNUNET_CRYPTO_EddsaPublicKey);
+ ;
const struct GNUNET_TESTING_Command *peer1_cmd;
// const struct GNUNET_TESTING_Command *peer2_cmd;
struct GNUNET_TRANSPORT_ApplicationHandle *ah;
@@ -77,6 +93,8 @@ connect_peers_run (void *cls,
enum GNUNET_NetworkType nt = 0;
char *peer_id;
struct GNUNET_PeerIdentity *id;
+ struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
+ uint32_t num;
peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
@@ -88,9 +106,22 @@ connect_peers_run (void *cls,
GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
&id);
- if (strstr (hello, "60002") != NULL)
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
+ GNUNET_TESTING_get_trait_test_system (system_cmd,
+ &tl_system);
+
+ if (2 == cps->num)
+ num = 1;
+ else
+ num = 2;
+
+
+
+
+ // if (strstr (hello, "60002") != NULL)
+ if (2 == num)
{
- addr = "tcp-192.168.15.2:60003";
+ addr = "tcp-192.168.15.2:60002";
peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
}
else
@@ -99,10 +130,25 @@ connect_peers_run (void *cls,
peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
}
+ priv_key = GNUNET_TESTING_hostkey_get (tl_system,
+ num,
+ other);
+
+ GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
+ pub_key);
+
GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
strlen (peer_id),
&peer->public_key);
+ peer->public_key = *pub_key;
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "\nnum: %u\n peer_id: %s\n pub_key %s\n",
+ num,
+ peer_id,
+ GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
+
cps->id = peer;
// TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
@@ -210,12 +256,16 @@ connect_peers_cleanup (void *cls,
*/
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
- const char *start_peer_label)
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num)
{
struct ConnectPeersState *cps;
cps = GNUNET_new (struct ConnectPeersState);
cps->start_peer_label = start_peer_label;
+ cps->num = num;
+ cps->create_label = create_label;
struct GNUNET_TESTING_Command cmd = {
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
new file mode 100644
index 000000000..0d286b714
--- /dev/null
+++ b/src/transport/transport_api_cmd_connecting_peers_v2.c
@@ -0,0 +1,242 @@
+/*
+ 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_api_cmd_start_peer.c
+ * @brief cmd to start a peer.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_transport_application_service.h"
+#include "gnunet_hello_lib.h"
+#include "gnunet_transport_service.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+#define CONNECT_ADDRESS_TEMPLATE "tcp-192.168.15.%u:60002"
+
+/**
+ * Struct to store information needed in callbacks.
+ *
+ */
+struct ConnectPeersState
+{
+ // Label of the cmd which started the test system.
+ const char *create_label;
+
+ /**
+ * Number globally identifying the node.
+ *
+ */
+ uint32_t num;
+
+ /**
+ * 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,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct ConnectPeersState *cps = cls;
+ const struct GNUNET_TESTING_Command *system_cmd;
+ struct GNUNET_TESTING_System *tl_system;
+ struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
+ GNUNET_CRYPTO_EddsaPrivateKey);
+ struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
+ GNUNET_CRYPTO_EddsaPublicKey);
+ const struct GNUNET_TESTING_Command *peer1_cmd;
+ struct GNUNET_TRANSPORT_ApplicationHandle *ah;
+ struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
+ char *addr;
+ enum GNUNET_NetworkType nt = 0;
+ struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
+ uint32_t num;
+
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
+ GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
+ &ah);
+
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
+ GNUNET_TESTING_get_trait_test_system (system_cmd,
+ &tl_system);
+
+ if (1 == cps->num)
+ {
+ num = 2;
+ // addr = "tcp-192.168.15.2:60002";
+ }
+ else
+ {
+ num = 1;
+ // addr = "tcp-192.168.15.1:60002";
+ }
+
+ GNUNET_asprintf (&addr,
+ CONNECT_ADDRESS_TEMPLATE,
+ num);
+
+ priv_key = GNUNET_TESTING_hostkey_get (tl_system,
+ num,
+ other);
+
+ GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
+ pub_key);
+
+
+ peer->public_key = *pub_key;
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "num: %u pub_key %s\n",
+ num,
+ GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
+
+ cps->id = peer;
+
+ GNUNET_TRANSPORT_application_validate (ah,
+ peer,
+ nt,
+ addr);
+}
+
+
+/**
+ * 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,
+ void *cont_cls)
+{
+ struct ConnectPeersState *cps = cls;
+ const struct GNUNET_TESTING_Command *peer1_cmd;
+ struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
+ unsigned int ret;
+ struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
+ struct GNUNET_HashCode hc;
+ int node_number;
+
+ peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
+ GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
+ &connected_peers_map);
+
+ node_number = 1;
+ 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);
+
+ if (GNUNET_YES == ret)
+ {
+ cont (cont_cls);
+ }
+
+ GNUNET_free (key);
+ return ret;
+}
+
+
+/**
+ * Trait function of this cmd does nothing.
+ *
+ */
+static int
+connect_peers_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * 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);
+}
+
+
+/**
+ * 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_v2 (const char *label,
+ const char *start_peer_label,
+ const char *create_label,
+ uint32_t num)
+{
+ struct ConnectPeersState *cps;
+
+ cps = GNUNET_new (struct ConnectPeersState);
+ cps->start_peer_label = start_peer_label;
+ cps->num = num;
+ cps->create_label = create_label;
+
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = cps,
+ .label = label,
+ .run = &connect_peers_run,
+ .finish = &connect_peers_finish,
+ .cleanup = &connect_peers_cleanup,
+ .traits = &connect_peers_traits
+ };
+
+ return cmd;
+}
diff --git a/src/transport/transport_api_cmd_send_simple_v2.c b/src/transport/transport_api_cmd_send_simple_v2.c
new file mode 100644
index 000000000..d43c0b425
--- /dev/null
+++ b/src/transport/transport_api_cmd_send_simple_v2.c
@@ -0,0 +1,156 @@
+/*
+ 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_api_cmd_start_peer.c
+ * @brief cmd to start a peer.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+#include "transport-testing2.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
+struct SendSimpleState
+{
+ /**
+ * Number globally identifying the node.
+ *
+ */
+ uint32_t num;
+
+ /**
+ * 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,
+ const char *trait,
+ unsigned int index)
+{
+ return GNUNET_OK;
+}
+
+
+/**
+ * The cleanup function of this cmd frees resources the cmd allocated.
+ *
+ */
+static void
+send_simple_cleanup (void *cls,
+ const struct GNUNET_TESTING_Command *cmd)
+{
+ struct SendSimpleState *sss = cls;
+
+ GNUNET_free (sss);
+}
+
+
+/**
+ * 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,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct SendSimpleState *sss = cls;
+ struct GNUNET_MQ_Envelope *env;
+ struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
+ struct GNUNET_MQ_Handle *mq;
+ struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
+ const struct GNUNET_TESTING_Command *peer1_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->start_peer_label);
+ GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
+ &connected_peers_map);
+
+ node_number = 1;
+ GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
+ memcpy (key,
+ &hc,
+ sizeof (*key));
+
+ mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
+ key);
+
+ env = GNUNET_MQ_msg_extra (test,
+ 2600 - sizeof(*test),
+ GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
+ test->num = htonl (sss->num);
+ memset (&test[1],
+ sss->num,
+ 2600 - sizeof(*test));
+ GNUNET_MQ_send (mq,
+ env);
+ GNUNET_free (key);
+
+}
+
+
+/**
+ * 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_v2 (const char *label,
+ const char *start_peer_label,
+ uint32_t num)
+{
+ struct SendSimpleState *sss;
+
+ sss = GNUNET_new (struct SendSimpleState);
+ sss->num = num;
+ sss->start_peer_label = start_peer_label;
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sss,
+ .label = label,
+ .run = &send_simple_run,
+ .cleanup = &send_simple_cleanup,
+ .traits = &send_simple_traits
+ };
+
+ return cmd;
+}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 729d981c0..f4e92944b 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -29,7 +29,7 @@
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"
-#include "transport-testing-ng.h"
+#include "transport-testing-cmds.h"
/**
* Generic logging shortcut
@@ -185,6 +185,10 @@ start_peer_run (void *cls,
struct GNUNET_PeerIdentity dummy;
const struct GNUNET_TESTING_Command *system_cmd;
struct GNUNET_TESTING_System *tl_system;
+ char *home;
+ char *transport_unix_path;
+ char *communicator_unix_path;
+ char *bindto;
if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
{
@@ -200,6 +204,34 @@ start_peer_run (void *cls,
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
+ GNUNET_asprintf (&home,
+ "$GNUNET_TMP/test-transport/api-tcp-p%u",
+ sps->no);
+
+ GNUNET_asprintf (&transport_unix_path,
+ "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
+ sps->no);
+
+ GNUNET_asprintf (&communicator_unix_path,
+ "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
+ sps->no);
+
+ GNUNET_asprintf (&bindto,
+ "%s:60002",
+ sps->node_ip);
+
+
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
+ home);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
+ transport_unix_path);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
+ "BINDTO",
+ bindto);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
+ "UNIXPATH",
+ communicator_unix_path);
+
system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label);
GNUNET_TESTING_get_trait_test_system (system_cmd,
&tl_system);
@@ -536,6 +568,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
char *m,
char *n,
char *local_m,
+ char *node_ip,
struct GNUNET_MQ_MessageHandler *handlers,
const char *cfgname)
{
@@ -552,6 +585,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
sps->system_label = system_label;
sps->connected_peers_map = connected_peers_map;
sps->cfgname = cfgname;
+ sps->node_ip = node_ip;
if (NULL != handlers)
{
diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c
new file mode 100644
index 000000000..0e39bd915
--- /dev/null
+++ b/src/transport/transport_api_cmd_start_peer_v2.c
@@ -0,0 +1,607 @@
+/*
+ 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_api_cmd_start_peer.c
+ * @brief cmd to start a peer.
+ * @author t3sserakt
+ */
+#include "platform.h"
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_ng_lib.h"
+#include "gnunet_peerstore_service.h"
+#include "gnunet_transport_core_service.h"
+#include "gnunet_transport_application_service.h"
+#include "transport-testing-cmds.h"
+
+/**
+ * Generic logging shortcut
+ */
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
+
+
+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,
+ const char *emsg)
+{
+ struct StartPeerState_v2 *sps = cb_cls;
+ if (NULL == record)
+ {
+ sps->pic = NULL;
+ sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
+ return;
+ }
+ // Check record type et al?
+ sps->hello_size = record->value_size;
+ sps->hello = GNUNET_malloc (sps->hello_size);
+ memcpy (sps->hello, record->value, sps->hello_size);
+ sps->hello[sps->hello_size - 1] = '\0';
+
+ GNUNET_PEERSTORE_iterate_cancel (sps->pic);
+ sps->pic = NULL;
+ sps->finished = GNUNET_YES;
+}
+
+
+/**
+ * Function to start the retrieval task to retrieve the hello of this peer
+ * from the peerstore.
+ *
+ */
+static void
+retrieve_hello (void *cls)
+{
+ struct StartPeerState_v2 *sps = cls;
+ sps->rh_task = NULL;
+ sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
+ "transport",
+ &sps->id,
+ GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
+ hello_iter_cb,
+ sps);
+
+}
+
+
+/**
+ * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved.
+ *
+ */
+static int
+start_peer_finish (void *cls,
+ GNUNET_SCHEDULER_TaskCallback cont,
+ void *cont_cls)
+{
+ struct StartPeerState_v2 *sps = cls;
+
+ if (GNUNET_YES == sps->finished)
+ {
+ cont (cont_cls);
+ }
+
+ return sps->finished;
+}
+
+
+/**
+ * Disconnect callback for the connection to the core service.
+ *
+ */
+static void
+notify_disconnect (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ void *handler_cls)
+{
+ struct StartPeerState_v2 *sps = cls;
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %s disconnected from peer %u (`%s')\n",
+ GNUNET_i2s (peer),
+ sps->no,
+ GNUNET_i2s (&sps->id));
+
+}
+
+
+/**
+ * Connect callback for the connection to the core service.
+ *
+ */
+static void *
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct StartPeerState_v2 *sps = cls;
+ struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
+ struct GNUNET_HashCode hc;
+ int node_number;
+
+ void *ret = NULL;
+
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %s connected to peer %u (`%s')\n",
+ GNUNET_i2s (peer),
+ sps->no,
+ 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);
+
+
+ memcpy (key,
+ &hc,
+ sizeof (*key));
+ GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
+ 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,
+ struct GNUNET_TESTING_Interpreter *is)
+{
+ struct StartPeerState_v2 *sps = cls;
+ char *emsg = NULL;
+ struct GNUNET_PeerIdentity dummy;
+ const struct GNUNET_TESTING_Command *system_cmd;
+ struct GNUNET_TESTING_System *tl_system;
+ char *home;
+ char *transport_unix_path;
+ char *communicator_unix_path;
+ char *bindto;
+
+ if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "File not found: `%s'\n",
+ sps->cfgname);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+
+
+ sps->cfg = GNUNET_CONFIGURATION_create ();
+ GNUNET_assert (GNUNET_OK ==
+ GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
+
+ GNUNET_asprintf (&home,
+ "$GNUNET_TMP/test-transport/api-tcp-p%u",
+ sps->no);
+
+ GNUNET_asprintf (&transport_unix_path,
+ "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
+ sps->no);
+
+ GNUNET_asprintf (&communicator_unix_path,
+ "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
+ sps->no);
+
+ GNUNET_asprintf (&bindto,
+ "%s:60002",
+ sps->node_ip);
+
+
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
+ home);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
+ transport_unix_path);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
+ "BINDTO",
+ bindto);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
+ "UNIXPATH",
+ communicator_unix_path);
+
+ system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label);
+ GNUNET_TESTING_get_trait_test_system (system_cmd,
+ &tl_system);
+
+ sps->tl_system = tl_system;
+
+ if (GNUNET_SYSERR ==
+ GNUNET_TESTING_configuration_create (tl_system,
+ sps->cfg))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Testing library failed to create unique configuration based on `%s'\n",
+ sps->cfgname);
+ GNUNET_CONFIGURATION_destroy (sps->cfg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+
+ sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
+ sps->cfg,
+ sps->no,
+ NULL,
+ &emsg);
+ if (NULL == sps->peer)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Testing library failed to create unique configuration based on `%s': `%s'\n",
+ sps->cfgname,
+ emsg);
+ GNUNET_free (emsg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+
+ if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Testing library failed to create unique configuration based on `%s'\n",
+ sps->cfgname);
+ GNUNET_free (emsg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+
+ memset (&dummy,
+ '\0',
+ sizeof(dummy));
+
+ GNUNET_TESTING_peer_get_identity (sps->peer,
+ &sps->id);
+
+ if (0 == memcmp (&dummy,
+ &sps->id,
+ sizeof(struct GNUNET_PeerIdentity)))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Testing library failed to obtain peer identity for peer %u\n",
+ sps->no);
+ GNUNET_free (emsg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer %u configured with identity `%s'\n",
+ sps->no,
+ GNUNET_i2s_full (&sps->id));
+
+ sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
+ NULL,
+ sps->handlers,
+ sps,
+ &notify_connect,
+ &notify_disconnect);
+ if (NULL == sps->th)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to transport service for peer `%s': `%s'\n",
+ sps->cfgname,
+ emsg);
+ GNUNET_free (emsg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+
+ sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
+ if (NULL == sps->th)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to connect to peerstore service for peer `%s': `%s'\n",
+ sps->cfgname,
+ emsg);
+ GNUNET_free (emsg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+
+ sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
+ if (NULL == sps->ah)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
+ sps->cfgname,
+ emsg);
+ GNUNET_free (emsg);
+ GNUNET_TESTING_interpreter_fail ();
+ return;
+ }
+ 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_v2 *sps = cls;
+
+ if (NULL != sps->handlers)
+ {
+ GNUNET_free (sps->handlers);
+ sps->handlers = NULL;
+ }
+ if (NULL != sps->cfg)
+ {
+ GNUNET_CONFIGURATION_destroy (sps->cfg);
+ sps->cfg = NULL;
+ }
+ 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,
+ const char *trait,
+ unsigned int index)
+{
+ struct StartPeerState_v2 *sps = cls;
+ struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
+ struct GNUNET_PeerIdentity *id = &sps->id;
+ struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
+ sps->connected_peers_map;
+ char *hello = sps->hello;
+ size_t hello_size = sps->hello_size;
+
+
+ struct GNUNET_TESTING_Trait traits[] = {
+ {
+ .index = 0,
+ .trait_name = "application_handle",
+ .ptr = (const void *) ah,
+ },
+ {
+ .index = 1,
+ .trait_name = "peer_id",
+ .ptr = (const void *) id,
+ },
+ {
+ .index = 2,
+ .trait_name = "connected_peers_map",
+ .ptr = (const void *) connected_peers_map,
+ },
+ {
+ .index = 3,
+ .trait_name = "hello",
+ .ptr = (const void *) hello,
+ },
+ {
+ .index = 4,
+ .trait_name = "hello_size",
+ .ptr = (const void *) hello_size,
+ },
+ {
+ .index = 5,
+ .trait_name = "state",
+ .ptr = (const void *) sps,
+ },
+ GNUNET_TESTING_trait_end ()
+ };
+
+ return GNUNET_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Function to get the trait with the struct StartPeerState_v2.
+ *
+ * @param[out] sps struct StartPeerState_v2.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
+int
+GNUNET_TRANSPORT_get_trait_state_v2 (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ struct StartPeerState_v2 **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_v2 (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ size_t **hello_size)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) hello_size,
+ "hello_size",
+ (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_v2 (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ char **hello)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) hello,
+ "hello",
+ (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_v2 (const struct
+ GNUNET_TESTING_Command
+ *cmd,
+ struct
+ GNUNET_CONTAINER_MultiShortmap
+ *
+ *
+ connected_peers_map)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) connected_peers_map,
+ "connected_peers_map",
+ (unsigned int) 2);
+}
+
+
+/**
+ * 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_v2 (const struct
+ GNUNET_TESTING_Command *cmd,
+ struct
+ GNUNET_TRANSPORT_ApplicationHandle
+ **ah)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) ah,
+ "application_handle",
+ (unsigned int) 0);
+}
+
+
+/**
+ * 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_v2 (const struct
+ GNUNET_TESTING_Command *cmd,
+ struct GNUNET_PeerIdentity **id)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) id,
+ "peer_id",
+ (unsigned int) 1);
+}
+
+
+/**
+ * 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
+GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
+ const char *system_label,
+ uint32_t no,
+ char *node_ip,
+ struct GNUNET_MQ_MessageHandler *handlers,
+ const char *cfgname)
+{
+ struct StartPeerState_v2 *sps;
+ struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
+ GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
+ unsigned int i;
+
+ sps = GNUNET_new (struct StartPeerState_v2);
+ sps->no = no;
+ sps->system_label = system_label;
+ sps->connected_peers_map = connected_peers_map;
+ sps->cfgname = cfgname;
+ sps->node_ip = node_ip;
+
+ if (NULL != handlers)
+ {
+ for (i = 0; NULL != handlers[i].cb; i++)
+ ;
+ sps->handlers = GNUNET_new_array (i + 1,
+ struct GNUNET_MQ_MessageHandler);
+ GNUNET_memcpy (sps->handlers,
+ handlers,
+ i * sizeof(struct GNUNET_MQ_MessageHandler));
+ }
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sps,
+ .label = label,
+ .run = &start_peer_run,
+ .finish = &start_peer_finish,
+ .cleanup = &start_peer_cleanup,
+ .traits = &start_peer_traits
+ };
+
+ return cmd;
+}
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index 7a0050a63..4d7228378 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -29,7 +29,7 @@
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"
-#include "transport-testing-ng.h"
+#include "transport-testing-cmds.h"
/**
* Generic logging shortcut