summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-11-09 17:38:47 +0100
committert3sserakt <t3ss@posteo.de>2021-11-09 17:43:25 +0100
commit8cd4dadfb9ebd4db232fda79d5c4353eacb15690 (patch)
treea063e52d71d1b6611371f6c129c6ae1b0215cf99 /src
parent6fb788ca2ec44837ea10a36be7fd0030fb08955b (diff)
- moved global netjail methods to its own header file.dev/t3ss/tng
- added configuration by string in test skript instead of config file. - moved netjail scripts to contrib/netjail and install them into the share/gnunet directory.
Diffstat (limited to 'src')
-rw-r--r--src/dhtu/test_dhtu_ip.c2
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c1
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_testing_netjail_lib.h463
-rw-r--r--src/include/gnunet_testing_ng_lib.h60
-rw-r--r--src/include/gnunet_testing_plugin.h4
-rw-r--r--src/testing/Makefile.am40
-rw-r--r--src/testing/gnunet-cmds-helper.c41
-rw-r--r--src/testing/test_testing_api_cmd_netjail.c87
-rw-r--r--src/testing/test_testing_hello_world.c68
-rw-r--r--src/testing/test_testing_plugin_testcmd.c123
-rw-r--r--src/testing/test_testing_topology.c44
-rw-r--r--src/testing/testing.c99
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c107
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c1
-rw-r--r--src/testing/testing_api_cmd_finish.c2
-rw-r--r--src/testing/testing_api_cmd_hello_world.c126
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c161
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c1
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c1
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c43
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c187
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c77
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c14
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c1
-rw-r--r--src/testing/testing_api_cmd_system_create.c1
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c1
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-communicator-udp.c41
-rw-r--r--src/transport/gnunet-service-tng.c80
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c17
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c13
-rwxr-xr-xsrc/transport/test_transport_simple_send_string.sh16
-rw-r--r--src/transport/test_transport_start_with_config.c76
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c1
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c5
-rw-r--r--src/transport/transport_api_cmd_send_simple.c1
-rw-r--r--src/transport/transport_api_cmd_send_simple_v3.c194
-rw-r--r--src/transport/transport_api_cmd_start_peer.c5
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c1
40 files changed, 991 insertions, 1217 deletions
diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c
index c9528053f..7913cfc35 100644
--- a/src/dhtu/test_dhtu_ip.c
+++ b/src/dhtu/test_dhtu_ip.c
@@ -24,7 +24,7 @@
* @author Christian Grothoff
*/
#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
index e620e329e..fe8e1c18a 100644
--- a/src/dhtu/testing_dhtu_cmd_send.c
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
/**
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 9c22b5977..e4b02b8ee 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -118,6 +118,7 @@ gnunetinclude_HEADERS = \
gnunet_testing_lib.h \
gnunet_testing_plugin.h \
gnunet_testing_ng_lib.h \
+ gnunet_testing_netjail_lib.h \
gnunet_time_lib.h \
gnunet_transport_service.h \
gnunet_transport_application_service.h \
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
new file mode 100644
index 000000000..3a5e9f749
--- /dev/null
+++ b/src/include/gnunet_testing_netjail_lib.h
@@ -0,0 +1,463 @@
+/*
+ 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
+ */
+
+/**
+ * @brief API for writing an interpreter to test GNUnet components
+ * @author Christian Grothoff <christian@grothoff.org>
+ * @author Marcello Stanisci
+ * @author t3sserakt
+ */
+#ifndef GNUNET_TESTING_NG_LIB_H
+#define GNUNET_TESTING_NG_LIB_H
+
+#include "gnunet_util_lib.h"
+#include "gnunet_testing_plugin.h"
+#include "gnunet_testing_ng_lib.h"
+
+
+/**
+ * Router of a netjail subnet.
+ */
+struct GNUNET_TESTING_NetjailRouter
+{
+ /**
+ * Will tcp be forwarded?
+ */
+ unsigned int tcp_port;
+
+ /**
+ * Will udp be forwarded?
+ */
+ unsigned int udp_port;
+};
+
+
+/**
+ * Enum for the different types of nodes.
+ */
+enum GNUNET_TESTING_NODE_TYPE
+{
+ /**
+ * Node in a subnet.
+ */
+ GNUNET_TESTING_SUBNET_NODE,
+
+ /**
+ * Global known node.
+ */
+ GNUNET_TESTING_GLOBAL_NODE
+};
+
+/**
+ * Protocol address prefix für a connection between nodes.
+ */
+struct GNUNET_TESTING_AddressPrefix
+{
+ /**
+ * Pointer to the previous prefix in the DLL.
+ */
+ struct GNUNET_TESTING_AddressPrefix *prev;
+
+ /**
+ * Pointer to the next prefix in the DLL.
+ */
+ struct GNUNET_TESTING_AddressPrefix *next;
+
+ /**
+ * The address prefix.
+ */
+ char *address_prefix;
+};
+
+
+/**
+ * Node in a netjail topology.
+ */
+struct GNUNET_TESTING_NetjailNode;
+
+/**
+ * Connection to another node.
+ */
+struct GNUNET_TESTING_NodeConnection
+{
+ /**
+ * Pointer to the previous connection in the DLL.
+ */
+ struct GNUNET_TESTING_NodeConnection *prev;
+
+ /**
+ * Pointer to the next connection in the DLL.
+ */
+ struct GNUNET_TESTING_NodeConnection *next;
+
+ /**
+ * The number of the subnet of the node this connection points to. This is 0,
+ * if the node is a global known node.
+ */
+ unsigned int namespace_n;
+
+ /**
+ * The number of the node this connection points to.
+ */
+ unsigned int node_n;
+
+ /**
+ * The type of the node this connection points to.
+ */
+ enum GNUNET_TESTING_NODE_TYPE node_type;
+
+ /**
+ * The node which establish the connection
+ */
+ struct GNUNET_TESTING_NetjailNode *node;
+
+ /**
+ * Head of the DLL with the address prefixes for the protocolls this node is reachable.
+ */
+ struct GNUNET_TESTING_AddressPrefix *address_prefixes_head;
+
+ /**
+ * Tail of the DLL with the address prefixes for the protocolls this node is reachable.
+ */
+ struct GNUNET_TESTING_AddressPrefix *address_prefixes_tail;
+};
+
+/**
+ * Node in the netjail topology.
+ */
+struct GNUNET_TESTING_NetjailNode
+{
+ /**
+ * Plugin for the test case to be run on this node.
+ */
+ char *plugin;
+
+ /**
+ * Flag indicating if this node is a global known node.
+ */
+ unsigned int is_global;
+
+ /**
+ * The number of the subnet this node is running in.
+ */
+ unsigned int namespace_n;
+
+ /**
+ * The number of this node in the subnet.
+ */
+ unsigned int node_n;
+
+ /**
+ * Head of the DLL with the connections which shall be established to other nodes.
+ */
+ struct GNUNET_TESTING_NodeConnection *node_connections_head;
+
+ /**
+ * Tail of the DLL with the connections which shall be established to other nodes.
+ */
+ struct GNUNET_TESTING_NodeConnection *node_connections_tail;
+};
+
+
+/**
+ * Subnet in a topology.
+ */
+struct GNUNET_TESTING_NetjailNamespace
+{
+ /**
+ * The number of the subnet.
+ */
+ unsigned int namespace_n;
+
+ /**
+ * Router of the subnet.
+ */
+ struct GNUNET_TESTING_NetjailRouter *router;
+
+ /**
+ * Hash map containing the nodes in this subnet.
+ */
+ struct GNUNET_CONTAINER_MultiShortmap *nodes;
+};
+
+/**
+ * Toplogy of our netjail setup.
+ */
+struct GNUNET_TESTING_NetjailTopology
+{
+
+ /**
+ * Default plugin for the test case to be run on nodes.
+ */
+ char *plugin;
+
+ /**
+ * Number of subnets.
+ */
+ unsigned int namespaces_n;
+
+ /**
+ * Number of nodes per subnet.
+ */
+ unsigned int nodes_m;
+
+ /**
+ * Number of global known nodes.
+ */
+ unsigned int nodes_x;
+
+ /**
+ * Hash map containing the subnets (for natted nodes) of the topology.
+ */
+ struct GNUNET_CONTAINER_MultiShortmap *map_namespaces;
+
+ /**
+ * Hash map containing the global known nodes which are not natted.
+ */
+ struct GNUNET_CONTAINER_MultiShortmap *map_globals;
+};
+
+/**
+ * Getting the topology from file.
+ *
+ * @param filename The name of the topology file.
+ * @return The GNUNET_TESTING_NetjailTopology
+ */
+struct GNUNET_TESTING_NetjailTopology *
+GNUNET_TESTING_get_topo_from_file (const char *filename);
+
+
+/**
+ * Parse the topology data.
+ *
+ * @param data The topology data.
+ * @return The GNUNET_TESTING_NetjailTopology
+ */
+struct GNUNET_TESTING_NetjailTopology *
+GNUNET_TESTING_get_topo_from_string (char *data);
+
+
+/**
+ * Get the connections to other nodes for a specific node.
+ *
+ * @param num The specific node we want the connections for.
+ * @param topology The topology we get the connections from.
+ * @return The connections of the node.
+ */
+struct GNUNET_TESTING_NodeConnection *
+GNUNET_TESTING_get_connections (unsigned int num, struct
+ GNUNET_TESTING_NetjailTopology *topology);
+
+
+/**
+ * Get the address for a specific communicator from a connection.
+ *
+ * @param connection The connection we like to have the address from.
+ * @param prefix The communicator protocol prefix.
+ * @return The address of the communicator.
+ */
+char *
+GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
+ char *prefix);
+
+
+/**
+ * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
+ *
+ * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated.
+ */
+void
+GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
+
+
+/**
+ * Calculate the unique id identifying a node from a given connction.
+ *
+ * @param node_connection The connection we calculate the id from.
+ * @param topology The topology we get all needed information from.
+ * @return The unique id of the node from the connection.
+ */
+unsigned int
+GNUNET_TESTING_calculate_num (struct
+ GNUNET_TESTING_NodeConnection *node_connection,
+ struct GNUNET_TESTING_NetjailTopology *topology);
+
+
+/**
+ * Struct to hold information for callbacks.
+ *
+ */
+struct LocalPreparedState
+{
+ /**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext *ac;
+
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
+ TESTING_CMD_HELPER_write_cb write_message;
+};
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param topology_config Configuration file for the test topology.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_netjail_start (const char *label,
+ char *topology_config,
+ unsigned int *read_file);
+
+
+/**
+ * Create command.
+ *
+ * @param label Name for the command.
+ * @param topology The complete topology information.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_netjail_start_testing_system (
+ const char *label,
+ struct GNUNET_TESTING_NetjailTopology *topology);
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param topology_config Configuration file for the test topology.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_netjail_stop (const char *label,
+ char *topology_config,
+ unsigned int *read_file);
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param helper_start_label label of the cmd to start the test system.
+ * @param topology The complete topology information.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_stop_testing_system (
+ const char *label,
+ const char *helper_start_label,
+ struct GNUNET_TESTING_NetjailTopology *topology);
+
+
+/**
+ * Create a GNUNET_CMDS_LOCAL_FINISHED message.
+ *
+ * @param rv The result of the local test as GNUNET_GenericReturnValue.
+ * @return The GNUNET_CMDS_LOCAL_FINISHED message.
+*/
+struct GNUNET_MessageHeader *
+GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv);
+
+
+/**
+ * Function to get the trait with the async context.
+ *
+ * @param[out] ac GNUNET_TESTING_AsyncContext.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ */
+int
+GNUNET_TESTING_get_trait_async_context (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct GNUNET_TESTING_AsyncContext **ac);
+
+
+/**
+ * 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.
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_TESTING_get_trait_helper_handles (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct GNUNET_HELPER_Handle ***helper);
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_block_until_all_peers_started (
+ const char *label,
+ unsigned int *all_peers_started);
+
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_block_until_external_trigger (
+ const char *label);
+
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_send_peer_ready (const char *label,
+ TESTING_CMD_HELPER_write_cb write_message);
+
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param write_message Callback to write messages to the master loop.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_local_test_finished (
+ const char *label,
+ TESTING_CMD_HELPER_write_cb write_message);
+
+/**
+ * Create command.
+ *
+ * @param label name for command.
+ * @param write_message Callback to write messages to the master loop.
+ * @param all_local_tests_prepared Flag which will be set from outside.
+ * @return command.
+ */
+struct GNUNET_TESTING_Command
+GNUNET_TESTING_cmd_local_test_prepared (const char *label,
+ TESTING_CMD_HELPER_write_cb
+ write_message);
+
+/**
+ * Function to get the trait with the struct LocalPreparedState.
+ *
+ * @param[out] lfs struct LocalPreparedState.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
+enum GNUNET_GenericReturnValue
+GNUNET_TESTING_get_trait_local_prepared_state (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct LocalPreparedState **lfs);
+
+#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 7ce73baef..2d040ac21 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -657,6 +657,16 @@ GNUNET_TESTING_get_topo_from_file (const char *filename);
/**
+ * Parse the topology data.
+ *
+ * @param data The topology data.
+ * @return The GNUNET_TESTING_NetjailTopology
+ */
+struct GNUNET_TESTING_NetjailTopology *
+GNUNET_TESTING_get_topo_from_string (char *data);
+
+
+/**
* Get the connections to other nodes for a specific node.
*
* @param num The specific node we want the connections for.
@@ -1073,28 +1083,6 @@ struct LocalPreparedState
TESTING_CMD_HELPER_write_cb write_message;
};
-/**
- * Create command.
- *
- * @param label name for command.
- * @param now when the command was started.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_hello_world_birth (const char *label,
- struct GNUNET_TIME_Absolute *now);
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param message initial message.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_hello_world (const char *label,
- const char *birthLabel,
- char *message);
/**
* Offer data from trait
@@ -1135,20 +1123,25 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start (const char *label,
- char *topology_config);
+ char *topology_config,
+ unsigned int *read_file);
/**
* Create command.
*
* @param label Name for the command.
- * @param topology_config Configuration file for the test topology.
- * @param rv Pointer to the return value of the test.
+ * @param topology The complete topology information.
+ * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
+ * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- const char *topology_config);
+GNUNET_TESTING_cmd_netjail_start_testing_system (
+ const char *label,
+ struct GNUNET_TESTING_NetjailTopology *topology,
+ unsigned int *read_file,
+ char *topology_data);
/**
@@ -1160,20 +1153,23 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_stop (const char *label,
- char *topology_config);
+ char *topology_config,
+ unsigned int *read_file);
/**
* Create command.
*
* @param label name for command.
- * @param topology_config Configuration file for the test topology.
+ * @param helper_start_label label of the cmd to start the test system.
+ * @param topology The complete topology information.
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stop_testing_system (const char *label,
- const char *helper_start_label,
- const char *topology_config);
+GNUNET_TESTING_cmd_stop_testing_system (
+ const char *label,
+ const char *helper_start_label,
+ struct GNUNET_TESTING_NetjailTopology *topology);
/**
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 4a6a9368e..b59d2cea1 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -46,7 +46,9 @@ typedef void
char *node_ip,
char *n,
char *m,
- char *local_m);
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file);
typedef void
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 3daa29e1e..a9a1b5a02 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -18,9 +18,6 @@ libexec_PROGRAMS = \
plugindir = $(libdir)/gnunet
-plugin_LTLIBRARIES = \
- libgnunet_test_testing_plugin_testcmd.la
-
lib_LTLIBRARIES = \
libgnunettesting.la
@@ -31,25 +28,12 @@ gnunet_cmds_helper_LDADD = $(XLIB) \
libgnunettesting.la \
$(LTLIBINTL) $(Z_LIBS)
-libgnunet_test_testing_plugin_testcmd_la_SOURCES = \
- test_testing_plugin_testcmd.c
-libgnunet_test_testing_plugin_testcmd_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- $(top_builddir)/src/arm/libgnunetarm.la \
- libgnunettesting.la \
- $(top_builddir)/src/statistics/libgnunetstatistics.la \
- $(LTLIBINTL)
-libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
- $(GN_PLUGIN_LDFLAGS)
-
-
libgnunettesting_la_SOURCES = \
testing_api_cmd_end.c \
testing_api_cmd_finish.c \
testing_api_cmd_local_test_finished.c \
testing_api_cmd_local_test_prepared.c \
testing_api_cmd_send_peer_ready.c \
- testing_api_cmd_block_until_all_peers_started.c \
testing_api_cmd_block_until_external_trigger.c \
testing_api_cmd_netjail_start.c \
testing_api_cmd_netjail_start_testsystem.c \
@@ -59,8 +43,6 @@ libgnunettesting_la_SOURCES = \
testing_api_cmd_system_create.c \
testing_api_cmd_system_destroy.c \
testing_api_cmd_batch.c \
- testing_api_cmd_hello_world.c \
- testing_api_cmd_hello_world_birth.c \
testing_api_loop.c \
testing_api_trait_cmd.c \
testing_api_trait_process.c \
@@ -94,8 +76,6 @@ list_keys_LDADD = \
check_PROGRAMS = \
- test_testing_api_cmd_netjail \
- test_testing_hello_world \
test_testing_portreservation \
test_testing_servicestartup \
test_testing_peerstartup \
@@ -105,32 +85,12 @@ check_PROGRAMS = \
if ENABLE_TEST_RUN
AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
TESTS = \
- test_testing_api_cmd_netjail \
- test_testing_hello_world \
test_testing_portreservation \
test_testing_peerstartup \
test_testing_peerstartup2 \
test_testing_servicestartup
endif
-#test_testing_topology_SOURCES = \
-# test_testing_topology.c
-#test_testing_topology_LDADD = \
-# libgnunettesting.la \
-# $(top_builddir)/src/util/libgnunetutil.la
-
-test_testing_api_cmd_netjail_SOURCES = \
- test_testing_api_cmd_netjail.c
-test_testing_api_cmd_netjail_LDADD = \
- libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
-test_testing_hello_world_SOURCES = \
- test_testing_hello_world.c
-test_testing_hello_world_LDADD = \
- libgnunettesting.la \
- $(top_builddir)/src/util/libgnunetutil.la
-
test_testing_portreservation_SOURCES = \
test_testing_portreservation.c
test_testing_portreservation_LDADD = \
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 4aeccb115..f90cc3cc4 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -142,6 +142,16 @@ struct NodeIdentifier
*
*/
char *local_m;
+
+ /**
+ * Shall we read the topology from file, or from a string.
+ */
+ unsigned int *read_file;
+
+ /**
+ * String with topology data or name of topology file.
+ */
+ char *topology_data;
};
/**
@@ -402,7 +412,8 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
strcat (node_ip, plugin->m);
plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
- plugin->n, plugin->local_m);
+ plugin->n, plugin->local_m, ni->topology_data,
+ ni->read_file);
GNUNET_free (binary);
@@ -559,6 +570,10 @@ main (int argc, char **argv)
struct GNUNET_GETOPT_CommandLineOption options[] =
{ GNUNET_GETOPT_OPTION_END };
int ret;
+ int i;
+ size_t topology_data_length = 0;
+ unsigned int read_file;
+ char cr[1] = "\n";
GNUNET_log_setup ("gnunet-cmds-helper",
"DEBUG",
@@ -569,6 +584,30 @@ main (int argc, char **argv)
ni->m = argv[3];
ni->n = argv[4];
+ sscanf (argv[5], "%u", &read_file);
+
+ if (1 == read_file)
+ ni->topology_data = argv[6];
+ else
+ {
+ for (i = 6; i<argc; i++)
+ topology_data_length += strlen (argv[i]) + 1;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "topo data length %lu\n",
+ topology_data_length);
+ ni->topology_data = GNUNET_malloc (topology_data_length);
+ for (i = 6; i<argc; i++)
+ {
+ strcat (ni->topology_data, argv[i]);
+ strcat (ni->topology_data, cr);
+ }
+ }
+ ni->read_file = &read_file;
+ ni->topology_data[topology_data_length - 1] = '\0';
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "topo data %s\n",
+ ni->topology_data);
+
status = GNUNET_OK;
if (NULL ==
(sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
diff --git a/src/testing/test_testing_api_cmd_netjail.c b/src/testing/test_testing_api_cmd_netjail.c
deleted file mode 100644
index aeddfb7c9..000000000
--- a/src/testing/test_testing_api_cmd_netjail.c
+++ /dev/null
@@ -1,87 +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/test_testbed_api_cmd_netjail.c
- * @brief Test case executing a script in a network name space.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_util_lib.h"
-
-
-/**
- * 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-1",
- "2",
- "2"),
- GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1",
- "2",
- "2",
- "libgnunet_plugin_testcmd",
- &rv),
- GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
- "netjail-start-testbed-1",
- "2",
- "2"),
- GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1",
- "2",
- "2"),
- GNUNET_TESTING_cmd_end ()
- };
-
- GNUNET_TESTING_run (NULL,
- commands,
- GNUNET_TIME_UNIT_FOREVER_REL);
-}
-
-
-int
-main (int argc,
- char *const *argv)
-{
- int rv = 0;
-
- 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/testing/test_testing_hello_world.c b/src/testing/test_testing_hello_world.c
deleted file mode 100644
index 6300e26a4..000000000
--- a/src/testing/test_testing_hello_world.c
+++ /dev/null
@@ -1,68 +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/test_testing_hello_world.c
- * @brief hello world test case
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_util_lib.h"
-
-/**
- * Main function to run the test cases.
- *
- * @param cls not used.
- *
- */
-static void
-run (void *cls)
-{
- (void *) cls;
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-
- struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
- &now),
- GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
- GNUNET_TESTING_cmd_end ()
- };
-
- GNUNET_TESTING_run (NULL,
- commands,
- GNUNET_TIME_UNIT_FOREVER_REL);
-}
-
-int
-main (int argc,
- char *const *argv)
-{
- int rv = 0;
-
- GNUNET_log_setup ("test-hello-world",
- "DEBUG",
- NULL);
-
- GNUNET_SCHEDULER_run (&run,
- NULL);
-
- return rv;
-}
diff --git a/src/testing/test_testing_plugin_testcmd.c b/src/testing/test_testing_plugin_testcmd.c
deleted file mode 100644
index 32e2b38a7..000000000
--- a/src/testing/test_testing_plugin_testcmd.c
+++ /dev/null
@@ -1,123 +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 testbed/plugin_testcmd.c
- * @brief a plugin to provide the API for running test cases.
- * @author t3sserakt
- *
- * // FIXME: too verbose, no logic to return final status, will segv!
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-
-
-// FIXME: bad global!
-unsigned int are_all_peers_started;
-
-
-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);
-}
-
-
-static void
-start_testcase (TESTING_CMD_HELPER_write_cb write_message,
- char *router_ip,
- char *node_ip,
- char *n,
- char *m,
- char *local_m)
-{
- struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 6!\n");
-
- are_all_peers_started = GNUNET_NO;
-
- struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
- &now),
- GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
- GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
- write_message),
- GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
- &are_all_peers_started),
- GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
- write_message)
- };
-
- GNUNET_TESTING_run (commands,
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, /* FIXME: pass continuation! */
- NULL);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "We got here 7!\n");
-
-}
-
-
-/**
- * Entry point for the plugin.
- *
- * @param cls NULL
- * @return the exported block API
- */
-void *
-libgnunet_plugin_testcmd_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_plugin_block_test_init
- * @return NULL
- */
-void *
-libgnunet_plugin_testcmd_done (void *cls)
-{
- struct GNUNET_TESTING_PluginFunctions *api = cls;
-
- GNUNET_free (api);
- return NULL;
-}
-
-
-
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
deleted file mode 100644
index cfc91e609..000000000
--- a/src/testing/test_testing_topology.c
+++ /dev/null
@@ -1,44 +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 testbed/plugin_testcmd.c
- * @brief a plugin to provide the API for running test cases.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
-
-int
-main (int argc,
- char *const *argv)
-{
- GNUNET_log_setup ("test-topology",
- "DEBUG",
- NULL);
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Test\n");
- GNUNET_TESTING_get_topo_from_file ("topo.conf");
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Test2\n");
-}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 02cedc744..4ccf93c6b 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -33,7 +33,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
-#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
@@ -2102,6 +2102,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
struct GNUNET_HashCode hc;
struct GNUNET_TESTING_NetjailNamespace *namespace;
unsigned int namespace_n, node_m;
+ struct GNUNET_TESTING_NodeConnection *node_connections = NULL;
LOG (GNUNET_ERROR_TYPE_DEBUG,
"gaga 1\n");
@@ -2121,6 +2122,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
sizeof (*hkey));
node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
hkey);
+ node_connections = node->node_connections_head;
}
else
{
@@ -2147,10 +2149,11 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
sizeof (*hkey));
node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
hkey);
+ node_connections = node->node_connections_head;
}
GNUNET_free (hkey);
- return node->node_connections_head;
+ return node_connections;
}
@@ -2355,16 +2358,14 @@ GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv)
/**
- * Getting the topology from file.
+ * Parse the topology data.
*
- * @param filename The name of the topology file.
+ * @param data The topology data.
* @return The GNUNET_TESTING_NetjailTopology
*/
struct GNUNET_TESTING_NetjailTopology *
-GNUNET_TESTING_get_topo_from_file (const char *filename)
+GNUNET_TESTING_get_topo_from_string (char *data)
{
- uint64_t fs;
- char *data;
char *token;
char *key = NULL;
unsigned int out;
@@ -2379,36 +2380,9 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
struct GNUNET_ShortHashCode *hkey;
struct GNUNET_HashCode hc;
- if (GNUNET_YES != GNUNET_DISK_file_test (filename))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Topology file %s not found\n"),
- filename);
- return NULL;
- }
- if (GNUNET_OK !=
- GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Topology file %s has no data\n"),
- filename);
- return NULL;
- }
- data = GNUNET_malloc (fs);
- if (fs != GNUNET_DISK_fn_read (filename, data, fs))
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- _ ("Topology file %s cannot be read\n"),
- filename);
- GNUNET_free (data);
- return NULL;
- }
-
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "data: %s\n",
+ "data %s\n",
data);
-
- data[fs] = '\0';
token = strtok_r (data, "\n", &rest);
topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology);
topo->map_namespaces =
@@ -2626,7 +2600,62 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
node_connections (token, node);
}
token = strtok_r (NULL, "\n", &rest);
+ if (NULL != token)
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "Next token %s\n",
+ token);
+ }
+
+ return topo;
+}
+
+
+/**
+ * Getting the topology from file.
+ *
+ * @param filename The name of the topology file.
+ * @return The GNUNET_TESTING_NetjailTopology
+ */
+struct GNUNET_TESTING_NetjailTopology *
+GNUNET_TESTING_get_topo_from_file (const char *filename)
+{
+ uint64_t fs;
+ char *data;
+ struct GNUNET_TESTING_NetjailTopology *topo;
+
+ if (GNUNET_YES != GNUNET_DISK_file_test (filename))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Topology file %s not found\n"),
+ filename);
+ return NULL;
+ }
+ if (GNUNET_OK !=
+ GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Topology file %s has no data\n"),
+ filename);
+ return NULL;
}
+ data = GNUNET_malloc (fs);
+ if (fs != GNUNET_DISK_fn_read (filename, data, fs))
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ _ ("Topology file %s cannot be read\n"),
+ filename);
+ GNUNET_free (data);
+ return NULL;
+ }
+
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "data: %s\n",
+ data);
+
+ data[fs] = '\0';
+
+ topo = GNUNET_TESTING_get_topo_from_string (data);
+
GNUNET_free (data);
return topo;
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
deleted file mode 100644
index 763713e15..000000000
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ /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
- */
-
-/**
- * @file testing_api_cmd_block_until_all_peers_started.c
- * @brief cmd to block the interpreter loop until all peers started.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-/**
- * Generic logging shortcut
- */
-#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-
-/**
- * Struct with information for callbacks.
- *
- */
-struct BlockState
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- /**
- * Flag to indicate if all peers have started.
- *
- */
- unsigned int *all_peers_started;
-};
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-block_until_all_peers_started_cleanup (void *cls)
-{
- struct BlockState *bs = cls;
-
- GNUNET_free (bs);
-}
-
-
-/**
- * This function does nothing but to start the cmd.
- *
- */
-static void
-block_until_all_peers_started_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "block_until_all_peers_started_run!\n");
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param all_peers_started Flag which will be set from outside.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
- unsigned int *
- all_peers_started)
-{
- struct BlockState *bs;
-
- bs = GNUNET_new (struct BlockState);
- bs->all_peers_started = all_peers_started;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = bs,
- .label = label,
- .run = &block_until_all_peers_started_run,
- .ac = &bs->ac,
- .cleanup = &block_until_all_peers_started_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
index aeb9ffda3..7ff554280 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
/**
* Generic logging shortcut
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c
index 3ac0871a5..47199d3d6 100644
--- a/src/testing/testing_api_cmd_finish.c
+++ b/src/testing/testing_api_cmd_finish.c
@@ -25,6 +25,8 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
+
/**
* Struct to use for command-specific context information closure of a command waiting
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
deleted file mode 100644
index 73dcd6dff..000000000
--- a/src/testing/testing_api_cmd_hello_world.c
+++ /dev/null
@@ -1,126 +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 implementation of a hello world command.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-
-struct HelloWorldState
-{
- char *message;
- const char *birthLabel;
-};
-
-
-/**
- *
- *
- * @param cls closure
- */
-static void
-hello_world_cleanup (void *cls)
-{
- struct HelloWorldState *hs = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Cleaning up message %s\n",
- hs->message);
- GNUNET_free (hs);
-}
-
-
-/**
- *
- *
- * @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 enum GNUNET_GenericReturnValue
-hello_world_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_NO;
-}
-
-
-/**
-* Run the "hello world" CMD.
-*
-* @param cls closure.
-* @param is interpreter state.
-*/
-static void
-hello_world_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct HelloWorldState *hs = cls;
- const struct GNUNET_TESTING_Command *birth_cmd;
-
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "%s\n",
- hs->message);
- birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- hs->birthLabel);
- GNUNET_TESTING_get_trait_what_am_i (birth_cmd,
- &hs->message);
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Now I am a %s\n",
- hs->message);
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param message initial message.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_hello_world (const char *label,
- const char *birthLabel,
- char *message)
-{
- struct HelloWorldState *hs;
-
- hs = GNUNET_new (struct HelloWorldState);
- hs->message = "Hello World, I was nobody!";
- hs->birthLabel = birthLabel;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = hs,
- .label = label,
- .run = &hello_world_run,
- .cleanup = &hello_world_cleanup,
- .traits = &hello_world_traits
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
deleted file mode 100644
index 8415b99f0..000000000
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ /dev/null
@@ -1,161 +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 implementation of a hello world command.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-struct HelloWorldBirthState
-{
- struct GNUNET_TIME_Absolute *date;
- char *what_am_i;
-};
-
-/**
-*
-*
-* @param cls closure
-* @param cmd current CMD being cleaned up.
-*/
-static void
-hello_world_birth_cleanup (void *cls)
-{
- struct HelloWorldBirthState *hbs = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "Finished birth of %s\n",
- hbs->what_am_i);
-}
-
-
-/**
-*
-*
-* @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
-hello_world_birth_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct HelloWorldBirthState *hbs = cls;
- const char *what_am_i = hbs->what_am_i;
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "what_am_i",
- .ptr = (const void *) what_am_i,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
-* Run the "hello world" CMD.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-hello_world_birth_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct HelloWorldBirthState *hbs = cls;
- struct GNUNET_TIME_Relative relative;
-
- relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
- GNUNET_TIME_absolute_get ());
-
- if (0 == relative.rel_value_us % 10)
- {
- hbs->what_am_i = "creature!";
- }
- else if (0 == relative.rel_value_us % 2)
- {
- hbs->what_am_i = "girl!";
- }
- else
- {
- hbs->what_am_i = "boy!";
- }
-}
-
-
-/**
- * Offer data 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_what_am_i (const struct GNUNET_TESTING_Command *cmd,
- char **what_am_i)
-{
- return cmd->traits (cmd->cls,
- (const void **) what_am_i,
- "what_am_i",
- (unsigned int) 0);
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param now when the command was started.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_hello_world_birth (const char *label,
- struct GNUNET_TIME_Absolute *now)
-{
- struct HelloWorldBirthState *hbs;
-
- hbs = GNUNET_new (struct HelloWorldBirthState);
- hbs->date = now;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = hbs,
- .label = label,
- .run = &hello_world_birth_run,
- .cleanup = &hello_world_birth_cleanup,
- .traits = &hello_world_birth_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 8f8a8230c..709c6b62f 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
/**
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 2554d6fec..9dc7dfa9a 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
/**
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 35fb90f3c..2ff70c33e 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -26,8 +26,11 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
-#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh"
+#define NETJAIL_START_SCRIPT "netjail_start.sh"
+
+#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
/**
* Struct to hold information for callbacks.
@@ -53,6 +56,10 @@ struct NetJailState
*/
char *topology_config;
+ /**
+ * Shall we read the topology from file, or from a string.
+ */
+ unsigned int *read_file;
};
@@ -70,11 +77,15 @@ netjail_start_cleanup (void *cls)
if (NULL != ns->cwh)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cancel child\n");
GNUNET_wait_child_cancel (ns->cwh);
ns->cwh = NULL;
}
if (NULL != ns->start_proc)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Kill process\n");
GNUNET_assert (0 ==
GNUNET_OS_process_kill (ns->start_proc,
SIGKILL));
@@ -100,6 +111,7 @@ child_completed_callback (void *cls,
GNUNET_OS_process_destroy (ns->start_proc);
ns->start_proc = NULL;
+ ns->cwh = NULL;
if (0 == exit_code)
{
GNUNET_TESTING_async_finish (&ns->ac);
@@ -127,20 +139,28 @@ netjail_start_run (void *cls,
struct NetJailState *ns = cls;
char pid[15];
enum GNUNET_GenericReturnValue helper_check;
+ char *data_dir;
+ char *script_name;
+ char *read_file;
+
+ data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_START_SCRIPT);
+ GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
- // FIXME: NETJAIL_START_SCRIPT like this is bad,
- // use location from share/gnunet/ of installed
- // binary in case libgnunettesting is used as a lib!
helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_START_SCRIPT,
+ script_name,
GNUNET_YES,
NULL);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "script_name %s\n",
+ script_name);
+
if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
- NETJAIL_START_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
return;
}
@@ -148,7 +168,7 @@ netjail_start_run (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
- NETJAIL_START_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
return;
}
@@ -159,9 +179,10 @@ netjail_start_run (void *cls,
getpid ());
{
char *const script_argv[] = {
- NETJAIL_START_SCRIPT,
+ script_name,
ns->topology_config,
pid,
+ read_file,
NULL
};
@@ -170,7 +191,7 @@ netjail_start_run (void *cls,
NULL,
NULL,
NULL,
- NETJAIL_START_SCRIPT,
+ script_name,
script_argv);
}
ns->cwh = GNUNET_wait_child (ns->start_proc,
@@ -189,12 +210,14 @@ netjail_start_run (void *cls,
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start (const char *label,
- char *topology_config)
+ char *topology_config,
+ unsigned int *read_file)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
ns->topology_config = topology_config;
+ ns->read_file = read_file;
{
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index c3598d174..89c193de5 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -25,9 +25,10 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
-#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh"
+#define NETJAIL_EXEC_SCRIPT "netjail_exec.sh"
/**
* Generic logging shortcut
@@ -83,18 +84,6 @@ struct NetJailState
struct GNUNET_TESTING_NetjailTopology *topology;
/**
- * 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;
-
- /**
* Array with handles of helper processes.
*/
struct GNUNET_HELPER_Handle **helper;
@@ -123,27 +112,6 @@ struct NetJailState
*/
unsigned int known;
- /**
- * The send handle for the helper
- */
- // struct GNUNET_HELPER_SendHandle **shandle;
-
- /**
- * Size of the array NetJailState#shandle.
- *
- */
- // unsigned int n_shandle;
-
- /**
- * 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.
@@ -176,16 +144,14 @@ struct NetJailState
char *plugin_name;
/**
- * HEAD of the DLL containing TestingSystemCount.
- *
+ * Shall we read the topology from file, or from a string.
*/
- struct TestingSystemCount *tbcs_head;
+ unsigned int *read_file;
/**
- * TAIL of the DLL containing TestingSystemCount.
- *
+ * String with topology data or name of topology file.
*/
- struct TestingSystemCount *tbcs_tail;
+ char *topology_data;
};
/**
@@ -207,13 +173,7 @@ struct TestingSystemCount
/**
* The send handle for the helper
*/
- struct GNUNET_HELPER_SendHandle *shandle;// **shandle;
-
- /**
- * Size of the array NetJailState#shandle.
- *
- */
- // unsigned int n_shandle;
+ struct GNUNET_HELPER_SendHandle *shandle;
/**
* The number of the test environment.
@@ -226,6 +186,11 @@ struct TestingSystemCount
*
*/
struct NetJailState *ns;
+
+ /**
+ * The messages send to the helper.
+ */
+ struct GNUNET_MessageHeader *msg;
};
/**
@@ -237,24 +202,7 @@ static void
netjail_exec_cleanup (void *cls)
{
struct NetJailState *ns = cls;
- struct HelperMessage *message_pos;
- struct TestingSystemCount *tbc_pos;
- 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_TESTING_free_topology (ns->topology);
GNUNET_free (ns);
}
@@ -271,7 +219,6 @@ netjail_exec_traits (void *cls,
{
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[] = {
@@ -280,11 +227,6 @@ netjail_exec_traits (void *cls,
.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 ()
};
@@ -327,12 +269,12 @@ static void
clear_msg (void *cls, int result)
{
struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
- GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]);
- tbc->shandle = NULL;// [tbc->count - 1] = NULL;
- GNUNET_free (ns->msg[tbc->count - 1]);
- ns->msg[tbc->count - 1] = NULL;
+ GNUNET_assert (NULL != tbc->shandle);
+ GNUNET_free (tbc->shandle);
+ tbc->shandle = NULL;
+ GNUNET_free (tbc->msg);
+ tbc->msg = NULL;
}
@@ -361,7 +303,7 @@ send_message_to_locals (
helper = ns->helper[tbc->count - 1];// - total_number];
- GNUNET_array_append (ns->msg, ns->n_msg, header);
+
struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
helper,
@@ -427,7 +369,7 @@ static int
helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
{
// struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = cls;// tbc->ns;
+ struct NetJailState *ns = cls;
struct HelperMessage *hp_msg;
unsigned int total_number = ns->local_m * ns->global_n + ns->known;
// uint16_t message_type = ntohs (message->type);
@@ -543,11 +485,8 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
}
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);
+ // We received a message we can not handle.
+ GNUNET_assert (0);
}
@@ -629,6 +568,7 @@ start_helper (struct NetJailState *ns,
char *known_char;
char *node_id;
char *plugin;
+ char *read_file;
pid_t pid;
unsigned int script_num;
struct GNUNET_ShortHashCode *hkey;
@@ -636,6 +576,9 @@ start_helper (struct NetJailState *ns,
struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
struct GNUNET_TESTING_NetjailNode *node;
struct GNUNET_TESTING_NetjailNamespace *namespace;
+ char *data_dir;
+ char *script_name;
+ char *topology_data;
if (0 == n)
@@ -652,47 +595,31 @@ start_helper (struct NetJailState *ns,
GNUNET_asprintf (&node_id, "%06x-%08x\n",
pid,
script_num);
+ // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
+ GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
-
- char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
- m_char,
- n_char,
- GNUNET_OS_get_libexec_binary_path (
- HELPER_CMDS_BINARY),
- global_n_char,
- local_m_char,
- node_id,
- NULL};
-
+ data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT);
unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_EXEC_SCRIPT,
+ script_name,
GNUNET_YES,
NULL);
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
- if (0 == n)
- tbc->count = m;
- else
- tbc->count = (n - 1) * ns->local_m + m + ns->known;
-
- GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
- ns->tbcs_tail,
- tbc);
-
if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
- NETJAIL_EXEC_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (ns->is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
- NETJAIL_EXEC_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (ns->is);
}
@@ -705,17 +632,29 @@ start_helper (struct NetJailState *ns,
ns->local_m,
ns->global_n,
ns->known);
+ {
+ char *const script_argv[] = {script_name,
+ m_char,
+ n_char,
+ GNUNET_OS_get_libexec_binary_path (
+ HELPER_CMDS_BINARY),
+ global_n_char,
+ local_m_char,
+ node_id,
+ read_file,
+ ns->topology_data,
+ NULL};
+ helper = GNUNET_HELPER_start (
+ GNUNET_YES,
+ script_name,
+ script_argv,
+ &helper_mst,
+ &exp_cb,
+ ns);
+ GNUNET_array_append (ns->helper, ns->n_helper, helper);
+ }
- GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
- GNUNET_YES,
- NETJAIL_EXEC_SCRIPT,
- script_argv,
- &helper_mst,
- &exp_cb,
- ns));
-
- helper = ns->helper[tbc->count - 1];
-
+ tbc->count = ns->n_helper;
hkey = GNUNET_new (struct GNUNET_ShortHashCode);
plugin = topology->plugin;
@@ -767,8 +706,6 @@ start_helper (struct NetJailState *ns,
msg = create_helper_init_msg_ (plugin);
- GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
-
// GNUNET_array_append (tbc->shandle, tbc->n_shandle,
tbc->shandle = GNUNET_HELPER_send (
helper,
@@ -825,24 +762,28 @@ netjail_exec_run (void *cls,
* Create command.
*
* @param label Name for the command.
- * @param topology_config Configuration file for the test topology.
+ * @param topology The complete topology information.
+ * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
+ * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- const char *topology_config)
+GNUNET_TESTING_cmd_netjail_start_testing_system (
+ const char *label,
+ struct GNUNET_TESTING_NetjailTopology *topology,
+ unsigned int *read_file,
+ char *topology_data)
{
struct NetJailState *ns;
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
ns = GNUNET_new (struct NetJailState);
ns->local_m = topology->nodes_m;
ns->global_n = topology->namespaces_n;
ns->known = topology->nodes_x;
ns->plugin_name = topology->plugin;
ns->topology = topology;
+ ns->read_file = read_file;
+ ns->topology_data = topology_data;
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 5033272a3..e3bf7da62 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -26,12 +26,10 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
-#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
-
-// Child Wait handle
-static struct GNUNET_ChildWaitHandle *cwh;
+#define NETJAIL_STOP_SCRIPT "netjail_stop.sh"
/**
* Struct to hold information for callbacks.
@@ -44,6 +42,9 @@ struct NetJailState
*/
struct GNUNET_TESTING_AsyncContext ac;
+ // Child Wait handle
+ struct GNUNET_ChildWaitHandle *cwh;
+
/**
* Configuration file for the test topology.
*/
@@ -54,6 +55,11 @@ struct NetJailState
*/
struct GNUNET_OS_Process *stop_proc;
+ /**
+ * Shall we read the topology from file, or from a string.
+ */
+ unsigned int *read_file;
+
};
@@ -66,10 +72,10 @@ netjail_stop_cleanup (void *cls)
{
struct NetJailState *ns = cls;
- if (NULL != cwh)
+ if (NULL != ns->cwh)
{
- GNUNET_wait_child_cancel (cwh);
- cwh = NULL;
+ GNUNET_wait_child_cancel (ns->cwh);
+ ns->cwh = NULL;
}
if (NULL != ns->stop_proc)
{
@@ -95,7 +101,7 @@ child_completed_callback (void *cls,
{
struct NetJailState *ns = cls;
- cwh = NULL; // WTF? globals!?!?!
+ ns->cwh = NULL;
GNUNET_OS_process_destroy (ns->stop_proc);
ns->stop_proc = NULL;
if (0 == exit_code)
@@ -121,16 +127,16 @@ netjail_stop_run (void *cls,
{
struct NetJailState *ns = cls;
char *pid;
+ char *data_dir;
+ char *script_name;
+ char *read_file;
- GNUNET_asprintf (&pid,
- "%u",
- getpid ());
- char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
- ns->topology_config,
- pid,
- NULL};
+
+ data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
+ GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT);
+ GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_STOP_SCRIPT,
+ script_name,
GNUNET_YES,
NULL);
@@ -138,39 +144,50 @@ netjail_stop_run (void *cls,
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
- NETJAIL_STOP_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
- NETJAIL_STOP_SCRIPT);
+ script_name);
GNUNET_TESTING_interpreter_fail (is);
}
- ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_STOP_SCRIPT,
- script_argv);
-
- cwh = GNUNET_wait_child (ns->stop_proc,
- &child_completed_callback,
- ns);
- GNUNET_break (NULL != cwh);
+ GNUNET_asprintf (&pid,
+ "%u",
+ getpid ());
+ {
+ char *const script_argv[] = {script_name,
+ ns->topology_config,
+ pid,
+ read_file,
+ NULL};
+ ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
+ NULL,
+ NULL,
+ NULL,
+ script_name,
+ script_argv);
+ }
+ ns->cwh = GNUNET_wait_child (ns->stop_proc,
+ &child_completed_callback,
+ ns);
+ GNUNET_break (NULL != ns->cwh);
}
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_stop (const char *label,
- char *topology_config)
+ char *topology_config,
+ unsigned int *read_file)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
ns->topology_config = topology_config;
+ ns->read_file = read_file;
{
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index e37e955be..4b52878c4 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
@@ -70,7 +71,6 @@ stop_testing_system_cleanup (void *cls)
{
struct StopHelperState *shs = cls;
- GNUNET_TESTING_free_topology (shs->topology);
GNUNET_free (shs);
}
@@ -124,19 +124,17 @@ stop_testing_system_run (void *cls,
*
* @param label name for command.
* @param helper_start_label label of the cmd to start the test system.
- * @param topology_config Configuration file for the test topology.
+ * @param topology The complete topology information.
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stop_testing_system (const char *label,
- const char *helper_start_label,
- const char *topology_config)
+GNUNET_TESTING_cmd_stop_testing_system (
+ const char *label,
+ const char *helper_start_label,
+ struct GNUNET_TESTING_NetjailTopology *topology)
{
struct StopHelperState *shs;
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
shs = GNUNET_new (struct StopHelperState);
shs->helper_start_label = helper_start_label;
shs->local_m = topology->nodes_m;
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index 8eef1d8f1..5bbabce51 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "testing_cmds.h"
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 820adf1bd..275132684 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_testing_lib.h"
/**
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index 338123d91..cdfc65d53 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_testing_lib.h"
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index d281c4ffb..5fe8229e7 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -738,7 +738,9 @@ endif
endif
check_SCRIPTS= \
+ test_transport_simple_send_string.sh \
test_transport_simple_send.sh \
+ test_transport_simple_send_broadcast.sh \
test_transport_udp_backchannel.sh
test_transport_start_with_config_SOURCES = \
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 659fd7d26..b7a3b4082 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -2262,6 +2262,7 @@ static void
sock_read (void *cls)
{
struct sockaddr_storage sa;
+ struct sockaddr_in *addr_verify;
socklen_t salen = sizeof(sa);
char buf[UINT16_MAX];
ssize_t rcvd;
@@ -2341,12 +2342,22 @@ sock_read (void *cls)
{
const struct UDPBroadcast *ub;
struct UdpBroadcastSignature uhs;
+ struct GNUNET_PeerIdentity sender;
+ addr_verify = GNUNET_memdup (&sa, salen);
+ addr_verify->sin_port = 0;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "received UDPBroadcast from %s\n",
+ GNUNET_a2s ((const struct sockaddr *) addr_verify, salen));
ub = (const struct UDPBroadcast *) buf;
uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
uhs.purpose.size = htonl (sizeof(uhs));
uhs.sender = ub->sender;
- GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address);
+ sender = ub->sender;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "checking UDPBroadcastSignature for %s\n",
+ GNUNET_i2s (&sender));
+ GNUNET_CRYPTO_hash ((struct sockaddr *) addr_verify, salen, &uhs.h_address);
if (GNUNET_OK ==
GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
&uhs,
@@ -2362,10 +2373,23 @@ sock_read (void *cls)
/* use our own mechanism to determine network type */
nt =
GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
- GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "validating address %s received from UDPBroadcast\n",
+ GNUNET_i2s (&sender));
+ GNUNET_TRANSPORT_application_validate (ah, &sender, nt, addr_s);
GNUNET_free (addr_s);
return;
}
+ else
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "VerifyingPeer %s is verifying UDPBroadcast\n",
+ GNUNET_i2s (&my_identity));
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Verifying UDPBroadcast from %s failed\n",
+ GNUNET_i2s (&ub->sender));
+ }
+ GNUNET_free (addr_verify);
/* continue with KX, mostly for statistics... */
}
@@ -3477,7 +3501,7 @@ ifc_broadcast (void *cls)
delay.rel_value_us =
GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
bi->broadcast_task =
- GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi);
+ GNUNET_SCHEDULER_add_delayed (delay, &ifc_broadcast, bi);
switch (bi->sa->sa_family)
{
@@ -3494,6 +3518,12 @@ ifc_broadcast (void *cls)
sizeof(int)))
GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
"setsockopt");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "creating UDPBroadcast from %s\n",
+ GNUNET_i2s (&(bi->bcm.sender)));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "sending UDPBroadcast to add %s\n",
+ GNUNET_a2s (bi->ba, bi->salen));
sent = GNUNET_NETWORK_socket_sendto (udp_sock,
&bi->bcm,
sizeof(bi->bcm),
@@ -3521,6 +3551,8 @@ ifc_broadcast (void *cls)
dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "sending UDPBroadcast\n");
sent = GNUNET_NETWORK_socket_sendto (udp_sock,
&bi->bcm,
sizeof(bi->bcm),
@@ -3608,6 +3640,9 @@ iface_proc (void *cls,
ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
ubs.purpose.size = htonl (sizeof(ubs));
ubs.sender = my_identity;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "creating UDPBroadcastSignature for %s\n",
+ GNUNET_a2s (addr, addrlen));
GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
GNUNET_CRYPTO_eddsa_sign (my_private_key,
&ubs,
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index a90bef3b5..84199a75f 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -4738,15 +4738,17 @@ send_dv_to_neighbour (void *cls,
* @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
*/
static struct GNUNET_TIME_Relative
-route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
+route_control_message_without_fc (struct VirtualLink *vl,
+// route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
const struct GNUNET_MessageHeader *hdr,
enum RouteMessageOptions options)
{
- struct VirtualLink *vl;
+ // struct VirtualLink *vl;
struct Neighbour *n;
struct DistanceVector *dv;
struct GNUNET_TIME_Relative rtt1;
struct GNUNET_TIME_Relative rtt2;
+ const struct GNUNET_PeerIdentity *target = &vl->target;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Trying to route message of type %u to %s without fc\n",
@@ -4754,7 +4756,7 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
GNUNET_i2s (target));
// TODO Do this elsewhere. vl should be given as parameter to method.
- vl = lookup_virtual_link (target);
+ // vl = lookup_virtual_link (target);
GNUNET_assert (NULL != vl);
if (NULL == vl)
return GNUNET_TIME_UNIT_FOREVER_REL;
@@ -4892,7 +4894,7 @@ consider_sending_fc (void *cls)
fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used);
fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size);
fc.sender_time = GNUNET_TIME_absolute_hton (monotime);
- rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE);
+ rtt = route_control_message_without_fc (vl, &fc.header, RMO_NONE);
if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
{
rtt = GNUNET_TIME_UNIT_SECONDS;
@@ -5086,6 +5088,8 @@ handle_communicator_backchannel (
void *cls,
const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
{
+ struct Neighbour *n;
+ struct VirtualLink *vl;
struct TransportClient *tc = cls;
const struct GNUNET_MessageHeader *inbox =
(const struct GNUNET_MessageHeader *) &cb[1];
@@ -5116,7 +5120,22 @@ handle_communicator_backchannel (
+ isize],
is,
strlen (is) + 1);
- route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
+ // route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
+ vl = lookup_virtual_link (&cb->pid);
+ if (NULL != vl)
+ {
+ route_control_message_without_fc (vl, &be->header, RMO_DV_ALLOWED);
+ }
+ else
+ {
+ /* Use route via neighbour */
+ n = lookup_neighbour (&cb->pid);
+ if (NULL != n)
+ route_via_neighbour (
+ n,
+ &be->header,
+ RMO_NONE);
+ }
GNUNET_SERVICE_client_continue (tc->client);
}
@@ -5540,6 +5559,8 @@ destroy_ack_cummulator (void *cls)
static void
transmit_cummulative_ack_cb (void *cls)
{
+ struct Neighbour *n;
+ struct VirtualLink *vl;
struct AcknowledgementCummulator *ac = cls;
char buf[sizeof(struct TransportReliabilityAckMessage)
+ ac->ack_counter
@@ -5566,7 +5587,28 @@ transmit_cummulative_ack_cb (void *cls)
ap[i].ack_delay = GNUNET_TIME_relative_hton (
GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time));
}
- route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED);
+ /*route_control_message_without_fc (
+ &ac->target,
+ &ack->header,
+ RMO_DV_ALLOWED);*/
+ vl = lookup_virtual_link (&ac->target);
+ if (NULL != vl)
+ {
+ route_control_message_without_fc (
+ vl,
+ &ack->header,
+ RMO_DV_ALLOWED);
+ }
+ else
+ {
+ /* Use route via neighbour */
+ n = lookup_neighbour (&ac->target);
+ if (NULL != n)
+ route_via_neighbour (
+ n,
+ &ack->header,
+ RMO_NONE);
+ }
ac->num_acks = 0;
ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT,
&destroy_ack_cummulator,
@@ -6558,6 +6600,8 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
const struct DVPathEntryP *hops,
struct GNUNET_TIME_Absolute in_time)
{
+ struct Neighbour *n;
+ struct VirtualLink *vl;
struct DVPathEntryP *dhops;
char buf[sizeof(struct TransportDVLearnMessage)
+ (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN;
@@ -6598,9 +6642,26 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
&dhp,
&dhops[nhops].hop_sig);
}
- route_control_message_without_fc (next_hop,
+ /*route_control_message_without_fc (next_hop,
&fwd->header,
- RMO_UNCONFIRMED_ALLOWED);
+ RMO_UNCONFIRMED_ALLOWED);*/
+ vl = lookup_virtual_link (next_hop);
+ if (NULL != vl)
+ {
+ route_control_message_without_fc (vl,
+ &fwd->header,
+ RMO_UNCONFIRMED_ALLOWED);
+ }
+ else
+ {
+ /* Use route via neighbour */
+ n = lookup_neighbour (next_hop);
+ if (NULL != n)
+ route_via_neighbour (
+ n,
+ &fwd->header,
+ RMO_UNCONFIRMED_ALLOWED);
+ }
}
@@ -7937,7 +7998,8 @@ handle_validation_challenge (
vl = lookup_virtual_link (&sender);
if (NULL != vl)
{
- route_control_message_without_fc (&cmc->im.sender,
+ // route_control_message_without_fc (&cmc->im.sender,
+ route_control_message_without_fc (vl,
&tvr.header,
RMO_ANYTHING_GOES | RMO_REDUNDANT);
}
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index c374fc2d0..2c987e601 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_application_service.h"
#include "transport-testing2.h"
@@ -213,7 +214,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *node_ip,
char *m,
char *n,
- char *local_m)
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file)
{
unsigned int n_int;
@@ -221,8 +224,16 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
unsigned int local_m_int;
unsigned int num;
struct TestState *ts = GNUNET_new (struct TestState);
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ if (GNUNET_YES == *read_file)
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "read from file\n");
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ }
+ else
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
ts->topology = topology;
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index f3afbec48..db320844f 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_transport_application_service.h"
#include "transport-testing2.h"
@@ -207,7 +208,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *node_ip,
char *m,
char *n,
- char *local_m)
+ char *local_m,
+ char *topology_data,
+ unsigned int *read_file)
{
unsigned int n_int;
@@ -216,8 +219,12 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
unsigned int num;
struct TestState *ts = GNUNET_new (struct TestState);
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ if (GNUNET_YES == *read_file)
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ else
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
ts->topology = topology;
diff --git a/src/transport/test_transport_simple_send_string.sh b/src/transport/test_transport_simple_send_string.sh
new file mode 100755
index 000000000..018ea55e8
--- /dev/null
+++ b/src/transport/test_transport_simple_send_string.sh
@@ -0,0 +1,16 @@
+#!/bin/bash
+string=$(cat << EOF
+M:2
+N:1
+X:0
+T:libgnunet_test_transport_plugin_cmd_simple_send
+P:1:1|{connect:{P:1:2:tcp}}
+P:1:2|{connect:{P:1:1:tcp}}
+EOF
+)
+if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then
+ exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config -s '$string'"
+else
+ echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
+ exit 78
+fi
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
index 932b0e583..7eb92d629 100644
--- a/src/transport/test_transport_start_with_config.c
+++ b/src/transport/test_transport_start_with_config.c
@@ -25,6 +25,7 @@
*/
#include "platform.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_util_lib.h"
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
@@ -34,27 +35,86 @@ int
main (int argc,
char *const *argv)
{
- char *topology_config;
+ char *topology_data;
+ char *topology_data_script;
+ struct GNUNET_TESTING_NetjailTopology *topology;
+ unsigned int read_file = GNUNET_YES;
+ int ret;
+ char *rest = NULL;
+ char *token;
+ size_t single_line_len;
+ size_t data_len;
GNUNET_log_setup ("test-netjail",
"DEBUG",
NULL);
- topology_config = argv[1];
+ if (0 == strcmp ("-s", argv[1]))
+ {
+ data_len = strlen (argv[2]);
+ topology_data = GNUNET_malloc (data_len);
+ topology_data_script = GNUNET_malloc (data_len);
+ token = strtok_r (argv[2], "\n", &rest);
+ while (NULL != token)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "token1 %s\n",
+ token);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "token2 %s\n",
+ token);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "topology_data %s\n",
+ topology_data);
+ strcat (topology_data_script, token);
+ strcat (topology_data_script, " ");
+ strcat (topology_data, token);
+ strcat (topology_data, "\n");
+ token = strtok_r (NULL, "\n", &rest);
+ }
+ single_line_len = strlen (topology_data);
+ topology_data_script [single_line_len - 1] = '\0';
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "read from string\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "topology_data %s\n",
+ topology_data);
+ read_file = GNUNET_NO;
+ topology = GNUNET_TESTING_get_topo_from_string (topology_data);
+ }
+ else
+ {
+ topology_data = argv[1];
+ topology_data_script = argv[1];
+ topology = GNUNET_TESTING_get_topo_from_file (topology_data);
+ }
struct GNUNET_TESTING_Command commands[] = {
GNUNET_TESTING_cmd_netjail_start ("netjail-start",
- topology_config),
+ topology_data_script,
+ &read_file),
GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
- topology_config),
+ topology,
+ &read_file,
+ topology_data_script),
GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
"netjail-start-testbed",
- topology_config),
+ topology),
GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
- topology_config),
+ topology_data_script,
+ &read_file),
GNUNET_TESTING_cmd_end ()
};
- return GNUNET_TESTING_main (commands,
- TIMEOUT);
+ ret = GNUNET_TESTING_main (commands,
+ TIMEOUT);
+
+ if (0 == strcmp ("-s", argv[1]))
+ {
+ GNUNET_free (topology_data_script);
+ GNUNET_free (topology_data);
+ }
+ GNUNET_TESTING_free_topology (topology);
+
+ return ret;
}
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
index 03b231347..529b4690b 100644
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -27,6 +27,7 @@
#include "gnunet_common.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_transport_service.h"
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 2eb1b0914..b50b63c62 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_transport_application_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_transport_service.h"
@@ -91,6 +92,10 @@ connect_peers_run (void *cls,
addr = GNUNET_TESTING_get_address (pos_connection,
pos_prefix->address_prefix);
peer = GNUNET_TESTING_get_pub_key (num, tl_system);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "validating peer number %u with identity %s\n",
+ num,
+ GNUNET_i2s (peer));
GNUNET_TRANSPORT_application_validate (ah,
peer,
nt,
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 9c34c50d7..790139cce 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "transport-testing2.h"
#include "transport-testing-cmds.h"
diff --git a/src/transport/transport_api_cmd_send_simple_v3.c b/src/transport/transport_api_cmd_send_simple_v3.c
deleted file mode 100644
index a4ce2c4e9..000000000
--- a/src/transport/transport_api_cmd_send_simple_v3.c
+++ /dev/null
@@ -1,194 +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_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;
-
- /**
- * Label of the cmd which started the test system.
- *
- */
- const char *create_label;
-
- /**
- * The topology we get the connected nodes from.
- */
- struct GNUNET_TESTING_NetjailTopology *topology;
-};
-
-
-/**
- * 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 peers.
- *
- */
-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;
- struct GNUNET_TESTING_NodeConnection *node_connections_head;
- struct GNUNET_PeerIdentity *peer;
- struct GNUNET_CRYPTO_EddsaPublicKey public_key;
- uint32_t num;
- struct GNUNET_TESTING_NodeConnection *pos_connection;
- const struct GNUNET_TESTING_Command *system_cmd;
- struct GNUNET_TESTING_System *tl_system;
-
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
- GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
- &connected_peers_map);
-
- system_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->create_label);
- GNUNET_TESTING_get_trait_test_system (system_cmd,
- &tl_system);
-
- node_connections_head = GNUNET_TESTING_get_connections (sss->num,
- sss->topology);
-
- for (int i = 0; i < 1; i++)
- {
- for (pos_connection = node_connections_head; NULL != pos_connection;
- pos_connection = pos_connection->next)
- {
- num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology);
- peer = GNUNET_TESTING_get_pub_key (num, tl_system);
- public_key = peer->public_key;
- GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
-
- memcpy (key,
- &hc,
- sizeof (*key));
- mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
- key);
- env = GNUNET_MQ_msg_extra (test,
- 1000 - sizeof(*test),
- GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
- test->num = htonl (sss->num);
- memset (&test[1],
- sss->num,
- 1000 - sizeof(*test));
- GNUNET_MQ_send (mq,
- env);
- }
- }
-
- GNUNET_free (key);
-
-}
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param start_peer_label Label of the cmd to start a peer.
- * @param start_peer_label Label of the cmd which started the test system.
- * @param num Number globally identifying the node.
- * @param The topology for the test setup.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
- const char *start_peer_label,
- const char *create_label,
- uint32_t num,
- struct GNUNET_TESTING_NetjailTopology *
- topology)
-{
- struct SendSimpleState *sss;
-
- sss = GNUNET_new (struct SendSimpleState);
- sss->num = num;
- sss->start_peer_label = start_peer_label;
- sss->create_label = create_label;
- sss->topology = topology;
-
- 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 a026d48cc..60f416f85 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"
@@ -172,6 +173,7 @@ start_peer_run (void *cls,
char *tcp_communicator_unix_path;
char *udp_communicator_unix_path;
char *bindto;
+ char *bindto_udp;
if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
{
@@ -207,6 +209,9 @@ start_peer_run (void *cls,
"%s:60002",
sps->node_ip);
+ GNUNET_asprintf (&bindto_udp,
+ "2086");
+
LOG (GNUNET_ERROR_TYPE_ERROR,
"node_ip %s\n",
bindto);
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index dcb982a65..97408b083 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -26,6 +26,7 @@
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "gnunet_testing_netjail_lib.h"
#include "gnunet_peerstore_service.h"
#include "gnunet_transport_core_service.h"
#include "gnunet_transport_application_service.h"