summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
committert3sserakt <t3ss@posteo.de>2021-10-14 16:39:24 +0200
commitd64ac269856744b9bab170964e1d6f36896ecc55 (patch)
treeed5aa79b91fe3cf9388433a5611581b7ce3b846c /src
parent003910fc614cd347919707d1bf3c37a939978459 (diff)
removed versioned artefacts with v2 and v3. changes to reflect the changes in testing_api_loop.c
Diffstat (limited to 'src')
-rw-r--r--src/dhtu/test_dhtu_ip.c8
-rw-r--r--src/include/gnunet_testing_ng_lib.h86
-rw-r--r--src/testing/Makefile.am4
-rwxr-xr-xsrc/testing/netjail_core.sh190
-rwxr-xr-xsrc/testing/netjail_core_v2.sh260
-rwxr-xr-xsrc/testing/netjail_exec.sh6
-rwxr-xr-xsrc/testing/netjail_exec_v2.sh14
-rwxr-xr-xsrc/testing/netjail_start.sh70
-rwxr-xr-xsrc/testing/netjail_start_v2.sh74
-rwxr-xr-xsrc/testing/netjail_stop.sh49
-rwxr-xr-xsrc/testing/netjail_stop_v2.sh59
-rw-r--r--src/testing/testing.c30
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c6
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c63
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c71
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c327
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c723
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c209
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c54
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c79
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c141
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c185
-rw-r--r--src/testing/testing_api_loop.c8
-rw-r--r--src/testing/testing_cmds.h2
-rw-r--r--src/transport/Makefile.am48
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c192
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c235
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c175
-rw-r--r--src/transport/test_transport_port_forward.c85
-rw-r--r--src/transport/test_transport_simple_send.c86
-rwxr-xr-xsrc/transport/test_transport_simple_send.sh2
-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/test_transport_start_with_config.c59
-rw-r--r--src/transport/transport-testing-cmds.h201
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c482
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c237
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v3.c496
-rw-r--r--src/transport/transport_api_cmd_send_simple.c20
-rw-r--r--src/transport/transport_api_cmd_send_simple_v2.c156
-rw-r--r--src/transport/transport_api_cmd_start_peer.c78
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c605
-rw-r--r--src/transport/transport_api_cmd_start_peer_v3.c617
-rw-r--r--src/util/child_management.c19
44 files changed, 1441 insertions, 5155 deletions
diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c
index eb886e994..c9528053f 100644
--- a/src/dhtu/test_dhtu_ip.c
+++ b/src/dhtu/test_dhtu_ip.c
@@ -37,10 +37,10 @@ main (int argc,
char *const *argv)
{
struct GNUNET_TESTING_Command commands[] = {
- GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
- CONFIG_FILE),
- GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
- CONFIG_FILE),
+ GNUNET_TESTING_cmd_netjail_start ("netjail-start",
+ CONFIG_FILE),
+ GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
+ CONFIG_FILE),
GNUNET_TESTING_cmd_end ()
};
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 0cab64504..adf5453e1 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -1054,40 +1054,12 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
* Create command.
*
* @param label name for command.
- * @param local_m Number of local nodes in each namespace.
- * @param global_n The number of namespaces.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start (const char *label,
- char *local_m,
- char *global_n);
-
-/**
- * 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_v2 (const char *label,
- char *topology_config);
-
-
-/**
- * Create command.
- *
- * @param label name for command.
- * @param binaryname to exec.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- char *local_m,
- char *global_n,
- char *plugin_name,
- unsigned int *rv);
+GNUNET_TESTING_cmd_netjail_start (const char *label,
+ char *topology_config);
/**
@@ -1099,22 +1071,20 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label,
- const char *topology_config,
- unsigned int *rv);
+GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
+ const char *topology_config);
/**
* Create command.
*
* @param label name for command.
- * @param binaryname to stop.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_stop (const char *label,
- char *local_m,
- char *global_n);
+ char *topology_config);
/**
@@ -1125,34 +1095,31 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
- char *topology_config);
-
-
-struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_stop_testing_system (const char *label,
const char *helper_start_label,
- char *local_m,
- char *global_n);
+ const char *topology_config);
+
/**
- * Create command.
+ * Create a GNUNET_CMDS_LOCAL_FINISHED message.
*
- * @param label name for command.
- * @param topology_config Configuration file for the test topology.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
- const char *helper_start_label,
- const char *topology_config);
+ * @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);
-// FIXME: document!
-enum GNUNET_GenericReturnValue
-GNUNET_TESTING_get_trait_helper_handles (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***helper);
+/**
+ * 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);
/**
@@ -1163,7 +1130,7 @@ GNUNET_TESTING_get_trait_helper_handles (const struct
* @return #GNUNET_OK on success.
*/
enum GNUNET_GenericReturnValue
-GNUNET_TESTING_get_trait_helper_handles_v2 (
+GNUNET_TESTING_get_trait_helper_handles (
const struct GNUNET_TESTING_Command *cmd,
struct GNUNET_HELPER_Handle ***helper);
@@ -1176,8 +1143,7 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_block_until_external_trigger (
- const char *label,
- unsigned int *stop_blocking);
+ const char *label);
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_send_peer_ready (const char *label,
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index e9389a876..39e85c4ac 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -51,13 +51,9 @@ libgnunettesting_la_SOURCES = \
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_v2.c \
testing_api_cmd_netjail_start_testsystem.c \
- testing_api_cmd_netjail_start_testsystem_v2.c \
testing_api_cmd_netjail_stop_testsystem.c \
- testing_api_cmd_netjail_stop_testsystem_v2.c \
testing_api_cmd_netjail_stop.c \
- testing_api_cmd_netjail_stop_v2.c \
testing.c testing.h \
testing_api_cmd_system_create.c \
testing_api_cmd_system_destroy.c \
diff --git a/src/testing/netjail_core.sh b/src/testing/netjail_core.sh
index cf350d3fa..ef0a54a5e 100755
--- a/src/testing/netjail_core.sh
+++ b/src/testing/netjail_core.sh
@@ -2,6 +2,7 @@
#
+PREFIX=${PPID:?must run from a parent process}
# running with `sudo` is required to be
# able running the actual commands as the
@@ -9,10 +10,61 @@
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-netjail_check() {
- NODE_COUNT=$1
+export RESULT=
+export NAMESPACE_NUM=0
+export INTERFACE_NUM=0
+
+netjail_next_namespace() {
+ local NUM=$NAMESPACE_NUM
+ NAMESPACE_NUM=$(($NAMESPACE_NUM + 1))
+ RESULT=$NUM
+}
+
+netjail_next_interface() {
+ local NUM=$INTERFACE_NUM
+ INTERFACE_NUM=$(($INTERFACE_NUM + 1))
+ RESULT=$NUM
+}
+
+netjail_opt() {
+ local OPT=$1
+ shift 1
+
+ INDEX=1
+
+ while [ $# -gt 0 ]; do
+ if [ "$1" = "$OPT" ]; then
+ RESULT=$INDEX
+ return
+ fi
+
+ INDEX=$(($INDEX + 1))
+ shift 1
+ done
+
+ RESULT=0
+}
+
+netjail_opts() {
+ local OPT=$1
+ local DEF=$2
+ shift 2
+
+ while [ $# -gt 0 ]; do
+ if [ "$1" = "$OPT" ]; then
+ printf "$2"
+ return
+ fi
+
+ shift 1
+ done
+
+ RESULT="$DEF"
+}
- FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
+netjail_check() {
+ local NODE_COUNT=$1
+ local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
# quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
# the script also requires `sudo -C ($FD_COUNT + 4)`
@@ -25,43 +77,81 @@ netjail_check() {
fi
}
-netjail_print_name() {
- printf "%s%02x%02x" $1 $2 ${3:-0}
+netjail_check_bin() {
+ local PROGRAM=$1
+ local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }')
+
+ # quit if the required binary $PROGRAM can not be
+ # found in the used $PATH.
+
+ if [ "$MATCH" != "$PROGRAM" ]; then
+ echo "Required binary not found: $PROGRAM" >&2
+ exit 1
+ fi
}
netjail_bridge() {
- BRIDGE=$1
+ netjail_next_interface
+ local NUM=$RESULT
+ local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
ip link add $BRIDGE type bridge
ip link set dev $BRIDGE up
+
+ RESULT=$BRIDGE
+}
+
+netjail_bridge_name() {
+ netjail_next_interface
+ local NUM=$RESULT
+ local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
+
+ RESULT=$BRIDGE
}
netjail_bridge_clear() {
- BRIDGE=$1
+ local BRIDGE=$1
ip link delete $BRIDGE
}
netjail_node() {
- NODE=$1
+ netjail_next_namespace
+ local NUM=$RESULT
+ local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
ip netns add $NODE
+
+ RESULT=$NODE
+}
+
+netjail_node_name() {
+ netjail_next_namespace
+ local NUM=$RESULT
+ local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
+
+ RESULT=$NODE
}
netjail_node_clear() {
- NODE=$1
+ local NODE=$1
ip netns delete $NODE
}
netjail_node_link_bridge() {
- NODE=$1
- BRIDGE=$2
- ADDRESS=$3
- MASK=$4
+ local NODE=$1
+ local BRIDGE=$2
+ local ADDRESS=$3
+ local MASK=$4
- LINK_IF="$NODE-$BRIDGE-0"
- LINK_BR="$NODE-$BRIDGE-1"
+ netjail_next_interface
+ local NUM_IF=$RESULT
+ netjail_next_interface
+ local NUM_BR=$RESULT
+
+ local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF)
+ local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
ip link add $LINK_IF type veth peer name $LINK_BR
ip link set $LINK_IF netns $NODE
@@ -72,28 +162,47 @@ netjail_node_link_bridge() {
ip -n $NODE link set up dev lo
ip link set $LINK_BR up
+
+ RESULT=$LINK_BR
+}
+
+netjail_node_link_bridge_name() {
+
+ netjail_next_interface
+ netjail_next_interface
+ local NUM_BR=$RESULT
+
+ local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
+
+ RESULT=$LINK_BR
+}
+
+netjail_node_unlink_bridge() {
+ local LINK_BR=$1
+
+ ip link delete $LINK_BR
}
netjail_node_add_nat() {
- NODE=$1
- ADDRESS=$2
- MASK=$3
+ local NODE=$1
+ local ADDRESS=$2
+ local MASK=$3
ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
}
netjail_node_add_default() {
- NODE=$1
- ADDRESS=$2
+ local NODE=$1
+ local ADDRESS=$2
ip -n $NODE route add default via $ADDRESS
}
netjail_node_exec() {
JAILOR=${SUDO_USER:?must run in sudo}
- NODE=$1
- FD_IN=$2
- FD_OUT=$3
+ local NODE=$1
+ local FD_IN=$2
+ local FD_OUT=$3
shift 3
ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
@@ -114,3 +223,38 @@ netjail_node_exec_without_fds_and_sudo() {
ip netns exec $NODE $@
}
+netjail_kill() {
+ local PID=$1
+ local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l)
+
+ if [ $MATCH -gt 0 ]; then
+ kill -n 19 $PID
+
+ for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do
+ netjail_kill $CHILD
+ done
+
+ kill $PID
+ fi
+}
+
+netjail_killall() {
+ if [ $# -gt 0 ]; then
+ local PIDS=$1
+
+ for PID in $PIDS; do
+ netjail_kill $PID
+ done
+ fi
+}
+
+netjail_waitall() {
+ if [ $# -gt 0 ]; then
+ local PIDS=$1
+
+ for PID in $PIDS; do
+ wait $PID
+ done
+ fi
+}
+
diff --git a/src/testing/netjail_core_v2.sh b/src/testing/netjail_core_v2.sh
deleted file mode 100755
index ef0a54a5e..000000000
--- a/src/testing/netjail_core_v2.sh
+++ /dev/null
@@ -1,260 +0,0 @@
-#!/bin/sh
-#
-
-
-PREFIX=${PPID:?must run from a parent process}
-
-# running with `sudo` is required to be
-# able running the actual commands as the
-# original user.
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-export RESULT=
-export NAMESPACE_NUM=0
-export INTERFACE_NUM=0
-
-netjail_next_namespace() {
- local NUM=$NAMESPACE_NUM
- NAMESPACE_NUM=$(($NAMESPACE_NUM + 1))
- RESULT=$NUM
-}
-
-netjail_next_interface() {
- local NUM=$INTERFACE_NUM
- INTERFACE_NUM=$(($INTERFACE_NUM + 1))
- RESULT=$NUM
-}
-
-netjail_opt() {
- local OPT=$1
- shift 1
-
- INDEX=1
-
- while [ $# -gt 0 ]; do
- if [ "$1" = "$OPT" ]; then
- RESULT=$INDEX
- return
- fi
-
- INDEX=$(($INDEX + 1))
- shift 1
- done
-
- RESULT=0
-}
-
-netjail_opts() {
- local OPT=$1
- local DEF=$2
- shift 2
-
- while [ $# -gt 0 ]; do
- if [ "$1" = "$OPT" ]; then
- printf "$2"
- return
- fi
-
- shift 1
- done
-
- RESULT="$DEF"
-}
-
-netjail_check() {
- local NODE_COUNT=$1
- local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
-
- # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
- # the script also requires `sudo -C ($FD_COUNT + 4)`
- # so you need 'Defaults closefrom_override' in the
- # sudoers file.
-
- if [ $FD_COUNT -lt $(($NODE_COUNT * 2)) ]; then
- echo "File descriptors do not match requirements!" >&2
- exit 1
- fi
-}
-
-netjail_check_bin() {
- local PROGRAM=$1
- local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }')
-
- # quit if the required binary $PROGRAM can not be
- # found in the used $PATH.
-
- if [ "$MATCH" != "$PROGRAM" ]; then
- echo "Required binary not found: $PROGRAM" >&2
- exit 1
- fi
-}
-
-netjail_bridge() {
- netjail_next_interface
- local NUM=$RESULT
- local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- ip link add $BRIDGE type bridge
- ip link set dev $BRIDGE up
-
- RESULT=$BRIDGE
-}
-
-netjail_bridge_name() {
- netjail_next_interface
- local NUM=$RESULT
- local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- RESULT=$BRIDGE
-}
-
-netjail_bridge_clear() {
- local BRIDGE=$1
-
- ip link delete $BRIDGE
-}
-
-netjail_node() {
- netjail_next_namespace
- local NUM=$RESULT
- local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- ip netns add $NODE
-
- RESULT=$NODE
-}
-
-netjail_node_name() {
- netjail_next_namespace
- local NUM=$RESULT
- local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
-
- RESULT=$NODE
-}
-
-netjail_node_clear() {
- local NODE=$1
-
- ip netns delete $NODE
-}
-
-netjail_node_link_bridge() {
- local NODE=$1
- local BRIDGE=$2
- local ADDRESS=$3
- local MASK=$4
-
- netjail_next_interface
- local NUM_IF=$RESULT
- netjail_next_interface
- local NUM_BR=$RESULT
-
- local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF)
- local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
-
- ip link add $LINK_IF type veth peer name $LINK_BR
- ip link set $LINK_IF netns $NODE
- ip link set $LINK_BR master $BRIDGE
-
- ip -n $NODE addr add "$ADDRESS/$MASK" dev $LINK_IF
- ip -n $NODE link set $LINK_IF up
- ip -n $NODE link set up dev lo
-
- ip link set $LINK_BR up
-
- RESULT=$LINK_BR
-}
-
-netjail_node_link_bridge_name() {
-
- netjail_next_interface
- netjail_next_interface
- local NUM_BR=$RESULT
-
- local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
-
- RESULT=$LINK_BR
-}
-
-netjail_node_unlink_bridge() {
- local LINK_BR=$1
-
- ip link delete $LINK_BR
-}
-
-netjail_node_add_nat() {
- local NODE=$1
- local ADDRESS=$2
- local MASK=$3
-
- ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
-}
-
-netjail_node_add_default() {
- local NODE=$1
- local ADDRESS=$2
-
- ip -n $NODE route add default via $ADDRESS
-}
-
-netjail_node_exec() {
- JAILOR=${SUDO_USER:?must run in sudo}
- local NODE=$1
- local FD_IN=$2
- local FD_OUT=$3
- shift 3
-
- ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
-}
-
-netjail_node_exec_without_fds() {
- JAILOR=${SUDO_USER:?must run in sudo}
- NODE=$1
- shift 1
-
- ip netns exec $NODE sudo -u $JAILOR -- $@
-}
-
-netjail_node_exec_without_fds_and_sudo() {
- NODE=$1
- shift 1
-
- ip netns exec $NODE $@
-}
-
-netjail_kill() {
- local PID=$1
- local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l)
-
- if [ $MATCH -gt 0 ]; then
- kill -n 19 $PID
-
- for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do
- netjail_kill $CHILD
- done
-
- kill $PID
- fi
-}
-
-netjail_killall() {
- if [ $# -gt 0 ]; then
- local PIDS=$1
-
- for PID in $PIDS; do
- netjail_kill $PID
- done
- fi
-}
-
-netjail_waitall() {
- if [ $# -gt 0 ]; then
- local PIDS=$1
-
- for PID in $PIDS; do
- wait $PID
- done
- fi
-}
-
diff --git a/src/testing/netjail_exec.sh b/src/testing/netjail_exec.sh
index 17a7caaac..cd993a39b 100755
--- a/src/testing/netjail_exec.sh
+++ b/src/testing/netjail_exec.sh
@@ -9,8 +9,6 @@ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
M=$1
N=$2
-NODE=$(netjail_print_name "N" $N $M)
+NODE=$6
-
-
-netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
+netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
diff --git a/src/testing/netjail_exec_v2.sh b/src/testing/netjail_exec_v2.sh
deleted file mode 100755
index 597baad20..000000000
--- a/src/testing/netjail_exec_v2.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-. "./../testing/netjail_core_v2.sh"
-
-set -eu
-set -x
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-M=$1
-N=$2
-
-NODE=$6
-
-netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
diff --git a/src/testing/netjail_start.sh b/src/testing/netjail_start.sh
index 0984a3c42..1dfe1dfdf 100755
--- a/src/testing/netjail_start.sh
+++ b/src/testing/netjail_start.sh
@@ -1,52 +1,74 @@
-#!/bin/sh
+#!/bin/bash
. "./../testing/netjail_core.sh"
+. "./../testing/topo.sh"
set -eu
set -x
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-LOCAL_M=$1
-GLOBAL_N=$2
+filename=$1
+PREFIX=$2
-# TODO: stunserver? ..and globally known peer?
+read_topology $filename
shift 2
LOCAL_GROUP="192.168.15"
GLOBAL_GROUP="92.68.150"
+KNOWN_GROUP="92.68.151"
-NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
-netjail_bridge $NETWORK_NET
+echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]"
-for N in $(seq $GLOBAL_N); do
- ROUTER=$(netjail_print_name "R" $N)
+netjail_bridge
+NETWORK_NET=$RESULT
- netjail_node $ROUTER
- netjail_node_link_bridge $ROUTER $NETWORK_NET "$GLOBAL_GROUP.$N" 24
+for X in $(seq $KNOWN); do
+ netjail_node
+ KNOWN_NODES[$X]=$RESULT
+ netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
+ KNOWN_LINKS[$X]=$RESULT
+done
- ROUTER_NET=$(netjail_print_name "r" $N)
+declare -A NODES
+declare -A NODE_LINKS
- netjail_bridge $ROUTER_NET
+for N in $(seq $GLOBAL_N); do
+ netjail_node
+ ROUTERS[$N]=$RESULT
+ netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
+ NETWORK_LINKS[$N]=$RESULT
+ netjail_bridge
+ ROUTER_NETS[$N]=$RESULT
for M in $(seq $LOCAL_M); do
- NODE=$(netjail_print_name "N" $N $M)
-
- netjail_node $NODE
- netjail_node_link_bridge $NODE $ROUTER_NET "$LOCAL_GROUP.$M" 24
+ netjail_node
+ NODES[$N,$M]=$RESULT
+ netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
+ NODE_LINKS[$N,$M]=$RESULT
done
ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
-
- netjail_node_link_bridge $ROUTER $ROUTER_NET $ROUTER_ADDR 24
- netjail_node_add_nat $ROUTER $ROUTER_ADDR 24
+ netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
+ ROUTER_LINKS[$N]=$RESULT
+
+ netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
for M in $(seq $LOCAL_M); do
- NODE=$(netjail_print_name "N" $N $M)
-
- netjail_node_add_default $NODE $ROUTER_ADDR
+ netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
done
-done
-
+ # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports.
+
+ if [ "1" == "${R_TCP[$N]}" ]
+ then
+ ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
+ ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
+ fi
+ if [ "1" == "${R_UDP[$N]}" ]
+ then
+ ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
+ ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
+ fi
+done
diff --git a/src/testing/netjail_start_v2.sh b/src/testing/netjail_start_v2.sh
deleted file mode 100755
index dd1f2ad93..000000000
--- a/src/testing/netjail_start_v2.sh
+++ /dev/null
@@ -1,74 +0,0 @@
-#!/bin/bash
-. "./../testing/netjail_core_v2.sh"
-. "./../testing/topo.sh"
-
-set -eu
-set -x
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-filename=$1
-PREFIX=$2
-
-read_topology $filename
-
-shift 2
-
-LOCAL_GROUP="192.168.15"
-GLOBAL_GROUP="92.68.150"
-KNOWN_GROUP="92.68.151"
-
-
-echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]"
-
-netjail_bridge
-NETWORK_NET=$RESULT
-
-for X in $(seq $KNOWN); do
- netjail_node
- KNOWN_NODES[$X]=$RESULT
- netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
- KNOWN_LINKS[$X]=$RESULT
-done
-
-declare -A NODES
-declare -A NODE_LINKS
-
-for N in $(seq $GLOBAL_N); do
- netjail_node
- ROUTERS[$N]=$RESULT
- netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
- NETWORK_LINKS[$N]=$RESULT
- netjail_bridge
- ROUTER_NETS[$N]=$RESULT
-
- for M in $(seq $LOCAL_M); do
- netjail_node
- NODES[$N,$M]=$RESULT
- netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
- NODE_LINKS[$N,$M]=$RESULT
- done
-
- ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
- netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
- ROUTER_LINKS[$N]=$RESULT
-
- netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
-
- for M in $(seq $LOCAL_M); do
- netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
- done
-
- # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports.
-
- if [ "1" == "${R_TCP[$N]}" ]
- then
- ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
- ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
- fi
- if [ "1" == "${R_UDP[$N]}" ]
- then
- ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
- ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
- fi
-done
diff --git a/src/testing/netjail_stop.sh b/src/testing/netjail_stop.sh
index 08f68cf7f..abfaf3acf 100755
--- a/src/testing/netjail_stop.sh
+++ b/src/testing/netjail_stop.sh
@@ -1,24 +1,57 @@
-#!/bin/sh
+#!/bin/bash
. "./../testing/netjail_core.sh"
+. "./../testing/topo.sh"
set -eu
set -x
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-LOCAL_M=$1
-GLOBAL_N=$2
-NETWORK_NET=$(netjail_print_name "n" $GLOBAL_N $LOCAL_M)
+filename=$1
+PREFIX=$2
-shift 2
+read_topology $filename
+
+declare -A NODES
+declare -A NODE_LINKS
+
+netjail_bridge_name
+NETWORK_NET=$RESULT
+
+for X in $(seq $KNOWN); do
+ netjail_node_name
+ KNOWN_NODES[$X]=$RESULT
+ netjail_node_link_bridge_name
+ KNOWN_LINKS[$X]=$RESULT
+ netjail_node_unlink_bridge ${KNOWN_LINKS[$X]}
+ netjail_node_clear ${KNOWN_NODES[$X]}
+done
for N in $(seq $GLOBAL_N); do
+ netjail_node_name
+ ROUTERS[$N]=$RESULT
+ netjail_node_link_bridge_name
+ NETWORK_LINKS[$N]=$RESULT
+ netjail_bridge_name
+ ROUTER_NETS[$N]=$RESULT
+ netjail_node_link_bridge_name
+ ROUTER_LINKS[$N]=$RESULT
+
+ netjail_node_unlink_bridge ${ROUTER_LINKS[$N]}
+
for M in $(seq $LOCAL_M); do
- netjail_node_clear $(netjail_print_name "N" $N $M)
+ netjail_node_name
+ NODES[$N,$M]=$RESULT
+ netjail_node_link_bridge_name
+ NODE_LINKS[$N,$M]=$RESULT
+ netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]}
+ netjail_node_clear ${NODES[$N,$M]}
done
+
- netjail_bridge_clear $(netjail_print_name "r" $N)
- netjail_node_clear $(netjail_print_name "R" $N)
+ netjail_bridge_clear ${ROUTER_NETS[$N]}
+ netjail_node_unlink_bridge ${NETWORK_LINKS[$N]}
+ netjail_node_clear ${ROUTERS[$N]}
done
netjail_bridge_clear $NETWORK_NET
diff --git a/src/testing/netjail_stop_v2.sh b/src/testing/netjail_stop_v2.sh
deleted file mode 100755
index 6e9fd1ccc..000000000
--- a/src/testing/netjail_stop_v2.sh
+++ /dev/null
@@ -1,59 +0,0 @@
-#!/bin/bash
-. "./../testing/netjail_core_v2.sh"
-. "./../testing/topo.sh"
-
-set -eu
-set -x
-
-export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
-
-filename=$1
-PREFIX=$2
-
-read_topology $filename
-
-declare -A NODES
-declare -A NODE_LINKS
-
-netjail_bridge_name
-NETWORK_NET=$RESULT
-
-for X in $(seq $KNOWN); do
- netjail_node_name
- KNOWN_NODES[$X]=$RESULT
- netjail_node_link_bridge_name
- KNOWN_LINKS[$X]=$RESULT
- netjail_node_unlink_bridge ${KNOWN_LINKS[$X]}
- netjail_node_clear ${KNOWN_NODES[$X]}
-done
-
-for N in $(seq $GLOBAL_N); do
- netjail_node_name
- ROUTERS[$N]=$RESULT
- netjail_node_link_bridge_name
- NETWORK_LINKS[$N]=$RESULT
- netjail_bridge_name
- ROUTER_NETS[$N]=$RESULT
- netjail_node_link_bridge_name
- ROUTER_LINKS[$N]=$RESULT
-
- netjail_node_unlink_bridge ${ROUTER_LINKS[$N]}
-
- for M in $(seq $LOCAL_M); do
- netjail_node_name
- NODES[$N,$M]=$RESULT
- netjail_node_link_bridge_name
- NODE_LINKS[$N,$M]=$RESULT
- netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]}
- netjail_node_clear ${NODES[$N,$M]}
- done
-
-
- netjail_bridge_clear ${ROUTER_NETS[$N]}
- netjail_node_unlink_bridge ${NETWORK_LINKS[$N]}
- netjail_node_clear ${ROUTERS[$N]}
-done
-
-netjail_bridge_clear $NETWORK_NET
-
-echo "Done"
diff --git a/src/testing/testing.c b/src/testing/testing.c
index a11d404a5..766c7b084 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -34,6 +34,7 @@
#include "gnunet_arm_service.h"
#include "gnunet_testing_lib.h"
#include "gnunet_testing_ng_lib.h"
+#include "testing_cmds.h"
#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
@@ -1961,10 +1962,6 @@ get_connect_value (char *line, struct GNUNET_TESTING_NetjailNode *node)
}
GNUNET_free (copy);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "address_prefix %s\n",
- prefix->address_prefix);
-
return node_connection;
}
@@ -2007,6 +2004,31 @@ node_connections (char *line, struct GNUNET_TESTING_NetjailNode *node)
/**
+ * 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)
+{
+ struct GNUNET_CMDS_LOCAL_FINISHED *reply;
+ size_t msg_length;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Local test exits with status %d\n",
+ rv);
+ msg_length = sizeof(struct GNUNET_CMDS_LOCAL_FINISHED);
+ reply = GNUNET_new (struct GNUNET_CMDS_LOCAL_FINISHED);
+ reply->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED);
+ reply->header.size = htons ((uint16_t) msg_length);
+ reply->result = htons (rv);
+
+ return (struct GNUNET_MessageHeader *) reply;
+}
+
+
+/**
* Getting the topology from file.
*
* @param filename The name of the topology file.
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c
index 8a47a7ce0..763713e15 100644
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ b/src/testing/testing_api_cmd_block_until_all_peers_started.c
@@ -39,6 +39,11 @@
struct BlockState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* Flag to indicate if all peers have started.
*
*/
@@ -93,6 +98,7 @@ GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
.cls = bs,
.label = label,
.run = &block_until_all_peers_started_run,
+ .ac = &bs->ac,
.cleanup = &block_until_all_peers_started_cleanup
};
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 b416fa595..aeb9ffda3 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -39,9 +39,14 @@
struct BlockState
{
/**
- * Flag to indicate if all peers have started.
+ * Context for our asynchronous completion.
*/
- unsigned int *stop_blocking;
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
+ * The label of this command.
+ */
+ const char *label;
};
@@ -57,6 +62,47 @@ block_until_all_peers_started_cleanup (void *cls)
GNUNET_free (bs);
}
+static int
+block_until_external_trigger_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct BlockState *bs = cls;
+ struct GNUNET_TESTING_AsyncContext *ac = &bs->ac;
+ struct GNUNET_TESTING_Trait traits[] = {
+ {
+ .index = 0,
+ .trait_name = "async_context",
+ .ptr = (const void *) ac,
+ },
+ GNUNET_TESTING_trait_end ()
+ };
+
+ return GNUNET_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * 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)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) ac,
+ "async_context",
+ (unsigned int) 0);
+}
+
/**
* This function does nothing but to start the cmd.
@@ -66,8 +112,11 @@ static void
block_until_all_peers_started_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
+ struct BlockState *bs = cls;
+
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "block_until_all_peers_started_run!\n");
+ "block %s running!\n",
+ bs->label);
}
@@ -79,20 +128,20 @@ block_until_all_peers_started_run (void *cls,
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_block_until_external_trigger (const char *label,
- unsigned int *
- stop_blocking)
+GNUNET_TESTING_cmd_block_until_external_trigger (const char *label)
{
struct BlockState *bs;
bs = GNUNET_new (struct BlockState);
- bs->stop_blocking = stop_blocking;
+ bs->label = label;
{
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,
+ .traits = block_until_external_trigger_traits
};
return cmd;
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 9cd84cb4f..35fb90f3c 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -19,7 +19,7 @@
*/
/**
- * @file testing/testing_api_cmd_hello_world.c
+ * @file testing/testing_api_cmd_netjail_start.c
* @brief Command to start the netjail script.
* @author t3sserakt
*/
@@ -43,16 +43,16 @@ struct NetJailState
// Child Wait handle
struct GNUNET_ChildWaitHandle *cwh;
- // Number of local nodes in each namespace.
- char *local_m;
-
- // The number of namespaces.
- char *global_n;
-
/**
* The process id of the start script.
*/
struct GNUNET_OS_Process *start_proc;
+
+ /**
+ * Configuration file for the test topology.
+ */
+ char *topology_config;
+
};
@@ -67,6 +67,7 @@ netjail_start_cleanup (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"netjail_start_cleanup!\n");
+
if (NULL != ns->cwh)
{
GNUNET_wait_child_cancel (ns->cwh);
@@ -105,9 +106,9 @@ child_completed_callback (void *cls,
}
else
{
- // FIXME: log status code
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Child completed with an error!\n");
+ "Child failed with error %lu!\n",
+ exit_code);
GNUNET_TESTING_async_fail (&ns->ac);
}
}
@@ -124,13 +125,13 @@ netjail_start_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct NetJailState *ns = cls;
- char *const script_argv[] = {
- NETJAIL_START_SCRIPT,
- ns->local_m,
- ns->global_n,
- NULL
- };
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
+ char pid[15];
+ enum GNUNET_GenericReturnValue helper_check;
+
+ // 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,
GNUNET_YES,
NULL);
@@ -141,22 +142,37 @@ netjail_start_run (void *cls,
"No SUID for %s!\n",
NETJAIL_START_SCRIPT);
GNUNET_TESTING_interpreter_fail (is);
+ return;
}
- else if (GNUNET_NO == helper_check)
+ if (GNUNET_SYSERR == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
NETJAIL_START_SCRIPT);
GNUNET_TESTING_interpreter_fail (is);
+ return;
}
- ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_START_SCRIPT,
- script_argv);
+ GNUNET_snprintf (pid,
+ sizeof (pid),
+ "%u",
+ getpid ());
+ {
+ char *const script_argv[] = {
+ NETJAIL_START_SCRIPT,
+ ns->topology_config,
+ pid,
+ NULL
+ };
+ ns->start_proc
+ = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
+ NULL,
+ NULL,
+ NULL,
+ NETJAIL_START_SCRIPT,
+ script_argv);
+ }
ns->cwh = GNUNET_wait_child (ns->start_proc,
&child_completed_callback,
ns);
@@ -168,20 +184,17 @@ netjail_start_run (void *cls,
* Create command.
*
* @param label name for command.
- * @param local_m Number of local nodes in each namespace.
- * @param global_n The number of namespaces.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start (const char *label,
- char *local_m,
- char *global_n)
+ char *topology_config)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
+ ns->topology_config = topology_config;
{
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 4224a5736..a1d71c436 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -67,6 +67,11 @@ struct NetJailState
struct GNUNET_TESTING_AsyncContext ac;
/**
+ * The complete topology information.
+ */
+ struct GNUNET_TESTING_NetjailTopology *topology;
+
+ /**
* Pointer to the return value of the test.
*
*/
@@ -96,16 +101,22 @@ struct NetJailState
unsigned int n_helper;
/**
- * Number of nodes in a network namespace. //TODO make this a unsigned int
+ * Number of nodes in a natted subnet.
+ *
+ */
+ unsigned int local_m;
+
+ /**
+ * Number of natted subnets.
*
*/
- char *local_m;
+ unsigned int global_n;
/**
- * Number of network namespaces. //TODO make this a unsigned int
+ * Number of global known nodes.
*
*/
- char *global_n;
+ unsigned int known;
/**
* The send handle for the helper
@@ -271,7 +282,8 @@ netjail_exec_traits (void *cls,
int
GNUNET_TESTING_get_trait_helper_handles (const struct
GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***helper)
+ struct GNUNET_HELPER_Handle ***
+ helper)
{
return cmd->traits (cmd->cls,
(const void **) helper,
@@ -301,6 +313,43 @@ clear_msg (void *cls, int result)
}
+static void
+send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
+{
+ unsigned int total_number = ns->local_m * ns->global_n + ns->known;
+ struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
+ size_t msg_length;
+ struct GNUNET_HELPER_Handle *helper;
+ struct TestingSystemCount *tbc;
+
+ tbc = GNUNET_new (struct TestingSystemCount);
+ tbc->ns = ns;
+ // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
+ if (0 == i)
+ tbc->count = j + total_number;
+ else
+ tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known;
+
+ helper = ns->helper[tbc->count - 1 - total_number];
+ msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
+ reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
+ reply->header.type = htons (
+ GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
+ reply->header.size = htons ((uint16_t) msg_length);
+
+ GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
+
+ struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
+ helper,
+ &reply->header,
+ GNUNET_NO,
+ &clear_msg,
+ tbc);
+
+ GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
+}
+
+
/**
* Functions with this signature are called whenever a
* complete message is received by the tokenizer.
@@ -319,6 +368,7 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
struct TestingSystemCount *tbc = cls;
struct NetJailState *ns = tbc->ns;
struct HelperMessage *hp_msg;
+ unsigned int total_number = ns->local_m * ns->global_n + ns->known;
if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
{
@@ -328,11 +378,31 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
message->type))
{
ns->number_of_peers_started++;
+ if (ns->number_of_peers_started == total_number)
+ {
+ for (int i = 1; i <= ns->known; i++)
+ {
+ send_all_peers_started (0,i, ns);
+ }
+
+ for (int i = 1; i <= ns->global_n; i++)
+ {
+ for (int j = 1; j <= ns->local_m; j++)
+ {
+ send_all_peers_started (i,j, ns);
+ }
+ }
+ ns->number_of_peers_started = 0;
+ }
}
else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
message->type))
{
ns->number_of_local_test_finished++;
+ if (ns->number_of_local_test_finished == total_number)
+ {
+ GNUNET_TESTING_async_finish (&ns->ac);
+ }
}
else
{
@@ -343,6 +413,12 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
hp_msg);
}
+
+
+
+
+
+
return GNUNET_OK;
}
@@ -354,24 +430,21 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
static void
exp_cb (void *cls)
{
- struct NetJailState *ns = cls;
+ struct TestingSystemCount *tbc = cls;
+
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (tbc->ns->ac.is);
}
/**
* Function to initialize a init message for the helper.
*
- * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
- * @param n_char The actual namespace. //TODO Change this to unsigned int
* @param plugin_name Name of the test case plugin the helper will load.
*
*/
static struct GNUNET_CMDS_HelperInit *
-create_helper_init_msg_ (char *m_char,
- char *n_char,
- const char *plugin_name)
+create_helper_init_msg_ (const char *plugin_name)
{
struct GNUNET_CMDS_HelperInit *msg;
uint16_t plugin_name_len;
@@ -398,24 +471,49 @@ create_helper_init_msg_ (char *m_char,
static void
start_helper (struct NetJailState *ns, struct
GNUNET_CONFIGURATION_Handle *config,
- char *m_char,
- char *n_char)
+ unsigned int m,
+ unsigned int n)
{
struct GNUNET_HELPER_Handle *helper;
struct GNUNET_CMDS_HelperInit *msg;
struct TestingSystemCount *tbc;
- char *const script_argv[] = {
- NETJAIL_EXEC_SCRIPT,
- m_char,
- n_char,
- GNUNET_OS_get_libexec_binary_path (
- HELPER_CMDS_BINARY),
- ns->global_n,
- ns->local_m,
- NULL
- };
- unsigned int m = atoi (m_char);
- unsigned int n = atoi (n_char);
+ char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
+ *plugin;
+ pid_t pid;
+ unsigned int script_num;
+ struct GNUNET_ShortHashCode *hkey;
+ struct GNUNET_HashCode hc;
+ struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
+ struct GNUNET_TESTING_NetjailNode *node;
+ struct GNUNET_TESTING_NetjailNamespace *namespace;
+
+
+ if (0 == n)
+ script_num = m - 1;
+ else
+ script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
+ pid = getpid ();
+
+ GNUNET_asprintf (&m_char, "%u", m);
+ GNUNET_asprintf (&n_char, "%u", n);
+ GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
+ GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
+ GNUNET_asprintf (&known_char, "%u",ns->known);
+ GNUNET_asprintf (&node_id, "%06x-%08x\n",
+ pid,
+ script_num);
+
+
+ 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};
+
unsigned int helper_check = GNUNET_OS_check_helper_binary (
NETJAIL_EXEC_SCRIPT,
GNUNET_YES,
@@ -423,7 +521,10 @@ start_helper (struct NetJailState *ns, struct
tbc = GNUNET_new (struct TestingSystemCount);
tbc->ns = ns;
- tbc->count = (n - 1) * atoi (ns->local_m) + m;
+ 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);
@@ -434,18 +535,17 @@ start_helper (struct NetJailState *ns, struct
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"No SUID for %s!\n",
NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (ns->ac.is);
}
else if (GNUNET_NO == helper_check)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"%s not found!\n",
NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (ns->ac.is);
}
- GNUNET_array_append (ns->helper,
- ns->n_helper,
- GNUNET_HELPER_start (
+
+ GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
GNUNET_YES,
NETJAIL_EXEC_SCRIPT,
script_argv,
@@ -455,9 +555,57 @@ start_helper (struct NetJailState *ns, struct
helper = ns->helper[tbc->count - 1];
- msg = create_helper_init_msg_ (m_char,
- n_char,
- ns->plugin_name);
+ hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+
+ plugin = topology->plugin;
+
+ if (0 == m)
+ {
+
+ GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
+ hkey))
+ {
+ node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
+ hkey);
+ if (NULL != node->plugin)
+ plugin = node->plugin;
+ }
+
+ }
+ else
+ {
+ GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
+ hkey))
+ {
+ namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
+ hkey);
+ GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
+ hkey))
+ {
+ node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
+ hkey);
+ if (NULL != node->plugin)
+ plugin = node->plugin;
+ }
+ }
+
+
+ }
+
+ msg = create_helper_init_msg_ (plugin);
+
GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
@@ -472,7 +620,7 @@ start_helper (struct NetJailState *ns, struct
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Send handle is NULL!\n");
GNUNET_free (msg);
- *ns->rv = 1;
+ GNUNET_TESTING_interpreter_fail (ns->ac.is);
}
}
@@ -488,93 +636,26 @@ static void
netjail_exec_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
- char str_m[12];
- char str_n[12];
struct NetJailState *ns = cls;
struct GNUNET_CONFIGURATION_Handle *config =
GNUNET_CONFIGURATION_create ();
- for (int i = 1; i <= atoi (ns->global_n); i++)
+ for (int i = 1; i <= ns->known; i++)
{
- for (int j = 1; j <= atoi (ns->local_m); j++)
- {
- sprintf (str_n, "%d", i);
- sprintf (str_m, "%d", j);
- start_helper (ns, config,
- str_m,
- str_n);
- }
+ start_helper (ns, config,
+ i,
+ 0);
}
-}
-
-/**
- * This function checks on three different information.
- *
- * 1. Did all helpers start. This is only logged.
- * 2. Did all peer start.
- * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
- * 3. Did all peers finished the test case. In this case interpreter_next will be called.
- *
- * => FIXME: must change _completely_.
- */
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- unsigned int ret = GNUNET_NO;
- struct NetJailState *ns = cls;
- unsigned int total_number = atoi (ns->local_m) * atoi (ns->global_n);
- struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
- size_t msg_length;
- struct GNUNET_HELPER_Handle *helper;
- struct TestingSystemCount *tbc;
-
- if (ns->number_of_local_test_finished == total_number)
+ for (int i = 1; i <= ns->global_n; i++)
{
- ret = GNUNET_YES;
- cont (cont_cls);
- }
-
- if (ns->number_of_testsystems_started == total_number)
- {
- ns->number_of_testsystems_started = 0;
- }
-
- if (ns->number_of_peers_started == total_number)
- {
- for (int i = 1; i <= atoi (ns->global_n); i++)
+ for (int j = 1; j <= ns->local_m; j++)
{
- for (int j = 1; j <= atoi (ns->local_m); j++)
- {
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
- tbc->count = (i - 1) * atoi (ns->local_m) + j + total_number;
-
- helper = ns->helper[tbc->count - 1 - total_number];
- msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
-
- GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
-
- struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
- helper,
- &reply->header,
- GNUNET_NO,
- &clear_msg,
- tbc);
-
- GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
- }
+ start_helper (ns, config,
+ j,
+ i);
}
- ns->number_of_peers_started = 0;
}
- return ret;
}
@@ -582,26 +663,24 @@ netjail_start_finish (void *cls,
* Create command.
*
* @param label Name for the command.
- * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
- * @param global_n Number of network namespaces. //TODO make this a unsigned int
- * @param plugin_name Name of the test case plugin the helper will load.
- * @param rv Pointer to the return value of the test.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
- char *local_m,
- char *global_n,
- char *plugin_name,
- unsigned int *rv)
+ const char *topology_config)
{
struct NetJailState *ns;
+ struct GNUNET_TESTING_NetjailTopology *topology =
+ GNUNET_TESTING_get_topo_from_file (topology_config);
+
ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
- ns->plugin_name = plugin_name;
- ns->rv = rv;
+ 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;
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
deleted file mode 100644
index d319b73b4..000000000
--- a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
+++ /dev/null
@@ -1,723 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to start the netjail peers.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "testing_cmds.h"
-
-#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh"
-
-/**
- * Struct to store messages send/received by the helper into a DLL
- *
- */
-struct HelperMessage
-{
-
- /**
- * Kept in a DLL.
- */
- struct HelperMessage *next;
-
- /**
- * Kept in a DLL.
- */
- struct HelperMessage *prev;
-
- /**
- * Size of the original message.
- */
- uint16_t bytes_msg;
-
- /* Followed by @e bytes_msg of msg.*/
-};
-
-
-/**
- * Struct to store information handed over to callbacks.
- *
- */
-struct NetJailState
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- /**
- * The complete topology information.
- */
- struct GNUNET_TESTING_NetjailTopology *topology;
-
- /**
- * Pointer to the return value of the test.
- *
- */
- unsigned int *rv;
-
- /**
- * Head of the DLL which stores messages received by the helper.
- *
- */
- struct HelperMessage *hp_messages_head;
-
- /**
- * Tail of the DLL which stores messages received by the helper.
- *
- */
- struct HelperMessage *hp_messages_tail;
-
- /**
- * Array with handles of helper processes.
- */
- struct GNUNET_HELPER_Handle **helper;
-
- /**
- * Size of the array NetJailState#helper.
- *
- */
- unsigned int n_helper;
-
- /**
- * Number of nodes in a natted subnet.
- *
- */
- unsigned int local_m;
-
- /**
- * Number of natted subnets.
- *
- */
- unsigned int global_n;
-
- /**
- * Number of global known nodes.
- *
- */
- 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.
- *
- */
- unsigned int number_of_testsystems_started;
-
- /**
- * Number of peers started.
- *
- */
- unsigned int number_of_peers_started;
-
- /**
- * Number of local tests finished.
- *
- */
- unsigned int number_of_local_test_finished;
-
- /**
- * Name of the test case plugin the helper will load.
- *
- */
- char *plugin_name;
-
- /**
- * HEAD of the DLL containing TestingSystemCount.
- *
- */
- struct TestingSystemCount *tbcs_head;
-
- /**
- * TAIL of the DLL containing TestingSystemCount.
- *
- */
- struct TestingSystemCount *tbcs_tail;
-};
-
-/**
- * Struct containing the number of the test environment and the NetJailState which
- * will be handed to callbacks specific to a test environment.
- */
-struct TestingSystemCount
-{
- /**
- * Kept in a DLL.
- */
- struct TestingSystemCount *next;
-
- /**
- * Kept in a DLL.
- */
- struct TestingSystemCount *prev;
-
- /**
- * The number of the test environment.
- *
- */
- unsigned int count;
-
- /**
- * Struct to store information handed over to callbacks.
- *
- */
- struct NetJailState *ns;
-};
-
-/**
-* Code to clean up resource this cmd used.
-*
-* @param cls closure
-*/
-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_free (ns);
-}
-
-
-/**
- * This function prepares an array with traits.
- *
- */
-static int
-netjail_exec_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- struct NetJailState *ns = cls;
- struct GNUNET_HELPER_Handle **helper = ns->helper;
- struct HelperMessage *hp_messages_head = ns->hp_messages_head;
-
-
- struct GNUNET_TESTING_Trait traits[] = {
- {
- .index = 0,
- .trait_name = "helper_handles",
- .ptr = (const void *) helper,
- },
- {
- .index = 1,
- .trait_name = "hp_msgs_head",
- .ptr = (const void *) hp_messages_head,
- },
- GNUNET_TESTING_trait_end ()
- };
-
- return GNUNET_TESTING_get_trait (traits,
- ret,
- trait,
- index);
-}
-
-
-/**
- * Offer handles to testing cmd helper from trait
- *
- * @param cmd command to extract the message from.
- * @param pt pointer to message.
- * @return #GNUNET_OK on success.
- */
-int
-GNUNET_TESTING_get_trait_helper_handles_v2 (const struct
- GNUNET_TESTING_Command *cmd,
- struct GNUNET_HELPER_Handle ***
- helper)
-{
- return cmd->traits (cmd->cls,
- (const void **) helper,
- "helper_handles",
- (unsigned int) 0);
-}
-
-
-/**
- * Continuation function from GNUNET_HELPER_send()
- *
- * @param cls closure
- * @param result GNUNET_OK on success,
- * GNUNET_NO if helper process died
- * GNUNET_SYSERR during GNUNET_HELPER_stop
- */
-static void
-clear_msg (void *cls, int result)
-{
- struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
-
- GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
- ns->shandle[tbc->count - 1] = NULL;
- GNUNET_free (ns->msg[tbc->count - 1]);
- ns->msg[tbc->count - 1] = NULL;
-}
-
-
-/**
- * Functions with this signature are called whenever a
- * complete message is received by the tokenizer.
- *
- * Do not call GNUNET_SERVER_mst_destroy in callback
- *
- * @param cls closure
- * @param client identification of the client
- * @param message the actual message
- *
- * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
- */
-static int
-helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
-{
- struct TestingSystemCount *tbc = cls;
- struct NetJailState *ns = tbc->ns;
- struct HelperMessage *hp_msg;
-
- if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
- {
- ns->number_of_testsystems_started++;
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
- message->type))
- {
- ns->number_of_peers_started++;
- }
- else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
- message->type))
- {
- ns->number_of_local_test_finished++;
- }
- else
- {
- hp_msg = GNUNET_new (struct HelperMessage);
- hp_msg->bytes_msg = message->size;
- memcpy (&hp_msg[1], message, message->size);
- GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
- hp_msg);
- }
-
- return GNUNET_OK;
-}
-
-
-/**
- * Callback called if there was an exception during execution of the helper.
- *
- */
-static void
-exp_cb (void *cls)
-{
- struct NetJailState *ns = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
- *ns->rv = 1;
-}
-
-
-/**
- * Function to initialize a init message for the helper.
- *
- * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
- * @param n_char The actual namespace. //TODO Change this to unsigned int
- * @param plugin_name Name of the test case plugin the helper will load.
- *
- */
-static struct GNUNET_CMDS_HelperInit *
-create_helper_init_msg_ (const char *plugin_name)
-{
- struct GNUNET_CMDS_HelperInit *msg;
- uint16_t plugin_name_len;
- uint16_t msg_size;
-
- GNUNET_assert (NULL != plugin_name);
- plugin_name_len = strlen (plugin_name);
- msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
- msg = GNUNET_malloc (msg_size);
- msg->header.size = htons (msg_size);
- msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
- msg->plugin_name_size = htons (plugin_name_len);
- GNUNET_memcpy ((char *) &msg[1],
- plugin_name,
- plugin_name_len);
- return msg;
-}
-
-
-/**
- * Function which start a single helper process.
- *
- */
-static void
-start_helper (struct NetJailState *ns, struct
- GNUNET_CONFIGURATION_Handle *config,
- unsigned int m,
- unsigned int n)
-{
- struct GNUNET_HELPER_Handle *helper;
- struct GNUNET_CMDS_HelperInit *msg;
- struct TestingSystemCount *tbc;
- char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
- *plugin;
- pid_t pid;
- unsigned int script_num;
- struct GNUNET_ShortHashCode *hkey;
- struct GNUNET_HashCode hc;
- struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
- struct GNUNET_TESTING_NetjailNode *node;
- struct GNUNET_TESTING_NetjailNamespace *namespace;
-
-
- if (0 == n)
- script_num = m - 1;
- else
- script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
- pid = getpid ();
-
- GNUNET_asprintf (&m_char, "%u", m);
- GNUNET_asprintf (&n_char, "%u", n);
- GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
- GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
- GNUNET_asprintf (&known_char, "%u",ns->known);
- GNUNET_asprintf (&node_id, "%06x-%08x\n",
- pid,
- script_num);
-
-
- 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};
-
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_EXEC_SCRIPT,
- 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);
- *ns->rv = 1;
- }
- else if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_EXEC_SCRIPT);
- *ns->rv = 1;
- }
-
- GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
- GNUNET_YES,
- NETJAIL_EXEC_SCRIPT,
- script_argv,
- &helper_mst,
- &exp_cb,
- tbc));
-
- helper = ns->helper[tbc->count - 1];
-
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
-
- plugin = topology->plugin;
-
- if (0 == m)
- {
-
- GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
- hkey))
- {
- node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
- hkey);
- if (NULL != node->plugin)
- plugin = node->plugin;
- }
-
- }
- else
- {
- GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
- hkey))
- {
- namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
- hkey);
- GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
- hkey))
- {
- node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
- hkey);
- if (NULL != node->plugin)
- plugin = node->plugin;
- }
- }
-
-
- }
-
- msg = create_helper_init_msg_ (plugin);
-
- GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
-
- GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
- helper,
- &msg->header,
- GNUNET_NO,
- &clear_msg,
- tbc));
-
- if (NULL == ns->shandle[tbc->count - 1])
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Send handle is NULL!\n");
- GNUNET_free (msg);
- *ns->rv = 1;
- }
-}
-
-
-/**
-* This function starts a helper process for each node.
-*
-* @param cls closure.
-* @param cmd CMD being run.
-* @param is interpreter state.
-*/
-static void
-netjail_exec_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct NetJailState *ns = cls;
- struct GNUNET_CONFIGURATION_Handle *config =
- GNUNET_CONFIGURATION_create ();
-
- for (int i = 1; i <= ns->known; i++)
- {
- start_helper (ns, config,
- i,
- 0);
- }
-
- for (int i = 1; i <= ns->global_n; i++)
- {
- for (int j = 1; j <= ns->local_m; j++)
- {
- start_helper (ns, config,
- j,
- i);
- }
- }
-}
-
-
-static void
-send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
-{
- unsigned int total_number = ns->local_m * ns->global_n + ns->known;
- struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
- size_t msg_length;
- struct GNUNET_HELPER_Handle *helper;
- struct TestingSystemCount *tbc;
-
- tbc = GNUNET_new (struct TestingSystemCount);
- tbc->ns = ns;
- // TODO This needs to be more generic. As we send more messages back and forth, we can not grow the arrays again and again, because this is to error prone.
- if (0 == i)
- tbc->count = j + total_number;
- else
- tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known;
-
- helper = ns->helper[tbc->count - 1 - total_number];
- msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
- reply->header.type = htons (
- GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
- reply->header.size = htons ((uint16_t) msg_length);
-
- GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
-
- struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
- helper,
- &reply->header,
- GNUNET_NO,
- &clear_msg,
- tbc);
-
- GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
-}
-
-
-/**
- * This function checks on three different information.
- *
- * 1. Did all helpers start. This is only logged.
- * 2. Did all peer start.
- * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
- * 3. Did all peers finished the test case. In this case interpreter_next will be called.
- *
- */
-// FIXME: must change completely!
-static int
-netjail_start_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
-{
- unsigned int ret = GNUNET_NO;
- struct NetJailState *ns = cls;
- unsigned int total_number = ns->local_m * ns->global_n + ns->known;
-
-
- if (ns->number_of_local_test_finished == total_number)
- {
- ret = GNUNET_YES;
- cont (cont_cls);
- }
-
- if (ns->number_of_testsystems_started == total_number)
- {
- ns->number_of_testsystems_started = 0;
- }
-
- if (ns->number_of_peers_started == total_number)
- {
- for (int i = 1; i <= ns->known; i++)
- {
- send_all_peers_started (0,i, ns);
- }
-
- for (int i = 1; i <= ns->global_n; i++)
- {
- for (int j = 1; j <= ns->local_m; j++)
- {
- send_all_peers_started (i,j, ns);
- }
- }
- ns->number_of_peers_started = 0;
- }
- return ret;
-}
-
-
-/**
- * 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.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label,
- const char *topology_config,
- unsigned int *rv)
-{
- struct NetJailState *ns;
-
- struct GNUNET_TESTING_NetjailTopology *topology =
- GNUNET_TESTING_get_topo_from_file (topology_config);
-
- ns = GNUNET_new (struct NetJailState);
- ns->rv = rv;
- 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;
-
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_exec_run,
- .ac = &ns->ac,
- .cleanup = &netjail_exec_cleanup,
- .traits = &netjail_exec_traits
- };
-
- return cmd;
-}
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
deleted file mode 100644
index 7567c2981..000000000
--- a/src/testing/testing_api_cmd_netjail_start_v2.c
+++ /dev/null
@@ -1,209 +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_netjail_start_v2.c
- * @brief Command to start the netjail script.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-#define NETJAIL_START_SCRIPT "./../testing/netjail_start_v2.sh"
-
-/**
- * Struct to hold information for callbacks.
- *
- */
-struct NetJailState
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- // Child Wait handle
- struct GNUNET_ChildWaitHandle *cwh;
-
- /**
- * Configuration file for the test topology.
- */
- char *topology_config;
-
- /**
- * The process id of the start script.
- */
- struct GNUNET_OS_Process *start_proc;
-
-};
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-netjail_start_cleanup (void *cls)
-{
- struct NetJailState *ns = cls;
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "netjail_start_cleanup!\n");
-
- if (NULL != ns->cwh)
- {
- GNUNET_wait_child_cancel (ns->cwh);
- ns->cwh = NULL;
- }
- if (NULL != ns->start_proc)
- {
- GNUNET_assert (0 ==
- GNUNET_OS_process_kill (ns->start_proc,
- SIGKILL));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_OS_process_wait (ns->start_proc));
- GNUNET_OS_process_destroy (ns->start_proc);
- ns->start_proc = NULL;
- }
- GNUNET_free (ns);
-}
-
-
-/**
- * Callback which will be called if the setup script finished.
- *
- */
-static void
-child_completed_callback (void *cls,
- enum GNUNET_OS_ProcessStatusType type,
- long unsigned int exit_code)
-{
- struct NetJailState *ns = cls;
-
- GNUNET_OS_process_destroy (ns->start_proc);
- ns->start_proc = NULL;
- if (0 == exit_code)
- {
- GNUNET_TESTING_async_finish (&ns->ac);
- }
- else
- {
- // FIXME: log status code
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Child completed with an error!\n");
- GNUNET_TESTING_async_fail (&ns->ac);
- }
-}
-
-
-/**
-* The run method starts the script which setup the network namespaces.
-*
-* @param cls closure.
-* @param is interpreter state.
-*/
-static void
-netjail_start_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct NetJailState *ns = cls;
- char pid[15];
- enum GNUNET_GenericReturnValue helper_check;
-
- // 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,
- GNUNET_YES,
- NULL);
-
- if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No SUID for %s!\n",
- NETJAIL_START_SCRIPT);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- }
- if (GNUNET_SYSERR == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_START_SCRIPT);
- GNUNET_TESTING_interpreter_fail (is);
- return;
- }
-
- GNUNET_snprintf (pid,
- sizeof (pid),
- "%u",
- getpid ());
- {
- char *const script_argv[] = {
- NETJAIL_START_SCRIPT,
- ns->topology_config,
- pid,
- NULL
- };
-
- ns->start_proc
- = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
- NULL,
- NULL,
- NULL,
- NETJAIL_START_SCRIPT,
- script_argv);
- }
- ns->cwh = GNUNET_wait_child (ns->start_proc,
- &child_completed_callback,
- ns);
- GNUNET_break (NULL != ns->cwh);
-}
-
-
-/**
- * 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_v2 (const char *label,
- char *topology_config)
-{
- struct NetJailState *ns;
-
- ns = GNUNET_new (struct NetJailState);
- ns->topology_config = topology_config;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_start_run,
- .ac = &ns->ac,
- .cleanup = &netjail_start_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 8c78b5e93..5033272a3 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -31,7 +31,7 @@
#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh"
// Child Wait handle
-struct GNUNET_ChildWaitHandle *cwh;
+static struct GNUNET_ChildWaitHandle *cwh;
/**
* Struct to hold information for callbacks.
@@ -44,11 +44,10 @@ struct NetJailState
*/
struct GNUNET_TESTING_AsyncContext ac;
- // Number of local nodes in each namespace.
- char *local_m;
-
- // The number of namespaces.
- char *global_n;
+ /**
+ * Configuration file for the test topology.
+ */
+ char *topology_config;
/**
* The process id of the start script.
@@ -86,20 +85,6 @@ netjail_stop_cleanup (void *cls)
/**
- * Trait function of this cmd does nothing.
- *
- */
-static enum GNUNET_GenericReturnValue
-netjail_stop_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_NO;
-}
-
-
-/**
* Callback which will be called if the setup script finished.
*
*/
@@ -110,7 +95,7 @@ child_completed_callback (void *cls,
{
struct NetJailState *ns = cls;
- cwh = NULL;
+ cwh = NULL; // WTF? globals!?!?!
GNUNET_OS_process_destroy (ns->stop_proc);
ns->stop_proc = NULL;
if (0 == exit_code)
@@ -119,7 +104,6 @@ child_completed_callback (void *cls,
}
else
{
- // FIXME: log exit code!
GNUNET_TESTING_async_fail (&ns->ac);
}
}
@@ -129,7 +113,6 @@ child_completed_callback (void *cls,
* The run method starts the script which deletes the network namespaces.
*
* @param cls closure.
-* @param cmd CMD being run.
* @param is interpreter state.
*/
static void
@@ -137,12 +120,15 @@ netjail_stop_run (void *cls,
struct GNUNET_TESTING_Interpreter *is)
{
struct NetJailState *ns = cls;
- char *const script_argv[] = {
- NETJAIL_STOP_SCRIPT,
- ns->local_m,
- ns->global_n,
- NULL
- };
+ char *pid;
+
+ GNUNET_asprintf (&pid,
+ "%u",
+ getpid ());
+ char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
+ ns->topology_config,
+ pid,
+ NULL};
unsigned int helper_check = GNUNET_OS_check_helper_binary (
NETJAIL_STOP_SCRIPT,
GNUNET_YES,
@@ -174,28 +160,24 @@ netjail_stop_run (void *cls,
&child_completed_callback,
ns);
GNUNET_break (NULL != cwh);
-
}
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_netjail_stop (const char *label,
- char *local_m,
- char *global_n)
+ char *topology_config)
{
struct NetJailState *ns;
ns = GNUNET_new (struct NetJailState);
- ns->local_m = local_m;
- ns->global_n = global_n;
+ ns->topology_config = topology_config;
{
struct GNUNET_TESTING_Command cmd = {
.cls = ns,
.label = label,
.run = &netjail_stop_run,
.ac = &ns->ac,
- .cleanup = &netjail_stop_cleanup,
- .traits = &netjail_stop_traits
+ .cleanup = &netjail_stop_cleanup
};
return cmd;
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index 04b0e4e94..d3754153d 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -42,9 +42,15 @@ struct StopHelperState
*/
struct GNUNET_HELPER_Handle **helper;
- char *local_m;
+ unsigned int local_m;
- char *global_n;
+ unsigned int global_n;
+
+ /**
+ * Number of global known nodes.
+ *
+ */
+ unsigned int known;
};
@@ -57,6 +63,7 @@ struct StopHelperState
static void
stop_testing_system_cleanup (void *cls)
{
+
}
@@ -64,13 +71,13 @@ stop_testing_system_cleanup (void *cls)
* Trait function of this cmd does nothing.
*
*/
-static enum GNUNET_GenericReturnValue
+static int
stop_testing_system_traits (void *cls,
const void **ret,
const char *trait,
unsigned int index)
{
- return GNUNET_NO;
+ return GNUNET_OK;
}
@@ -88,17 +95,30 @@ stop_testing_system_run (void *cls,
struct GNUNET_HELPER_Handle **helper;
const struct GNUNET_TESTING_Command *start_helper_cmd;
- start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
- is,
- shs->helper_start_label);
+ start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (NULL,
+ shs->
+ helper_start_label);
GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
&helper);
- for (int i = 1; i <= atoi (shs->global_n); i++)
+ for (int i = 1; i <= shs->known; i++)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "i: %u\n",
+ i);
+ GNUNET_HELPER_stop (helper[i - 1],
+ GNUNET_YES);
+ }
+
+ for (int i = 1; i <= shs->global_n; i++)
{
- for (int j = 1; j <= atoi (shs->local_m); j++)
+ for (int j = 1; j <= shs->local_m; j++)
{
- GNUNET_HELPER_stop (helper[(i - 1) * atoi (shs->local_m) + j - 1],
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "i: %u j: %u\n",
+ i,
+ j);
+ GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j + shs->known - 1],
GNUNET_YES);
}
}
@@ -107,34 +127,35 @@ stop_testing_system_run (void *cls,
/**
* Create command.
- * @param helper_start_label label of the cmd to start the test system.
+ *
* @param label name for command.
- * @param .
- * @param local_m Number of nodes in a network namespace. //TODO make this a unsigned int
- * @param global_n Number of network namespaces. //TODO make this a unsigned int
+ * @param helper_start_label label of the cmd to start the test system.
+ * @param topology_config Configuration file for the test topology.
* @return command.
*/
struct GNUNET_TESTING_Command
GNUNET_TESTING_cmd_stop_testing_system (const char *label,
const char *helper_start_label,
- char *local_m,
- char *global_n)
+ const char *topology_config)
{
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 = local_m;
- shs->global_n = global_n;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = shs,
- .label = label,
- .run = &stop_testing_system_run,
- .cleanup = &stop_testing_system_cleanup,
- .traits = &stop_testing_system_traits
- };
-
- return cmd;
- }
+ shs->local_m = topology->nodes_m;
+ shs->global_n = topology->namespaces_n;
+ shs->known = topology->nodes_x;
+
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = shs,
+ .label = label,
+ .run = &stop_testing_system_run,
+ .cleanup = &stop_testing_system_cleanup,
+ .traits = &stop_testing_system_traits
+ };
+
+ return cmd;
}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
deleted file mode 100644
index 65eb85d9a..000000000
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- This file is part of GNUnet
- Copyright (C) 2021 GNUnet e.V.
-
- GNUnet is free software: you can redistribute it and/or modify it
- under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License,
- or (at your option) any later version.
-
- GNUnet is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Affero General Public License for more details.
-
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
-
- SPDX-License-Identifier: AGPL3.0-or-later
- */
-
-/**
- * @file testing/testing_api_cmd_hello_world.c
- * @brief Command to start the netjail peers.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_testing_ng_lib.h"
-#include "testing_cmds.h"
-
-
-/**
- * Struct to store information handed over to callbacks.
- *
- */
-struct StopHelperState
-{
-
- const char *helper_start_label;
-
- /**
- * The process handle
- */
- struct GNUNET_HELPER_Handle **helper;
-
- unsigned int local_m;
-
- unsigned int global_n;
-};
-
-
-/**
-* Code to clean up resource this cmd used.
-*
-* @param cls closure
-*/
-static void
-stop_testing_system_cleanup (void *cls)
-{
-
-}
-
-
-/**
- * Trait function of this cmd does nothing.
- *
- */
-static enum GNUNET_GenericReturnValue
-stop_testing_system_traits (void *cls,
- const void **ret,
- const char *trait,
- unsigned int index)
-{
- return GNUNET_NO;
-}
-
-
-/**
-* This function stops the helper process for each node.
-*
-* @param cls closure.
-* @param is interpreter state.
-*/
-static void
-stop_testing_system_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct StopHelperState *shs = cls;
- struct GNUNET_HELPER_Handle **helper;
- const struct GNUNET_TESTING_Command *start_helper_cmd;
-
- start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
- is,
- shs->helper_start_label);
- GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
- &helper);
-
- for (int i = 1; i <= shs->global_n; i++)
- {
- for (int j = 1; j <= shs->local_m; j++)
- {
- GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j - 1],
- GNUNET_YES);
- }
- }
-}
-
-
-/**
- * Create command.
- *
- * @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.
- * @return command.
- */
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
- const char *helper_start_label,
- const char *topology_config)
-{
- 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;
- shs->global_n = topology->namespaces_n;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = shs,
- .label = label,
- .run = &stop_testing_system_run,
- .cleanup = &stop_testing_system_cleanup,
- .traits = &stop_testing_system_traits
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c
deleted file mode 100644
index a0e2657cb..000000000
--- a/src/testing/testing_api_cmd_netjail_stop_v2.c
+++ /dev/null
@@ -1,185 +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_netjail_stop_v2.c
- * @brief Command to stop the netjail script.
- * @author t3sserakt
- */
-#include "platform.h"
-#include "gnunet_util_lib.h"
-#include "gnunet_testing_ng_lib.h"
-
-
-#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop_v2.sh"
-
-// Child Wait handle
-static struct GNUNET_ChildWaitHandle *cwh;
-
-/**
- * Struct to hold information for callbacks.
- *
- */
-struct NetJailState
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- /**
- * Configuration file for the test topology.
- */
- char *topology_config;
-
- /**
- * The process id of the start script.
- */
- struct GNUNET_OS_Process *stop_proc;
-
-};
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-netjail_stop_cleanup (void *cls)
-{
- struct NetJailState *ns = cls;
-
- if (NULL != cwh)
- {
- GNUNET_wait_child_cancel (cwh);
- cwh = NULL;
- }
- if (NULL != ns->stop_proc)
- {
- GNUNET_assert (0 ==
- GNUNET_OS_process_kill (ns->stop_proc,
- SIGKILL));
- GNUNET_assert (GNUNET_OK ==
- GNUNET_OS_process_wait (ns->stop_proc));
- GNUNET_OS_process_destroy (ns->stop_proc);
- ns->stop_proc = NULL;
- }
-}
-
-
-/**
- * Callback which will be called if the setup script finished.
- *
- */
-static void
-child_completed_callback (void *cls,
- enum GNUNET_OS_ProcessStatusType type,
- long unsigned int exit_code)
-{
- struct NetJailState *ns = cls;
-
- cwh = NULL; // WTF? globals!?!?!
- GNUNET_OS_process_destroy (ns->stop_proc);
- ns->stop_proc = NULL;
- if (0 == exit_code)
- {
- GNUNET_TESTING_async_finish (&ns->ac);
- }
- else
- {
- GNUNET_TESTING_async_fail (&ns->ac);
- }
-}
-
-
-/**
-* The run method starts the script which deletes the network namespaces.
-*
-* @param cls closure.
-* @param is interpreter state.
-*/
-static void
-netjail_stop_run (void *cls,
- struct GNUNET_TESTING_Interpreter *is)
-{
- struct NetJailState *ns = cls;
- char *pid;
-
- GNUNET_asprintf (&pid,
- "%u",
- getpid ());
- char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
- ns->topology_config,
- pid,
- NULL};
- unsigned int helper_check = GNUNET_OS_check_helper_binary (
- NETJAIL_STOP_SCRIPT,
- GNUNET_YES,
- NULL);
-
- if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "No SUID for %s!\n",
- NETJAIL_STOP_SCRIPT);
- GNUNET_TESTING_interpreter_fail (is);
- }
- else if (GNUNET_NO == helper_check)
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "%s not found!\n",
- NETJAIL_STOP_SCRIPT);
- 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);
-}
-
-
-struct GNUNET_TESTING_Command
-GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
- char *topology_config)
-{
- struct NetJailState *ns;
-
- ns = GNUNET_new (struct NetJailState);
- ns->topology_config = topology_config;
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = ns,
- .label = label,
- .run = &netjail_stop_run,
- .ac = &ns->ac,
- .cleanup = &netjail_stop_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index e0cb3fcda..3727d2543 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -313,8 +313,12 @@ interpreter_run (void *cls)
}
cmd->run (cmd->cls,
is);
- if ( (cmd->asynchronous_finish) &&
- (NULL != cmd->ac->cont) )
+ if (NULL == cmd->ac)
+ {
+ interpreter_next (is);
+ }
+ else if ( (cmd->asynchronous_finish) &&
+ (NULL != cmd->ac->cont) )
{
cmd->ac->cont = NULL;
interpreter_next (is);
diff --git a/src/testing/testing_cmds.h b/src/testing/testing_cmds.h
index 7a5860aea..09e4f2dcb 100644
--- a/src/testing/testing_cmds.h
+++ b/src/testing/testing_cmds.h
@@ -83,6 +83,8 @@ struct GNUNET_CMDS_LOCAL_FINISHED
* Type is GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED
*/
struct GNUNET_MessageHeader header;
+
+ enum GNUNET_GenericReturnValue result;
};
GNUNET_NETWORK_STRUCT_END
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index a539f3f25..0df422976 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -159,14 +159,9 @@ libgnunettransporttesting_la_LDFLAGS = \
libgnunettransporttesting2_la_SOURCES = \
transport_api_cmd_connecting_peers.c \
- transport_api_cmd_connecting_peers_v2.c \
- transport_api_cmd_connecting_peers_v3.c \
transport_api_cmd_start_peer.c \
- transport_api_cmd_start_peer_v2.c \
- transport_api_cmd_start_peer_v3.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-cmds.h \
transport-testing-filenames2.c \
@@ -394,7 +389,6 @@ plugin_LTLIBRARIES = \
$(WLAN_PLUGIN_LA) \
$(BT_PLUGIN_LA) \
libgnunet_test_transport_plugin_cmd_simple_send.la \
- libgnunet_test_transport_plugin_cmd_simple_send_v2.la \
libgnunet_test_transport_plugin_cmd_udp_backchannel.la
libgnunet_test_transport_plugin_cmd_udp_backchannel_la_SOURCES = \
@@ -431,23 +425,6 @@ 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 \
- libgnunettransportcore.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
@@ -593,8 +570,6 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
$(MHD_CFLAGS) $(AM_CFLAGS) -DBUILD_HTTPS
check_PROGRAMS = \
- test_transport_simple_send \
- test_transport_simple_send_v2 \
test_transport_start_with_config \
test_transport_address_switch_tcp \
test_transport_testing_startstop \
@@ -743,8 +718,6 @@ test_transport_api_slow_ats
endif
if HAVE_EXPERIMENTAL
TESTS += \
- test_transport_simple_send \
- test_transport_simple_send_v2 \
test_transport_start_with_config \
test_transport_address_switch_udp \
test_plugin_udp \
@@ -765,7 +738,6 @@ endif
check_SCRIPTS= \
test_transport_simple_send.sh \
- test_transport_simple_send_v2.sh \
test_transport_udp_backchannel.sh
test_transport_start_with_config_SOURCES = \
@@ -778,26 +750,6 @@ test_transport_start_with_config_LDADD = \
libgnunettransportcore.la \
libgnunettransporttesting2.la
-test_transport_simple_send_SOURCES = \
- test_transport_simple_send.c
-test_transport_simple_send_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 \
- libgnunettransportcore.la \
- libgnunettransporttesting2.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 \
- libgnunettransportcore.la \
- libgnunettransporttesting2.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 21167415d..5384bf24d 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -37,28 +37,34 @@
#define BASE_DIR "testdir"
-/**
- * The name for a specific test environment directory.
- *
- */
-char *testdir;
+#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
-/**
- * The name for the configuration file of the specific node.
- *
- */
-char *cfgname;
+struct TestState
+{
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
+ TESTING_CMD_HELPER_write_cb write_message;
-/**
- * Flag indicating if all peers have been started.
- *
- */
-unsigned int are_all_peers_started;
+ /**
+ * The name for a specific test environment directory.
+ *
+ */
+ char *testdir;
-/**
- * Flag indicating a received message.
- */
-unsigned int message_received;
+ /**
+ * The name for the configuration file of the specific node.
+ *
+ */
+ char *cfgname;
+};
+
+static struct GNUNET_TESTING_Command block_send;
+
+static struct GNUNET_TESTING_Command block_receive;
+
+static struct GNUNET_TESTING_Command connect_peers;
/**
@@ -83,7 +89,14 @@ static void
handle_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- message_received = GNUNET_YES;
+ struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_TESTING_get_trait_async_context (&block_receive,
+ &ac);
+ if ((NULL == ac) || (NULL == ac->cont))
+ GNUNET_TESTING_async_fail (ac);
+ else
+ GNUNET_TESTING_async_finish (ac);
}
@@ -94,7 +107,62 @@ handle_test (void *cls,
static void
all_peers_started ()
{
- are_all_peers_started = GNUNET_YES;
+ struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_TESTING_get_trait_async_context (&block_send,
+ &ac);
+ if ((NULL == ac) || (NULL == ac->cont))
+ GNUNET_TESTING_async_fail (ac);
+ else
+ GNUNET_TESTING_async_finish (ac);
+}
+
+
+/**
+ * Function called with the final result of the test.
+ *
+ * @param cls the `struct MainParams`
+ * @param rv #GNUNET_OK if the test passed
+ */
+static void
+handle_result (void *cls,
+ enum GNUNET_GenericReturnValue rv)
+{
+ struct TestState *ts = cls;
+ struct GNUNET_MessageHeader *reply;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Local test exits with status %d\n",
+ rv);
+ reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+
+ ts->write_message (reply,
+ ntohs (reply->size));
+ GNUNET_free (ts->testdir);
+ GNUNET_free (ts->cfgname);
+ GNUNET_free (ts);
+}
+
+
+/**
+ * Callback from start peer cmd for signaling a peer got connected.
+ *
+ */
+static void *
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct ConnectPeersState *cps;
+
+ GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
+ &cps);
+ void *ret = NULL;
+
+ cps->notify_connect (cps,
+ peer,
+ mq);
+ return ret;
}
@@ -116,24 +184,46 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *local_m)
{
- GNUNET_asprintf (&cfgname,
- "test_transport_api2_tcp_node%s.conf",
- "1");
+ unsigned int n_int;
+ unsigned int m_int;
+ 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);
+
+ if (0 == m_int)
+ num = n_int;
+ else
+ num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
+
+ block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
+ block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "block-receive");
+ connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
+ "start-peer",
+ "system-create",
+ num,
+ NULL);
+
+
+
+ sscanf (m, "%u", &m_int);
+ sscanf (n, "%u", &n_int);
+ sscanf (local_m, "%u", &local_m_int);
+
+ GNUNET_asprintf (&ts->cfgname,
+ "test_transport_api2_tcp_node1.conf");
LOG (GNUNET_ERROR_TYPE_ERROR,
"plugin cfgname: %s\n",
- cfgname);
+ ts->cfgname);
LOG (GNUNET_ERROR_TYPE_ERROR,
"node ip: %s\n",
node_ip);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "m: %s n: %s\n",
- m,
- n);
-
- GNUNET_asprintf (&testdir,
+ GNUNET_asprintf (&ts->testdir,
"%s%s%s",
BASE_DIR,
m,
@@ -143,50 +233,38 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
GNUNET_MQ_hd_var_size (test,
GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
struct GNUNET_TRANSPORT_TESTING_TestMessage,
- NULL),
+ ts),
GNUNET_MQ_handler_end ()
};
struct GNUNET_TESTING_Command commands[] = {
GNUNET_TESTING_cmd_system_create ("system-create",
- testdir),
+ ts->testdir),
GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
"system-create",
- m,
- n,
- local_m,
+ num,
node_ip,
handlers,
- cfgname),
+ ts->cfgname,
+ notify_connect),
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 ("connect-peers",
- "start-peer",
- "system-create",
- (atoi (n) - 1) * atoi (local_m) + atoi (
- m)),
+ block_send,
+ connect_peers,
GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
- m,
- n,
- (atoi (n) - 1) * atoi (local_m) + atoi (
- m),
- "start-peer"),
- GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
- &message_received),
+ "start-peer",
+ num),
+ block_receive,
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)
+ "system-create")
};
GNUNET_TESTING_run (commands,
GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, /* FIXME: will crash */
- NULL);
+ &handle_result,
+ ts);
}
@@ -221,8 +299,6 @@ 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;
}
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
deleted file mode 100644
index 98e9d5fca..000000000
--- a/src/transport/test_transport_plugin_cmd_simple_send_v2.c
+++ /dev/null
@@ -1,235 +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_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;
-
-/**
- * Flag indicating a received message.
- */
-unsigned int message_received;
-
-
-/**
- * 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)
-{
- message_received = GNUNET_YES;
-}
-
-
-/**
- * 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;
-}
-
-
-/**
- * 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_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_TESTING_cmd_block_until_external_trigger ("block-receive",
- &message_received),
- 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 (commands,
- GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, /* FIXME: will crash */
- NULL);
-
-}
-
-
-/**
- * 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.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index 6b0342e51..108e1ac09 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -39,28 +39,32 @@
#define TOPOLOGY_CONFIG "test_transport_udp_backchannel_topo.conf"
-/**
- * The name for a specific test environment directory.
- *
- */
-char *testdir;
+struct TestState
+{
+ /**
+ * Callback to write messages to the master loop.
+ *
+ */
+ TESTING_CMD_HELPER_write_cb write_message;
-/**
- * The name for the configuration file of the specific node.
- *
- */
-char *cfgname;
+ /**
+ * The name for a specific test environment directory.
+ *
+ */
+ char *testdir;
-/**
- * Flag indicating if all peers have been started.
- *
- */
-unsigned int are_all_peers_started;
+ /**
+ * The name for the configuration file of the specific node.
+ *
+ */
+ char *cfgname;
+};
-/**
- * Flag indicating a received message.
- */
-unsigned int message_received;
+static struct GNUNET_TESTING_Command block_send;
+
+static struct GNUNET_TESTING_Command block_receive;
+
+static struct GNUNET_TESTING_Command connect_peers;
/**
@@ -85,7 +89,14 @@ static void
handle_test (void *cls,
const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
{
- message_received = GNUNET_YES;
+ struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_TESTING_get_trait_async_context (&block_receive,
+ &ac);
+ if ((NULL == ac) || (NULL == ac->cont))
+ GNUNET_TESTING_async_fail (ac);
+ else
+ GNUNET_TESTING_async_finish (ac);
}
@@ -96,10 +107,62 @@ handle_test (void *cls,
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);
+ struct GNUNET_TESTING_AsyncContext *ac;
+
+ GNUNET_TESTING_get_trait_async_context (&block_send,
+ &ac);
+ if ((NULL == ac) || (NULL == ac->cont))
+ GNUNET_TESTING_async_fail (ac);
+ else
+ GNUNET_TESTING_async_finish (ac);
+}
+
+
+/**
+* Function called with the final result of the test.
+*
+* @param cls the `struct MainParams`
+* @param rv #GNUNET_OK if the test passed
+*/
+static void
+handle_result (void *cls,
+ enum GNUNET_GenericReturnValue rv)
+{
+ struct TestState *ts = cls;
+ struct GNUNET_MessageHeader *reply;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Local test exits with status %d\n",
+ rv);
+ reply = GNUNET_TESTING_send_local_test_finished_msg (rv);
+
+ ts->write_message (reply,
+ ntohs (reply->size));
+ GNUNET_free (ts->testdir);
+ GNUNET_free (ts->cfgname);
+ GNUNET_free (ts);
+}
+
+
+/**
+ * Callback from start peer cmd for signaling a peer got connected.
+ *
+ */
+static void *
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
+{
+ struct ConnectPeersState *cps;
+
+ GNUNET_TESTING_get_trait_connect_peer_state (&connect_peers,
+ &cps);
+ void *ret = NULL;
+
+ cps->notify_connect (cps,
+ peer,
+ mq);
+ return ret;
}
@@ -121,7 +184,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
char *local_m)
{
- unsigned int n_int, m_int, local_m_int, num;
+ unsigned int n_int;
+ unsigned int m_int;
+ 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);
@@ -136,18 +203,27 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
else
num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
- GNUNET_asprintf (&cfgname,
+ block_send = GNUNET_TESTING_cmd_block_until_external_trigger ("block");
+ block_receive = GNUNET_TESTING_cmd_block_until_external_trigger (
+ "block-receive");
+ connect_peers = GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
+ "start-peer",
+ "system-create",
+ num,
+ NULL);
+
+ GNUNET_asprintf (&ts->cfgname,
"test_transport_api2_tcp_node1.conf");
LOG (GNUNET_ERROR_TYPE_ERROR,
"plugin cfgname: %s\n",
- cfgname);
+ ts->cfgname);
LOG (GNUNET_ERROR_TYPE_ERROR,
"node ip: %s\n",
node_ip);
- GNUNET_asprintf (&testdir,
+ GNUNET_asprintf (&ts->testdir,
"%s%s%s",
BASE_DIR,
m,
@@ -163,39 +239,32 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
struct GNUNET_TESTING_Command commands[] = {
GNUNET_TESTING_cmd_system_create ("system-create",
- testdir),
- GNUNET_TRANSPORT_cmd_start_peer_v3 ("start-peer",
- "system-create",
- num,
- node_ip,
- handlers,
- cfgname),
+ ts->testdir),
+ GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
+ "system-create",
+ num,
+ node_ip,
+ handlers,
+ ts->cfgname,
+ notify_connect),
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_v3 ("connect-peers",
- "start-peer",
- "system-create",
- num,
- topology),
- GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
- "start-peer",
- num),
- GNUNET_TESTING_cmd_block_until_external_trigger ("block-receive",
- &message_received),
+ block_send,
+ connect_peers,
+ GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
+ "start-peer",
+ num),
+ block_receive,
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)
+ "system-create")
};
GNUNET_TESTING_run (commands,
GNUNET_TIME_UNIT_FOREVER_REL,
- NULL, /* FIMXE: will crash */
- NULL);
+ &handle_result,
+ ts);
}
@@ -234,8 +303,6 @@ libgnunet_test_transport_plugin_cmd_udp_backchannel_done (void *cls)
struct GNUNET_TESTING_PluginFunctions *api = cls;
GNUNET_free (api);
- GNUNET_free (testdir);
- GNUNET_free (cfgname);
return NULL;
}
diff --git a/src/transport/test_transport_port_forward.c b/src/transport/test_transport_port_forward.c
deleted file mode 100644
index d3233c2da..000000000
--- a/src/transport/test_transport_port_forward.c
+++ /dev/null
@@ -1,85 +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 transport/test_transport_port_forward.c
- * @brief Test case executing a script which sends a test UDP message from a nated peer
- * to a global 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
deleted file mode 100644
index 924990d0a..000000000
--- a/src/transport/test_transport_simple_send.c
+++ /dev/null
@@ -1,86 +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 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.sh b/src/transport/test_transport_simple_send.sh
index 25d5b6797..2dd269fcc 100755
--- a/src/transport/test_transport_simple_send.sh
+++ b/src/transport/test_transport_simple_send.sh
@@ -1,2 +1,2 @@
#!/bin/bash
-exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send"
+exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config test_transport_simple_send_topo.conf"
diff --git a/src/transport/test_transport_simple_send_v2.c b/src/transport/test_transport_simple_send_v2.c
deleted file mode 100644
index aeac1bfb6..000000000
--- a/src/transport/test_transport_simple_send_v2.c
+++ /dev/null
@@ -1,83 +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 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
deleted file mode 100755
index 8462d1849..000000000
--- a/src/transport/test_transport_simple_send_v2.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/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/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
index 795c157d7..932b0e583 100644
--- a/src/transport/test_transport_start_with_config.c
+++ b/src/transport/test_transport_start_with_config.c
@@ -20,7 +20,7 @@
/**
* @file transport/test_transport_start_with_config.c
- * @brief Test case executing a script which sends a test message between two peers.
+ * @brief Generic program to start testcases in an configurable topology.
* @author t3sserakt
*/
#include "platform.h"
@@ -29,57 +29,32 @@
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
-/**
- * Return value of the test.
- *
- */
-static unsigned int rv = 0;
-
-static char *topology_config;
-
-/**
- * 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)
{
+ char *topology_config;
+
GNUNET_log_setup ("test-netjail",
"DEBUG",
NULL);
topology_config = argv[1];
- GNUNET_SCHEDULER_run (&run,
- NULL);
+ struct GNUNET_TESTING_Command commands[] = {
+ GNUNET_TESTING_cmd_netjail_start ("netjail-start",
+ topology_config),
+ GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
+ topology_config),
+ GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
+ "netjail-start-testbed",
+ topology_config),
+ GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
+ topology_config),
+ GNUNET_TESTING_cmd_end ()
+ };
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Test finished!\n");
- return rv;
+ return GNUNET_TESTING_main (commands,
+ TIMEOUT);
}
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index ecdabd35f..f6e34df62 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -29,92 +29,71 @@
#include "gnunet_testing_lib.h"
-struct StartPeerState_v2
+/**
+ * Struct to store information needed in callbacks.
+ *
+ */
+struct ConnectPeersState
{
/**
- * The ip of a node.
- */
- char *node_ip;
-
- /**
- * Receive callback
+ * Context for our asynchronous completion.
*/
- struct GNUNET_MQ_MessageHandler *handlers;
+ struct GNUNET_TESTING_AsyncContext ac;
- const char *cfgname;
+ GNUNET_TRANSPORT_NotifyConnect notify_connect;
/**
- * Peer's configuration
+ * The testing system of this node.
*/
- struct GNUNET_CONFIGURATION_Handle *cfg;
-
- struct GNUNET_TESTING_Peer *peer;
+ struct GNUNET_TESTING_System *tl_system;
- /**
- * Peer identity
- */
- struct GNUNET_PeerIdentity id;
+ // Label of the cmd which started the test system.
+ const char *create_label;
/**
- * Peer's transport service handle
+ * Number globally identifying the node.
+ *
*/
- struct GNUNET_TRANSPORT_CoreHandle *th;
+ uint32_t num;
/**
- * Application handle
+ * Label of the cmd to start a peer.
+ *
*/
- struct GNUNET_TRANSPORT_ApplicationHandle *ah;
+ const char *start_peer_label;
/**
- * Peer's PEERSTORE Handle
+ * The peer identity of this peer.
+ *
*/
- struct GNUNET_PEERSTORE_Handle *ph;
+ struct GNUNET_PeerIdentity *id;
/**
- * Hello get task
+ * The topology of the test setup.
*/
- struct GNUNET_SCHEDULER_Task *rh_task;
+ struct GNUNET_TESTING_NetjailTopology *topology;
/**
- * Peer's transport get hello handle to retrieve peer's HELLO message
+ * Connections to other peers.
*/
- struct GNUNET_PEERSTORE_IterateContext *pic;
+ struct GNUNET_TESTING_NodeConnection *node_connections_head;
- /**
- * Hello
- */
- char *hello;
+ struct GNUNET_TESTING_Interpreter *is;
/**
- * Hello size
+ * Number of connections.
*/
- 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;
-
+ unsigned int con_num;
};
-
struct StartPeerState
{
/**
+ * Context for our asynchronous completion.
+ */
+ struct GNUNET_TESTING_AsyncContext ac;
+
+ /**
* The ip of a node.
*/
char *node_ip;
@@ -179,8 +158,6 @@ struct StartPeerState
char *local_m;
- unsigned int finished;
-
const char *system_label;
/**
@@ -192,9 +169,24 @@ struct StartPeerState
struct GNUNET_TESTING_System *tl_system;
+ GNUNET_TRANSPORT_NotifyConnect notify_connect;
+
};
+/**
+ * Function to get the trait with the struct ConnectPeersState.
+ *
+ * @param[out] sps struct ConnectPeersState.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
+int
+GNUNET_TESTING_get_trait_connect_peer_state (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct ConnectPeersState **cps);
+
+
int
GNUNET_TRANSPORT_get_trait_state (const struct
GNUNET_TESTING_Command
@@ -203,61 +195,28 @@ GNUNET_TRANSPORT_get_trait_state (const struct
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_v3 (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,
+ uint32_t no,
char *node_ip,
struct GNUNET_MQ_MessageHandler *handlers,
- const char *cfgname);
+ const char *cfgname,
+ GNUNET_TRANSPORT_NotifyConnect notify_connect);
+
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
const char *start_label);
+
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
const char *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_connect_peers_v3 (const char *label,
- const char *start_peer_label,
- const char *create_label,
- uint32_t num,
- struct GNUNET_TESTING_NetjailTopology *
- topology);
+ uint32_t num,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology);
-struct GNUNET_TESTING_Command
-GNUNET_TRANSPORT_cmd_send_simple (const char *label,
- char *m,
- char *n,
- uint32_t num,
- const char *start_peer_label);
/**
* Create command.
@@ -270,43 +229,29 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
* @return command.
*/
struct GNUNET_TESTING_Command
-GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
- const char *start_peer_label,
- uint32_t num);
+GNUNET_TRANSPORT_cmd_send_simple (const char *label,
+ const char *start_peer_label,
+ uint32_t num);
+
+
+
+
int
GNUNET_TRANSPORT_get_trait_peer_id (const struct
GNUNET_TESTING_Command *cmd,
struct GNUNET_PeerIdentity **id);
+
int
GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
GNUNET_TESTING_Command
*cmd,
struct
- GNUNET_CONTAINER_MultiShortmap *
+ 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_connected_peers_map_v3 (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
@@ -327,19 +272,5 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct
GNUNET_TRANSPORT_ApplicationHandle
**ah);
-int
-GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
- GNUNET_TESTING_Command *cmd,
- struct
- GNUNET_TRANSPORT_ApplicationHandle
- **ah);
-
-int
-GNUNET_TRANSPORT_get_trait_application_handle_v3 (const struct
- GNUNET_TESTING_Command *cmd,
- struct
- GNUNET_TRANSPORT_ApplicationHandle
- **ah);
-
#endif
/* end of transport_testing.h */
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 82194ff15..2e51363f6 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -36,40 +36,240 @@
*/
#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
-/**
- * Struct to store information needed in callbacks.
- *
- */
-struct ConnectPeersState
+#define CONNECT_ADDRESS_TEMPLATE_TCP "tcp-192.168.15.%u:60002"
+
+#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
+
+#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
+
+#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
+
+#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
+
+#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
+
+#define PREFIX_TCP "tcp"
+
+#define PREFIX_UDP "udp"
+
+
+
+
+static struct GNUNET_PeerIdentity *
+get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- // Label of the cmd which started the test system.
- const char *create_label;
-
- /**
- * Number globally identifying the node.
- *
- */
- uint32_t num;
+ struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
+ struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
+ GNUNET_CRYPTO_EddsaPublicKey);
+ struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
+ GNUNET_CRYPTO_EddsaPrivateKey);
+
+ priv_key = GNUNET_TESTING_hostkey_get (tl_system,
+ num,
+ peer);
+
+ GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
+ pub_key);
+ peer->public_key = *pub_key;
+ return peer;
+}
+
+
+static int
+log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
+{
+ struct GNUNET_TESTING_NetjailNode *node = value;
+ struct GNUNET_TESTING_NodeConnection *pos_connection;
+ struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "plugin: %s space: %u node: %u global: %u\n",
+ node->plugin,
+ node->namespace_n,
+ node->node_n,
+ node->is_global);
+
+ for (pos_connection = node->node_connections_head; NULL != pos_connection;
+ pos_connection = pos_connection->next)
+ {
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "namespace_n: %u node_n: %u node_type: %u\n",
+ pos_connection->namespace_n,
+ pos_connection->node_n,
+ pos_connection->node_type);
+
+ for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
+ pos_prefix =
+ pos_prefix->next)
+ {
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "prefix: %s\n",
+ pos_prefix->address_prefix);
+ }
+ }
+ return GNUNET_YES;
+}
+
+
+static int
+log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
+{
+ struct GNUNET_TESTING_NetjailNamespace *namespace = value;
+ struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "router_tcp: %u router_udp: %u spaces: %u\n",
+ router->tcp_port,
+ router->udp_port,
+ namespace->namespace_n);
+ GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
+ return GNUNET_YES;
+}
+
+
+static int
+log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
+{
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "plugin: %s spaces: %u nodes: %u known: %u\n",
+ topology->plugin,
+ topology->namespaces_n,
+ topology->nodes_m,
+ topology->nodes_x);
+
+ GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
+ log_namespaces, NULL);
+ GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
+ NULL);
+ return GNUNET_YES;
+}
+
+
+static struct GNUNET_TESTING_NodeConnection *
+get_connections (unsigned int num, struct
+ GNUNET_TESTING_NetjailTopology *topology)
+{
+ struct GNUNET_TESTING_NetjailNode *node;
+ struct GNUNET_ShortHashCode *hkey;
+ struct GNUNET_HashCode hc;
+ struct GNUNET_TESTING_NetjailNamespace *namespace;
+ unsigned int namespace_n, node_m;
+
+ log_topo (topology);
+
+ hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+ if (topology->nodes_x >= num)
+ {
+
+ GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
+ hkey);
+ }
+ else
+ {
+ namespace_n = (unsigned int) floor ((num - topology->nodes_x)
+ / topology->nodes_m);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
+ num,
+ topology->nodes_x,
+ topology->nodes_m,
+ namespace_n);
+ hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+ GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
+ hkey);
+ node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
+ hkey = GNUNET_new (struct GNUNET_ShortHashCode);
+ GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
+ memcpy (hkey,
+ &hc,
+ sizeof (*hkey));
+ node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
+ hkey);
+ }
+
+
+ return node->node_connections_head;
+}
- /**
- * Label of the cmd to start a peer.
- *
- */
- const char *start_peer_label;
- /**
- * The peer identity of this peer.
- *
- */
- struct GNUNET_PeerIdentity *id;
+static unsigned int
+calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
+ struct GNUNET_TESTING_NetjailTopology *topology)
+{
+ unsigned int n, m, num;
+
+ n = node_connection->namespace_n;
+ m = node_connection->node_n;
- struct GNUNET_TESTING_Interpreter *is;
-};
+ if (0 == n)
+ num = m;
+ else
+ num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
+
+ return num;
+}
+
+
+static char *
+get_address (struct GNUNET_TESTING_NodeConnection *connection,
+ char *prefix)
+{
+ struct GNUNET_TESTING_NetjailNode *node;
+ char *addr;
+
+ node = connection->node;
+ if (connection->namespace_n == node->namespace_n)
+ {
+ if (0 == strcmp (PREFIX_TCP, prefix))
+ {
+
+ GNUNET_asprintf (&addr,
+ CONNECT_ADDRESS_TEMPLATE_TCP,
+ connection->node_n);
+ }
+ else if (0 == strcmp (PREFIX_UDP, prefix))
+ {
+ GNUNET_asprintf (&addr,
+ CONNECT_ADDRESS_TEMPLATE_UDP,
+ connection->node_n);
+ }
+ else
+ {
+ GNUNET_break (0);
+ }
+ }
+ else
+ {
+ if (0 == strcmp (PREFIX_TCP, prefix))
+ {
+
+ GNUNET_asprintf (&addr,
+ ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
+ connection->namespace_n);
+ }
+ else if (0 == strcmp (PREFIX_UDP, prefix))
+ {
+ GNUNET_asprintf (&addr,
+ ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
+ connection->namespace_n);
+ }
+ else
+ {
+ GNUNET_break (0);
+ }
+ }
+
+ return addr;
+}
/**
@@ -83,24 +283,17 @@ connect_peers_run (void *cls,
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;
- struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
+ struct GNUNET_PeerIdentity *peer;
char *addr;
- // struct GNUNET_TIME_Absolute t;
- char *hello;
- // size_t *hello_size;
enum GNUNET_NetworkType nt = 0;
- char *peer_id;
- struct GNUNET_PeerIdentity *id;
- struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
uint32_t num;
+ struct GNUNET_TESTING_NodeConnection *pos_connection;
+ struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
+ unsigned int con_num = 0;
cps->is = is;
peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
@@ -108,121 +301,82 @@ connect_peers_run (void *cls,
GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
&ah);
- GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
- &hello);
-
- GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
- &id);
-
system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
cps->create_label);
GNUNET_TESTING_get_trait_test_system (system_cmd,
&tl_system);
- if (2 == cps->num)
- num = 1;
- else
- num = 2;
+ cps->tl_system = tl_system;
+ cps->node_connections_head = get_connections (cps->num, cps->topology);
- // if (strstr (hello, "60002") != NULL)
- if (2 == num)
- {
- addr = "tcp-192.168.15.2:60002";
- peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
- }
- else
+ for (pos_connection = cps->node_connections_head; NULL != pos_connection;
+ pos_connection = pos_connection->next)
{
- addr = "tcp-192.168.15.1:60002";
- peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
+ con_num++;
+ num = calculate_num (pos_connection, cps->topology);
+ for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
+ pos_prefix =
+ pos_prefix->next)
+ {
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "prefix: %s\n",
+ pos_prefix->address_prefix);
+
+ addr = get_address (pos_connection, pos_prefix->address_prefix);
+
+ peer = get_pub_key (num, tl_system);
+
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "num: %u pub_key %s addr: %s\n",
+ num,
+ GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
+ addr);
+
+ cps->id = peer;
+
+ GNUNET_TRANSPORT_application_validate (ah,
+ peer,
+ nt,
+ addr);
+ }
}
-
- 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.
- // ---------------------------------------------
- /*peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label);
- GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd,
- &id);
- GNUNET_TRANSPORT_get_trait_hello (peer2_cmd,
- &hello);
- GNUNET_TRANSPORT_get_trait_hello_size (peer2_cmd,
- &hello_size);
-
- addr = GNUNET_HELLO_extract_address (hello,
- *hello_size,
- id,
- &nt,
- &t);*/
-
- // ----------------------------------------------
-
-
- GNUNET_TRANSPORT_application_validate (ah,
- peer,
- nt,
- addr);
+ cps->con_num = con_num;
}
/**
- * 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.
+ * Callback from start peer cmd for signaling a peer got connected.
*
*/
-// FIXME: this needs a complete rewrite!
-static int
-connect_peers_finish (void *cls,
- GNUNET_SCHEDULER_TaskCallback cont,
- void *cont_cls)
+static void *
+notify_connect (void *cls,
+ const struct GNUNET_PeerIdentity *peer,
+ struct GNUNET_MQ_Handle *mq)
{
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->is,
- cps->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);
+ struct GNUNET_PeerIdentity *peer_connection;
+ unsigned int con_num = 0;
+ struct GNUNET_TESTING_NodeConnection *pos_connection;
+ unsigned int num;
+ void *ret = NULL;
+
+ for (pos_connection = cps->node_connections_head; NULL != pos_connection;
+ pos_connection = pos_connection->next)
+ {
+ num = calculate_num (pos_connection, cps->topology);
+ peer_connection = get_pub_key (num, cps->tl_system);
+ if (0 == GNUNET_memcmp (peer,
+ peer_connection))
+ con_num++;
+ }
- // 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)
+ if (cps->con_num == con_num)
{
- cont (cont_cls);
+ GNUNET_TESTING_async_finish (&cps->ac);
}
-
- GNUNET_free (key);
return ret;
}
@@ -241,11 +395,58 @@ connect_peers_cleanup (void *cls)
}
+/**
+ * This function prepares an array with traits.
+ *
+ */
+static int
+connect_peers_traits (void *cls,
+ const void **ret,
+ const char *trait,
+ unsigned int index)
+{
+ struct StartPeerState *cps = cls;
+ struct GNUNET_TESTING_Trait traits[] = {
+ {
+ .index = 0,
+ .trait_name = "state",
+ .ptr = (const void *) cps,
+ },
+ GNUNET_TESTING_trait_end ()
+ };
+ return GNUNET_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+}
+
+
+/**
+ * Function to get the trait with the struct ConnectPeersState.
+ *
+ * @param[out] sps struct ConnectPeersState.
+ * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
+ *
+ */
+int
+GNUNET_TESTING_get_trait_connect_peer_state (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct ConnectPeersState **cps)
+{
+ return cmd->traits (cmd->cls,
+ (const void **) cps,
+ "state",
+ (unsigned int) 0);
+}
+
+
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
const char *start_peer_label,
const char *create_label,
- uint32_t num)
+ uint32_t num,
+ struct GNUNET_TESTING_NetjailTopology *
+ topology)
{
struct ConnectPeersState *cps;
@@ -253,6 +454,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
cps->start_peer_label = start_peer_label;
cps->num = num;
cps->create_label = create_label;
+ cps->topology = topology;
+ cps->notify_connect = &notify_connect;
{
struct GNUNET_TESTING_Command cmd = {
@@ -260,7 +463,8 @@ GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
.label = label,
.run = &connect_peers_run,
.ac = &cps->ac,
- .cleanup = &connect_peers_cleanup
+ .cleanup = &connect_peers_cleanup,
+ .traits = &connect_peers_traits
};
return cmd;
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
deleted file mode 100644
index 8d0f74916..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v2.c
+++ /dev/null
@@ -1,237 +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 "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
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- // 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;
-
- struct GNUNET_TESTING_Interpreter *is;
-};
-
-
-/**
- * The run method of this cmd will connect to peers.
- *
- */
-static void
-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;
- 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;
-
- cps->is = is;
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- cps->start_peer_label);
- GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
- &ah);
-
- system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- 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->is,
- 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;
-}
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-connect_peers_cleanup (void *cls)
-{
- 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,
- .ac = &cps->ac,
- .cleanup = &connect_peers_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/transport/transport_api_cmd_connecting_peers_v3.c b/src/transport/transport_api_cmd_connecting_peers_v3.c
deleted file mode 100644
index ae32a087a..000000000
--- a/src/transport/transport_api_cmd_connecting_peers_v3.c
+++ /dev/null
@@ -1,496 +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 "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 "tcp-192.168.15.%u:60002"
-
-#define CONNECT_ADDRESS_TEMPLATE_UDP "udp-192.168.15.%u:60002"
-
-#define ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.150.%u:60002"
-
-#define ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.150.%u:60002"
-
-#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_TCP "tcp-92.68.151.%u:60002"
-
-#define GLOBAL_CONNECT_ADDRESS_TEMPLATE_UDP "udp-92.68.151.%u:60002"
-
-#define PREFIX_TCP "tcp"
-
-#define PREFIX_UDP "udp"
-
-/**
- * Struct to store information needed in callbacks.
- *
- */
-struct ConnectPeersState
-{
- /**
- * Context for our asynchronous completion.
- */
- struct GNUNET_TESTING_AsyncContext ac;
-
- /**
- * The testing system of this node.
- */
- struct GNUNET_TESTING_System *tl_system;
-
- // 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 topology of the test setup.
- */
- struct GNUNET_TESTING_NetjailTopology *topology;
-
- /**
- * Connections to other peers.
- */
- struct GNUNET_TESTING_NodeConnection *node_connections_head;
-
- struct GNUNET_TESTING_Interpreter *is;
-
- /**
- * Number of connections.
- */
- unsigned int con_num;
-};
-
-
-static struct GNUNET_PeerIdentity *
-get_pub_key (unsigned int num, struct GNUNET_TESTING_System *tl_system)
-{
- struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
- struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
- GNUNET_CRYPTO_EddsaPublicKey);
- struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
- GNUNET_CRYPTO_EddsaPrivateKey);
-
- priv_key = GNUNET_TESTING_hostkey_get (tl_system,
- num,
- peer);
-
- GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
- pub_key);
- peer->public_key = *pub_key;
- return peer;
-}
-
-
-static int
-log_nodes (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
-{
- struct GNUNET_TESTING_NetjailNode *node = value;
- struct GNUNET_TESTING_NodeConnection *pos_connection;
- struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin: %s space: %u node: %u global: %u\n",
- node->plugin,
- node->namespace_n,
- node->node_n,
- node->is_global);
-
- for (pos_connection = node->node_connections_head; NULL != pos_connection;
- pos_connection = pos_connection->next)
- {
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "namespace_n: %u node_n: %u node_type: %u\n",
- pos_connection->namespace_n,
- pos_connection->node_n,
- pos_connection->node_type);
-
- for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
- pos_prefix =
- pos_prefix->next)
- {
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "prefix: %s\n",
- pos_prefix->address_prefix);
- }
- }
- return GNUNET_YES;
-}
-
-
-static int
-log_namespaces (void *cls, const struct GNUNET_ShortHashCode *id, void *value)
-{
- struct GNUNET_TESTING_NetjailNamespace *namespace = value;
- struct GNUNET_TESTING_NetjailRouter *router = namespace->router;
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "router_tcp: %u router_udp: %u spaces: %u\n",
- router->tcp_port,
- router->udp_port,
- namespace->namespace_n);
- GNUNET_CONTAINER_multishortmap_iterate (namespace->nodes, &log_nodes, NULL);
- return GNUNET_YES;
-}
-
-
-static int
-log_topo (struct GNUNET_TESTING_NetjailTopology *topology)
-{
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "plugin: %s spaces: %u nodes: %u known: %u\n",
- topology->plugin,
- topology->namespaces_n,
- topology->nodes_m,
- topology->nodes_x);
-
- GNUNET_CONTAINER_multishortmap_iterate (topology->map_namespaces,
- log_namespaces, NULL);
- GNUNET_CONTAINER_multishortmap_iterate (topology->map_globals, &log_nodes,
- NULL);
- return GNUNET_YES;
-}
-
-
-static struct GNUNET_TESTING_NodeConnection *
-get_connections (unsigned int num, struct
- GNUNET_TESTING_NetjailTopology *topology)
-{
- struct GNUNET_TESTING_NetjailNode *node;
- struct GNUNET_ShortHashCode *hkey;
- struct GNUNET_HashCode hc;
- struct GNUNET_TESTING_NetjailNamespace *namespace;
- unsigned int namespace_n, node_m;
-
- log_topo (topology);
-
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- if (topology->nodes_x >= num)
- {
-
- GNUNET_CRYPTO_hash (&num, sizeof(num), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
- hkey);
- }
- else
- {
- namespace_n = (unsigned int) floor ((num - topology->nodes_x)
- / topology->nodes_m);
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "num: %u nodes_x: %u nodes_m: %u namespace_n: %u\n",
- num,
- topology->nodes_x,
- topology->nodes_m,
- namespace_n);
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- GNUNET_CRYPTO_hash (&namespace_n, sizeof(namespace_n), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
- hkey);
- node_m = num - topology->nodes_x - topology->nodes_m * (namespace_n - 1);
- hkey = GNUNET_new (struct GNUNET_ShortHashCode);
- GNUNET_CRYPTO_hash (&node_m, sizeof(node_m), &hc);
- memcpy (hkey,
- &hc,
- sizeof (*hkey));
- node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
- hkey);
- }
-
-
- return node->node_connections_head;
-}
-
-
-static unsigned int
-calculate_num (struct GNUNET_TESTING_NodeConnection *node_connection,
- struct GNUNET_TESTING_NetjailTopology *topology)
-{
- unsigned int n, m, num;
-
- n = node_connection->namespace_n;
- m = node_connection->node_n;
-
- if (0 == n)
- num = m;
- else
- num = (n - 1) * topology->nodes_m + m + topology->nodes_x;
-
- return num;
-}
-
-
-static char *
-get_address (struct GNUNET_TESTING_NodeConnection *connection,
- char *prefix)
-{
- struct GNUNET_TESTING_NetjailNode *node;
- char *addr;
-
- node = connection->node;
- if (connection->namespace_n == node->namespace_n)
- {
- if (0 == strcmp (PREFIX_TCP, prefix))
- {
-
- GNUNET_asprintf (&addr,
- CONNECT_ADDRESS_TEMPLATE_TCP,
- connection->node_n);
- }
- else if (0 == strcmp (PREFIX_UDP, prefix))
- {
- GNUNET_asprintf (&addr,
- CONNECT_ADDRESS_TEMPLATE_UDP,
- connection->node_n);
- }
- else
- {
- GNUNET_break (0);
- }
- }
- else
- {
- if (0 == strcmp (PREFIX_TCP, prefix))
- {
-
- GNUNET_asprintf (&addr,
- ROUTER_CONNECT_ADDRESS_TEMPLATE_TCP,
- connection->namespace_n);
- }
- else if (0 == strcmp (PREFIX_UDP, prefix))
- {
- GNUNET_asprintf (&addr,
- ROUTER_CONNECT_ADDRESS_TEMPLATE_UDP,
- connection->namespace_n);
- }
- else
- {
- GNUNET_break (0);
- }
- }
-
- return addr;
-}
-
-
-/**
- * The run method of this cmd will connect to peers.
- *
- */
-static void
-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;
-
-
- const struct GNUNET_TESTING_Command *peer1_cmd;
- struct GNUNET_TRANSPORT_ApplicationHandle *ah;
- struct GNUNET_PeerIdentity *peer;
- char *addr;
- enum GNUNET_NetworkType nt = 0;
- uint32_t num;
- struct GNUNET_TESTING_NodeConnection *pos_connection;
- struct GNUNET_TESTING_ADDRESS_PREFIX *pos_prefix;
- unsigned int con_num = 0;
-
- cps->is = is;
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- cps->start_peer_label);
- GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
- &ah);
-
- system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- cps->create_label);
- GNUNET_TESTING_get_trait_test_system (system_cmd,
- &tl_system);
-
- cps->tl_system = tl_system;
-
- cps->node_connections_head = get_connections (cps->num, cps->topology);
-
- for (pos_connection = cps->node_connections_head; NULL != pos_connection;
- pos_connection = pos_connection->next)
- {
- con_num++;
- num = calculate_num (pos_connection, cps->topology);
- for (pos_prefix = pos_connection->address_prefixes_head; NULL != pos_prefix;
- pos_prefix =
- pos_prefix->next)
- {
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "prefix: %s\n",
- pos_prefix->address_prefix);
-
- addr = get_address (pos_connection, pos_prefix->address_prefix);
-
- peer = get_pub_key (num, tl_system);
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "num: %u pub_key %s addr: %s\n",
- num,
- GNUNET_CRYPTO_eddsa_public_key_to_string (&(peer->public_key)),
- addr);
-
- cps->id = peer;
-
- GNUNET_TRANSPORT_application_validate (ah,
- peer,
- nt,
- addr);
- }
- }
- cps->con_num = con_num;
-}
-
-
-/**
- * The finish function of this cmd will check if the peers we are trying to
- * connect to are 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;
- struct GNUNET_PeerIdentity *peer;
- unsigned int con_num = 0;
- struct GNUNET_TESTING_NodeConnection *pos_connection;
- unsigned int num;
-
- peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->is,
- cps->start_peer_label);
- GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
- &connected_peers_map);
-
- for (pos_connection = cps->node_connections_head; NULL != pos_connection;
- pos_connection = pos_connection->next)
- {
- num = calculate_num (pos_connection, cps->topology);
- peer = get_pub_key (num, cps->tl_system);
- GNUNET_CRYPTO_hash (&(peer->public_key), sizeof(peer->public_key), &hc);
- memcpy (key,
- &hc,
- sizeof (*key));
- if (GNUNET_YES == GNUNET_CONTAINER_multishortmap_contains (
- connected_peers_map,
- key))
- con_num++;
- }
-
-
- if (cps->con_num == con_num)
- {
- cont (cont_cls);
- ret = GNUNET_YES;
- }
-
- GNUNET_free (key);
- return ret;
-}
-
-
-/**
- * The cleanup function of this cmd frees resources the cmd allocated.
- *
- */
-static void
-connect_peers_cleanup (void *cls)
-{
- struct ConnectPeersState *cps = cls;
-
- GNUNET_free (cps->id);
- GNUNET_free (cps);
-}
-
-
-struct GNUNET_TESTING_Command
-GNUNET_TRANSPORT_cmd_connect_peers_v3 (const char *label,
- const char *start_peer_label,
- const char *create_label,
- uint32_t num,
- struct GNUNET_TESTING_NetjailTopology *
- topology)
-{
- struct ConnectPeersState *cps;
-
- cps = GNUNET_new (struct ConnectPeersState);
- cps->start_peer_label = start_peer_label;
- cps->num = num;
- cps->create_label = create_label;
- cps->topology = topology;
-
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = cps,
- .label = label,
- .run = &connect_peers_run,
- .ac = &cps->ac,
- .cleanup = &connect_peers_cleanup
- };
-
- return cmd;
- }
-}
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 1599dfe97..0631f7051 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -36,18 +36,6 @@
struct SendSimpleState
{
/**
- * The number of the local node of the actual network namespace.
- *
- */
- char *m;
-
- /**
- * The number of the actual namespace.
- *
- */
- char *n;
-
- /**
* Number globally identifying the node.
*
*/
@@ -146,16 +134,12 @@ send_simple_run (void *cls,
*/
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_send_simple (const char *label,
- char *m,
- char *n,
- uint32_t num,
- const char *start_peer_label)
+ const char *start_peer_label,
+ uint32_t num)
{
struct SendSimpleState *sss;
sss = GNUNET_new (struct SendSimpleState);
- sss->m = m;
- sss->n = n;
sss->num = num;
sss->start_peer_label = start_peer_label;
{
diff --git a/src/transport/transport_api_cmd_send_simple_v2.c b/src/transport/transport_api_cmd_send_simple_v2.c
deleted file mode 100644
index 8d65eb684..000000000
--- a/src/transport/transport_api_cmd_send_simple_v2.c
+++ /dev/null
@@ -1,156 +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;
-};
-
-
-/**
- * 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)
-{
- 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,
- 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 (is,
- 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 44fc68807..dc19f10eb 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -51,7 +51,6 @@ hello_iter_cb (void *cb_cls,
const char *emsg)
{
struct StartPeerState *sps = cb_cls;
-
if (NULL == record)
{
sps->pic = NULL;
@@ -66,7 +65,7 @@ hello_iter_cb (void *cb_cls,
GNUNET_PEERSTORE_iterate_cancel (sps->pic);
sps->pic = NULL;
- sps->finished = GNUNET_YES;
+ GNUNET_TESTING_async_finish (&sps->ac);
}
@@ -122,7 +121,7 @@ notify_connect (void *cls,
struct StartPeerState *sps = cls;
struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
struct GNUNET_HashCode hc;
- int node_number;
+ struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
void *ret = NULL;
@@ -133,9 +132,7 @@ notify_connect (void *cls,
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);
+ GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
memcpy (key,
@@ -147,6 +144,11 @@ notify_connect (void *cls,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
GNUNET_free (key);
+
+ sps->notify_connect (cls,
+ peer,
+ mq);
+
// TODO what does the handler function need?
return ret;
}
@@ -167,7 +169,8 @@ start_peer_run (void *cls,
struct GNUNET_TESTING_System *tl_system;
char *home;
char *transport_unix_path;
- char *communicator_unix_path;
+ char *tcp_communicator_unix_path;
+ char *udp_communicator_unix_path;
char *bindto;
if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
@@ -192,7 +195,11 @@ start_peer_run (void *cls,
"$GNUNET_RUNTIME_DIR/tng-p%u.sock",
sps->no);
- GNUNET_asprintf (&communicator_unix_path,
+ GNUNET_asprintf (&tcp_communicator_unix_path,
+ "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
+ sps->no);
+
+ GNUNET_asprintf (&udp_communicator_unix_path,
"$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
sps->no);
@@ -200,6 +207,9 @@ start_peer_run (void *cls,
"%s:60002",
sps->node_ip);
+ LOG (GNUNET_ERROR_TYPE_ERROR,
+ "node_ip %s\n",
+ bindto);
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
home);
@@ -208,9 +218,15 @@ start_peer_run (void *cls,
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
"BINDTO",
bindto);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
+ "BINDTO",
+ bindto);
GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
"UNIXPATH",
- communicator_unix_path);
+ tcp_communicator_unix_path);
+ GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
+ "UNIXPATH",
+ udp_communicator_unix_path);
system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
sps->system_label);
@@ -417,10 +433,9 @@ start_peer_traits (void *cls,
*
*/
int
-GNUNET_TRANSPORT_get_trait_state (const struct
- GNUNET_TESTING_Command
- *cmd,
- struct StartPeerState **sps)
+GNUNET_TRANSPORT_get_trait_state (
+ const struct GNUNET_TESTING_Command *cmd,
+ struct StartPeerState **sps)
{
return cmd->traits (cmd->cls,
(const void **) sps,
@@ -481,7 +496,8 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
GNUNET_TESTING_Command
*cmd,
struct
- GNUNET_CONTAINER_MultiShortmap *
+ GNUNET_CONTAINER_MultiShortmap
+ *
*
connected_peers_map)
{
@@ -545,12 +561,11 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
struct GNUNET_TESTING_Command
GNUNET_TRANSPORT_cmd_start_peer (const char *label,
const char *system_label,
- char *m,
- char *n,
- char *local_m,
+ uint32_t no,
char *node_ip,
struct GNUNET_MQ_MessageHandler *handlers,
- const char *cfgname)
+ const char *cfgname,
+ GNUNET_TRANSPORT_NotifyConnect notify_connect)
{
struct StartPeerState *sps;
struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
@@ -558,14 +573,12 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
unsigned int i;
sps = GNUNET_new (struct StartPeerState);
- sps->m = m;
- sps->n = n;
- sps->local_m = local_m;
- sps->no = (atoi (n) - 1) * atoi (sps->local_m) + atoi (m);
+ sps->no = no;
sps->system_label = system_label;
sps->connected_peers_map = connected_peers_map;
sps->cfgname = cfgname;
sps->node_ip = node_ip;
+ sps->notify_connect = notify_connect;
if (NULL != handlers)
{
@@ -578,15 +591,14 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
i * sizeof(struct GNUNET_MQ_MessageHandler));
}
- {
- struct GNUNET_TESTING_Command cmd = {
- .cls = sps,
- .label = label,
- .run = &start_peer_run,
- .cleanup = &start_peer_cleanup,
- .traits = &start_peer_traits
- };
-
- return cmd;
- }
+ struct GNUNET_TESTING_Command cmd = {
+ .cls = sps,
+ .label = label,
+ .run = &start_peer_run,
+ .ac = &sps->ac,
+ .cleanup = &start_peer_cleanup,
+ .traits = &start_peer_traits
+ };
+
+ return cmd;
}
diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c
deleted file mode 100644
index 94799eddd..000000000
--- a/src/transport/transport_api_cmd_start_peer_v2.c
+++ /dev/null
@@ -1,605 +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 "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,
- 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 (is);
- 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 (is,
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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)
-{
- 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,
- .cleanup = &start_peer_cleanup,
- .traits = &start_peer_traits
- };
-
- return cmd;
-}
diff --git a/src/transport/transport_api_cmd_start_peer_v3.c b/src/transport/transport_api_cmd_start_peer_v3.c
deleted file mode 100644
index 1a19ce60e..000000000
--- a/src/transport/transport_api_cmd_start_peer_v3.c
+++ /dev/null
@@ -1,617 +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 "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;
- struct GNUNET_CRYPTO_EddsaPublicKey public_key = peer->public_key;
-
- 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));
-
- GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &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,
- 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 *tcp_communicator_unix_path;
- char *udp_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 (is);
- 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 (&tcp_communicator_unix_path,
- "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
- sps->no);
-
- GNUNET_asprintf (&udp_communicator_unix_path,
- "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
- sps->no);
-
- GNUNET_asprintf (&bindto,
- "%s:60002",
- sps->node_ip);
-
- LOG (GNUNET_ERROR_TYPE_ERROR,
- "node_ip %s\n",
- bindto);
-
- 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-udp",
- "BINDTO",
- bindto);
- GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
- "UNIXPATH",
- tcp_communicator_unix_path);
- GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-udp",
- "UNIXPATH",
- udp_communicator_unix_path);
-
- system_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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 (is);
- 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)
-{
- 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_v3 (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_v3 (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_v3 (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_v3 (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_v3 (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_v3 (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_v3 (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,
- .cleanup = &start_peer_cleanup,
- .traits = &start_peer_traits
- };
-
- return cmd;
-}
diff --git a/src/util/child_management.c b/src/util/child_management.c
index 4ef42dba2..832e05ece 100644
--- a/src/util/child_management.c
+++ b/src/util/child_management.c
@@ -19,7 +19,7 @@
*/
/**
- * @file testing/child_management.c
+ * @file util/child_management.c
* @brief Handling of child processes in GNUnet.
* @author Christian Grothoff (ANASTASIS)
* @author Dominik Meister (ANASTASIS)
@@ -153,7 +153,9 @@ sighandler_child_death (void)
errno = old_errno; /* restore errno */
}
-
+/**
+ * Initializing the signal pipe for child handling.
+ */
static void
child_management_start (void)
{
@@ -191,6 +193,14 @@ child_management_done (void)
}
+/**
+ * Adding a child process to be monitored by the child management.
+ *
+ * @param proc The child process to be monitored.
+ * @param cp The callback to be called, when the child process completed.
+ * @param cb_cls The closure for the callback.
+ * @return An handle for the the child being monitored.
+ */
struct GNUNET_ChildWaitHandle *
GNUNET_wait_child (struct GNUNET_OS_Process *proc,
GNUNET_ChildCompletedCallback cb,
@@ -219,6 +229,11 @@ GNUNET_wait_child (struct GNUNET_OS_Process *proc,
}
+/**
+ * Removing child handle.
+ *
+ * @param cwh The handle to be removed.
+ */
void
GNUNET_wait_child_cancel (struct GNUNET_ChildWaitHandle *cwh)
{