aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-09-13 18:25:21 +0200
committert3sserakt <t3ss@posteo.de>2021-09-13 18:25:21 +0200
commit72d77af5270ba1dabe6fa8c45009601b44d23b7b (patch)
tree3ea58e04fdaf79befff8925086b2dbf391586d64 /src
parent46e07ed8eb64ff5a7473ac51de2e39c5a8a6ab3d (diff)
downloadgnunet-72d77af5270ba1dabe6fa8c45009601b44d23b7b.tar.gz
gnunet-72d77af5270ba1dabe6fa8c45009601b44d23b7b.zip
- added tng milestone 2 versions with improvements onto version 1 files , fixed smaller issues in milestone 1 versions, added version 1 to buildbot, added new testcase for testing udp backchannel
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_testing_ng_lib.h179
-rw-r--r--src/include/gnunet_transport_application_service.h7
-rw-r--r--src/testing/Makefile.am12
-rw-r--r--src/testing/gnunet-cmds-helper.c20
-rwxr-xr-xsrc/testing/netjail_core_v2.sh260
-rwxr-xr-xsrc/testing/netjail_exec_v2.sh14
-rwxr-xr-xsrc/testing/netjail_start_v2.sh61
-rwxr-xr-xsrc/testing/netjail_stop_v2.sh59
-rw-r--r--src/testing/test_testing_api_cmd_netjail.c10
-rw-r--r--src/testing/testing.c381
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c20
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem_v2.c718
-rw-r--r--src/testing/testing_api_cmd_netjail_start_v2.c229
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c143
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_v2.c225
-rwxr-xr-xsrc/testing/topo.sh95
-rw-r--r--src/transport/Makefile.am39
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c13
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send_v2.c262
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c262
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel_send.c262
-rw-r--r--src/transport/test_transport_port_forward.c85
-rw-r--r--src/transport/test_transport_simple_send.c86
-rw-r--r--src/transport/test_transport_simple_send_v2.c83
-rwxr-xr-xsrc/transport/test_transport_simple_send_v2.sh2
-rw-r--r--src/transport/transport-testing-cmds.h233
-rw-r--r--src/transport/transport-testing-ng.h107
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c56
-rw-r--r--src/transport/transport_api_cmd_connecting_peers_v2.c242
-rw-r--r--src/transport/transport_api_cmd_send_simple_v2.c156
-rw-r--r--src/transport/transport_api_cmd_start_peer.c36
-rw-r--r--src/transport/transport_api_cmd_start_peer_v2.c607
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c2
33 files changed, 4810 insertions, 156 deletions
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 939863d67..a6f8429f4 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -47,6 +47,109 @@
47 } while (0) 47 } while (0)
48 48
49 49
50/**
51 * Router of a network namespace.
52 */
53struct GNUNET_TESTING_NetjailRouter
54{
55 /**
56 * Will tcp be forwarded?
57 */
58 unsigned int tcp_port;
59
60 /**
61 * Will udp be forwarded?
62 */
63 unsigned int udp_port;
64};
65
66
67/**
68 * Node in the netjail topology.
69 */
70struct GNUNET_TESTING_NetjailNode
71{
72 /**
73 * Plugin for the test case to be run on this node.
74 */
75 char *plugin;
76
77 /**
78 * Flag indicating if this node is a global known node.
79 */
80 unsigned int is_global;
81
82 /**
83 * The number of the namespace this node is running in.
84 */
85 unsigned int namespace_n;
86
87 /**
88 * The number of this node in the namespace.
89 */
90 unsigned int node_n;
91};
92
93
94/**
95 * Namespace in a topology.
96 */
97struct GNUNET_TESTING_NetjailNamespace
98{
99 /**
100 * The number of the namespace.
101 */
102 unsigned int namespace_n;
103
104 /**
105 * Router of the namespace.
106 */
107 struct GNUNET_TESTING_NetjailRouter *router;
108
109 /**
110 * Hash map containing the nodes in this namespace.
111 */
112 struct GNUNET_CONTAINER_MultiShortmap *nodes;
113};
114
115/**
116 * Toplogy of our netjail setup.
117 */
118struct GNUNET_TESTING_NetjailTopology
119{
120
121 /**
122 * Default plugin for the test case to be run on nodes.
123 */
124 char *plugin;
125
126 /**
127 * Number of namespaces.
128 */
129 unsigned int namespaces_n;
130
131 /**
132 * Number of nodes per namespace.
133 */
134 unsigned int nodes_m;
135
136 /**
137 * Number of global known nodes per namespace.
138 */
139 unsigned int nodes_x;
140
141 /**
142 * Hash map containing the namespaces (for natted nodes) of the topology.
143 */
144 struct GNUNET_CONTAINER_MultiShortmap *map_namespaces;
145
146 /**
147 * Hash map containing the global known nodes which are not natted.
148 */
149 struct GNUNET_CONTAINER_MultiShortmap *map_globals;
150};
151
152
50/* ******************* Generic interpreter logic ************ */ 153/* ******************* Generic interpreter logic ************ */
51 154
52/** 155/**
@@ -456,6 +559,16 @@ struct GNUNET_TESTING_Timer
456 559
457 560
458/** 561/**
562 * Getting the topology from file.
563 *
564 * @param filename The name of the topology file.
565 * @return The GNUNET_TESTING_NetjailTopology
566 */
567struct GNUNET_TESTING_NetjailTopology *
568GNUNET_TESTING_get_topo_from_file (const char *filename);
569
570
571/**
459 * Obtain performance data from the interpreter. 572 * Obtain performance data from the interpreter.
460 * 573 *
461 * @param timers what commands (by label) to obtain runtimes for 574 * @param timers what commands (by label) to obtain runtimes for
@@ -853,7 +966,8 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
853 * Create command. 966 * Create command.
854 * 967 *
855 * @param label name for command. 968 * @param label name for command.
856 * @param binaryname to start. 969 * @param local_m Number of local nodes in each namespace.
970 * @param global_n The number of namespaces.
857 * @return command. 971 * @return command.
858 */ 972 */
859struct GNUNET_TESTING_Command 973struct GNUNET_TESTING_Command
@@ -861,6 +975,17 @@ GNUNET_TESTING_cmd_netjail_start (const char *label,
861 char *local_m, 975 char *local_m,
862 char *global_n); 976 char *global_n);
863 977
978/**
979 * Create command.
980 *
981 * @param label name for command.
982 * @param topology_config Configuration file for the test topology.
983 * @return command.
984 */
985struct GNUNET_TESTING_Command
986GNUNET_TESTING_cmd_netjail_start_v2 (const char *label,
987 char *topology_config);
988
864 989
865/** 990/**
866 * Create command. 991 * Create command.
@@ -880,6 +1005,20 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
880/** 1005/**
881 * Create command. 1006 * Create command.
882 * 1007 *
1008 * @param label Name for the command.
1009 * @param topology_config Configuration file for the test topology.
1010 * @param rv Pointer to the return value of the test.
1011 * @return command.
1012 */
1013struct GNUNET_TESTING_Command
1014GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label,
1015 const char *topology_config,
1016 unsigned int *rv);
1017
1018
1019/**
1020 * Create command.
1021 *
883 * @param label name for command. 1022 * @param label name for command.
884 * @param binaryname to stop. 1023 * @param binaryname to stop.
885 * @return command. 1024 * @return command.
@@ -890,12 +1029,36 @@ GNUNET_TESTING_cmd_netjail_stop (const char *label,
890 char *global_n); 1029 char *global_n);
891 1030
892 1031
1032/**
1033 * Create command.
1034 *
1035 * @param label name for command.
1036 * @param topology_config Configuration file for the test topology.
1037 * @return command.
1038 */
1039struct GNUNET_TESTING_Command
1040GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
1041 char *topology_config);
1042
1043
893struct GNUNET_TESTING_Command 1044struct GNUNET_TESTING_Command
894GNUNET_TESTING_cmd_stop_testing_system (const char *label, 1045GNUNET_TESTING_cmd_stop_testing_system (const char *label,
895 const char *helper_start_label, 1046 const char *helper_start_label,
896 char *local_m, 1047 char *local_m,
897 char *global_n); 1048 char *global_n);
898 1049
1050/**
1051 * Create command.
1052 *
1053 * @param label name for command.
1054 * @param topology_config Configuration file for the test topology.
1055 * @return command.
1056 */
1057struct GNUNET_TESTING_Command
1058GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
1059 const char *helper_start_label,
1060 const char *topology_config);
1061
899 1062
900int 1063int
901GNUNET_TESTING_get_trait_helper_handles (const struct 1064GNUNET_TESTING_get_trait_helper_handles (const struct
@@ -903,6 +1066,20 @@ GNUNET_TESTING_get_trait_helper_handles (const struct
903 struct GNUNET_HELPER_Handle ***helper); 1066 struct GNUNET_HELPER_Handle ***helper);
904 1067
905 1068
1069/**
1070 * Offer handles to testing cmd helper from trait
1071 *
1072 * @param cmd command to extract the message from.
1073 * @param pt pointer to message.
1074 * @return #GNUNET_OK on success.
1075 */
1076int
1077GNUNET_TESTING_get_trait_helper_handles_v2 (const struct
1078 GNUNET_TESTING_Command *cmd,
1079 struct GNUNET_HELPER_Handle ***
1080 helper);
1081
1082
906struct GNUNET_TESTING_Command 1083struct GNUNET_TESTING_Command
907GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label, 1084GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
908 unsigned int * 1085 unsigned int *
diff --git a/src/include/gnunet_transport_application_service.h b/src/include/gnunet_transport_application_service.h
index 0562e2183..f5d4c4ee0 100644
--- a/src/include/gnunet_transport_application_service.h
+++ b/src/include/gnunet_transport_application_service.h
@@ -116,13 +116,6 @@ GNUNET_TRANSPORT_application_validate (
116 enum GNUNET_NetworkType nt, 116 enum GNUNET_NetworkType nt,
117 const char *addr); 117 const char *addr);
118 118
119int
120GNUNET_TRANSPORT_get_trait_application_handle (const struct
121 GNUNET_TESTING_Command *cmd,
122 struct
123 GNUNET_TRANSPORT_ApplicationHandle
124 **ah);
125
126/** @} */ /* end of group */ 119/** @} */ /* end of group */
127 120
128#endif 121#endif
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 038f0cb08..3e9d15986 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -45,9 +45,13 @@ libgnunettesting_la_SOURCES = \
45 testing_api_cmd_send_peer_ready.c \ 45 testing_api_cmd_send_peer_ready.c \
46 testing_api_cmd_block_until_all_peers_started.c \ 46 testing_api_cmd_block_until_all_peers_started.c \
47 testing_api_cmd_netjail_start.c \ 47 testing_api_cmd_netjail_start.c \
48 testing_api_cmd_netjail_start_v2.c \
48 testing_api_cmd_netjail_start_testsystem.c \ 49 testing_api_cmd_netjail_start_testsystem.c \
50 testing_api_cmd_netjail_start_testsystem_v2.c \
49 testing_api_cmd_netjail_stop_testsystem.c \ 51 testing_api_cmd_netjail_stop_testsystem.c \
52 testing_api_cmd_netjail_stop_testsystem_v2.c \
50 testing_api_cmd_netjail_stop.c \ 53 testing_api_cmd_netjail_stop.c \
54 testing_api_cmd_netjail_stop_v2.c \
51 testing.c testing.h \ 55 testing.c testing.h \
52 testing_api_cmd_system_create.c \ 56 testing_api_cmd_system_create.c \
53 testing_api_cmd_system_destroy.c \ 57 testing_api_cmd_system_destroy.c \
@@ -87,6 +91,7 @@ list_keys_LDADD = \
87 91
88 92
89check_PROGRAMS = \ 93check_PROGRAMS = \
94 test_testing_topology \
90 test_testing_api_cmd_netjail \ 95 test_testing_api_cmd_netjail \
91 test_testing_hello_world \ 96 test_testing_hello_world \
92 test_testing_portreservation \ 97 test_testing_portreservation \
@@ -98,6 +103,7 @@ check_PROGRAMS = \
98if ENABLE_TEST_RUN 103if ENABLE_TEST_RUN
99AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 104AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
100TESTS = \ 105TESTS = \
106 test_testing_topology \
101 test_testing_api_cmd_netjail \ 107 test_testing_api_cmd_netjail \
102 test_testing_hello_world \ 108 test_testing_hello_world \
103 test_testing_portreservation \ 109 test_testing_portreservation \
@@ -106,6 +112,12 @@ TESTS = \
106 test_testing_servicestartup 112 test_testing_servicestartup
107endif 113endif
108 114
115test_testing_topology_SOURCES = \
116 test_testing_topology.c
117test_testing_topology_LDADD = \
118 libgnunettesting.la \
119 $(top_builddir)/src/util/libgnunetutil.la
120
109test_testing_api_cmd_netjail_SOURCES = \ 121test_testing_api_cmd_netjail_SOURCES = \
110 test_testing_api_cmd_netjail.c 122 test_testing_api_cmd_netjail.c
111test_testing_api_cmd_netjail_LDADD = \ 123test_testing_api_cmd_netjail_LDADD = \
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 21ea33888..8f9e77709 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -163,14 +163,17 @@ struct WriteContext
163 size_t pos; 163 size_t pos;
164}; 164};
165 165
166struct Plugin *plugin;
167
168/** 166/**
169 * The process handle to the testbed service 167 * The process handle to the testbed service
170 168
171static struct GNUNET_OS_Process *cmd_binary_process;*/ 169static struct GNUNET_OS_Process *cmd_binary_process;*/
172 170
173/** 171/**
172 * Plugin to dynamically load a test case.
173 */
174struct Plugin *plugin;
175
176/**
174 * Handle to the testing system 177 * Handle to the testing system
175 */ 178 */
176static struct GNUNET_TESTING_System *test_system; 179static struct GNUNET_TESTING_System *test_system;
@@ -329,6 +332,7 @@ write_message (struct GNUNET_MessageHeader *message, size_t msg_length)
329static int 332static int
330tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message) 333tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
331{ 334{
335
332 struct NodeIdentifier *ni = cls; 336 struct NodeIdentifier *ni = cls;
333 const struct GNUNET_CMDS_HelperInit *msg; 337 const struct GNUNET_CMDS_HelperInit *msg;
334 struct GNUNET_CMDS_HelperReply *reply; 338 struct GNUNET_CMDS_HelperReply *reply;
@@ -369,14 +373,14 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
369 plugin->n = ni->n; 373 plugin->n = ni->n;
370 plugin->m = ni->m; 374 plugin->m = ni->m;
371 375
372 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->m) 376 router_ip = GNUNET_malloc (strlen (ROUTER_BASE_IP) + strlen (plugin->n)
373 + 1); 377 + 1);
374 strcpy (router_ip, ROUTER_BASE_IP); 378 strcpy (router_ip, ROUTER_BASE_IP);
375 strcat (router_ip, plugin->m); 379 strcat (router_ip, plugin->n);
376 380
377 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->n) + 1); 381 node_ip = GNUNET_malloc (strlen (NODE_BASE_IP) + strlen (plugin->m) + 1);
378 strcat (node_ip, NODE_BASE_IP); 382 strcat (node_ip, NODE_BASE_IP);
379 strcat (node_ip, plugin->n); 383 strcat (node_ip, plugin->m);
380 384
381 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, 385 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
382 plugin->n, plugin->local_m); 386 plugin->n, plugin->local_m);
@@ -533,8 +537,8 @@ main (int argc, char **argv)
533 ni = GNUNET_new (struct NodeIdentifier); 537 ni = GNUNET_new (struct NodeIdentifier);
534 ni->global_n = argv[1]; 538 ni->global_n = argv[1];
535 ni->local_m = argv[2]; 539 ni->local_m = argv[2];
536 ni->n = argv[3]; 540 ni->m = argv[3];
537 ni->m = argv[4]; 541 ni->n = argv[4];
538 542
539 status = GNUNET_OK; 543 status = GNUNET_OK;
540 if (NULL == 544 if (NULL ==
diff --git a/src/testing/netjail_core_v2.sh b/src/testing/netjail_core_v2.sh
new file mode 100755
index 000000000..ef0a54a5e
--- /dev/null
+++ b/src/testing/netjail_core_v2.sh
@@ -0,0 +1,260 @@
1#!/bin/sh
2#
3
4
5PREFIX=${PPID:?must run from a parent process}
6
7# running with `sudo` is required to be
8# able running the actual commands as the
9# original user.
10
11export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
12
13export RESULT=
14export NAMESPACE_NUM=0
15export INTERFACE_NUM=0
16
17netjail_next_namespace() {
18 local NUM=$NAMESPACE_NUM
19 NAMESPACE_NUM=$(($NAMESPACE_NUM + 1))
20 RESULT=$NUM
21}
22
23netjail_next_interface() {
24 local NUM=$INTERFACE_NUM
25 INTERFACE_NUM=$(($INTERFACE_NUM + 1))
26 RESULT=$NUM
27}
28
29netjail_opt() {
30 local OPT=$1
31 shift 1
32
33 INDEX=1
34
35 while [ $# -gt 0 ]; do
36 if [ "$1" = "$OPT" ]; then
37 RESULT=$INDEX
38 return
39 fi
40
41 INDEX=$(($INDEX + 1))
42 shift 1
43 done
44
45 RESULT=0
46}
47
48netjail_opts() {
49 local OPT=$1
50 local DEF=$2
51 shift 2
52
53 while [ $# -gt 0 ]; do
54 if [ "$1" = "$OPT" ]; then
55 printf "$2"
56 return
57 fi
58
59 shift 1
60 done
61
62 RESULT="$DEF"
63}
64
65netjail_check() {
66 local NODE_COUNT=$1
67 local FD_COUNT=$(($(ls /proc/self/fd | wc -w) - 4))
68
69 # quit if `$FD_COUNT < ($LOCAL_M * $GLOBAL_N * 2)`:
70 # the script also requires `sudo -C ($FD_COUNT + 4)`
71 # so you need 'Defaults closefrom_override' in the
72 # sudoers file.
73
74 if [ $FD_COUNT -lt $(($NODE_COUNT * 2)) ]; then
75 echo "File descriptors do not match requirements!" >&2
76 exit 1
77 fi
78}
79
80netjail_check_bin() {
81 local PROGRAM=$1
82 local MATCH=$(ls $(echo $PATH | tr ":" "\n") | grep "^$PROGRAM\$" | tr "\n" " " | awk '{ print $1 }')
83
84 # quit if the required binary $PROGRAM can not be
85 # found in the used $PATH.
86
87 if [ "$MATCH" != "$PROGRAM" ]; then
88 echo "Required binary not found: $PROGRAM" >&2
89 exit 1
90 fi
91}
92
93netjail_bridge() {
94 netjail_next_interface
95 local NUM=$RESULT
96 local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
97
98 ip link add $BRIDGE type bridge
99 ip link set dev $BRIDGE up
100
101 RESULT=$BRIDGE
102}
103
104netjail_bridge_name() {
105 netjail_next_interface
106 local NUM=$RESULT
107 local BRIDGE=$(printf "%06x-%08x" $PREFIX $NUM)
108
109 RESULT=$BRIDGE
110}
111
112netjail_bridge_clear() {
113 local BRIDGE=$1
114
115 ip link delete $BRIDGE
116}
117
118netjail_node() {
119 netjail_next_namespace
120 local NUM=$RESULT
121 local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
122
123 ip netns add $NODE
124
125 RESULT=$NODE
126}
127
128netjail_node_name() {
129 netjail_next_namespace
130 local NUM=$RESULT
131 local NODE=$(printf "%06x-%08x" $PREFIX $NUM)
132
133 RESULT=$NODE
134}
135
136netjail_node_clear() {
137 local NODE=$1
138
139 ip netns delete $NODE
140}
141
142netjail_node_link_bridge() {
143 local NODE=$1
144 local BRIDGE=$2
145 local ADDRESS=$3
146 local MASK=$4
147
148 netjail_next_interface
149 local NUM_IF=$RESULT
150 netjail_next_interface
151 local NUM_BR=$RESULT
152
153 local LINK_IF=$(printf "%06x-%08x" $PREFIX $NUM_IF)
154 local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
155
156 ip link add $LINK_IF type veth peer name $LINK_BR
157 ip link set $LINK_IF netns $NODE
158 ip link set $LINK_BR master $BRIDGE
159
160 ip -n $NODE addr add "$ADDRESS/$MASK" dev $LINK_IF
161 ip -n $NODE link set $LINK_IF up
162 ip -n $NODE link set up dev lo
163
164 ip link set $LINK_BR up
165
166 RESULT=$LINK_BR
167}
168
169netjail_node_link_bridge_name() {
170
171 netjail_next_interface
172 netjail_next_interface
173 local NUM_BR=$RESULT
174
175 local LINK_BR=$(printf "%06x-%08x" $PREFIX $NUM_BR)
176
177 RESULT=$LINK_BR
178}
179
180netjail_node_unlink_bridge() {
181 local LINK_BR=$1
182
183 ip link delete $LINK_BR
184}
185
186netjail_node_add_nat() {
187 local NODE=$1
188 local ADDRESS=$2
189 local MASK=$3
190
191 ip netns exec $NODE iptables -t nat -A POSTROUTING -s "$ADDRESS/$MASK" -j MASQUERADE
192}
193
194netjail_node_add_default() {
195 local NODE=$1
196 local ADDRESS=$2
197
198 ip -n $NODE route add default via $ADDRESS
199}
200
201netjail_node_exec() {
202 JAILOR=${SUDO_USER:?must run in sudo}
203 local NODE=$1
204 local FD_IN=$2
205 local FD_OUT=$3
206 shift 3
207
208 ip netns exec $NODE sudo -u $JAILOR -- $@ 1>& $FD_OUT 0<& $FD_IN
209}
210
211netjail_node_exec_without_fds() {
212 JAILOR=${SUDO_USER:?must run in sudo}
213 NODE=$1
214 shift 1
215
216 ip netns exec $NODE sudo -u $JAILOR -- $@
217}
218
219netjail_node_exec_without_fds_and_sudo() {
220 NODE=$1
221 shift 1
222
223 ip netns exec $NODE $@
224}
225
226netjail_kill() {
227 local PID=$1
228 local MATCH=$(ps --pid $PID | awk "{ if ( \$1 == $PID ) { print \$1 } }" | wc -l)
229
230 if [ $MATCH -gt 0 ]; then
231 kill -n 19 $PID
232
233 for CHILD in $(ps -o pid,ppid -ax | awk "{ if ( \$2 == $PID ) { print \$1 } }"); do
234 netjail_kill $CHILD
235 done
236
237 kill $PID
238 fi
239}
240
241netjail_killall() {
242 if [ $# -gt 0 ]; then
243 local PIDS=$1
244
245 for PID in $PIDS; do
246 netjail_kill $PID
247 done
248 fi
249}
250
251netjail_waitall() {
252 if [ $# -gt 0 ]; then
253 local PIDS=$1
254
255 for PID in $PIDS; do
256 wait $PID
257 done
258 fi
259}
260
diff --git a/src/testing/netjail_exec_v2.sh b/src/testing/netjail_exec_v2.sh
new file mode 100755
index 000000000..597baad20
--- /dev/null
+++ b/src/testing/netjail_exec_v2.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2. "./../testing/netjail_core_v2.sh"
3
4set -eu
5set -x
6
7export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
8
9M=$1
10N=$2
11
12NODE=$6
13
14netjail_node_exec_without_fds_and_sudo $NODE $3 $4 $5 $1 $2
diff --git a/src/testing/netjail_start_v2.sh b/src/testing/netjail_start_v2.sh
new file mode 100755
index 000000000..cf1fe113a
--- /dev/null
+++ b/src/testing/netjail_start_v2.sh
@@ -0,0 +1,61 @@
1#!/bin/bash
2. "./../testing/netjail_core_v2.sh"
3. "./../testing/topo.sh"
4
5set -eu
6set -x
7
8export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
9
10filename=$1
11PREFIX=$2
12
13read_topology $filename
14
15shift 2
16
17LOCAL_GROUP="192.168.15"
18GLOBAL_GROUP="92.68.150"
19KNOWN_GROUP="92.68.151"
20
21
22echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]"
23
24netjail_bridge
25NETWORK_NET=$RESULT
26
27for X in $(seq $KNOWN); do
28 netjail_node
29 KNOWN_NODES[$X]=$RESULT
30 netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
31 KNOWN_LINKS[$X]=$RESULT
32done
33
34declare -A NODES
35declare -A NODE_LINKS
36
37for N in $(seq $GLOBAL_N); do
38 netjail_node
39 ROUTERS[$N]=$RESULT
40 netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
41 NETWORK_LINKS[$N]=$RESULT
42 netjail_bridge
43 ROUTER_NETS[$N]=$RESULT
44
45 for M in $(seq $LOCAL_M); do
46 netjail_node
47 NODES[$N,$M]=$RESULT
48 netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
49 NODE_LINKS[$N,$M]=$RESULT
50 done
51
52 ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
53 netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
54 ROUTER_LINKS[$N]=$RESULT
55
56 netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
57
58 for M in $(seq $LOCAL_M); do
59 netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
60 done
61done
diff --git a/src/testing/netjail_stop_v2.sh b/src/testing/netjail_stop_v2.sh
new file mode 100755
index 000000000..6e9fd1ccc
--- /dev/null
+++ b/src/testing/netjail_stop_v2.sh
@@ -0,0 +1,59 @@
1#!/bin/bash
2. "./../testing/netjail_core_v2.sh"
3. "./../testing/topo.sh"
4
5set -eu
6set -x
7
8export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
9
10filename=$1
11PREFIX=$2
12
13read_topology $filename
14
15declare -A NODES
16declare -A NODE_LINKS
17
18netjail_bridge_name
19NETWORK_NET=$RESULT
20
21for X in $(seq $KNOWN); do
22 netjail_node_name
23 KNOWN_NODES[$X]=$RESULT
24 netjail_node_link_bridge_name
25 KNOWN_LINKS[$X]=$RESULT
26 netjail_node_unlink_bridge ${KNOWN_LINKS[$X]}
27 netjail_node_clear ${KNOWN_NODES[$X]}
28done
29
30for N in $(seq $GLOBAL_N); do
31 netjail_node_name
32 ROUTERS[$N]=$RESULT
33 netjail_node_link_bridge_name
34 NETWORK_LINKS[$N]=$RESULT
35 netjail_bridge_name
36 ROUTER_NETS[$N]=$RESULT
37 netjail_node_link_bridge_name
38 ROUTER_LINKS[$N]=$RESULT
39
40 netjail_node_unlink_bridge ${ROUTER_LINKS[$N]}
41
42 for M in $(seq $LOCAL_M); do
43 netjail_node_name
44 NODES[$N,$M]=$RESULT
45 netjail_node_link_bridge_name
46 NODE_LINKS[$N,$M]=$RESULT
47 netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]}
48 netjail_node_clear ${NODES[$N,$M]}
49 done
50
51
52 netjail_bridge_clear ${ROUTER_NETS[$N]}
53 netjail_node_unlink_bridge ${NETWORK_LINKS[$N]}
54 netjail_node_clear ${ROUTERS[$N]}
55done
56
57netjail_bridge_clear $NETWORK_NET
58
59echo "Done"
diff --git a/src/testing/test_testing_api_cmd_netjail.c b/src/testing/test_testing_api_cmd_netjail.c
index 543642109..aeddfb7c9 100644
--- a/src/testing/test_testing_api_cmd_netjail.c
+++ b/src/testing/test_testing_api_cmd_netjail.c
@@ -29,6 +29,13 @@
29 29
30 30
31/** 31/**
32 * Return value of the test.
33 *
34 */
35static unsigned int rv = 0;
36
37
38/**
32 * Main function to run the test cases. 39 * Main function to run the test cases.
33 * 40 *
34 * @param cls not used. 41 * @param cls not used.
@@ -44,7 +51,8 @@ run (void *cls)
44 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1", 51 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1",
45 "2", 52 "2",
46 "2", 53 "2",
47 "libgnunet_plugin_testcmd"), 54 "libgnunet_plugin_testcmd",
55 &rv),
48 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", 56 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
49 "netjail-start-testbed-1", 57 "netjail-start-testbed-1",
50 "2", 58 "2",
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 991c11a6c..fcde39901 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -33,6 +33,7 @@
33#include "gnunet_util_lib.h" 33#include "gnunet_util_lib.h"
34#include "gnunet_arm_service.h" 34#include "gnunet_arm_service.h"
35#include "gnunet_testing_lib.h" 35#include "gnunet_testing_lib.h"
36#include "gnunet_testing_ng_lib.h"
36 37
37#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 38#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
38 39
@@ -1308,7 +1309,7 @@ GNUNET_TESTING_peer_configure (struct GNUNET_TESTING_System *system,
1308 peer->nports = nports; 1309 peer->nports = nports;
1309 return peer; 1310 return peer;
1310 1311
1311err_ret: 1312 err_ret:
1312 GNUNET_free (ss_instances); 1313 GNUNET_free (ss_instances);
1313 GNUNET_free (ports); 1314 GNUNET_free (ports);
1314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_); 1315 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "%s", emsg_);
@@ -1773,4 +1774,382 @@ GNUNET_TESTING_get_testname_from_underscore (const char *argv0)
1773} 1774}
1774 1775
1775 1776
1777static unsigned int
1778get_first_value (char *line)
1779{
1780 char *copy;
1781 size_t slen;
1782 char *token;
1783 unsigned int ret;
1784 char *rest = NULL;
1785
1786 slen = strlen (line) + 1;
1787 copy = malloc (slen);
1788 memcpy (copy, line, slen);
1789 token = strtok_r (copy, ":", &rest);
1790 token = strtok_r (NULL, ":", &rest);
1791 sscanf (token, "%u", &ret);
1792 free (copy);
1793 return ret;
1794}
1795
1796
1797static char *
1798get_key (char *line)
1799{
1800 char *copy;
1801 size_t slen;
1802 char *token;
1803 char *ret;
1804 char *rest = NULL;
1805
1806 slen = strlen (line) + 1;
1807 copy = malloc (slen);
1808 memcpy (copy, line, slen);
1809 token = strtok_r (copy, ":", &rest);
1810 ret = malloc (2);
1811 memcpy (ret, token, 2);
1812 free (copy);
1813 return ret;
1814}
1815
1816
1817static char *
1818get_first_string_value (char *line)
1819{
1820 char *copy;
1821 size_t slen, slen_token;
1822 char *token;
1823 char *ret;
1824 char *rest = NULL;
1825
1826 slen = strlen (line) + 1;
1827 copy = malloc (slen);
1828 memcpy (copy, line, slen);
1829 token = strtok_r (copy, ":", &rest);
1830 token = strtok_r (NULL, ":", &rest);
1831 LOG (GNUNET_ERROR_TYPE_DEBUG,
1832 "first token %s\n",
1833 token);
1834 slen_token = strlen (token);
1835 ret = malloc (slen_token + 1);
1836 memcpy (ret, token, slen_token + 1);
1837 free (copy);
1838 return ret;
1839}
1840
1841
1842static unsigned int
1843get_second_value (char *line)
1844{
1845 char *copy;
1846 size_t slen;
1847 char *token;
1848 unsigned int ret;
1849 char *rest = NULL;
1850
1851 slen = strlen (line) + 1;
1852 copy = malloc (slen);
1853 memcpy (copy, line, slen);
1854 token = strtok_r (copy, ":", &rest);
1855 token = strtok_r (NULL, ":", &rest);
1856 token = strtok_r (NULL, ":", &rest);
1857 sscanf (token, "%u", &ret);
1858 free (copy);
1859 return ret;
1860}
1861
1862
1863static char *
1864get_value (char *key, char *line)
1865{
1866 char *copy;
1867 size_t slen, slen_token;
1868 char *token;
1869 char *token2;
1870 char *temp;
1871 char *rest = NULL;
1872 char *ret;
1873
1874 slen = strlen (line) + 1;
1875 copy = malloc (slen);
1876 memcpy (copy, line, slen);
1877 temp = strstr (copy, key);
1878 if (NULL == temp)
1879 return NULL;
1880 token = strtok_r (temp, ":", &rest);
1881 token = strtok_r (NULL, ":", &rest);
1882 token2 = strtok_r (token, "}", &rest);
1883 slen_token = strlen (token2);
1884 ret = malloc (slen_token + 1);
1885 memcpy (ret, token2, slen_token + 1);
1886 free (copy);
1887 return ret;
1888}
1889
1890
1891/**
1892 * Getting the topology from file.
1893 *
1894 * @param filename The name of the topology file.
1895 * @return The GNUNET_TESTING_NetjailTopology
1896 */
1897struct GNUNET_TESTING_NetjailTopology *
1898GNUNET_TESTING_get_topo_from_file (const char *filename)
1899{
1900 uint64_t fs;
1901 char *data;
1902 char *token;
1903 char *key;
1904 unsigned int out;
1905 char *rest = NULL;
1906 char *value;
1907 int ret;
1908 struct GNUNET_TESTING_NetjailTopology *topo = GNUNET_new (struct
1909 GNUNET_TESTING_NetjailTopology);
1910 struct GNUNET_TESTING_NetjailNode *node;
1911 struct GNUNET_TESTING_NetjailRouter *router;
1912 struct GNUNET_TESTING_NetjailNamespace *namespace;
1913 struct GNUNET_ShortHashCode *hkey;
1914 struct GNUNET_HashCode hc;
1915 topo->map_namespaces =
1916 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
1917 topo->map_globals =
1918 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
1919
1920 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
1921 {
1922 LOG (GNUNET_ERROR_TYPE_ERROR,
1923 _ ("Topology file %s not found\n"),
1924 filename);
1925 return NULL;
1926 }
1927 if (GNUNET_OK !=
1928 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
1929 {
1930 LOG (GNUNET_ERROR_TYPE_ERROR,
1931 _ ("Topology file %s has no data\n"),
1932 filename);
1933 return NULL;
1934 }
1935 data = GNUNET_malloc (fs);
1936 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
1937 {
1938 LOG (GNUNET_ERROR_TYPE_ERROR,
1939 _ ("Topology file %s cannot be read\n"),
1940 filename);
1941 GNUNET_free (data);
1942 return NULL;
1943 }
1944
1945 LOG (GNUNET_ERROR_TYPE_DEBUG,
1946 "data: %s\n",
1947 data);
1948
1949 token = strtok_r (data, "\n", &rest);
1950
1951 while (NULL != token)
1952 {
1953 key = get_key (token);
1954 LOG (GNUNET_ERROR_TYPE_DEBUG,
1955 "In the loop with token: %s beginning with %s\n",
1956 token,
1957 key);
1958 if (0 == strcmp (key, "M"))
1959 {
1960 LOG (GNUNET_ERROR_TYPE_DEBUG,
1961 "Get first Value for M.\n");
1962 out = get_first_value (token);
1963 LOG (GNUNET_ERROR_TYPE_DEBUG,
1964 "M: %u\n",
1965 out);
1966 topo->nodes_m = out;
1967 }
1968 else if (0 == strcmp (key, "N"))
1969 {
1970 LOG (GNUNET_ERROR_TYPE_DEBUG,
1971 "Get first Value for N.\n");
1972 out = get_first_value (token);
1973 LOG (GNUNET_ERROR_TYPE_DEBUG,
1974 "N: %u\n",
1975 out);
1976 topo->namespaces_n = out;
1977 }
1978 else if (0 == strcmp (key, "X"))
1979 {
1980 LOG (GNUNET_ERROR_TYPE_DEBUG,
1981 "Get first Value for X.\n");
1982 out = get_first_value (token);
1983 LOG (GNUNET_ERROR_TYPE_DEBUG,
1984 "X: %u\n",
1985 out);
1986 topo->nodes_x = out;
1987 }
1988 else if (0 == strcmp (key, "T"))
1989 {
1990 LOG (GNUNET_ERROR_TYPE_DEBUG,
1991 "Get first string value for T.\n");
1992 value = get_first_string_value (token);
1993 LOG (GNUNET_ERROR_TYPE_DEBUG,
1994 "value: %s\n",
1995 value);
1996 topo->plugin = value;
1997 }
1998 else if (0 == strcmp (key, "K"))
1999 {
2000 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2001 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2002
2003 LOG (GNUNET_ERROR_TYPE_DEBUG,
2004 "Get first Value for K.\n");
2005 out = get_first_value (token);
2006 LOG (GNUNET_ERROR_TYPE_DEBUG,
2007 "K: %u\n",
2008 out);
2009 node->node_n = out;
2010 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2011 memcpy (hkey,
2012 &hc,
2013 sizeof (*hkey));
2014 node->is_global = GNUNET_YES;
2015 LOG (GNUNET_ERROR_TYPE_DEBUG,
2016 "Get value for key value on K.\n");
2017 value = get_value ("plugin", token);
2018 LOG (GNUNET_ERROR_TYPE_DEBUG,
2019 "value: %s\n",
2020 value);
2021 if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_globals,
2022 hkey))
2023 GNUNET_break (0);
2024 else
2025 GNUNET_CONTAINER_multishortmap_put (topo->map_globals,
2026 hkey,
2027 node,
2028 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2029 }
2030 else if (0 == strcmp (key, "R"))
2031 {
2032 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2033 router = GNUNET_new (struct GNUNET_TESTING_NetjailRouter);
2034 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2035
2036 LOG (GNUNET_ERROR_TYPE_DEBUG,
2037 "Get first Value for R.\n");
2038 out = get_first_value (token);
2039 LOG (GNUNET_ERROR_TYPE_DEBUG,
2040 "R: %u\n",
2041 out);
2042 node->node_n = out;
2043 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2044 memcpy (hkey,
2045 &hc,
2046 sizeof (*hkey));
2047 LOG (GNUNET_ERROR_TYPE_DEBUG,
2048 "Get value for key tcp_port on R.\n");
2049 value = get_value ("tcp_port", token);
2050 LOG (GNUNET_ERROR_TYPE_DEBUG,
2051 "tcp_port: %s\n",
2052 value);
2053 ret = sscanf (value, "%u", &(router->tcp_port));
2054
2055 GNUNET_break (0 == ret || 1 < router->tcp_port);
2056
2057 LOG (GNUNET_ERROR_TYPE_DEBUG,
2058 "Get value for key udp_port on R.\n");
2059 value = get_value ("udp_port", token);
2060 ret = sscanf (value, "%u", &(router->udp_port));
2061 GNUNET_break (0 == ret || 1 < router->udp_port);
2062 LOG (GNUNET_ERROR_TYPE_DEBUG,
2063 "udp_port: %s\n",
2064 value);
2065
2066 if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_namespaces,
2067 hkey))
2068 {
2069 namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2070 hkey);
2071 }
2072 else
2073 {
2074 namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2075 namespace->namespace_n = out;
2076 GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces,
2077 hkey,
2078 namespace,
2079 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2080 }
2081 namespace->router = router;
2082
2083 }
2084 else if (0 == strcmp (key, "P"))
2085 {
2086 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
2087 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2088
2089 LOG (GNUNET_ERROR_TYPE_DEBUG,
2090 "Get first Value for P.\n");
2091 out = get_first_value (token);
2092 LOG (GNUNET_ERROR_TYPE_DEBUG,
2093 "P: %u\n",
2094 out);
2095 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2096 memcpy (hkey,
2097 &hc,
2098 sizeof (*hkey));
2099
2100 LOG (GNUNET_ERROR_TYPE_DEBUG,
2101 "Get value for key plugin on P.\n");
2102 value = get_value ("plugin", token);
2103 LOG (GNUNET_ERROR_TYPE_DEBUG,
2104 "plugin: %s\n",
2105 value);
2106 if (0 == GNUNET_CONTAINER_multishortmap_contains (topo->map_namespaces,
2107 hkey))
2108 {
2109 namespace = GNUNET_CONTAINER_multishortmap_get (topo->map_namespaces,
2110 hkey);
2111 }
2112 else
2113 {
2114 namespace = GNUNET_new (struct GNUNET_TESTING_NetjailNamespace);
2115 namespace->namespace_n = out;
2116 GNUNET_CONTAINER_multishortmap_put (topo->map_namespaces,
2117 hkey,
2118 namespace,
2119 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2120 }
2121 LOG (GNUNET_ERROR_TYPE_DEBUG,
2122 "Get second Value for P.\n");
2123 out = get_second_value (token);
2124 LOG (GNUNET_ERROR_TYPE_DEBUG,
2125 "P: %u\n",
2126 out);
2127 GNUNET_CRYPTO_hash (&out, sizeof(out), &hc);
2128 memcpy (hkey,
2129 &hc,
2130 sizeof (*hkey));
2131 if (0 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
2132 hkey))
2133 {
2134 GNUNET_break (0);
2135 }
2136 else
2137 {
2138 node = GNUNET_new (struct GNUNET_TESTING_NetjailNode);
2139 GNUNET_CONTAINER_multishortmap_put (namespace->nodes,
2140 hkey,
2141 node,
2142 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2143 node->plugin = value;
2144 node->node_n = out;
2145 node->namespace_n = namespace->namespace_n;
2146 }
2147 }
2148 token = strtok_r (NULL, "\n", &rest);
2149 }
2150
2151 return topo;
2152}
2153
2154
1776/* end of testing.c */ 2155/* end of testing.c */
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index 0fe0541b0..531621eb5 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -278,26 +278,6 @@ GNUNET_TESTING_get_trait_helper_handles (const struct
278 278
279 279
280/** 280/**
281 * Offer messages received via testing cmd helper from trait
282 *
283 * @param cmd command to extract the message from.
284 * @param pt pointer to message.
285 * @return #GNUNET_OK on success.
286 */
287int
288GNUNET_TESTING_get_trait_helper_messages (const struct
289 GNUNET_TESTING_Command *cmd,
290 struct HelperMessage ***
291 hp_messages_head)
292{
293 return cmd->traits (cmd->cls,
294 (const void **) hp_messages_head,
295 "hp_msgs_head",
296 (unsigned int) 1);
297}
298
299
300/**
301 * Continuation function from GNUNET_HELPER_send() 281 * Continuation function from GNUNET_HELPER_send()
302 * 282 *
303 * @param cls closure 283 * @param cls closure
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
new file mode 100644
index 000000000..64ce549a4
--- /dev/null
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem_v2.c
@@ -0,0 +1,718 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "testing_cmds.h"
29
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec_v2.sh"
31
32/**
33 * Struct to store messages send/received by the helper into a DLL
34 *
35 */
36struct HelperMessage
37{
38
39 /**
40 * Kept in a DLL.
41 */
42 struct HelperMessage *next;
43
44 /**
45 * Kept in a DLL.
46 */
47 struct HelperMessage *prev;
48
49 /**
50 * Size of the original message.
51 */
52 uint16_t bytes_msg;
53
54 /* Followed by @e bytes_msg of msg.*/
55};
56
57
58/**
59 * Struct to store information handed over to callbacks.
60 *
61 */
62struct NetJailState
63{
64 /**
65 * The complete topology infomation.
66 */
67 struct GNUNET_TESTING_NetjailTopology *topology;
68
69 /**
70 * Pointer to the return value of the test.
71 *
72 */
73 unsigned int *rv;
74
75 /**
76 * Head of the DLL which stores messages received by the helper.
77 *
78 */
79 struct HelperMessage *hp_messages_head;
80
81 /**
82 * Tail of the DLL which stores messages received by the helper.
83 *
84 */
85 struct HelperMessage *hp_messages_tail;
86
87 /**
88 * Array with handles of helper processes.
89 */
90 struct GNUNET_HELPER_Handle **helper;
91
92 /**
93 * Size of the array NetJailState#helper.
94 *
95 */
96 unsigned int n_helper;
97
98 /**
99 * Number of nodes in a natted subnet.
100 *
101 */
102 unsigned int local_m;
103
104 /**
105 * Number of natted subnets.
106 *
107 */
108 unsigned int global_n;
109
110 /**
111 * Number of global known nodes.
112 *
113 */
114 unsigned int known;
115
116 /**
117 * The send handle for the helper
118 */
119 struct GNUNET_HELPER_SendHandle **shandle;
120
121 /**
122 * Size of the array NetJailState#shandle.
123 *
124 */
125 unsigned int n_shandle;
126
127 /**
128 * The messages send to the helper.
129 */
130 struct GNUNET_MessageHeader **msg;
131
132 /**
133 * Size of the array NetJailState#msg.
134 *
135 */
136 unsigned int n_msg;
137
138 /**
139 * Number of test environments started.
140 *
141 */
142 unsigned int number_of_testsystems_started;
143
144 /**
145 * Number of peers started.
146 *
147 */
148 unsigned int number_of_peers_started;
149
150 /**
151 * Number of local tests finished.
152 *
153 */
154 unsigned int number_of_local_test_finished;
155
156 /**
157 * Name of the test case plugin the helper will load.
158 *
159 */
160 char *plugin_name;
161
162 /**
163 * HEAD of the DLL containing TestingSystemCount.
164 *
165 */
166 struct TestingSystemCount *tbcs_head;
167
168 /**
169 * TAIL of the DLL containing TestingSystemCount.
170 *
171 */
172 struct TestingSystemCount *tbcs_tail;
173};
174
175/**
176 * Struct containing the number of the test environment and the NetJailState which
177 * will be handed to callbacks specific to a test environment.
178 */
179struct TestingSystemCount
180{
181 /**
182 * Kept in a DLL.
183 */
184 struct TestingSystemCount *next;
185
186 /**
187 * Kept in a DLL.
188 */
189 struct TestingSystemCount *prev;
190
191 /**
192 * The number of the test environment.
193 *
194 */
195 unsigned int count;
196
197 /**
198 * Struct to store information handed over to callbacks.
199 *
200 */
201 struct NetJailState *ns;
202};
203
204/**
205* Code to clean up resource this cmd used.
206*
207* @param cls closure
208* @param cmd current CMD being cleaned up.
209*/
210static void
211netjail_exec_cleanup (void *cls,
212 const struct GNUNET_TESTING_Command *cmd)
213{
214 struct NetJailState *ns = cls;
215 struct HelperMessage *message_pos;
216 struct TestingSystemCount *tbc_pos;
217
218 while (NULL != (message_pos = ns->hp_messages_head))
219 {
220 GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
221 ns->hp_messages_tail,
222 message_pos);
223 GNUNET_free (message_pos);
224 }
225 while (NULL != (tbc_pos = ns->tbcs_head))
226 {
227 GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
228 ns->tbcs_tail,
229 tbc_pos);
230 GNUNET_free (tbc_pos);
231 }
232 GNUNET_free (ns);
233}
234
235
236/**
237 * This function prepares an array with traits.
238 *
239 */
240static int
241netjail_exec_traits (void *cls,
242 const void **ret,
243 const char *trait,
244 unsigned int index)
245{
246 struct NetJailState *ns = cls;
247 struct GNUNET_HELPER_Handle **helper = ns->helper;
248 struct HelperMessage *hp_messages_head = ns->hp_messages_head;
249
250
251 struct GNUNET_TESTING_Trait traits[] = {
252 {
253 .index = 0,
254 .trait_name = "helper_handles",
255 .ptr = (const void *) helper,
256 },
257 {
258 .index = 1,
259 .trait_name = "hp_msgs_head",
260 .ptr = (const void *) hp_messages_head,
261 },
262 GNUNET_TESTING_trait_end ()
263 };
264
265 return GNUNET_TESTING_get_trait (traits,
266 ret,
267 trait,
268 index);
269}
270
271
272/**
273 * Offer handles to testing cmd helper from trait
274 *
275 * @param cmd command to extract the message from.
276 * @param pt pointer to message.
277 * @return #GNUNET_OK on success.
278 */
279int
280GNUNET_TESTING_get_trait_helper_handles_v2 (const struct
281 GNUNET_TESTING_Command *cmd,
282 struct GNUNET_HELPER_Handle ***
283 helper)
284{
285 return cmd->traits (cmd->cls,
286 (const void **) helper,
287 "helper_handles",
288 (unsigned int) 0);
289}
290
291
292/**
293 * Continuation function from GNUNET_HELPER_send()
294 *
295 * @param cls closure
296 * @param result GNUNET_OK on success,
297 * GNUNET_NO if helper process died
298 * GNUNET_SYSERR during GNUNET_HELPER_stop
299 */
300static void
301clear_msg (void *cls, int result)
302{
303 struct TestingSystemCount *tbc = cls;
304 struct NetJailState *ns = tbc->ns;
305
306 GNUNET_assert (NULL != ns->shandle[tbc->count - 1]);
307 ns->shandle[tbc->count - 1] = NULL;
308 GNUNET_free (ns->msg[tbc->count - 1]);
309 ns->msg[tbc->count - 1] = NULL;
310}
311
312
313/**
314 * Functions with this signature are called whenever a
315 * complete message is received by the tokenizer.
316 *
317 * Do not call GNUNET_SERVER_mst_destroy in callback
318 *
319 * @param cls closure
320 * @param client identification of the client
321 * @param message the actual message
322 *
323 * @return #GNUNET_OK on success, #GNUNET_SYSERR to stop further processing
324 */
325static int
326helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
327{
328 struct TestingSystemCount *tbc = cls;
329 struct NetJailState *ns = tbc->ns;
330 struct HelperMessage *hp_msg;
331
332 if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_REPLY == ntohs (message->type))
333 {
334 ns->number_of_testsystems_started++;
335 }
336 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_PEER_STARTED == ntohs (
337 message->type))
338 {
339 ns->number_of_peers_started++;
340 }
341 else if (GNUNET_MESSAGE_TYPE_CMDS_HELPER_LOCAL_FINISHED == ntohs (
342 message->type))
343 {
344 ns->number_of_local_test_finished++;
345 }
346 else
347 {
348 hp_msg = GNUNET_new (struct HelperMessage);
349 hp_msg->bytes_msg = message->size;
350 memcpy (&hp_msg[1], message, message->size);
351 GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
352 hp_msg);
353 }
354
355 return GNUNET_OK;
356}
357
358
359/**
360 * Callback called if there was an exception during execution of the helper.
361 *
362 */
363static void
364exp_cb (void *cls)
365{
366 struct NetJailState *ns = cls;
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Called exp_cb.\n");
368 *ns->rv = 1;
369}
370
371
372/**
373 * Function to initialize a init message for the helper.
374 *
375 * @param m_char The actual node in a namespace. //TODO Change this to unsigned int
376 * @param n_char The actual namespace. //TODO Change this to unsigned int
377 * @param plugin_name Name of the test case plugin the helper will load.
378 *
379 */
380static struct GNUNET_CMDS_HelperInit *
381create_helper_init_msg_ (const char *plugin_name)
382{
383 struct GNUNET_CMDS_HelperInit *msg;
384 uint16_t plugin_name_len;
385 uint16_t msg_size;
386
387 GNUNET_assert (NULL != plugin_name);
388 plugin_name_len = strlen (plugin_name);
389 msg_size = sizeof(struct GNUNET_CMDS_HelperInit) + plugin_name_len;
390 msg = GNUNET_malloc (msg_size);
391 msg->header.size = htons (msg_size);
392 msg->header.type = htons (GNUNET_MESSAGE_TYPE_CMDS_HELPER_INIT);
393 msg->plugin_name_size = htons (plugin_name_len);
394 GNUNET_memcpy ((char *) &msg[1],
395 plugin_name,
396 plugin_name_len);
397 return msg;
398}
399
400
401/**
402 * Function which start a single helper process.
403 *
404 */
405static void
406start_helper (struct NetJailState *ns, struct
407 GNUNET_CONFIGURATION_Handle *config,
408 unsigned int m,
409 unsigned int n)
410{
411 struct GNUNET_HELPER_Handle *helper;
412 struct GNUNET_CMDS_HelperInit *msg;
413 struct TestingSystemCount *tbc;
414 char *m_char, *n_char, *global_n_char, *local_m_char, *known_char, *node_id,
415 *plugin;
416 pid_t pid;
417 unsigned int script_num;
418 struct GNUNET_ShortHashCode *hkey;
419 struct GNUNET_HashCode hc;
420 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
421 struct GNUNET_TESTING_NetjailNode *node;
422 struct GNUNET_TESTING_NetjailNamespace *namespace;
423
424
425 if (0 == m)
426 script_num = n - 1;
427 else
428 script_num = n - 1 + (n - 1) * ns->local_m + m + ns->known;
429 pid = getpid ();
430
431 GNUNET_asprintf (&m_char, "%u", m);
432 GNUNET_asprintf (&n_char, "%u", n);
433 GNUNET_asprintf (&local_m_char, "%u", ns->local_m);
434 GNUNET_asprintf (&global_n_char, "%u",ns->global_n);
435 GNUNET_asprintf (&known_char, "%u",ns->known);
436 GNUNET_asprintf (&node_id, "%06x-%08x\n",
437 pid,
438 script_num);
439
440
441 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT,
442 m_char,
443 n_char,
444 GNUNET_OS_get_libexec_binary_path (
445 HELPER_CMDS_BINARY),
446 global_n_char,
447 local_m_char,
448 node_id,
449 NULL};
450
451 unsigned int helper_check = GNUNET_OS_check_helper_binary (
452 NETJAIL_EXEC_SCRIPT,
453 GNUNET_YES,
454 NULL);
455
456 tbc = GNUNET_new (struct TestingSystemCount);
457 tbc->ns = ns;
458 if (0 == m)
459 tbc->count = n;
460 else
461 tbc->count = (n - 1) * ns->local_m + m + ns->known;
462
463 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head, ns->tbcs_tail,
464 tbc);
465
466
467 if (GNUNET_NO == helper_check)
468 {
469 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
470 "No SUID for %s!\n",
471 NETJAIL_EXEC_SCRIPT);
472 *ns->rv = 1;
473 }
474 else if (GNUNET_NO == helper_check)
475 {
476 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
477 "%s not found!\n",
478 NETJAIL_EXEC_SCRIPT);
479 *ns->rv = 1;
480 }
481
482 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start (
483 GNUNET_YES,
484 NETJAIL_EXEC_SCRIPT,
485 script_argv,
486 &helper_mst,
487 &exp_cb,
488 tbc));
489
490 helper = ns->helper[tbc->count - 1];
491
492 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
493
494 plugin = ns->plugin_name;
495
496 if (0 == m)
497 {
498
499 GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
500 memcpy (hkey,
501 &hc,
502 sizeof (*hkey));
503 if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_globals,
504 hkey))
505 {
506 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
507 hkey);
508 plugin = node->plugin;
509 }
510
511 }
512 else
513 {
514 GNUNET_CRYPTO_hash (&m, sizeof(m), &hc);
515 memcpy (hkey,
516 &hc,
517 sizeof (*hkey));
518 if (1 == GNUNET_CONTAINER_multishortmap_contains (topology->map_namespaces,
519 hkey))
520 {
521 namespace = GNUNET_CONTAINER_multishortmap_get (topology->map_namespaces,
522 hkey);
523 GNUNET_CRYPTO_hash (&n, sizeof(n), &hc);
524 memcpy (hkey,
525 &hc,
526 sizeof (*hkey));
527 if (1 == GNUNET_CONTAINER_multishortmap_contains (namespace->nodes,
528 hkey))
529 {
530 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
531 hkey);
532 plugin = node->plugin;
533 }
534 }
535
536
537 }
538
539 msg = create_helper_init_msg_ (plugin);
540
541 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
542
543 GNUNET_array_append (ns->shandle, ns->n_shandle, GNUNET_HELPER_send (
544 helper,
545 &msg->header,
546 GNUNET_NO,
547 &clear_msg,
548 tbc));
549
550 if (NULL == ns->shandle[tbc->count - 1])
551 {
552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
553 "Send handle is NULL!\n");
554 GNUNET_free (msg);
555 *ns->rv = 1;
556 }
557}
558
559
560/**
561* This function starts a helper process for each node.
562*
563* @param cls closure.
564* @param cmd CMD being run.
565* @param is interpreter state.
566*/
567static void
568netjail_exec_run (void *cls,
569 const struct GNUNET_TESTING_Command *cmd,
570 struct GNUNET_TESTING_Interpreter *is)
571{
572 struct NetJailState *ns = cls;
573 struct GNUNET_CONFIGURATION_Handle *config =
574 GNUNET_CONFIGURATION_create ();
575
576 for (int i = 1; i <= ns->known; i++)
577 {
578 start_helper (ns, config,
579 i,
580 0);
581 }
582
583 for (int i = 1; i <= ns->global_n; i++)
584 {
585 for (int j = 1; j <= ns->local_m; j++)
586 {
587 start_helper (ns, config,
588 j,
589 i);
590 }
591 }
592}
593
594
595static void
596send_all_peers_started (unsigned int i, unsigned int j, struct NetJailState *ns)
597{
598 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
599 struct GNUNET_CMDS_ALL_PEERS_STARTED *reply;
600 size_t msg_length;
601 struct GNUNET_HELPER_Handle *helper;
602 struct TestingSystemCount *tbc;
603
604 tbc = GNUNET_new (struct TestingSystemCount);
605 tbc->ns = ns;
606 // 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.
607 if (0 == i)
608 tbc->count = j + total_number;
609 else
610 tbc->count = (i - 1) * ns->local_m + j + total_number + ns->known;
611
612 helper = ns->helper[tbc->count - 1 - total_number];
613 msg_length = sizeof(struct GNUNET_CMDS_ALL_PEERS_STARTED);
614 reply = GNUNET_new (struct GNUNET_CMDS_ALL_PEERS_STARTED);
615 reply->header.type = htons (
616 GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED);
617 reply->header.size = htons ((uint16_t) msg_length);
618
619 GNUNET_array_append (ns->msg, ns->n_msg, &reply->header);
620
621 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
622 helper,
623 &reply->header,
624 GNUNET_NO,
625 &clear_msg,
626 tbc);
627
628 GNUNET_array_append (ns->shandle, ns->n_shandle, sh);
629}
630
631
632/**
633 * This function checks on three different information.
634 *
635 * 1. Did all helpers start. This is only logged.
636 * 2. Did all peer start.
637 * In this case a GNUNET_MESSAGE_TYPE_CMDS_HELPER_ALL_PEERS_STARTED is send to all peers.
638 * 3. Did all peers finished the test case. In this case interpreter_next will be called.
639 *
640 */
641static int
642netjail_start_finish (void *cls,
643 GNUNET_SCHEDULER_TaskCallback cont,
644 void *cont_cls)
645{
646 unsigned int ret = GNUNET_NO;
647 struct NetJailState *ns = cls;
648 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
649
650
651 if (ns->number_of_local_test_finished == total_number)
652 {
653 ret = GNUNET_YES;
654 cont (cont_cls);
655 }
656
657 if (ns->number_of_testsystems_started == total_number)
658 {
659 ns->number_of_testsystems_started = 0;
660 }
661
662 if (ns->number_of_peers_started == total_number)
663 {
664 for (int i = 1; i <= ns->known; i++)
665 {
666 send_all_peers_started (0,i, ns);
667 }
668
669 for (int i = 1; i <= ns->global_n; i++)
670 {
671 for (int j = 1; j <= ns->local_m; j++)
672 {
673 send_all_peers_started (i,j, ns);
674 }
675 }
676 ns->number_of_peers_started = 0;
677 }
678 return ret;
679}
680
681
682/**
683 * Create command.
684 *
685 * @param label Name for the command.
686 * @param topology_config Configuration file for the test topology.
687 * @param rv Pointer to the return value of the test.
688 * @return command.
689 */
690struct GNUNET_TESTING_Command
691GNUNET_TESTING_cmd_netjail_start_testing_system_v2 (const char *label,
692 const char *topology_config,
693 unsigned int *rv)
694{
695 struct NetJailState *ns;
696
697 struct GNUNET_TESTING_NetjailTopology *topology =
698 GNUNET_TESTING_get_topo_from_file (topology_config);
699
700 ns = GNUNET_new (struct NetJailState);
701 ns->rv = rv;
702 ns->local_m = topology->nodes_m;
703 ns->global_n = topology->namespaces_n;
704 ns->known = topology->nodes_x;
705 ns->plugin_name = topology->plugin;
706 ns->topology = topology;
707
708 struct GNUNET_TESTING_Command cmd = {
709 .cls = ns,
710 .label = label,
711 .run = &netjail_exec_run,
712 .finish = &netjail_start_finish,
713 .cleanup = &netjail_exec_cleanup,
714 .traits = &netjail_exec_traits
715 };
716
717 return cmd;
718}
diff --git a/src/testing/testing_api_cmd_netjail_start_v2.c b/src/testing/testing_api_cmd_netjail_start_v2.c
new file mode 100644
index 000000000..36fbb0e10
--- /dev/null
+++ b/src/testing/testing_api_cmd_netjail_start_v2.c
@@ -0,0 +1,229 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail script.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define NETJAIL_START_SCRIPT "./../testing/netjail_start_v2.sh"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct NetJailState
37{
38 // Child Wait handle
39 struct GNUNET_ChildWaitHandle *cwh;
40
41 /**
42 * Configuration file for the test topology.
43 */
44 char *topology_config;
45
46 /**
47 * The process id of the start script.
48 */
49 struct GNUNET_OS_Process *start_proc;
50
51 // Flag indication if the script finished.
52 unsigned int finished;
53};
54
55
56/**
57 * The cleanup function of this cmd frees resources the cmd allocated.
58 *
59 */
60static void
61netjail_start_cleanup (void *cls,
62 const struct GNUNET_TESTING_Command *cmd)
63{
64 struct NetJailState *ns = cls;
65
66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
67 "netjail_start_cleanup!\n");
68
69 if (NULL != ns->cwh)
70 {
71 GNUNET_wait_child_cancel (ns->cwh);
72 ns->cwh = NULL;
73 }
74 if (NULL != ns->start_proc)
75 {
76 GNUNET_assert (0 ==
77 GNUNET_OS_process_kill (ns->start_proc,
78 SIGKILL));
79 GNUNET_assert (GNUNET_OK ==
80 GNUNET_OS_process_wait (ns->start_proc));
81 GNUNET_OS_process_destroy (ns->start_proc);
82 ns->start_proc = NULL;
83 }
84 GNUNET_free (ns);
85}
86
87
88/**
89 * Trait function of this cmd does nothing.
90 *
91 */
92static int
93netjail_start_traits (void *cls,
94 const void **ret,
95 const char *trait,
96 unsigned int index)
97{
98 return GNUNET_OK;
99}
100
101
102/**
103 * Callback which will be called if the setup script finished.
104 *
105 */
106static void
107child_completed_callback (void *cls,
108 enum GNUNET_OS_ProcessStatusType type,
109 long unsigned int exit_code)
110{
111 struct NetJailState *ns = cls;
112
113 if (0 == exit_code)
114 {
115 ns->finished = GNUNET_YES;
116 }
117 else
118 {
119 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
120 "Child completed with an error!\n");
121 ns->finished = GNUNET_SYSERR;
122 }
123 GNUNET_OS_process_destroy (ns->start_proc);
124 ns->start_proc = NULL;
125}
126
127
128
129/**
130* The run method starts the script which setup the network namespaces.
131*
132* @param cls closure.
133* @param cmd CMD being run.
134* @param is interpreter state.
135*/
136static void
137netjail_start_run (void *cls,
138 const struct GNUNET_TESTING_Command *cmd,
139 struct GNUNET_TESTING_Interpreter *is)
140{
141 struct NetJailState *ns = cls;
142 char *pid;
143 GNUNET_asprintf (&pid,
144 "%u",
145 getpid ());
146 char *const script_argv[] = {NETJAIL_START_SCRIPT,
147 ns->topology_config,
148 pid,
149 NULL};
150 unsigned int helper_check = GNUNET_OS_check_helper_binary (
151 NETJAIL_START_SCRIPT,
152 GNUNET_YES,
153 NULL);
154
155 if (GNUNET_NO == helper_check)
156 {
157 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
158 "No SUID for %s!\n",
159 NETJAIL_START_SCRIPT);
160 GNUNET_TESTING_interpreter_fail ();
161 }
162 else if (GNUNET_NO == helper_check)
163 {
164 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
165 "%s not found!\n",
166 NETJAIL_START_SCRIPT);
167 GNUNET_TESTING_interpreter_fail ();
168 }
169
170 ns->start_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
171 NULL,
172 NULL,
173 NULL,
174 NETJAIL_START_SCRIPT,
175 script_argv);
176
177 ns->cwh = GNUNET_wait_child (ns->start_proc,
178 &child_completed_callback,
179 ns);
180 GNUNET_break (NULL != ns->cwh);
181}
182
183
184/**
185 * This function checks the flag NetJailState#finished, if this cmd finished.
186 *
187 */
188static int
189netjail_start_finish (void *cls,
190 GNUNET_SCHEDULER_TaskCallback cont,
191 void *cont_cls)
192{
193 struct NetJailState *ns = cls;
194
195 if (ns->finished)
196 {
197 cont (cont_cls);
198 }
199 return ns->finished;
200}
201
202/**
203 * Create command.
204 *
205 * @param label name for command.
206 * @param topology_config Configuration file for the test topology.
207 * @return command.
208 */
209struct GNUNET_TESTING_Command
210GNUNET_TESTING_cmd_netjail_start_v2 (const char *label,
211 char *topology_config)
212{
213 struct NetJailState *ns;
214
215 ns = GNUNET_new (struct NetJailState);
216 ns->finished = GNUNET_NO;
217 ns->topology_config = topology_config;
218
219 struct GNUNET_TESTING_Command cmd = {
220 .cls = ns,
221 .label = label,
222 .run = &netjail_start_run,
223 .finish = &netjail_start_finish,
224 .cleanup = &netjail_start_cleanup,
225 .traits = &netjail_start_traits
226 };
227
228 return cmd;
229}
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
new file mode 100644
index 000000000..8eccc5764
--- /dev/null
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem_v2.c
@@ -0,0 +1,143 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_cmd_hello_world.c
23 * @brief Command to start the netjail peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "testing_cmds.h"
29
30
31/**
32 * Struct to store information handed over to callbacks.
33 *
34 */
35struct StopHelperState
36{
37
38 const char *helper_start_label;
39
40 /**
41 * The process handle
42 */
43 struct GNUNET_HELPER_Handle **helper;
44
45 unsigned int local_m;
46
47 unsigned int global_n;
48};
49
50
51/**
52* Code to clean up resource this cmd used.
53*
54* @param cls closure
55* @param cmd current CMD being cleaned up.
56*/
57static void
58stop_testing_system_cleanup (void *cls,
59 const struct GNUNET_TESTING_Command *cmd)
60{
61
62}
63
64
65/**
66 * Trait function of this cmd does nothing.
67 *
68 */
69static int
70stop_testing_system_traits (void *cls,
71 const void **ret,
72 const char *trait,
73 unsigned int index)
74{
75 return GNUNET_OK;
76}
77
78
79/**
80* This function stops the helper process for each node.
81*
82* @param cls closure.
83* @param cmd CMD being run.
84* @param is interpreter state.
85*/
86static void
87stop_testing_system_run (void *cls,
88 const struct GNUNET_TESTING_Command *cmd,
89 struct GNUNET_TESTING_Interpreter *is)
90{
91 struct StopHelperState *shs = cls;
92 struct GNUNET_HELPER_Handle **helper;
93 const struct GNUNET_TESTING_Command *start_helper_cmd;
94
95 start_helper_cmd = GNUNET_TESTING_interpreter_lookup_command (
96 shs->helper_start_label);
97 GNUNET_TESTING_get_trait_helper_handles (start_helper_cmd,
98 &helper);
99
100 for (int i = 1; i <= shs->global_n; i++)
101 {
102 for (int j = 1; j <= shs->local_m; j++)
103 {
104 GNUNET_HELPER_stop (helper[(i - 1) * shs->local_m + j - 1],
105 GNUNET_YES);
106 }
107 }
108}
109
110
111/**
112 * Create command.
113 *
114 * @param label name for command.
115 * @param helper_start_label label of the cmd to start the test system.
116 * @param topology_config Configuration file for the test topology.
117 * @return command.
118 */
119struct GNUNET_TESTING_Command
120GNUNET_TESTING_cmd_stop_testing_system_v2 (const char *label,
121 const char *helper_start_label,
122 const char *topology_config)
123{
124 struct StopHelperState *shs;
125
126 struct GNUNET_TESTING_NetjailTopology *topology =
127 GNUNET_TESTING_get_topo_from_file (topology_config);
128
129 shs = GNUNET_new (struct StopHelperState);
130 shs->helper_start_label = helper_start_label;
131 shs->local_m = topology->nodes_m;
132 shs->global_n = topology->namespaces_n;
133
134 struct GNUNET_TESTING_Command cmd = {
135 .cls = shs,
136 .label = label,
137 .run = &stop_testing_system_run,
138 .cleanup = &stop_testing_system_cleanup,
139 .traits = &stop_testing_system_traits
140 };
141
142 return cmd;
143}
diff --git a/src/testing/testing_api_cmd_netjail_stop_v2.c b/src/testing/testing_api_cmd_netjail_stop_v2.c
new file mode 100644
index 000000000..1d13407d7
--- /dev/null
+++ b/src/testing/testing_api_cmd_netjail_stop_v2.c
@@ -0,0 +1,225 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing/testing_api_cmd_hello_world.c
23 * @brief Command to stop the netjail script.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30
31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop_v2.sh"
32
33// Child Wait handle
34struct GNUNET_ChildWaitHandle *cwh;
35
36/**
37 * Struct to hold information for callbacks.
38 *
39 */
40struct NetJailState
41{
42 /**
43 * Configuration file for the test topology.
44 */
45 char *topology_config;
46
47 /**
48 * The process id of the start script.
49 */
50 struct GNUNET_OS_Process *stop_proc;
51
52 // Flag indication if the script finished.
53 unsigned int finished;
54};
55
56
57/**
58 * The cleanup function of this cmd frees resources the cmd allocated.
59 *
60 */
61static void
62netjail_stop_cleanup (void *cls,
63 const struct GNUNET_TESTING_Command *cmd)
64{
65 struct NetJailState *ns = cls;
66
67 if (NULL != cwh)
68 {
69 GNUNET_wait_child_cancel (cwh);
70 cwh = NULL;
71 }
72 if (NULL != ns->stop_proc)
73 {
74 GNUNET_assert (0 ==
75 GNUNET_OS_process_kill (ns->stop_proc,
76 SIGKILL));
77 GNUNET_assert (GNUNET_OK ==
78 GNUNET_OS_process_wait (ns->stop_proc));
79 GNUNET_OS_process_destroy (ns->stop_proc);
80 ns->stop_proc = NULL;
81 }
82}
83
84
85/**
86 * Trait function of this cmd does nothing.
87 *
88 */
89static int
90netjail_stop_traits (void *cls,
91 const void **ret,
92 const char *trait,
93 unsigned int index)
94{
95 return GNUNET_OK;
96}
97
98
99/**
100 * Callback which will be called if the setup script finished.
101 *
102 */
103static void
104child_completed_callback (void *cls,
105 enum GNUNET_OS_ProcessStatusType type,
106 long unsigned int exit_code)
107{
108 struct NetJailState *ns = cls;
109
110 cwh = NULL;
111 if (0 == exit_code)
112 {
113 ns->finished = GNUNET_YES;
114 }
115 else
116 {
117 ns->finished = GNUNET_SYSERR;
118 }
119 GNUNET_OS_process_destroy (ns->stop_proc);
120 ns->stop_proc = NULL;
121}
122
123
124/**
125* The run method starts the script which deletes the network namespaces.
126*
127* @param cls closure.
128* @param cmd CMD being run.
129* @param is interpreter state.
130*/
131static void
132netjail_stop_run (void *cls,
133 const struct GNUNET_TESTING_Command *cmd,
134 struct GNUNET_TESTING_Interpreter *is)
135{
136 struct NetJailState *ns = cls;
137 char *pid;
138 GNUNET_asprintf (&pid,
139 "%u",
140 getpid ());
141 char *const script_argv[] = {NETJAIL_STOP_SCRIPT,
142 ns->topology_config,
143 pid,
144 NULL};
145 unsigned int helper_check = GNUNET_OS_check_helper_binary (
146 NETJAIL_STOP_SCRIPT,
147 GNUNET_YES,
148 NULL);
149
150 if (GNUNET_NO == helper_check)
151 {
152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
153 "No SUID for %s!\n",
154 NETJAIL_STOP_SCRIPT);
155 GNUNET_TESTING_interpreter_fail ();
156 }
157 else if (GNUNET_NO == helper_check)
158 {
159 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
160 "%s not found!\n",
161 NETJAIL_STOP_SCRIPT);
162 GNUNET_TESTING_interpreter_fail ();
163 }
164
165 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
166 NULL,
167 NULL,
168 NULL,
169 NETJAIL_STOP_SCRIPT,
170 script_argv);
171
172 cwh = GNUNET_wait_child (ns->stop_proc,
173 &child_completed_callback,
174 ns);
175 GNUNET_break (NULL != cwh);
176
177}
178
179
180/**
181 * This function checks the flag NetJailState#finished, if this cmd finished.
182 *
183 */
184static int
185netjail_stop_finish (void *cls,
186 GNUNET_SCHEDULER_TaskCallback cont,
187 void *cont_cls)
188{
189 struct NetJailState *ns = cls;
190
191 if (ns->finished)
192 {
193 cont (cont_cls);
194 }
195 return ns->finished;
196}
197
198
199/**
200 * Create command.
201 *
202 * @param label name for command.
203 * @param topology_config Configuration file for the test topology.
204 * @return command.
205 */
206struct GNUNET_TESTING_Command
207GNUNET_TESTING_cmd_netjail_stop_v2 (const char *label,
208 char *topology_config)
209{
210 struct NetJailState *ns;
211
212 ns = GNUNET_new (struct NetJailState);
213 ns->topology_config = topology_config;
214
215 struct GNUNET_TESTING_Command cmd = {
216 .cls = ns,
217 .label = label,
218 .run = &netjail_stop_run,
219 .finish = &netjail_stop_finish,
220 .cleanup = &netjail_stop_cleanup,
221 .traits = &netjail_stop_traits
222 };
223
224 return cmd;
225}
diff --git a/src/testing/topo.sh b/src/testing/topo.sh
new file mode 100755
index 000000000..090c3053f
--- /dev/null
+++ b/src/testing/topo.sh
@@ -0,0 +1,95 @@
1#!/bin/bash
2
3declare -A K_PLUGIN
4declare -A R_TCP
5declare -A R_UDP
6declare -A P_PLUGIN
7
8extract_attributes()
9{
10 line_key=$1
11 line=$2
12
13 if [ "$line_key" = "P" ]
14 then
15 n=$(echo $line|cut -d \| -f 1|awk -F: '{print $2}')
16 echo $n
17 m=$(echo $line|cut -d \| -f 1|awk -F: '{print $3}')
18 echo $m
19 else
20 number=$(echo $line|cut -d \| -f 1| cut -c 2-|cut -d : -f 2 )
21 echo $number
22 fi
23
24
25 nf=$(echo $line|awk -F: '{print NF}')
26 for ((i=2;i<=$nf;i++))
27 do
28 entry=$(echo $line |awk -v i=$i -F\| '{print $i}')
29 key=$(echo $entry|cut -d { -f 2|cut -d } -f 1|cut -d : -f 1)
30 value=$(echo $entry|cut -d { -f 2|cut -d } -f 1|cut -d : -f 2)
31 if [ "$key" = "tcp_port" ]
32 then
33 echo tcp port: $value
34 R_TCP[$number]=$value
35 elif [ "$key" = "udp_port" ]
36 then
37 echo udp port: $value
38 R_UDP[$number]=$value
39 elif [ "$key" = "plugin" ]
40 then
41 echo plugin: $value
42 echo $line_key
43 if [ "$line_key" = "P" ]
44 then
45 P_PLUGIN[$n,$m]=$value
46 echo $n $m ${P_PLUGIN[$n,$m]}
47 elif [ "$line_key" = "K" ]
48 then
49 K_PLUGIN[$number]=$value
50 fi
51 fi
52 done
53}
54
55read_topology(){
56
57local filename=$1
58while read line; do
59# reading each line
60 echo $line
61 key=$(cut -c -1 <<< $line)
62 if [ "$key" = "M" ]
63 then
64 LOCAL_M=$(cut -d : -f 2 <<< $line)
65 echo $LOCAL_M
66 elif [ "$key" = "N" ]
67 then
68 GLOBAL_N=$(cut -d : -f 2 <<< $line)
69 echo $GLOBAL_N
70 elif [ "$key" = "X" ]
71 then
72 KNOWN=$(cut -d : -f 2 <<< $line)
73 echo $KNOWN
74 elif [ "$key" = "T" ]
75 then
76 PLUGIN=$(cut -d : -f 2 <<< $line)
77 echo $PLUGIN
78 elif [ "$key" = "K" ]
79 then
80 echo know node
81 extract_attributes $key $line
82 elif [ "$key" = "R" ]
83 then
84 echo router
85 extract_attributes $key $line
86 elif [ "$key" = "P" ]
87 then
88 echo node
89 extract_attributes $key $line
90 fi
91done < $filename
92}
93
94
95
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 4ea3b58c4..8bd35b5a3 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -161,11 +161,13 @@ libgnunettransporttesting_la_LDFLAGS = \
161 161
162libgnunettransporttesting2_la_SOURCES = \ 162libgnunettransporttesting2_la_SOURCES = \
163 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
164 transport_api_cmd_connecting_peers_v2.c \
164 transport_api_cmd_start_peer.c \ 165 transport_api_cmd_start_peer.c \
166 transport_api_cmd_start_peer_v2.c \
165 transport_api_cmd_stop_peer.c \ 167 transport_api_cmd_stop_peer.c \
166 transport_api_cmd_send_simple.c \ 168 transport_api_cmd_send_simple.c \
169 transport_api_cmd_send_simple_v2.c \
167 transport-testing2.c transport-testing2.h \ 170 transport-testing2.c transport-testing2.h \
168 transport-testing-ng.h \
169 transport-testing-cmds.h \ 171 transport-testing-cmds.h \
170 transport-testing-filenames2.c \ 172 transport-testing-filenames2.c \
171 transport-testing-loggers2.c \ 173 transport-testing-loggers2.c \
@@ -391,7 +393,8 @@ plugin_LTLIBRARIES = \
391 $(HTTPS_SERVER_PLUGIN_LA) \ 393 $(HTTPS_SERVER_PLUGIN_LA) \
392 $(WLAN_PLUGIN_LA) \ 394 $(WLAN_PLUGIN_LA) \
393 $(BT_PLUGIN_LA) \ 395 $(BT_PLUGIN_LA) \
394 libgnunet_test_transport_plugin_cmd_simple_send.la 396 libgnunet_test_transport_plugin_cmd_simple_send.la \
397 libgnunet_test_transport_plugin_cmd_simple_send_v2.la
395 398
396libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \ 399libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \
397 test_transport_plugin_cmd_simple_send.c 400 test_transport_plugin_cmd_simple_send.c
@@ -410,6 +413,23 @@ libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
410libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \ 413libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
411 $(GN_PLUGIN_LDFLAGS) 414 $(GN_PLUGIN_LDFLAGS)
412 415
416libgnunet_test_transport_plugin_cmd_simple_send_v2_la_SOURCES = \
417 test_transport_plugin_cmd_simple_send_v2.c
418libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LIBADD = \
419 libgnunettransporttesting2.la \
420 libgnunettransportapplication.la \
421 libgnunettransport.la \
422 $(top_builddir)/src/testing/libgnunettesting.la \
423 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
424 $(top_builddir)/src/statistics/libgnunetstatistics.la \
425 $(top_builddir)/src/hello/libgnunethello.la \
426 $(top_builddir)/src/ats/libgnunetats.la \
427 $(top_builddir)/src/arm/libgnunetarm.la \
428 $(top_builddir)/src/util/libgnunetutil.la \
429 $(LTLIBINTL)
430libgnunet_test_transport_plugin_cmd_simple_send_v2_la_LDFLAGS = \
431 $(GN_PLUGIN_LDFLAGS)
432
413if HAVE_EXPERIMENTAL 433if HAVE_EXPERIMENTAL
414plugin_LTLIBRARIES += \ 434plugin_LTLIBRARIES += \
415 libgnunet_plugin_transport_udp.la 435 libgnunet_plugin_transport_udp.la
@@ -557,6 +577,7 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
557if HAVE_TESTING 577if HAVE_TESTING
558check_PROGRAMS = \ 578check_PROGRAMS = \
559 test_transport_simple_send \ 579 test_transport_simple_send \
580 test_transport_simple_send_v2 \
560 test_transport_address_switch_tcp \ 581 test_transport_address_switch_tcp \
561 test_transport_testing_startstop \ 582 test_transport_testing_startstop \
562 test_transport_testing_restart \ 583 test_transport_testing_restart \
@@ -706,6 +727,7 @@ endif
706if HAVE_EXPERIMENTAL 727if HAVE_EXPERIMENTAL
707TESTS += \ 728TESTS += \
708 test_transport_simple_send \ 729 test_transport_simple_send \
730 test_transport_simple_send_v2 \
709 test_transport_address_switch_udp \ 731 test_transport_address_switch_udp \
710 test_plugin_udp \ 732 test_plugin_udp \
711 test_transport_api_udp \ 733 test_transport_api_udp \
@@ -724,7 +746,8 @@ endif
724endif 746endif
725 747
726check_SCRIPTS= \ 748check_SCRIPTS= \
727 test_transport_simple_send.sh 749 test_transport_simple_send.sh \
750 test_transport_simple_send_v2.sh
728 751
729test_transport_simple_send_SOURCES = \ 752test_transport_simple_send_SOURCES = \
730 test_transport_simple_send.c 753 test_transport_simple_send.c
@@ -736,6 +759,16 @@ test_transport_simple_send_LDADD = \
736 libgnunettransport.la \ 759 libgnunettransport.la \
737 libgnunettransporttesting.la 760 libgnunettransporttesting.la
738 761
762test_transport_simple_send_v2_SOURCES = \
763 test_transport_simple_send_v2.c
764test_transport_simple_send_v2_LDADD = \
765 $(top_builddir)/src/testing/libgnunettesting.la \
766 $(top_builddir)/src/util/libgnunetutil.la \
767 $(top_builddir)/src/testbed/libgnunettestbed.la \
768 $(top_builddir)/src/hello/libgnunethello.la \
769 libgnunettransport.la \
770 libgnunettransporttesting.la
771
739test_transport_testing_startstop_SOURCES = \ 772test_transport_testing_startstop_SOURCES = \
740 test_transport_testing_startstop.c 773 test_transport_testing_startstop.c
741test_transport_testing_startstop_LDADD = \ 774test_transport_testing_startstop_LDADD = \
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index 4b5018b60..1dc44c945 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -144,7 +144,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
144 144
145 GNUNET_asprintf (&cfgname, 145 GNUNET_asprintf (&cfgname,
146 "test_transport_api2_tcp_node%s.conf", 146 "test_transport_api2_tcp_node%s.conf",
147 n); 147 "1");
148 148
149 LOG (GNUNET_ERROR_TYPE_ERROR, 149 LOG (GNUNET_ERROR_TYPE_ERROR,
150 "plugin cfgname: %s\n", 150 "plugin cfgname: %s\n",
@@ -154,6 +154,11 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
154 "node ip: %s\n", 154 "node ip: %s\n",
155 node_ip); 155 node_ip);
156 156
157 LOG (GNUNET_ERROR_TYPE_ERROR,
158 "m: %s n: %s\n",
159 m,
160 n);
161
157 GNUNET_asprintf (&testdir, 162 GNUNET_asprintf (&testdir,
158 "%s%s%s", 163 "%s%s%s",
159 BASE_DIR, 164 BASE_DIR,
@@ -180,6 +185,7 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
180 m, 185 m,
181 n, 186 n,
182 local_m, 187 local_m,
188 node_ip,
183 handlers, 189 handlers,
184 cfgname), 190 cfgname),
185 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready", 191 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
@@ -187,7 +193,10 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
187 GNUNET_TESTING_cmd_block_until_all_peers_started ("block", 193 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
188 &are_all_peers_started), 194 &are_all_peers_started),
189 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers", 195 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
190 "start-peer"), 196 "start-peer",
197 "system-create",
198 (atoi (n) - 1) * atoi (local_m) + atoi (
199 m)),
191 GNUNET_TRANSPORT_cmd_send_simple ("send-simple", 200 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
192 m, 201 m,
193 n, 202 n,
diff --git a/src/transport/test_transport_plugin_cmd_simple_send_v2.c b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
new file mode 100644
index 000000000..ce1245296
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send_v2.c
@@ -0,0 +1,262 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41
42/**
43 * The name for a specific test environment directory.
44 *
45 */
46char *testdir;
47
48/**
49 * The name for the configuration file of the specific node.
50 *
51 */
52char *cfgname;
53
54/**
55 * Flag indicating if all peers have been started.
56 *
57 */
58unsigned int are_all_peers_started;
59
60
61/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
new file mode 100644
index 000000000..ce1245296
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel_recv.c
@@ -0,0 +1,262 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41
42/**
43 * The name for a specific test environment directory.
44 *
45 */
46char *testdir;
47
48/**
49 * The name for the configuration file of the specific node.
50 *
51 */
52char *cfgname;
53
54/**
55 * Flag indicating if all peers have been started.
56 *
57 */
58unsigned int are_all_peers_started;
59
60
61/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c b/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
new file mode 100644
index 000000000..ce1245296
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel_send.c
@@ -0,0 +1,262 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
41
42/**
43 * The name for a specific test environment directory.
44 *
45 */
46char *testdir;
47
48/**
49 * The name for the configuration file of the specific node.
50 *
51 */
52char *cfgname;
53
54/**
55 * Flag indicating if all peers have been started.
56 *
57 */
58unsigned int are_all_peers_started;
59
60
61/**
62 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
63 * received.
64 *
65 */
66static int
67check_test (void *cls,
68 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
69{
70 return GNUNET_OK;
71}
72
73
74/**
75 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
76 * being received.
77 *
78 */
79static void
80handle_test (void *cls,
81 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
82{
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "message received\n");
85}
86
87
88/**
89 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
90 * being received.
91 *
92 */
93static int
94check_test2 (void *cls,
95 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
96{
97 return GNUNET_OK;
98}
99
100
101/**
102 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
103 * being received.
104 *
105 */
106static void
107handle_test2 (void *cls,
108 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
109{
110 LOG (GNUNET_ERROR_TYPE_ERROR,
111 "message received\n");
112}
113
114
115/**
116 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
117 *
118 */
119static void
120all_peers_started ()
121{
122 are_all_peers_started = GNUNET_YES;
123 LOG (GNUNET_ERROR_TYPE_ERROR,
124 "setting are_all_peers_started: %d\n",
125 are_all_peers_started);
126}
127
128
129/**
130 * Function to start a local test case.
131 *
132 * @param write_message Callback to send a message to the master loop.
133 * @param router_ip Global address of the network namespace.
134 * @param node_ip Local address of a node i a network namespace.
135 * @param m The number of the node in a network namespace.
136 * @param n The number of the network namespace.
137 * @param local_m The number of nodes in a network namespace.
138 */
139static void
140start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
141 char *node_ip,
142 char *m,
143 char *n,
144 char *local_m)
145{
146
147 unsigned int n_int, m_int, local_m_int, num;
148
149 struct GNUNET_TESTING_NetjailTopology *topology =
150 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG);
151
152 sscanf (m, "%u", &m_int);
153 sscanf (n, "%u", &n_int);
154 sscanf (local_m, "%u", &local_m_int);
155
156
157 if (0 == m_int)
158 num = n_int;
159 else
160 num = (n_int - 1) * local_m_int + m_int + topology->nodes_x;
161
162 GNUNET_asprintf (&cfgname,
163 "test_transport_api2_tcp_node1.conf");
164
165 LOG (GNUNET_ERROR_TYPE_ERROR,
166 "plugin cfgname: %s\n",
167 cfgname);
168
169 LOG (GNUNET_ERROR_TYPE_ERROR,
170 "node ip: %s\n",
171 node_ip);
172
173 GNUNET_asprintf (&testdir,
174 "%s%s%s",
175 BASE_DIR,
176 m,
177 n);
178
179 struct GNUNET_MQ_MessageHandler handlers[] = {
180 GNUNET_MQ_hd_var_size (test,
181 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
182 struct GNUNET_TRANSPORT_TESTING_TestMessage,
183 NULL),
184 GNUNET_MQ_hd_var_size (test2,
185 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
186 struct GNUNET_TRANSPORT_TESTING_TestMessage,
187 NULL),
188 GNUNET_MQ_handler_end ()
189 };
190
191 struct GNUNET_TESTING_Command commands[] = {
192 GNUNET_TESTING_cmd_system_create ("system-create",
193 testdir),
194 GNUNET_TRANSPORT_cmd_start_peer_v2 ("start-peer",
195 "system-create",
196 num,
197 node_ip,
198 handlers,
199 cfgname),
200 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
201 write_message),
202 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
203 &are_all_peers_started),
204 GNUNET_TRANSPORT_cmd_connect_peers_v2 ("connect-peers",
205 "start-peer",
206 "system-create",
207 num),
208 GNUNET_TRANSPORT_cmd_send_simple_v2 ("send-simple",
209 "start-peer",
210 num),
211 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
212 "start-peer"),
213 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
214 "system-create"),
215 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
216 write_message)
217 };
218
219 GNUNET_TESTING_run (NULL,
220 commands,
221 GNUNET_TIME_UNIT_FOREVER_REL);
222
223}
224
225
226/**
227 * Entry point for the plugin.
228 *
229 * @param cls NULL
230 * @return the exported block API
231 */
232void *
233libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
234{
235 struct GNUNET_TESTING_PluginFunctions *api;
236
237 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
238 api->start_testcase = &start_testcase;
239 api->all_peers_started = &all_peers_started;
240 return api;
241}
242
243
244/**
245 * Exit point from the plugin.
246 *
247 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
248 * @return NULL
249 */
250void *
251libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
252{
253 struct GNUNET_TESTING_PluginFunctions *api = cls;
254
255 GNUNET_free (api);
256 GNUNET_free (testdir);
257 GNUNET_free (cfgname);
258 return NULL;
259}
260
261
262/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_port_forward.c b/src/transport/test_transport_port_forward.c
new file mode 100644
index 000000000..b0f0b113e
--- /dev/null
+++ b/src/transport/test_transport_port_forward.c
@@ -0,0 +1,85 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport/test_transport_port_forward.c
23 * @brief Test case executing a script which sends a test UDP message from a nated peer
24 * to a gloabl known peer. There is a tcp port forwarding in place towards the
25 * natted peer to test the backchannel functionality of the TNG service.
26 * @author t3sserakt
27 */
28#include "platform.h"
29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_util_lib.h"
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
33
34/**
35 * Return value of the test.
36 *
37 */
38static unsigned int rv = 0;
39
40
41/**
42 * Main function to run the test cases.
43 *
44 * @param cls not used.
45 *
46 */
47static void
48run (void *cls)
49{
50 const char *topology_config = "test_topology_port_forward.conf";
51
52 struct GNUNET_TESTING_Command commands[] = {
53 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
54 topology_config),
55 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
56 topology_config,
57 &rv),
58 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
59 "netjail-start-testbed",
60 topology_config),
61 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
62 topology_config),
63 GNUNET_TESTING_cmd_end ()
64 };
65
66 GNUNET_TESTING_run (NULL,
67 commands,
68 TIMEOUT);
69}
70
71
72int
73main (int argc,
74 char *const *argv)
75{
76 GNUNET_log_setup ("test-netjail",
77 "DEBUG",
78 NULL);
79 GNUNET_SCHEDULER_run (&run,
80 NULL);
81
82 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
83 "Test finished!\n");
84 return rv;
85}
diff --git a/src/transport/test_transport_simple_send.c b/src/transport/test_transport_simple_send.c
new file mode 100644
index 000000000..924990d0a
--- /dev/null
+++ b/src/transport/test_transport_simple_send.c
@@ -0,0 +1,86 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport/test_transport_api_cmd_simple_send.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31
32/**
33 * Return value of the test.
34 *
35 */
36static unsigned int rv = 0;
37
38
39/**
40 * Main function to run the test cases.
41 *
42 * @param cls not used.
43 *
44 */
45static void
46run (void *cls)
47{
48 struct GNUNET_TESTING_Command commands[] = {
49 GNUNET_TESTING_cmd_netjail_start ("netjail-start",
50 "2",
51 "1"),
52 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
53 "2",
54 "1",
55 "libgnunet_test_transport_plugin_cmd_simple_send",
56 &rv),
57 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
58 "netjail-start-testbed",
59 "2",
60 "1"),
61 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
62 "2",
63 "1"),
64 GNUNET_TESTING_cmd_end ()
65 };
66
67 GNUNET_TESTING_run (NULL,
68 commands,
69 TIMEOUT);
70}
71
72
73int
74main (int argc,
75 char *const *argv)
76{
77 GNUNET_log_setup ("test-netjail",
78 "DEBUG",
79 NULL);
80 GNUNET_SCHEDULER_run (&run,
81 NULL);
82
83 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
84 "Test finished!\n");
85 return rv;
86}
diff --git a/src/transport/test_transport_simple_send_v2.c b/src/transport/test_transport_simple_send_v2.c
new file mode 100644
index 000000000..aeac1bfb6
--- /dev/null
+++ b/src/transport/test_transport_simple_send_v2.c
@@ -0,0 +1,83 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport/test_transport_api_cmd_simple_send.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
31
32#define TOPOLOGY_CONFIG "test_transport_simple_send_topo.conf"
33
34/**
35 * Return value of the test.
36 *
37 */
38static unsigned int rv = 0;
39
40
41/**
42 * Main function to run the test cases.
43 *
44 * @param cls not used.
45 *
46 */
47static void
48run (void *cls)
49{
50 struct GNUNET_TESTING_Command commands[] = {
51 GNUNET_TESTING_cmd_netjail_start_v2 ("netjail-start",
52 TOPOLOGY_CONFIG),
53 GNUNET_TESTING_cmd_netjail_start_testing_system_v2 ("netjail-start-testbed",
54 TOPOLOGY_CONFIG,
55 &rv),
56 GNUNET_TESTING_cmd_stop_testing_system_v2 ("stop-testbed",
57 "netjail-start-testbed",
58 TOPOLOGY_CONFIG),
59 GNUNET_TESTING_cmd_netjail_stop_v2 ("netjail-stop",
60 TOPOLOGY_CONFIG),
61 GNUNET_TESTING_cmd_end ()
62 };
63
64 GNUNET_TESTING_run (NULL,
65 commands,
66 TIMEOUT);
67}
68
69
70int
71main (int argc,
72 char *const *argv)
73{
74 GNUNET_log_setup ("test-netjail",
75 "DEBUG",
76 NULL);
77 GNUNET_SCHEDULER_run (&run,
78 NULL);
79
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Test finished!\n");
82 return rv;
83}
diff --git a/src/transport/test_transport_simple_send_v2.sh b/src/transport/test_transport_simple_send_v2.sh
new file mode 100755
index 000000000..8462d1849
--- /dev/null
+++ b/src/transport/test_transport_simple_send_v2.sh
@@ -0,0 +1,2 @@
1#!/bin/bash
2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send_v2"
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
index 1461a3d4d..f9ebafade 100644
--- a/src/transport/transport-testing-cmds.h
+++ b/src/transport/transport-testing-cmds.h
@@ -28,12 +28,195 @@
28#define TRANSPORT_TESTING_CMDS_H 28#define TRANSPORT_TESTING_CMDS_H
29#include "gnunet_testing_lib.h" 29#include "gnunet_testing_lib.h"
30 30
31
32struct StartPeerState_v2
33{
34 /**
35 * The ip of a node.
36 */
37 char *node_ip;
38
39 /**
40 * Receive callback
41 */
42 struct GNUNET_MQ_MessageHandler *handlers;
43
44 const char *cfgname;
45
46 /**
47 * Peer's configuration
48 */
49 struct GNUNET_CONFIGURATION_Handle *cfg;
50
51 struct GNUNET_TESTING_Peer *peer;
52
53 /**
54 * Peer identity
55 */
56 struct GNUNET_PeerIdentity id;
57
58 /**
59 * Peer's transport service handle
60 */
61 struct GNUNET_TRANSPORT_CoreHandle *th;
62
63 /**
64 * Application handle
65 */
66 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
67
68 /**
69 * Peer's PEERSTORE Handle
70 */
71 struct GNUNET_PEERSTORE_Handle *ph;
72
73 /**
74 * Hello get task
75 */
76 struct GNUNET_SCHEDULER_Task *rh_task;
77
78 /**
79 * Peer's transport get hello handle to retrieve peer's HELLO message
80 */
81 struct GNUNET_PEERSTORE_IterateContext *pic;
82
83 /**
84 * Hello
85 */
86 char *hello;
87
88 /**
89 * Hello size
90 */
91 size_t hello_size;
92
93 char *m;
94
95 char *n;
96
97 char *local_m;
98
99 unsigned int finished;
100
101 const char *system_label;
102
103 /**
104 * An unique number to identify the peer
105 */
106 unsigned int no;
107
108 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
109
110 struct GNUNET_TESTING_System *tl_system;
111
112};
113
114
115struct StartPeerState
116{
117 /**
118 * The ip of a node.
119 */
120 char *node_ip;
121
122 /**
123 * Receive callback
124 */
125 struct GNUNET_MQ_MessageHandler *handlers;
126
127 const char *cfgname;
128
129 /**
130 * Peer's configuration
131 */
132 struct GNUNET_CONFIGURATION_Handle *cfg;
133
134 struct GNUNET_TESTING_Peer *peer;
135
136 /**
137 * Peer identity
138 */
139 struct GNUNET_PeerIdentity id;
140
141 /**
142 * Peer's transport service handle
143 */
144 struct GNUNET_TRANSPORT_CoreHandle *th;
145
146 /**
147 * Application handle
148 */
149 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
150
151 /**
152 * Peer's PEERSTORE Handle
153 */
154 struct GNUNET_PEERSTORE_Handle *ph;
155
156 /**
157 * Hello get task
158 */
159 struct GNUNET_SCHEDULER_Task *rh_task;
160
161 /**
162 * Peer's transport get hello handle to retrieve peer's HELLO message
163 */
164 struct GNUNET_PEERSTORE_IterateContext *pic;
165
166 /**
167 * Hello
168 */
169 char *hello;
170
171 /**
172 * Hello size
173 */
174 size_t hello_size;
175
176 char *m;
177
178 char *n;
179
180 char *local_m;
181
182 unsigned int finished;
183
184 const char *system_label;
185
186 /**
187 * An unique number to identify the peer
188 */
189 unsigned int no;
190
191 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
192
193 struct GNUNET_TESTING_System *tl_system;
194
195};
196
197
198int
199GNUNET_TRANSPORT_get_trait_state (const struct
200 GNUNET_TESTING_Command
201 *cmd,
202 struct StartPeerState **sps);
203
204
205struct GNUNET_TESTING_Command
206GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
207 const char *system_label,
208 uint32_t no,
209 char *node_ip,
210 struct GNUNET_MQ_MessageHandler *handlers,
211 const char *cfgname);
212
31struct GNUNET_TESTING_Command 213struct GNUNET_TESTING_Command
32GNUNET_TRANSPORT_cmd_start_peer (const char *label, 214GNUNET_TRANSPORT_cmd_start_peer (const char *label,
33 const char *system_label, 215 const char *system_label,
34 char *m, 216 char *m,
35 char *n, 217 char *n,
36 char *local_m, 218 char *local_m,
219 char *node_ip,
37 struct GNUNET_MQ_MessageHandler *handlers, 220 struct GNUNET_MQ_MessageHandler *handlers,
38 const char *cfgname); 221 const char *cfgname);
39 222
@@ -43,7 +226,15 @@ GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
43 226
44struct GNUNET_TESTING_Command 227struct GNUNET_TESTING_Command
45GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 228GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
46 const char *start_peer_label); 229 const char *start_peer_label,
230 const char *create_label,
231 uint32_t num);
232
233struct GNUNET_TESTING_Command
234GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
235 const char *start_peer_label,
236 const char *create_label,
237 uint32_t num);
47 238
48struct GNUNET_TESTING_Command 239struct GNUNET_TESTING_Command
49GNUNET_TRANSPORT_cmd_send_simple (const char *label, 240GNUNET_TRANSPORT_cmd_send_simple (const char *label,
@@ -52,6 +243,21 @@ GNUNET_TRANSPORT_cmd_send_simple (const char *label,
52 uint32_t num, 243 uint32_t num,
53 const char *start_peer_label); 244 const char *start_peer_label);
54 245
246/**
247 * Create command.
248 *
249 * @param label name for command.
250 * @param m The number of the local node of the actual network namespace.
251 * @param n The number of the actual namespace.
252 * @param num Number globally identifying the node.
253 * @param start_peer_label Label of the cmd to start a peer.
254 * @return command.
255 */
256struct GNUNET_TESTING_Command
257GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
258 const char *start_peer_label,
259 uint32_t num);
260
55int 261int
56GNUNET_TRANSPORT_get_trait_peer_id (const struct 262GNUNET_TRANSPORT_get_trait_peer_id (const struct
57 GNUNET_TESTING_Command *cmd, 263 GNUNET_TESTING_Command *cmd,
@@ -65,6 +271,16 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
65 GNUNET_CONTAINER_MultiShortmap * 271 GNUNET_CONTAINER_MultiShortmap *
66 * 272 *
67 connected_peers_map); 273 connected_peers_map);
274
275int
276GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
277 GNUNET_TESTING_Command
278 *cmd,
279 struct
280 GNUNET_CONTAINER_MultiShortmap
281 *
282 *
283 connected_peers_map);
68int 284int
69GNUNET_TRANSPORT_get_trait_hello_size (const struct 285GNUNET_TRANSPORT_get_trait_hello_size (const struct
70 GNUNET_TESTING_Command 286 GNUNET_TESTING_Command
@@ -77,5 +293,20 @@ GNUNET_TRANSPORT_get_trait_hello (const struct
77 *cmd, 293 *cmd,
78 char **hello); 294 char **hello);
79 295
296
297int
298GNUNET_TRANSPORT_get_trait_application_handle (const struct
299 GNUNET_TESTING_Command *cmd,
300 struct
301 GNUNET_TRANSPORT_ApplicationHandle
302 **ah);
303
304int
305GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
306 GNUNET_TESTING_Command *cmd,
307 struct
308 GNUNET_TRANSPORT_ApplicationHandle
309 **ah);
310
80#endif 311#endif
81/* end of transport_testing.h */ 312/* end of transport_testing.h */
diff --git a/src/transport/transport-testing-ng.h b/src/transport/transport-testing-ng.h
deleted file mode 100644
index cd4e1f3fe..000000000
--- a/src/transport/transport-testing-ng.h
+++ /dev/null
@@ -1,107 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @author t3sserakt
23 */
24
25struct StartPeerState
26{
27 /**
28 * Receive callback
29 */
30 struct GNUNET_MQ_MessageHandler *handlers;
31
32 const char *cfgname;
33
34 /**
35 * Peer's configuration
36 */
37 struct GNUNET_CONFIGURATION_Handle *cfg;
38
39 struct GNUNET_TESTING_Peer *peer;
40
41 /**
42 * Peer identity
43 */
44 struct GNUNET_PeerIdentity id;
45
46 /**
47 * Peer's transport service handle
48 */
49 struct GNUNET_TRANSPORT_CoreHandle *th;
50
51 /**
52 * Application handle
53 */
54 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
55
56 /**
57 * Peer's PEERSTORE Handle
58 */
59 struct GNUNET_PEERSTORE_Handle *ph;
60
61 /**
62 * Hello get task
63 */
64 struct GNUNET_SCHEDULER_Task *rh_task;
65
66 /**
67 * Peer's transport get hello handle to retrieve peer's HELLO message
68 */
69 struct GNUNET_PEERSTORE_IterateContext *pic;
70
71 /**
72 * Hello
73 */
74 char *hello;
75
76 /**
77 * Hello size
78 */
79 size_t hello_size;
80
81 char *m;
82
83 char *n;
84
85 char *local_m;
86
87 unsigned int finished;
88
89 const char *system_label;
90
91 /**
92 * An unique number to identify the peer
93 */
94 unsigned int no;
95
96 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
97
98 struct GNUNET_TESTING_System *tl_system;
99
100};
101
102
103int
104GNUNET_TRANSPORT_get_trait_state (const struct
105 GNUNET_TESTING_Command
106 *cmd,
107 struct StartPeerState **sps);
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 34b3d5925..09ca9e54c 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -42,6 +42,15 @@
42 */ 42 */
43struct ConnectPeersState 43struct ConnectPeersState
44{ 44{
45 // Label of the cmd which started the test system.
46 const char *create_label;
47
48 /**
49 * Number globally identifying the node.
50 *
51 */
52 uint32_t num;
53
45 /** 54 /**
46 * Label of the cmd to start a peer. 55 * Label of the cmd to start a peer.
47 * 56 *
@@ -66,6 +75,13 @@ connect_peers_run (void *cls,
66 struct GNUNET_TESTING_Interpreter *is) 75 struct GNUNET_TESTING_Interpreter *is)
67{ 76{
68 struct ConnectPeersState *cps = cls; 77 struct ConnectPeersState *cps = cls;
78 const struct GNUNET_TESTING_Command *system_cmd;
79 struct GNUNET_TESTING_System *tl_system;
80 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
81 GNUNET_CRYPTO_EddsaPrivateKey);
82 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
83 GNUNET_CRYPTO_EddsaPublicKey);
84 ;
69 const struct GNUNET_TESTING_Command *peer1_cmd; 85 const struct GNUNET_TESTING_Command *peer1_cmd;
70 // const struct GNUNET_TESTING_Command *peer2_cmd; 86 // const struct GNUNET_TESTING_Command *peer2_cmd;
71 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 87 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
@@ -77,6 +93,8 @@ connect_peers_run (void *cls,
77 enum GNUNET_NetworkType nt = 0; 93 enum GNUNET_NetworkType nt = 0;
78 char *peer_id; 94 char *peer_id;
79 struct GNUNET_PeerIdentity *id; 95 struct GNUNET_PeerIdentity *id;
96 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
97 uint32_t num;
80 98
81 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label); 99 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
82 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 100 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
@@ -88,9 +106,22 @@ connect_peers_run (void *cls,
88 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, 106 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
89 &id); 107 &id);
90 108
91 if (strstr (hello, "60002") != NULL) 109 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
110 GNUNET_TESTING_get_trait_test_system (system_cmd,
111 &tl_system);
112
113 if (2 == cps->num)
114 num = 1;
115 else
116 num = 2;
117
118
119
120
121 // if (strstr (hello, "60002") != NULL)
122 if (2 == num)
92 { 123 {
93 addr = "tcp-192.168.15.2:60003"; 124 addr = "tcp-192.168.15.2:60002";
94 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG"; 125 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
95 } 126 }
96 else 127 else
@@ -99,10 +130,25 @@ connect_peers_run (void *cls,
99 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730"; 130 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
100 } 131 }
101 132
133 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
134 num,
135 other);
136
137 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
138 pub_key);
139
102 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id, 140 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
103 strlen (peer_id), 141 strlen (peer_id),
104 &peer->public_key); 142 &peer->public_key);
105 143
144 peer->public_key = *pub_key;
145
146 LOG (GNUNET_ERROR_TYPE_ERROR,
147 "\nnum: %u\n peer_id: %s\n pub_key %s\n",
148 num,
149 peer_id,
150 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
151
106 cps->id = peer; 152 cps->id = peer;
107 153
108 // 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. 154 // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
@@ -210,12 +256,16 @@ connect_peers_cleanup (void *cls,
210 */ 256 */
211struct GNUNET_TESTING_Command 257struct GNUNET_TESTING_Command
212GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 258GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
213 const char *start_peer_label) 259 const char *start_peer_label,
260 const char *create_label,
261 uint32_t num)
214{ 262{
215 struct ConnectPeersState *cps; 263 struct ConnectPeersState *cps;
216 264
217 cps = GNUNET_new (struct ConnectPeersState); 265 cps = GNUNET_new (struct ConnectPeersState);
218 cps->start_peer_label = start_peer_label; 266 cps->start_peer_label = start_peer_label;
267 cps->num = num;
268 cps->create_label = create_label;
219 269
220 270
221 struct GNUNET_TESTING_Command cmd = { 271 struct GNUNET_TESTING_Command cmd = {
diff --git a/src/transport/transport_api_cmd_connecting_peers_v2.c b/src/transport/transport_api_cmd_connecting_peers_v2.c
new file mode 100644
index 000000000..0d286b714
--- /dev/null
+++ b/src/transport/transport_api_cmd_connecting_peers_v2.c
@@ -0,0 +1,242 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define CONNECT_ADDRESS_TEMPLATE "tcp-192.168.15.%u:60002"
40
41/**
42 * Struct to store information needed in callbacks.
43 *
44 */
45struct ConnectPeersState
46{
47 // Label of the cmd which started the test system.
48 const char *create_label;
49
50 /**
51 * Number globally identifying the node.
52 *
53 */
54 uint32_t num;
55
56 /**
57 * Label of the cmd to start a peer.
58 *
59 */
60 const char *start_peer_label;
61
62 /**
63 * The peer identity of this peer.
64 *
65 */
66 struct GNUNET_PeerIdentity *id;
67};
68
69
70/**
71 * The run method of this cmd will connect to peers.
72 *
73 */
74static void
75connect_peers_run (void *cls,
76 const struct GNUNET_TESTING_Command *cmd,
77 struct GNUNET_TESTING_Interpreter *is)
78{
79 struct ConnectPeersState *cps = cls;
80 const struct GNUNET_TESTING_Command *system_cmd;
81 struct GNUNET_TESTING_System *tl_system;
82 struct GNUNET_CRYPTO_EddsaPrivateKey *priv_key = GNUNET_new (struct
83 GNUNET_CRYPTO_EddsaPrivateKey);
84 struct GNUNET_CRYPTO_EddsaPublicKey *pub_key = GNUNET_new (struct
85 GNUNET_CRYPTO_EddsaPublicKey);
86 const struct GNUNET_TESTING_Command *peer1_cmd;
87 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
88 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
89 char *addr;
90 enum GNUNET_NetworkType nt = 0;
91 struct GNUNET_PeerIdentity *other = GNUNET_new (struct GNUNET_PeerIdentity);
92 uint32_t num;
93
94 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
95 GNUNET_TRANSPORT_get_trait_application_handle_v2 (peer1_cmd,
96 &ah);
97
98 system_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->create_label);
99 GNUNET_TESTING_get_trait_test_system (system_cmd,
100 &tl_system);
101
102 if (1 == cps->num)
103 {
104 num = 2;
105 // addr = "tcp-192.168.15.2:60002";
106 }
107 else
108 {
109 num = 1;
110 // addr = "tcp-192.168.15.1:60002";
111 }
112
113 GNUNET_asprintf (&addr,
114 CONNECT_ADDRESS_TEMPLATE,
115 num);
116
117 priv_key = GNUNET_TESTING_hostkey_get (tl_system,
118 num,
119 other);
120
121 GNUNET_CRYPTO_eddsa_key_get_public (priv_key,
122 pub_key);
123
124
125 peer->public_key = *pub_key;
126
127 LOG (GNUNET_ERROR_TYPE_ERROR,
128 "num: %u pub_key %s\n",
129 num,
130 GNUNET_CRYPTO_eddsa_public_key_to_string (pub_key));
131
132 cps->id = peer;
133
134 GNUNET_TRANSPORT_application_validate (ah,
135 peer,
136 nt,
137 addr);
138}
139
140
141/**
142 * 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.
143 *
144 */
145static int
146connect_peers_finish (void *cls,
147 GNUNET_SCHEDULER_TaskCallback cont,
148 void *cont_cls)
149{
150 struct ConnectPeersState *cps = cls;
151 const struct GNUNET_TESTING_Command *peer1_cmd;
152 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
153 unsigned int ret;
154 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
155 struct GNUNET_HashCode hc;
156 int node_number;
157
158 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
159 GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (peer1_cmd,
160 &connected_peers_map);
161
162 node_number = 1;
163 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
164
165 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
166 memcpy (key,
167 &hc,
168 sizeof (*key));
169 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
170 key);
171
172 if (GNUNET_YES == ret)
173 {
174 cont (cont_cls);
175 }
176
177 GNUNET_free (key);
178 return ret;
179}
180
181
182/**
183 * Trait function of this cmd does nothing.
184 *
185 */
186static int
187connect_peers_traits (void *cls,
188 const void **ret,
189 const char *trait,
190 unsigned int index)
191{
192 return GNUNET_OK;
193}
194
195
196/**
197 * The cleanup function of this cmd frees resources the cmd allocated.
198 *
199 */
200static void
201connect_peers_cleanup (void *cls,
202 const struct GNUNET_TESTING_Command *cmd)
203{
204 struct ConnectPeersState *cps = cls;
205
206 GNUNET_free (cps->id);
207 GNUNET_free (cps);
208}
209
210
211/**
212 * Create command.
213 *
214 * @param label name for command.
215 * @param start_peer_label Label of the cmd to start a peer.
216 * @return command.
217 */
218struct GNUNET_TESTING_Command
219GNUNET_TRANSPORT_cmd_connect_peers_v2 (const char *label,
220 const char *start_peer_label,
221 const char *create_label,
222 uint32_t num)
223{
224 struct ConnectPeersState *cps;
225
226 cps = GNUNET_new (struct ConnectPeersState);
227 cps->start_peer_label = start_peer_label;
228 cps->num = num;
229 cps->create_label = create_label;
230
231
232 struct GNUNET_TESTING_Command cmd = {
233 .cls = cps,
234 .label = label,
235 .run = &connect_peers_run,
236 .finish = &connect_peers_finish,
237 .cleanup = &connect_peers_cleanup,
238 .traits = &connect_peers_traits
239 };
240
241 return cmd;
242}
diff --git a/src/transport/transport_api_cmd_send_simple_v2.c b/src/transport/transport_api_cmd_send_simple_v2.c
new file mode 100644
index 000000000..d43c0b425
--- /dev/null
+++ b/src/transport/transport_api_cmd_send_simple_v2.c
@@ -0,0 +1,156 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "transport-testing2.h"
30#include "transport-testing-cmds.h"
31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
36struct SendSimpleState
37{
38 /**
39 * Number globally identifying the node.
40 *
41 */
42 uint32_t num;
43
44 /**
45 * Label of the cmd to start a peer.
46 *
47 */
48 const char *start_peer_label;
49};
50
51
52/**
53 * Trait function of this cmd does nothing.
54 *
55 */
56static int
57send_simple_traits (void *cls,
58 const void **ret,
59 const char *trait,
60 unsigned int index)
61{
62 return GNUNET_OK;
63}
64
65
66/**
67 * The cleanup function of this cmd frees resources the cmd allocated.
68 *
69 */
70static void
71send_simple_cleanup (void *cls,
72 const struct GNUNET_TESTING_Command *cmd)
73{
74 struct SendSimpleState *sss = cls;
75
76 GNUNET_free (sss);
77}
78
79
80/**
81 * The run method of this cmd will send a simple message to the connected peer.
82 *
83 */
84static void
85send_simple_run (void *cls,
86 const struct GNUNET_TESTING_Command *cmd,
87 struct GNUNET_TESTING_Interpreter *is)
88{
89 struct SendSimpleState *sss = cls;
90 struct GNUNET_MQ_Envelope *env;
91 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
92 struct GNUNET_MQ_Handle *mq;
93 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
94 const struct GNUNET_TESTING_Command *peer1_cmd;
95 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
96 struct GNUNET_HashCode hc;
97 int node_number;
98
99 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
100 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
101 &connected_peers_map);
102
103 node_number = 1;
104 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
105 memcpy (key,
106 &hc,
107 sizeof (*key));
108
109 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
110 key);
111
112 env = GNUNET_MQ_msg_extra (test,
113 2600 - sizeof(*test),
114 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
115 test->num = htonl (sss->num);
116 memset (&test[1],
117 sss->num,
118 2600 - sizeof(*test));
119 GNUNET_MQ_send (mq,
120 env);
121 GNUNET_free (key);
122
123}
124
125
126/**
127 * Create command.
128 *
129 * @param label name for command.
130 * @param m The number of the local node of the actual network namespace.
131 * @param n The number of the actual namespace.
132 * @param num Number globally identifying the node.
133 * @param start_peer_label Label of the cmd to start a peer.
134 * @return command.
135 */
136struct GNUNET_TESTING_Command
137GNUNET_TRANSPORT_cmd_send_simple_v2 (const char *label,
138 const char *start_peer_label,
139 uint32_t num)
140{
141 struct SendSimpleState *sss;
142
143 sss = GNUNET_new (struct SendSimpleState);
144 sss->num = num;
145 sss->start_peer_label = start_peer_label;
146
147 struct GNUNET_TESTING_Command cmd = {
148 .cls = sss,
149 .label = label,
150 .run = &send_simple_run,
151 .cleanup = &send_simple_cleanup,
152 .traits = &send_simple_traits
153 };
154
155 return cmd;
156}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index 729d981c0..f4e92944b 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -29,7 +29,7 @@
29#include "gnunet_peerstore_service.h" 29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h" 30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h" 31#include "gnunet_transport_application_service.h"
32#include "transport-testing-ng.h" 32#include "transport-testing-cmds.h"
33 33
34/** 34/**
35 * Generic logging shortcut 35 * Generic logging shortcut
@@ -185,6 +185,10 @@ start_peer_run (void *cls,
185 struct GNUNET_PeerIdentity dummy; 185 struct GNUNET_PeerIdentity dummy;
186 const struct GNUNET_TESTING_Command *system_cmd; 186 const struct GNUNET_TESTING_Command *system_cmd;
187 struct GNUNET_TESTING_System *tl_system; 187 struct GNUNET_TESTING_System *tl_system;
188 char *home;
189 char *transport_unix_path;
190 char *communicator_unix_path;
191 char *bindto;
188 192
189 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) 193 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
190 { 194 {
@@ -200,6 +204,34 @@ start_peer_run (void *cls,
200 GNUNET_assert (GNUNET_OK == 204 GNUNET_assert (GNUNET_OK ==
201 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname)); 205 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
202 206
207 GNUNET_asprintf (&home,
208 "$GNUNET_TMP/test-transport/api-tcp-p%u",
209 sps->no);
210
211 GNUNET_asprintf (&transport_unix_path,
212 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
213 sps->no);
214
215 GNUNET_asprintf (&communicator_unix_path,
216 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
217 sps->no);
218
219 GNUNET_asprintf (&bindto,
220 "%s:60002",
221 sps->node_ip);
222
223
224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
225 home);
226 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
227 transport_unix_path);
228 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
229 "BINDTO",
230 bindto);
231 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
232 "UNIXPATH",
233 communicator_unix_path);
234
203 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label); 235 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label);
204 GNUNET_TESTING_get_trait_test_system (system_cmd, 236 GNUNET_TESTING_get_trait_test_system (system_cmd,
205 &tl_system); 237 &tl_system);
@@ -536,6 +568,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
536 char *m, 568 char *m,
537 char *n, 569 char *n,
538 char *local_m, 570 char *local_m,
571 char *node_ip,
539 struct GNUNET_MQ_MessageHandler *handlers, 572 struct GNUNET_MQ_MessageHandler *handlers,
540 const char *cfgname) 573 const char *cfgname)
541{ 574{
@@ -552,6 +585,7 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
552 sps->system_label = system_label; 585 sps->system_label = system_label;
553 sps->connected_peers_map = connected_peers_map; 586 sps->connected_peers_map = connected_peers_map;
554 sps->cfgname = cfgname; 587 sps->cfgname = cfgname;
588 sps->node_ip = node_ip;
555 589
556 if (NULL != handlers) 590 if (NULL != handlers)
557 { 591 {
diff --git a/src/transport/transport_api_cmd_start_peer_v2.c b/src/transport/transport_api_cmd_start_peer_v2.c
new file mode 100644
index 000000000..0e39bd915
--- /dev/null
+++ b/src/transport/transport_api_cmd_start_peer_v2.c
@@ -0,0 +1,607 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testing_api_cmd_start_peer.c
23 * @brief cmd to start a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h"
32#include "transport-testing-cmds.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39
40static void
41retrieve_hello (void *cls);
42
43
44/**
45 * Callback delivering the hello of this peer from peerstore.
46 *
47 */
48static void
49hello_iter_cb (void *cb_cls,
50 const struct GNUNET_PEERSTORE_Record *record,
51 const char *emsg)
52{
53 struct StartPeerState_v2 *sps = cb_cls;
54 if (NULL == record)
55 {
56 sps->pic = NULL;
57 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
58 return;
59 }
60 // Check record type et al?
61 sps->hello_size = record->value_size;
62 sps->hello = GNUNET_malloc (sps->hello_size);
63 memcpy (sps->hello, record->value, sps->hello_size);
64 sps->hello[sps->hello_size - 1] = '\0';
65
66 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
67 sps->pic = NULL;
68 sps->finished = GNUNET_YES;
69}
70
71
72/**
73 * Function to start the retrieval task to retrieve the hello of this peer
74 * from the peerstore.
75 *
76 */
77static void
78retrieve_hello (void *cls)
79{
80 struct StartPeerState_v2 *sps = cls;
81 sps->rh_task = NULL;
82 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
83 "transport",
84 &sps->id,
85 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
86 hello_iter_cb,
87 sps);
88
89}
90
91
92/**
93 * This function checks StartPeerState_v2#finished, which is set when the hello was retrieved.
94 *
95 */
96static int
97start_peer_finish (void *cls,
98 GNUNET_SCHEDULER_TaskCallback cont,
99 void *cont_cls)
100{
101 struct StartPeerState_v2 *sps = cls;
102
103 if (GNUNET_YES == sps->finished)
104 {
105 cont (cont_cls);
106 }
107
108 return sps->finished;
109}
110
111
112/**
113 * Disconnect callback for the connection to the core service.
114 *
115 */
116static void
117notify_disconnect (void *cls,
118 const struct GNUNET_PeerIdentity *peer,
119 void *handler_cls)
120{
121 struct StartPeerState_v2 *sps = cls;
122
123 LOG (GNUNET_ERROR_TYPE_DEBUG,
124 "Peer %s disconnected from peer %u (`%s')\n",
125 GNUNET_i2s (peer),
126 sps->no,
127 GNUNET_i2s (&sps->id));
128
129}
130
131
132/**
133 * Connect callback for the connection to the core service.
134 *
135 */
136static void *
137notify_connect (void *cls,
138 const struct GNUNET_PeerIdentity *peer,
139 struct GNUNET_MQ_Handle *mq)
140{
141 struct StartPeerState_v2 *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc;
144 int node_number;
145
146 void *ret = NULL;
147
148
149 LOG (GNUNET_ERROR_TYPE_DEBUG,
150 "Peer %s connected to peer %u (`%s')\n",
151 GNUNET_i2s (peer),
152 sps->no,
153 GNUNET_i2s (&sps->id));
154
155 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
156 node_number = 1;
157 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
158
159
160 memcpy (key,
161 &hc,
162 sizeof (*key));
163 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
164 key,
165 mq,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
167
168 GNUNET_free (key);
169 // TODO what does the handler function need?
170 return ret;
171}
172
173
174/**
175 * The run method of this cmd will start all services of a peer to test the transport service.
176 *
177 */
178static void
179start_peer_run (void *cls,
180 const struct GNUNET_TESTING_Command *cmd,
181 struct GNUNET_TESTING_Interpreter *is)
182{
183 struct StartPeerState_v2 *sps = cls;
184 char *emsg = NULL;
185 struct GNUNET_PeerIdentity dummy;
186 const struct GNUNET_TESTING_Command *system_cmd;
187 struct GNUNET_TESTING_System *tl_system;
188 char *home;
189 char *transport_unix_path;
190 char *communicator_unix_path;
191 char *bindto;
192
193 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
194 {
195 LOG (GNUNET_ERROR_TYPE_ERROR,
196 "File not found: `%s'\n",
197 sps->cfgname);
198 GNUNET_TESTING_interpreter_fail ();
199 return;
200 }
201
202
203 sps->cfg = GNUNET_CONFIGURATION_create ();
204 GNUNET_assert (GNUNET_OK ==
205 GNUNET_CONFIGURATION_load (sps->cfg, sps->cfgname));
206
207 GNUNET_asprintf (&home,
208 "$GNUNET_TMP/test-transport/api-tcp-p%u",
209 sps->no);
210
211 GNUNET_asprintf (&transport_unix_path,
212 "$GNUNET_RUNTIME_DIR/tng-p%u.sock",
213 sps->no);
214
215 GNUNET_asprintf (&communicator_unix_path,
216 "$GNUNET_RUNTIME_DIR/tcp-comm-p%u.sock",
217 sps->no);
218
219 GNUNET_asprintf (&bindto,
220 "%s:60002",
221 sps->node_ip);
222
223
224 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "PATHS", "GNUNET_TEST_HOME",
225 home);
226 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "transport", "UNIXPATH",
227 transport_unix_path);
228 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
229 "BINDTO",
230 bindto);
231 GNUNET_CONFIGURATION_set_value_string (sps->cfg, "communicator-tcp",
232 "UNIXPATH",
233 communicator_unix_path);
234
235 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sps->system_label);
236 GNUNET_TESTING_get_trait_test_system (system_cmd,
237 &tl_system);
238
239 sps->tl_system = tl_system;
240
241 if (GNUNET_SYSERR ==
242 GNUNET_TESTING_configuration_create (tl_system,
243 sps->cfg))
244 {
245 LOG (GNUNET_ERROR_TYPE_ERROR,
246 "Testing library failed to create unique configuration based on `%s'\n",
247 sps->cfgname);
248 GNUNET_CONFIGURATION_destroy (sps->cfg);
249 GNUNET_TESTING_interpreter_fail ();
250 return;
251 }
252
253 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
254 sps->cfg,
255 sps->no,
256 NULL,
257 &emsg);
258 if (NULL == sps->peer)
259 {
260 LOG (GNUNET_ERROR_TYPE_ERROR,
261 "Testing library failed to create unique configuration based on `%s': `%s'\n",
262 sps->cfgname,
263 emsg);
264 GNUNET_free (emsg);
265 GNUNET_TESTING_interpreter_fail ();
266 return;
267 }
268
269 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
270 {
271 LOG (GNUNET_ERROR_TYPE_ERROR,
272 "Testing library failed to create unique configuration based on `%s'\n",
273 sps->cfgname);
274 GNUNET_free (emsg);
275 GNUNET_TESTING_interpreter_fail ();
276 return;
277 }
278
279 memset (&dummy,
280 '\0',
281 sizeof(dummy));
282
283 GNUNET_TESTING_peer_get_identity (sps->peer,
284 &sps->id);
285
286 if (0 == memcmp (&dummy,
287 &sps->id,
288 sizeof(struct GNUNET_PeerIdentity)))
289 {
290 LOG (GNUNET_ERROR_TYPE_ERROR,
291 "Testing library failed to obtain peer identity for peer %u\n",
292 sps->no);
293 GNUNET_free (emsg);
294 GNUNET_TESTING_interpreter_fail ();
295 return;
296 }
297 LOG (GNUNET_ERROR_TYPE_DEBUG,
298 "Peer %u configured with identity `%s'\n",
299 sps->no,
300 GNUNET_i2s_full (&sps->id));
301
302 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
303 NULL,
304 sps->handlers,
305 sps,
306 &notify_connect,
307 &notify_disconnect);
308 if (NULL == sps->th)
309 {
310 LOG (GNUNET_ERROR_TYPE_ERROR,
311 "Failed to connect to transport service for peer `%s': `%s'\n",
312 sps->cfgname,
313 emsg);
314 GNUNET_free (emsg);
315 GNUNET_TESTING_interpreter_fail ();
316 return;
317 }
318
319 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
320 if (NULL == sps->th)
321 {
322 LOG (GNUNET_ERROR_TYPE_ERROR,
323 "Failed to connect to peerstore service for peer `%s': `%s'\n",
324 sps->cfgname,
325 emsg);
326 GNUNET_free (emsg);
327 GNUNET_TESTING_interpreter_fail ();
328 return;
329 }
330
331 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
332 if (NULL == sps->ah)
333 {
334 LOG (GNUNET_ERROR_TYPE_ERROR,
335 "Failed to initialize the TRANSPORT application suggestion client handle for peer `%s': `%s'\n",
336 sps->cfgname,
337 emsg);
338 GNUNET_free (emsg);
339 GNUNET_TESTING_interpreter_fail ();
340 return;
341 }
342 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
343}
344
345
346/**
347 * The cleanup function of this cmd frees resources the cmd allocated.
348 *
349 */
350static void
351start_peer_cleanup (void *cls,
352 const struct GNUNET_TESTING_Command *cmd)
353{
354 struct StartPeerState_v2 *sps = cls;
355
356 if (NULL != sps->handlers)
357 {
358 GNUNET_free (sps->handlers);
359 sps->handlers = NULL;
360 }
361 if (NULL != sps->cfg)
362 {
363 GNUNET_CONFIGURATION_destroy (sps->cfg);
364 sps->cfg = NULL;
365 }
366 GNUNET_free (sps->hello);
367 GNUNET_free (sps->connected_peers_map);
368 GNUNET_free (sps);
369}
370
371
372/**
373 * This function prepares an array with traits.
374 *
375 */
376static int
377start_peer_traits (void *cls,
378 const void **ret,
379 const char *trait,
380 unsigned int index)
381{
382 struct StartPeerState_v2 *sps = cls;
383 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
384 struct GNUNET_PeerIdentity *id = &sps->id;
385 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
386 sps->connected_peers_map;
387 char *hello = sps->hello;
388 size_t hello_size = sps->hello_size;
389
390
391 struct GNUNET_TESTING_Trait traits[] = {
392 {
393 .index = 0,
394 .trait_name = "application_handle",
395 .ptr = (const void *) ah,
396 },
397 {
398 .index = 1,
399 .trait_name = "peer_id",
400 .ptr = (const void *) id,
401 },
402 {
403 .index = 2,
404 .trait_name = "connected_peers_map",
405 .ptr = (const void *) connected_peers_map,
406 },
407 {
408 .index = 3,
409 .trait_name = "hello",
410 .ptr = (const void *) hello,
411 },
412 {
413 .index = 4,
414 .trait_name = "hello_size",
415 .ptr = (const void *) hello_size,
416 },
417 {
418 .index = 5,
419 .trait_name = "state",
420 .ptr = (const void *) sps,
421 },
422 GNUNET_TESTING_trait_end ()
423 };
424
425 return GNUNET_TESTING_get_trait (traits,
426 ret,
427 trait,
428 index);
429}
430
431
432/**
433 * Function to get the trait with the struct StartPeerState_v2.
434 *
435 * @param[out] sps struct StartPeerState_v2.
436 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
437 *
438 */
439int
440GNUNET_TRANSPORT_get_trait_state_v2 (const struct
441 GNUNET_TESTING_Command
442 *cmd,
443 struct StartPeerState_v2 **sps)
444{
445 return cmd->traits (cmd->cls,
446 (const void **) sps,
447 "state",
448 (unsigned int) 5);
449}
450
451
452/**
453 * Function to get the trait with the size of the hello.
454 *
455 * @param[out] hello_size size of hello.
456 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
457 *
458 */
459int
460GNUNET_TRANSPORT_get_trait_hello_size_v2 (const struct
461 GNUNET_TESTING_Command
462 *cmd,
463 size_t **hello_size)
464{
465 return cmd->traits (cmd->cls,
466 (const void **) hello_size,
467 "hello_size",
468 (unsigned int) 4);
469}
470
471
472/**
473 * Function to get the trait with the hello.
474 *
475 * @param[out] hello The hello for the peer.
476 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
477 *
478 */
479int
480GNUNET_TRANSPORT_get_trait_hello_v2 (const struct
481 GNUNET_TESTING_Command
482 *cmd,
483 char **hello)
484{
485 return cmd->traits (cmd->cls,
486 (const void **) hello,
487 "hello",
488 (unsigned int) 3);
489}
490
491
492/**
493 * Function to get the trait with the map of connected peers.
494 *
495 * @param[out] connected_peers_map The map with connected peers.
496 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
497 *
498 */
499int
500GNUNET_TRANSPORT_get_trait_connected_peers_map_v2 (const struct
501 GNUNET_TESTING_Command
502 *cmd,
503 struct
504 GNUNET_CONTAINER_MultiShortmap
505 *
506 *
507 connected_peers_map)
508{
509 return cmd->traits (cmd->cls,
510 (const void **) connected_peers_map,
511 "connected_peers_map",
512 (unsigned int) 2);
513}
514
515
516/**
517 * Function to get the trait with the transport application handle.
518 *
519 * @param[out] ah The application handle.
520 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
521 */
522int
523GNUNET_TRANSPORT_get_trait_application_handle_v2 (const struct
524 GNUNET_TESTING_Command *cmd,
525 struct
526 GNUNET_TRANSPORT_ApplicationHandle
527 **ah)
528{
529 return cmd->traits (cmd->cls,
530 (const void **) ah,
531 "application_handle",
532 (unsigned int) 0);
533}
534
535
536/**
537 * Function to get the trait with the peer id.
538 *
539 * @param[out] id The peer id.
540 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
541 */
542int
543GNUNET_TRANSPORT_get_trait_peer_id_v2 (const struct
544 GNUNET_TESTING_Command *cmd,
545 struct GNUNET_PeerIdentity **id)
546{
547 return cmd->traits (cmd->cls,
548 (const void **) id,
549 "peer_id",
550 (unsigned int) 1);
551}
552
553
554/**
555 * Create command.
556 *
557 * @param label name for command.
558 * @param system_label Label of the cmd to setup a test environment.
559 * @param m The number of the local node of the actual network namespace.
560 * @param n The number of the actual namespace.
561 * @param local_m Number of local nodes in each namespace.
562 * @param handlers Handler for messages received by this peer.
563 * @param cfgname Configuration file name for this peer.
564 * @return command.
565 */
566struct GNUNET_TESTING_Command
567GNUNET_TRANSPORT_cmd_start_peer_v2 (const char *label,
568 const char *system_label,
569 uint32_t no,
570 char *node_ip,
571 struct GNUNET_MQ_MessageHandler *handlers,
572 const char *cfgname)
573{
574 struct StartPeerState_v2 *sps;
575 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
576 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
577 unsigned int i;
578
579 sps = GNUNET_new (struct StartPeerState_v2);
580 sps->no = no;
581 sps->system_label = system_label;
582 sps->connected_peers_map = connected_peers_map;
583 sps->cfgname = cfgname;
584 sps->node_ip = node_ip;
585
586 if (NULL != handlers)
587 {
588 for (i = 0; NULL != handlers[i].cb; i++)
589 ;
590 sps->handlers = GNUNET_new_array (i + 1,
591 struct GNUNET_MQ_MessageHandler);
592 GNUNET_memcpy (sps->handlers,
593 handlers,
594 i * sizeof(struct GNUNET_MQ_MessageHandler));
595 }
596
597 struct GNUNET_TESTING_Command cmd = {
598 .cls = sps,
599 .label = label,
600 .run = &start_peer_run,
601 .finish = &start_peer_finish,
602 .cleanup = &start_peer_cleanup,
603 .traits = &start_peer_traits
604 };
605
606 return cmd;
607}
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index 7a0050a63..4d7228378 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -29,7 +29,7 @@
29#include "gnunet_peerstore_service.h" 29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h" 30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h" 31#include "gnunet_transport_application_service.h"
32#include "transport-testing-ng.h" 32#include "transport-testing-cmds.h"
33 33
34/** 34/**
35 * Generic logging shortcut 35 * Generic logging shortcut