aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authort3sserakt <t3ss@posteo.de>2021-11-09 17:38:47 +0100
committert3sserakt <t3ss@posteo.de>2021-11-09 17:43:25 +0100
commit8cd4dadfb9ebd4db232fda79d5c4353eacb15690 (patch)
treea063e52d71d1b6611371f6c129c6ae1b0215cf99
parent6fb788ca2ec44837ea10a36be7fd0030fb08955b (diff)
downloadgnunet-dev/t3ss/tng.tar.gz
gnunet-dev/t3ss/tng.zip
- moved global netjail methods to its own header file.dev/t3ss/tng
- added configuration by string in test skript instead of config file. - moved netjail scripts to contrib/netjail and install them into the share/gnunet directory.
-rw-r--r--contrib/Makefile.am11
-rwxr-xr-xcontrib/netjail/netjail_core.sh260
-rwxr-xr-xcontrib/netjail/netjail_exec.sh14
-rwxr-xr-xcontrib/netjail/netjail_start.sh81
-rwxr-xr-xcontrib/netjail/netjail_stop.sh65
-rwxr-xr-xcontrib/netjail/topo.sh113
-rw-r--r--po/POTFILES.in6
-rw-r--r--src/dhtu/test_dhtu_ip.c2
-rw-r--r--src/dhtu/testing_dhtu_cmd_send.c1
-rw-r--r--src/include/Makefile.am1
-rw-r--r--src/include/gnunet_testing_netjail_lib.h463
-rw-r--r--src/include/gnunet_testing_ng_lib.h60
-rw-r--r--src/include/gnunet_testing_plugin.h4
-rw-r--r--src/testing/Makefile.am40
-rw-r--r--src/testing/gnunet-cmds-helper.c41
-rw-r--r--src/testing/test_testing_api_cmd_netjail.c87
-rw-r--r--src/testing/test_testing_hello_world.c68
-rw-r--r--src/testing/test_testing_plugin_testcmd.c123
-rw-r--r--src/testing/test_testing_topology.c44
-rw-r--r--src/testing/testing.c99
-rw-r--r--src/testing/testing_api_cmd_block_until_all_peers_started.c107
-rw-r--r--src/testing/testing_api_cmd_block_until_external_trigger.c1
-rw-r--r--src/testing/testing_api_cmd_finish.c2
-rw-r--r--src/testing/testing_api_cmd_hello_world.c126
-rw-r--r--src/testing/testing_api_cmd_hello_world_birth.c161
-rw-r--r--src/testing/testing_api_cmd_local_test_finished.c1
-rw-r--r--src/testing/testing_api_cmd_local_test_prepared.c1
-rw-r--r--src/testing/testing_api_cmd_netjail_start.c43
-rw-r--r--src/testing/testing_api_cmd_netjail_start_testsystem.c187
-rw-r--r--src/testing/testing_api_cmd_netjail_stop.c77
-rw-r--r--src/testing/testing_api_cmd_netjail_stop_testsystem.c14
-rw-r--r--src/testing/testing_api_cmd_send_peer_ready.c1
-rw-r--r--src/testing/testing_api_cmd_system_create.c1
-rw-r--r--src/testing/testing_api_cmd_system_destroy.c1
-rw-r--r--src/transport/Makefile.am2
-rw-r--r--src/transport/gnunet-communicator-udp.c41
-rw-r--r--src/transport/gnunet-service-tng.c80
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c17
-rw-r--r--src/transport/test_transport_plugin_cmd_udp_backchannel.c13
-rwxr-xr-xsrc/transport/test_transport_simple_send_string.sh16
-rw-r--r--src/transport/test_transport_start_with_config.c76
-rw-r--r--src/transport/transport_api_cmd_backchannel_check.c1
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c5
-rw-r--r--src/transport/transport_api_cmd_send_simple.c1
-rw-r--r--src/transport/transport_api_cmd_send_simple_v3.c194
-rw-r--r--src/transport/transport_api_cmd_start_peer.c5
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c1
47 files changed, 1535 insertions, 1223 deletions
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
index 464016ee8..44b0ff76d 100644
--- a/contrib/Makefile.am
+++ b/contrib/Makefile.am
@@ -24,6 +24,10 @@ dist_pkgdata_DATA = \
24 branding/logo/gnunet-logo-big.png \ 24 branding/logo/gnunet-logo-big.png \
25 branding/logo/gnunet-logo.pdf \ 25 branding/logo/gnunet-logo.pdf \
26 testing_hostkeys.ecc \ 26 testing_hostkeys.ecc \
27 netjail/netjail_core.sh \
28 netjail/netjail_start.sh \
29 netjail/netjail_stop.sh \
30 netjail/topo.sh \
27 $(BUILDCOMMON_SHLIB_FILES) 31 $(BUILDCOMMON_SHLIB_FILES)
28 32
29INITD_FILES = \ 33INITD_FILES = \
@@ -240,4 +244,11 @@ aclocaldir = $(datadir)/aclocal
240aclocal_DATA = \ 244aclocal_DATA = \
241 gnunet.m4 245 gnunet.m4
242 246
247install-data-hook:
248 chmod o+x $(pkgdatadir)/netjail_core.sh
249 chmod o+x $(pkgdatadir)/netjail_start.sh
250 chmod o+x $(pkgdatadir)/netjail_stop.sh
251 chmod o+x $(pkgdatadir)/netjail_exec.sh
252 chmod o+x $(pkgdatadir)/topo.sh
253
243## EOF 254## EOF
diff --git a/contrib/netjail/netjail_core.sh b/contrib/netjail/netjail_core.sh
new file mode 100755
index 000000000..ed363cf35
--- /dev/null
+++ b/contrib/netjail/netjail_core.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" broadcast + 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/contrib/netjail/netjail_exec.sh b/contrib/netjail/netjail_exec.sh
new file mode 100755
index 000000000..ab4aad5b8
--- /dev/null
+++ b/contrib/netjail/netjail_exec.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2. "$(dirname $0)/netjail_core.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 $7 $8
diff --git a/contrib/netjail/netjail_start.sh b/contrib/netjail/netjail_start.sh
new file mode 100755
index 000000000..997ad0a95
--- /dev/null
+++ b/contrib/netjail/netjail_start.sh
@@ -0,0 +1,81 @@
1#!/bin/bash
2. "$(dirname $0)/netjail_core.sh"
3. "$(dirname $0)/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
12readfile=$3
13
14if [ $readfile -eq 0 ]
15then
16 read_topology_string "$filename"
17else
18 echo read file
19 read_topology $filename
20fi
21
22shift 2
23
24LOCAL_GROUP="192.168.15"
25GLOBAL_GROUP="92.68.150"
26KNOWN_GROUP="92.68.151"
27
28
29echo "Start [local: $LOCAL_GROUP.0/24, global: $GLOBAL_GROUP.0/16]"
30
31netjail_bridge
32NETWORK_NET=$RESULT
33
34for X in $(seq $KNOWN); do
35 netjail_node
36 KNOWN_NODES[$X]=$RESULT
37 netjail_node_link_bridge ${KNOWN_NODES[$X]} $NETWORK_NET "$KNOWN_GROUP.$X" 16
38 KNOWN_LINKS[$X]=$RESULT
39done
40
41declare -A NODES
42declare -A NODE_LINKS
43
44for N in $(seq $GLOBAL_N); do
45 netjail_node
46 ROUTERS[$N]=$RESULT
47 netjail_node_link_bridge ${ROUTERS[$N]} $NETWORK_NET "$GLOBAL_GROUP.$N" 16
48 NETWORK_LINKS[$N]=$RESULT
49 netjail_bridge
50 ROUTER_NETS[$N]=$RESULT
51
52 for M in $(seq $LOCAL_M); do
53 netjail_node
54 NODES[$N,$M]=$RESULT
55 netjail_node_link_bridge ${NODES[$N,$M]} ${ROUTER_NETS[$N]} "$LOCAL_GROUP.$M" 24
56 NODE_LINKS[$N,$M]=$RESULT
57 done
58
59 ROUTER_ADDR="$LOCAL_GROUP.$(($LOCAL_M+1))"
60 netjail_node_link_bridge ${ROUTERS[$N]} ${ROUTER_NETS[$N]} $ROUTER_ADDR 24
61 ROUTER_LINKS[$N]=$RESULT
62
63 netjail_node_add_nat ${ROUTERS[$N]} $ROUTER_ADDR 24
64
65 for M in $(seq $LOCAL_M); do
66 netjail_node_add_default ${NODES[$N,$M]} $ROUTER_ADDR
67 done
68
69 # TODO Topology configuration must be enhanced to configure forwarding to more than one subnet node via different ports.
70
71 if [ "1" == "${R_TCP[$N]}" ]
72 then
73 ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p tcp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
74 ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
75 fi
76 if [ "1" == "${R_UDP[$N]}" ]
77 then
78 ip netns exec ${ROUTERS[$N]} iptables -t nat -A PREROUTING -p udp -d $GLOBAL_GROUP.$N --dport 60002 -j DNAT --to $LOCAL_GROUP.1
79 ip netns exec ${ROUTERS[$N]} iptables -A FORWARD -d $LOCAL_GROUP.1 -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
80 fi
81done
diff --git a/contrib/netjail/netjail_stop.sh b/contrib/netjail/netjail_stop.sh
new file mode 100755
index 000000000..c8739dc94
--- /dev/null
+++ b/contrib/netjail/netjail_stop.sh
@@ -0,0 +1,65 @@
1#!/bin/bash
2. "$(dirname $0)/netjail_core.sh"
3. "$(dirname $0)/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
12readfile=$3
13
14if [ $readfile -eq 0 ]
15then
16 read_topology_string $filename
17else
18 read_topology $filename
19fi
20
21declare -A NODES
22declare -A NODE_LINKS
23
24netjail_bridge_name
25NETWORK_NET=$RESULT
26
27for X in $(seq $KNOWN); do
28 netjail_node_name
29 KNOWN_NODES[$X]=$RESULT
30 netjail_node_link_bridge_name
31 KNOWN_LINKS[$X]=$RESULT
32 netjail_node_unlink_bridge ${KNOWN_LINKS[$X]}
33 netjail_node_clear ${KNOWN_NODES[$X]}
34done
35
36for N in $(seq $GLOBAL_N); do
37 netjail_node_name
38 ROUTERS[$N]=$RESULT
39 netjail_node_link_bridge_name
40 NETWORK_LINKS[$N]=$RESULT
41 netjail_bridge_name
42 ROUTER_NETS[$N]=$RESULT
43 netjail_node_link_bridge_name
44 ROUTER_LINKS[$N]=$RESULT
45
46 netjail_node_unlink_bridge ${ROUTER_LINKS[$N]}
47
48 for M in $(seq $LOCAL_M); do
49 netjail_node_name
50 NODES[$N,$M]=$RESULT
51 netjail_node_link_bridge_name
52 NODE_LINKS[$N,$M]=$RESULT
53 netjail_node_unlink_bridge ${NODE_LINKS[$N,$M]}
54 netjail_node_clear ${NODES[$N,$M]}
55 done
56
57
58 netjail_bridge_clear ${ROUTER_NETS[$N]}
59 netjail_node_unlink_bridge ${NETWORK_LINKS[$N]}
60 netjail_node_clear ${ROUTERS[$N]}
61done
62
63netjail_bridge_clear $NETWORK_NET
64
65echo "Done"
diff --git a/contrib/netjail/topo.sh b/contrib/netjail/topo.sh
new file mode 100755
index 000000000..9af017ff0
--- /dev/null
+++ b/contrib/netjail/topo.sh
@@ -0,0 +1,113 @@
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 nf=$(echo $line|awk -F: '{print NF}')
25 for ((i=2;i<=$nf;i++))
26 do
27 entry=$(echo $line |awk -v i=$i -F\| '{print $i}')
28 key=$(echo $entry|cut -d { -f 2|cut -d } -f 1|cut -d : -f 1)
29 value=$(echo $entry|cut -d { -f 2|cut -d } -f 1|cut -d : -f 2)
30 if [ "$key" = "tcp_port" ]
31 then
32 echo tcp port: $value
33 R_TCP[$number]=$value
34 elif [ "$key" = "udp_port" ]
35 then
36 echo udp port: $value
37 R_UDP[$number]=$value
38 elif [ "$key" = "plugin" ]
39 then
40 echo plugin: $value
41 echo $line_key
42 if [ "$line_key" = "P" ]
43 then
44 P_PLUGIN[$n,$m]=$value
45 echo $n $m ${P_PLUGIN[$n,$m]}
46 elif [ "$line_key" = "K" ]
47 then
48 K_PLUGIN[$number]=$value
49 fi
50 fi
51 done
52}
53
54parse_line(){
55 line=$1
56 echo $line
57 key=$(cut -c -1 <<< $line)
58 if [ "$key" = "M" ]
59 then
60 LOCAL_M=$(cut -d : -f 2 <<< $line)
61 echo $LOCAL_M
62 elif [ "$key" = "N" ]
63 then
64 GLOBAL_N=$(cut -d : -f 2 <<< $line)
65 echo $GLOBAL_N
66 for ((i=1;i<=$GLOBAL_N;i++))
67 do
68 R_TCP[$i]=0
69 R_UDP[$i]=0
70 done
71 elif [ "$key" = "X" ]
72 then
73 KNOWN=$(cut -d : -f 2 <<< $line)
74 echo $KNOWN
75 elif [ "$key" = "T" ]
76 then
77 PLUGIN=$(cut -d : -f 2 <<< $line)
78 echo $PLUGIN
79 elif [ "$key" = "K" ]
80 then
81 echo know node
82 extract_attributes $key $line
83 elif [ "$key" = "R" ]
84 then
85 echo router
86 extract_attributes $key $line
87 elif [ "$key" = "P" ]
88 then
89 echo node
90 extract_attributes $key $line
91 fi
92}
93
94read_topology_string(){
95 string=$1
96 IFS=' ' read -r -a array <<< $string
97 for element in "${array[@]}"
98 do
99 echo $element
100 parse_line $element
101 done
102}
103
104read_topology(){
105 local filename=$1
106 while read line; do
107 # reading each line
108 parse_line $line
109 done < $filename
110}
111
112
113
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b0035e712..ef74c2472 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -423,17 +423,13 @@ src/testing/gnunet-testing.c
423src/testing/list-keys.c 423src/testing/list-keys.c
424src/testing/testing.c 424src/testing/testing.c
425src/testing/testing_api_cmd_batch.c 425src/testing/testing_api_cmd_batch.c
426src/testing/testing_api_cmd_block_until_all_peers_started.c
427src/testing/testing_api_cmd_block_until_external_trigger.c 426src/testing/testing_api_cmd_block_until_external_trigger.c
428src/testing/testing_api_cmd_end.c 427src/testing/testing_api_cmd_end.c
429src/testing/testing_api_cmd_finish.c 428src/testing/testing_api_cmd_finish.c
430src/testing/testing_api_cmd_hello_world.c
431src/testing/testing_api_cmd_hello_world_birth.c
432src/testing/testing_api_cmd_local_test_finished.c 429src/testing/testing_api_cmd_local_test_finished.c
433src/testing/testing_api_cmd_local_test_prepared.c 430src/testing/testing_api_cmd_local_test_prepared.c
434src/testing/testing_api_cmd_netjail_start.c 431src/testing/testing_api_cmd_netjail_start.c
435src/testing/testing_api_cmd_netjail_start_testsystem.c 432src/testing/testing_api_cmd_netjail_start_testsystem.c
436src/testing/testing_api_cmd_netjail_start_testsystem_new.c
437src/testing/testing_api_cmd_netjail_stop.c 433src/testing/testing_api_cmd_netjail_stop.c
438src/testing/testing_api_cmd_netjail_stop_testsystem.c 434src/testing/testing_api_cmd_netjail_stop_testsystem.c
439src/testing/testing_api_cmd_send_peer_ready.c 435src/testing/testing_api_cmd_send_peer_ready.c
@@ -443,7 +439,6 @@ src/testing/testing_api_loop.c
443src/testing/testing_api_trait_cmd.c 439src/testing/testing_api_trait_cmd.c
444src/testing/testing_api_trait_process.c 440src/testing/testing_api_trait_process.c
445src/testing/testing_api_traits.c 441src/testing/testing_api_traits.c
446src/testing/testing_json_vnet.c
447src/topology/friends.c 442src/topology/friends.c
448src/topology/gnunet-daemon-topology.c 443src/topology/gnunet-daemon-topology.c
449src/transport/gnunet-communicator-tcp.c 444src/transport/gnunet-communicator-tcp.c
@@ -498,7 +493,6 @@ src/transport/transport_api_blacklist.c
498src/transport/transport_api_cmd_backchannel_check.c 493src/transport/transport_api_cmd_backchannel_check.c
499src/transport/transport_api_cmd_connecting_peers.c 494src/transport/transport_api_cmd_connecting_peers.c
500src/transport/transport_api_cmd_send_simple.c 495src/transport/transport_api_cmd_send_simple.c
501src/transport/transport_api_cmd_send_simple_v3.c
502src/transport/transport_api_cmd_start_peer.c 496src/transport/transport_api_cmd_start_peer.c
503src/transport/transport_api_cmd_stop_peer.c 497src/transport/transport_api_cmd_stop_peer.c
504src/transport/transport_api_core.c 498src/transport/transport_api_core.c
diff --git a/src/dhtu/test_dhtu_ip.c b/src/dhtu/test_dhtu_ip.c
index c9528053f..7913cfc35 100644
--- a/src/dhtu/test_dhtu_ip.c
+++ b/src/dhtu/test_dhtu_ip.c
@@ -24,7 +24,7 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_netjail_lib.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29 29
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
diff --git a/src/dhtu/testing_dhtu_cmd_send.c b/src/dhtu/testing_dhtu_cmd_send.c
index e620e329e..fe8e1c18a 100644
--- a/src/dhtu/testing_dhtu_cmd_send.c
+++ b/src/dhtu/testing_dhtu_cmd_send.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
28 29
29 30
30/** 31/**
diff --git a/src/include/Makefile.am b/src/include/Makefile.am
index 9c22b5977..e4b02b8ee 100644
--- a/src/include/Makefile.am
+++ b/src/include/Makefile.am
@@ -118,6 +118,7 @@ gnunetinclude_HEADERS = \
118 gnunet_testing_lib.h \ 118 gnunet_testing_lib.h \
119 gnunet_testing_plugin.h \ 119 gnunet_testing_plugin.h \
120 gnunet_testing_ng_lib.h \ 120 gnunet_testing_ng_lib.h \
121 gnunet_testing_netjail_lib.h \
121 gnunet_time_lib.h \ 122 gnunet_time_lib.h \
122 gnunet_transport_service.h \ 123 gnunet_transport_service.h \
123 gnunet_transport_application_service.h \ 124 gnunet_transport_application_service.h \
diff --git a/src/include/gnunet_testing_netjail_lib.h b/src/include/gnunet_testing_netjail_lib.h
new file mode 100644
index 000000000..3a5e9f749
--- /dev/null
+++ b/src/include/gnunet_testing_netjail_lib.h
@@ -0,0 +1,463 @@
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 * @brief API for writing an interpreter to test GNUnet components
23 * @author Christian Grothoff <christian@grothoff.org>
24 * @author Marcello Stanisci
25 * @author t3sserakt
26 */
27#ifndef GNUNET_TESTING_NG_LIB_H
28#define GNUNET_TESTING_NG_LIB_H
29
30#include "gnunet_util_lib.h"
31#include "gnunet_testing_plugin.h"
32#include "gnunet_testing_ng_lib.h"
33
34
35/**
36 * Router of a netjail subnet.
37 */
38struct GNUNET_TESTING_NetjailRouter
39{
40 /**
41 * Will tcp be forwarded?
42 */
43 unsigned int tcp_port;
44
45 /**
46 * Will udp be forwarded?
47 */
48 unsigned int udp_port;
49};
50
51
52/**
53 * Enum for the different types of nodes.
54 */
55enum GNUNET_TESTING_NODE_TYPE
56{
57 /**
58 * Node in a subnet.
59 */
60 GNUNET_TESTING_SUBNET_NODE,
61
62 /**
63 * Global known node.
64 */
65 GNUNET_TESTING_GLOBAL_NODE
66};
67
68/**
69 * Protocol address prefix für a connection between nodes.
70 */
71struct GNUNET_TESTING_AddressPrefix
72{
73 /**
74 * Pointer to the previous prefix in the DLL.
75 */
76 struct GNUNET_TESTING_AddressPrefix *prev;
77
78 /**
79 * Pointer to the next prefix in the DLL.
80 */
81 struct GNUNET_TESTING_AddressPrefix *next;
82
83 /**
84 * The address prefix.
85 */
86 char *address_prefix;
87};
88
89
90/**
91 * Node in a netjail topology.
92 */
93struct GNUNET_TESTING_NetjailNode;
94
95/**
96 * Connection to another node.
97 */
98struct GNUNET_TESTING_NodeConnection
99{
100 /**
101 * Pointer to the previous connection in the DLL.
102 */
103 struct GNUNET_TESTING_NodeConnection *prev;
104
105 /**
106 * Pointer to the next connection in the DLL.
107 */
108 struct GNUNET_TESTING_NodeConnection *next;
109
110 /**
111 * The number of the subnet of the node this connection points to. This is 0,
112 * if the node is a global known node.
113 */
114 unsigned int namespace_n;
115
116 /**
117 * The number of the node this connection points to.
118 */
119 unsigned int node_n;
120
121 /**
122 * The type of the node this connection points to.
123 */
124 enum GNUNET_TESTING_NODE_TYPE node_type;
125
126 /**
127 * The node which establish the connection
128 */
129 struct GNUNET_TESTING_NetjailNode *node;
130
131 /**
132 * Head of the DLL with the address prefixes for the protocolls this node is reachable.
133 */
134 struct GNUNET_TESTING_AddressPrefix *address_prefixes_head;
135
136 /**
137 * Tail of the DLL with the address prefixes for the protocolls this node is reachable.
138 */
139 struct GNUNET_TESTING_AddressPrefix *address_prefixes_tail;
140};
141
142/**
143 * Node in the netjail topology.
144 */
145struct GNUNET_TESTING_NetjailNode
146{
147 /**
148 * Plugin for the test case to be run on this node.
149 */
150 char *plugin;
151
152 /**
153 * Flag indicating if this node is a global known node.
154 */
155 unsigned int is_global;
156
157 /**
158 * The number of the subnet this node is running in.
159 */
160 unsigned int namespace_n;
161
162 /**
163 * The number of this node in the subnet.
164 */
165 unsigned int node_n;
166
167 /**
168 * Head of the DLL with the connections which shall be established to other nodes.
169 */
170 struct GNUNET_TESTING_NodeConnection *node_connections_head;
171
172 /**
173 * Tail of the DLL with the connections which shall be established to other nodes.
174 */
175 struct GNUNET_TESTING_NodeConnection *node_connections_tail;
176};
177
178
179/**
180 * Subnet in a topology.
181 */
182struct GNUNET_TESTING_NetjailNamespace
183{
184 /**
185 * The number of the subnet.
186 */
187 unsigned int namespace_n;
188
189 /**
190 * Router of the subnet.
191 */
192 struct GNUNET_TESTING_NetjailRouter *router;
193
194 /**
195 * Hash map containing the nodes in this subnet.
196 */
197 struct GNUNET_CONTAINER_MultiShortmap *nodes;
198};
199
200/**
201 * Toplogy of our netjail setup.
202 */
203struct GNUNET_TESTING_NetjailTopology
204{
205
206 /**
207 * Default plugin for the test case to be run on nodes.
208 */
209 char *plugin;
210
211 /**
212 * Number of subnets.
213 */
214 unsigned int namespaces_n;
215
216 /**
217 * Number of nodes per subnet.
218 */
219 unsigned int nodes_m;
220
221 /**
222 * Number of global known nodes.
223 */
224 unsigned int nodes_x;
225
226 /**
227 * Hash map containing the subnets (for natted nodes) of the topology.
228 */
229 struct GNUNET_CONTAINER_MultiShortmap *map_namespaces;
230
231 /**
232 * Hash map containing the global known nodes which are not natted.
233 */
234 struct GNUNET_CONTAINER_MultiShortmap *map_globals;
235};
236
237/**
238 * Getting the topology from file.
239 *
240 * @param filename The name of the topology file.
241 * @return The GNUNET_TESTING_NetjailTopology
242 */
243struct GNUNET_TESTING_NetjailTopology *
244GNUNET_TESTING_get_topo_from_file (const char *filename);
245
246
247/**
248 * Parse the topology data.
249 *
250 * @param data The topology data.
251 * @return The GNUNET_TESTING_NetjailTopology
252 */
253struct GNUNET_TESTING_NetjailTopology *
254GNUNET_TESTING_get_topo_from_string (char *data);
255
256
257/**
258 * Get the connections to other nodes for a specific node.
259 *
260 * @param num The specific node we want the connections for.
261 * @param topology The topology we get the connections from.
262 * @return The connections of the node.
263 */
264struct GNUNET_TESTING_NodeConnection *
265GNUNET_TESTING_get_connections (unsigned int num, struct
266 GNUNET_TESTING_NetjailTopology *topology);
267
268
269/**
270 * Get the address for a specific communicator from a connection.
271 *
272 * @param connection The connection we like to have the address from.
273 * @param prefix The communicator protocol prefix.
274 * @return The address of the communicator.
275 */
276char *
277GNUNET_TESTING_get_address (struct GNUNET_TESTING_NodeConnection *connection,
278 char *prefix);
279
280
281/**
282 * Deallocate memory of the struct GNUNET_TESTING_NetjailTopology.
283 *
284 * @param topology The GNUNET_TESTING_NetjailTopology to be deallocated.
285 */
286void
287GNUNET_TESTING_free_topology (struct GNUNET_TESTING_NetjailTopology *topology);
288
289
290/**
291 * Calculate the unique id identifying a node from a given connction.
292 *
293 * @param node_connection The connection we calculate the id from.
294 * @param topology The topology we get all needed information from.
295 * @return The unique id of the node from the connection.
296 */
297unsigned int
298GNUNET_TESTING_calculate_num (struct
299 GNUNET_TESTING_NodeConnection *node_connection,
300 struct GNUNET_TESTING_NetjailTopology *topology);
301
302
303/**
304 * Struct to hold information for callbacks.
305 *
306 */
307struct LocalPreparedState
308{
309 /**
310 * Context for our asynchronous completion.
311 */
312 struct GNUNET_TESTING_AsyncContext *ac;
313
314 /**
315 * Callback to write messages to the master loop.
316 *
317 */
318 TESTING_CMD_HELPER_write_cb write_message;
319};
320
321
322/**
323 * Create command.
324 *
325 * @param label name for command.
326 * @param topology_config Configuration file for the test topology.
327 * @return command.
328 */
329struct GNUNET_TESTING_Command
330GNUNET_TESTING_cmd_netjail_start (const char *label,
331 char *topology_config,
332 unsigned int *read_file);
333
334
335/**
336 * Create command.
337 *
338 * @param label Name for the command.
339 * @param topology The complete topology information.
340 * @return command.
341 */
342struct GNUNET_TESTING_Command
343GNUNET_TESTING_cmd_netjail_start_testing_system (
344 const char *label,
345 struct GNUNET_TESTING_NetjailTopology *topology);
346
347
348/**
349 * Create command.
350 *
351 * @param label name for command.
352 * @param topology_config Configuration file for the test topology.
353 * @return command.
354 */
355struct GNUNET_TESTING_Command
356GNUNET_TESTING_cmd_netjail_stop (const char *label,
357 char *topology_config,
358 unsigned int *read_file);
359
360
361/**
362 * Create command.
363 *
364 * @param label name for command.
365 * @param helper_start_label label of the cmd to start the test system.
366 * @param topology The complete topology information.
367 * @return command.
368 */
369struct GNUNET_TESTING_Command
370GNUNET_TESTING_cmd_stop_testing_system (
371 const char *label,
372 const char *helper_start_label,
373 struct GNUNET_TESTING_NetjailTopology *topology);
374
375
376/**
377 * Create a GNUNET_CMDS_LOCAL_FINISHED message.
378 *
379 * @param rv The result of the local test as GNUNET_GenericReturnValue.
380 * @return The GNUNET_CMDS_LOCAL_FINISHED message.
381*/
382struct GNUNET_MessageHeader *
383GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv);
384
385
386/**
387 * Function to get the trait with the async context.
388 *
389 * @param[out] ac GNUNET_TESTING_AsyncContext.
390 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
391 */
392int
393GNUNET_TESTING_get_trait_async_context (
394 const struct GNUNET_TESTING_Command *cmd,
395 struct GNUNET_TESTING_AsyncContext **ac);
396
397
398/**
399 * Offer handles to testing cmd helper from trait
400 *
401 * @param cmd command to extract the message from.
402 * @param pt pointer to message.
403 * @return #GNUNET_OK on success.
404 */
405enum GNUNET_GenericReturnValue
406GNUNET_TESTING_get_trait_helper_handles (
407 const struct GNUNET_TESTING_Command *cmd,
408 struct GNUNET_HELPER_Handle ***helper);
409
410
411struct GNUNET_TESTING_Command
412GNUNET_TESTING_cmd_block_until_all_peers_started (
413 const char *label,
414 unsigned int *all_peers_started);
415
416
417struct GNUNET_TESTING_Command
418GNUNET_TESTING_cmd_block_until_external_trigger (
419 const char *label);
420
421struct GNUNET_TESTING_Command
422GNUNET_TESTING_cmd_send_peer_ready (const char *label,
423 TESTING_CMD_HELPER_write_cb write_message);
424
425
426/**
427 * Create command.
428 *
429 * @param label name for command.
430 * @param write_message Callback to write messages to the master loop.
431 * @return command.
432 */
433struct GNUNET_TESTING_Command
434GNUNET_TESTING_cmd_local_test_finished (
435 const char *label,
436 TESTING_CMD_HELPER_write_cb write_message);
437
438/**
439 * Create command.
440 *
441 * @param label name for command.
442 * @param write_message Callback to write messages to the master loop.
443 * @param all_local_tests_prepared Flag which will be set from outside.
444 * @return command.
445 */
446struct GNUNET_TESTING_Command
447GNUNET_TESTING_cmd_local_test_prepared (const char *label,
448 TESTING_CMD_HELPER_write_cb
449 write_message);
450
451/**
452 * Function to get the trait with the struct LocalPreparedState.
453 *
454 * @param[out] lfs struct LocalPreparedState.
455 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
456 *
457 */
458enum GNUNET_GenericReturnValue
459GNUNET_TESTING_get_trait_local_prepared_state (
460 const struct GNUNET_TESTING_Command *cmd,
461 struct LocalPreparedState **lfs);
462
463#endif
diff --git a/src/include/gnunet_testing_ng_lib.h b/src/include/gnunet_testing_ng_lib.h
index 7ce73baef..2d040ac21 100644
--- a/src/include/gnunet_testing_ng_lib.h
+++ b/src/include/gnunet_testing_ng_lib.h
@@ -657,6 +657,16 @@ GNUNET_TESTING_get_topo_from_file (const char *filename);
657 657
658 658
659/** 659/**
660 * Parse the topology data.
661 *
662 * @param data The topology data.
663 * @return The GNUNET_TESTING_NetjailTopology
664 */
665struct GNUNET_TESTING_NetjailTopology *
666GNUNET_TESTING_get_topo_from_string (char *data);
667
668
669/**
660 * Get the connections to other nodes for a specific node. 670 * Get the connections to other nodes for a specific node.
661 * 671 *
662 * @param num The specific node we want the connections for. 672 * @param num The specific node we want the connections for.
@@ -1073,28 +1083,6 @@ struct LocalPreparedState
1073 TESTING_CMD_HELPER_write_cb write_message; 1083 TESTING_CMD_HELPER_write_cb write_message;
1074}; 1084};
1075 1085
1076/**
1077 * Create command.
1078 *
1079 * @param label name for command.
1080 * @param now when the command was started.
1081 * @return command.
1082 */
1083struct GNUNET_TESTING_Command
1084GNUNET_TESTING_cmd_hello_world_birth (const char *label,
1085 struct GNUNET_TIME_Absolute *now);
1086
1087/**
1088 * Create command.
1089 *
1090 * @param label name for command.
1091 * @param message initial message.
1092 * @return command.
1093 */
1094struct GNUNET_TESTING_Command
1095GNUNET_TESTING_cmd_hello_world (const char *label,
1096 const char *birthLabel,
1097 char *message);
1098 1086
1099/** 1087/**
1100 * Offer data from trait 1088 * Offer data from trait
@@ -1135,20 +1123,25 @@ GNUNET_TESTING_cmd_system_destroy (const char *label,
1135 */ 1123 */
1136struct GNUNET_TESTING_Command 1124struct GNUNET_TESTING_Command
1137GNUNET_TESTING_cmd_netjail_start (const char *label, 1125GNUNET_TESTING_cmd_netjail_start (const char *label,
1138 char *topology_config); 1126 char *topology_config,
1127 unsigned int *read_file);
1139 1128
1140 1129
1141/** 1130/**
1142 * Create command. 1131 * Create command.
1143 * 1132 *
1144 * @param label Name for the command. 1133 * @param label Name for the command.
1145 * @param topology_config Configuration file for the test topology. 1134 * @param topology The complete topology information.
1146 * @param rv Pointer to the return value of the test. 1135 * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
1136 * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
1147 * @return command. 1137 * @return command.
1148 */ 1138 */
1149struct GNUNET_TESTING_Command 1139struct GNUNET_TESTING_Command
1150GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, 1140GNUNET_TESTING_cmd_netjail_start_testing_system (
1151 const char *topology_config); 1141 const char *label,
1142 struct GNUNET_TESTING_NetjailTopology *topology,
1143 unsigned int *read_file,
1144 char *topology_data);
1152 1145
1153 1146
1154/** 1147/**
@@ -1160,20 +1153,23 @@ GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label,
1160 */ 1153 */
1161struct GNUNET_TESTING_Command 1154struct GNUNET_TESTING_Command
1162GNUNET_TESTING_cmd_netjail_stop (const char *label, 1155GNUNET_TESTING_cmd_netjail_stop (const char *label,
1163 char *topology_config); 1156 char *topology_config,
1157 unsigned int *read_file);
1164 1158
1165 1159
1166/** 1160/**
1167 * Create command. 1161 * Create command.
1168 * 1162 *
1169 * @param label name for command. 1163 * @param label name for command.
1170 * @param topology_config Configuration file for the test topology. 1164 * @param helper_start_label label of the cmd to start the test system.
1165 * @param topology The complete topology information.
1171 * @return command. 1166 * @return command.
1172 */ 1167 */
1173struct GNUNET_TESTING_Command 1168struct GNUNET_TESTING_Command
1174GNUNET_TESTING_cmd_stop_testing_system (const char *label, 1169GNUNET_TESTING_cmd_stop_testing_system (
1175 const char *helper_start_label, 1170 const char *label,
1176 const char *topology_config); 1171 const char *helper_start_label,
1172 struct GNUNET_TESTING_NetjailTopology *topology);
1177 1173
1178 1174
1179/** 1175/**
diff --git a/src/include/gnunet_testing_plugin.h b/src/include/gnunet_testing_plugin.h
index 4a6a9368e..b59d2cea1 100644
--- a/src/include/gnunet_testing_plugin.h
+++ b/src/include/gnunet_testing_plugin.h
@@ -46,7 +46,9 @@ typedef void
46 char *node_ip, 46 char *node_ip,
47 char *n, 47 char *n,
48 char *m, 48 char *m,
49 char *local_m); 49 char *local_m,
50 char *topology_data,
51 unsigned int *read_file);
50 52
51 53
52typedef void 54typedef void
diff --git a/src/testing/Makefile.am b/src/testing/Makefile.am
index 3daa29e1e..a9a1b5a02 100644
--- a/src/testing/Makefile.am
+++ b/src/testing/Makefile.am
@@ -18,9 +18,6 @@ libexec_PROGRAMS = \
18 18
19plugindir = $(libdir)/gnunet 19plugindir = $(libdir)/gnunet
20 20
21plugin_LTLIBRARIES = \
22 libgnunet_test_testing_plugin_testcmd.la
23
24lib_LTLIBRARIES = \ 21lib_LTLIBRARIES = \
25 libgnunettesting.la 22 libgnunettesting.la
26 23
@@ -31,25 +28,12 @@ gnunet_cmds_helper_LDADD = $(XLIB) \
31 libgnunettesting.la \ 28 libgnunettesting.la \
32 $(LTLIBINTL) $(Z_LIBS) 29 $(LTLIBINTL) $(Z_LIBS)
33 30
34libgnunet_test_testing_plugin_testcmd_la_SOURCES = \
35 test_testing_plugin_testcmd.c
36libgnunet_test_testing_plugin_testcmd_la_LIBADD = \
37 $(top_builddir)/src/util/libgnunetutil.la \
38 $(top_builddir)/src/arm/libgnunetarm.la \
39 libgnunettesting.la \
40 $(top_builddir)/src/statistics/libgnunetstatistics.la \
41 $(LTLIBINTL)
42libgnunet_test_testing_plugin_testcmd_la_LDFLAGS = \
43 $(GN_PLUGIN_LDFLAGS)
44
45
46libgnunettesting_la_SOURCES = \ 31libgnunettesting_la_SOURCES = \
47 testing_api_cmd_end.c \ 32 testing_api_cmd_end.c \
48 testing_api_cmd_finish.c \ 33 testing_api_cmd_finish.c \
49 testing_api_cmd_local_test_finished.c \ 34 testing_api_cmd_local_test_finished.c \
50 testing_api_cmd_local_test_prepared.c \ 35 testing_api_cmd_local_test_prepared.c \
51 testing_api_cmd_send_peer_ready.c \ 36 testing_api_cmd_send_peer_ready.c \
52 testing_api_cmd_block_until_all_peers_started.c \
53 testing_api_cmd_block_until_external_trigger.c \ 37 testing_api_cmd_block_until_external_trigger.c \
54 testing_api_cmd_netjail_start.c \ 38 testing_api_cmd_netjail_start.c \
55 testing_api_cmd_netjail_start_testsystem.c \ 39 testing_api_cmd_netjail_start_testsystem.c \
@@ -59,8 +43,6 @@ libgnunettesting_la_SOURCES = \
59 testing_api_cmd_system_create.c \ 43 testing_api_cmd_system_create.c \
60 testing_api_cmd_system_destroy.c \ 44 testing_api_cmd_system_destroy.c \
61 testing_api_cmd_batch.c \ 45 testing_api_cmd_batch.c \
62 testing_api_cmd_hello_world.c \
63 testing_api_cmd_hello_world_birth.c \
64 testing_api_loop.c \ 46 testing_api_loop.c \
65 testing_api_trait_cmd.c \ 47 testing_api_trait_cmd.c \
66 testing_api_trait_process.c \ 48 testing_api_trait_process.c \
@@ -94,8 +76,6 @@ list_keys_LDADD = \
94 76
95 77
96check_PROGRAMS = \ 78check_PROGRAMS = \
97 test_testing_api_cmd_netjail \
98 test_testing_hello_world \
99 test_testing_portreservation \ 79 test_testing_portreservation \
100 test_testing_servicestartup \ 80 test_testing_servicestartup \
101 test_testing_peerstartup \ 81 test_testing_peerstartup \
@@ -105,32 +85,12 @@ check_PROGRAMS = \
105if ENABLE_TEST_RUN 85if ENABLE_TEST_RUN
106AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 86AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
107TESTS = \ 87TESTS = \
108 test_testing_api_cmd_netjail \
109 test_testing_hello_world \
110 test_testing_portreservation \ 88 test_testing_portreservation \
111 test_testing_peerstartup \ 89 test_testing_peerstartup \
112 test_testing_peerstartup2 \ 90 test_testing_peerstartup2 \
113 test_testing_servicestartup 91 test_testing_servicestartup
114endif 92endif
115 93
116#test_testing_topology_SOURCES = \
117# test_testing_topology.c
118#test_testing_topology_LDADD = \
119# libgnunettesting.la \
120# $(top_builddir)/src/util/libgnunetutil.la
121
122test_testing_api_cmd_netjail_SOURCES = \
123 test_testing_api_cmd_netjail.c
124test_testing_api_cmd_netjail_LDADD = \
125 libgnunettesting.la \
126 $(top_builddir)/src/util/libgnunetutil.la
127
128test_testing_hello_world_SOURCES = \
129 test_testing_hello_world.c
130test_testing_hello_world_LDADD = \
131 libgnunettesting.la \
132 $(top_builddir)/src/util/libgnunetutil.la
133
134test_testing_portreservation_SOURCES = \ 94test_testing_portreservation_SOURCES = \
135 test_testing_portreservation.c 95 test_testing_portreservation.c
136test_testing_portreservation_LDADD = \ 96test_testing_portreservation_LDADD = \
diff --git a/src/testing/gnunet-cmds-helper.c b/src/testing/gnunet-cmds-helper.c
index 4aeccb115..f90cc3cc4 100644
--- a/src/testing/gnunet-cmds-helper.c
+++ b/src/testing/gnunet-cmds-helper.c
@@ -142,6 +142,16 @@ struct NodeIdentifier
142 * 142 *
143 */ 143 */
144 char *local_m; 144 char *local_m;
145
146 /**
147 * Shall we read the topology from file, or from a string.
148 */
149 unsigned int *read_file;
150
151 /**
152 * String with topology data or name of topology file.
153 */
154 char *topology_data;
145}; 155};
146 156
147/** 157/**
@@ -402,7 +412,8 @@ tokenizer_cb (void *cls, const struct GNUNET_MessageHeader *message)
402 strcat (node_ip, plugin->m); 412 strcat (node_ip, plugin->m);
403 413
404 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m, 414 plugin->api->start_testcase (&write_message, router_ip, node_ip, plugin->m,
405 plugin->n, plugin->local_m); 415 plugin->n, plugin->local_m, ni->topology_data,
416 ni->read_file);
406 417
407 GNUNET_free (binary); 418 GNUNET_free (binary);
408 419
@@ -559,6 +570,10 @@ main (int argc, char **argv)
559 struct GNUNET_GETOPT_CommandLineOption options[] = 570 struct GNUNET_GETOPT_CommandLineOption options[] =
560 { GNUNET_GETOPT_OPTION_END }; 571 { GNUNET_GETOPT_OPTION_END };
561 int ret; 572 int ret;
573 int i;
574 size_t topology_data_length = 0;
575 unsigned int read_file;
576 char cr[1] = "\n";
562 577
563 GNUNET_log_setup ("gnunet-cmds-helper", 578 GNUNET_log_setup ("gnunet-cmds-helper",
564 "DEBUG", 579 "DEBUG",
@@ -569,6 +584,30 @@ main (int argc, char **argv)
569 ni->m = argv[3]; 584 ni->m = argv[3];
570 ni->n = argv[4]; 585 ni->n = argv[4];
571 586
587 sscanf (argv[5], "%u", &read_file);
588
589 if (1 == read_file)
590 ni->topology_data = argv[6];
591 else
592 {
593 for (i = 6; i<argc; i++)
594 topology_data_length += strlen (argv[i]) + 1;
595 LOG (GNUNET_ERROR_TYPE_DEBUG,
596 "topo data length %lu\n",
597 topology_data_length);
598 ni->topology_data = GNUNET_malloc (topology_data_length);
599 for (i = 6; i<argc; i++)
600 {
601 strcat (ni->topology_data, argv[i]);
602 strcat (ni->topology_data, cr);
603 }
604 }
605 ni->read_file = &read_file;
606 ni->topology_data[topology_data_length - 1] = '\0';
607 LOG (GNUNET_ERROR_TYPE_DEBUG,
608 "topo data %s\n",
609 ni->topology_data);
610
572 status = GNUNET_OK; 611 status = GNUNET_OK;
573 if (NULL == 612 if (NULL ==
574 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE))) 613 (sigpipe = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE)))
diff --git a/src/testing/test_testing_api_cmd_netjail.c b/src/testing/test_testing_api_cmd_netjail.c
deleted file mode 100644
index aeddfb7c9..000000000
--- a/src/testing/test_testing_api_cmd_netjail.c
+++ /dev/null
@@ -1,87 +0,0 @@
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/test_testbed_api_cmd_netjail.c
23 * @brief Test case executing a script in a network name space.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30
31/**
32 * Return value of the test.
33 *
34 */
35static unsigned int rv = 0;
36
37
38/**
39 * Main function to run the test cases.
40 *
41 * @param cls not used.
42 *
43 */
44static void
45run (void *cls)
46{
47 struct GNUNET_TESTING_Command commands[] = {
48 GNUNET_TESTING_cmd_netjail_start ("netjail-start-1",
49 "2",
50 "2"),
51 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed-1",
52 "2",
53 "2",
54 "libgnunet_plugin_testcmd",
55 &rv),
56 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
57 "netjail-start-testbed-1",
58 "2",
59 "2"),
60 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop-1",
61 "2",
62 "2"),
63 GNUNET_TESTING_cmd_end ()
64 };
65
66 GNUNET_TESTING_run (NULL,
67 commands,
68 GNUNET_TIME_UNIT_FOREVER_REL);
69}
70
71
72int
73main (int argc,
74 char *const *argv)
75{
76 int rv = 0;
77
78 GNUNET_log_setup ("test-netjail",
79 "DEBUG",
80 NULL);
81 GNUNET_SCHEDULER_run (&run,
82 NULL);
83
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "Test finished!\n");
86 return rv;
87}
diff --git a/src/testing/test_testing_hello_world.c b/src/testing/test_testing_hello_world.c
deleted file mode 100644
index 6300e26a4..000000000
--- a/src/testing/test_testing_hello_world.c
+++ /dev/null
@@ -1,68 +0,0 @@
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/test_testing_hello_world.c
23 * @brief hello world test case
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29
30/**
31 * Main function to run the test cases.
32 *
33 * @param cls not used.
34 *
35 */
36static void
37run (void *cls)
38{
39 (void *) cls;
40 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
41
42 struct GNUNET_TESTING_Command commands[] = {
43 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
44 &now),
45 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
46 GNUNET_TESTING_cmd_end ()
47 };
48
49 GNUNET_TESTING_run (NULL,
50 commands,
51 GNUNET_TIME_UNIT_FOREVER_REL);
52}
53
54int
55main (int argc,
56 char *const *argv)
57{
58 int rv = 0;
59
60 GNUNET_log_setup ("test-hello-world",
61 "DEBUG",
62 NULL);
63
64 GNUNET_SCHEDULER_run (&run,
65 NULL);
66
67 return rv;
68}
diff --git a/src/testing/test_testing_plugin_testcmd.c b/src/testing/test_testing_plugin_testcmd.c
deleted file mode 100644
index 32e2b38a7..000000000
--- a/src/testing/test_testing_plugin_testcmd.c
+++ /dev/null
@@ -1,123 +0,0 @@
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 * @file testbed/plugin_testcmd.c
22 * @brief a plugin to provide the API for running test cases.
23 * @author t3sserakt
24 *
25 * // FIXME: too verbose, no logic to return final status, will segv!
26 */
27#include "platform.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_testing_ng_lib.h"
31
32/**
33 * Generic logging shortcut
34 */
35#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
36
37
38// FIXME: bad global!
39unsigned int are_all_peers_started;
40
41
42static void
43all_peers_started ()
44{
45 are_all_peers_started = GNUNET_YES;
46 LOG (GNUNET_ERROR_TYPE_ERROR,
47 "setting are_all_peers_started: %d\n",
48 are_all_peers_started);
49}
50
51
52static void
53start_testcase (TESTING_CMD_HELPER_write_cb write_message,
54 char *router_ip,
55 char *node_ip,
56 char *n,
57 char *m,
58 char *local_m)
59{
60 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
61
62 LOG (GNUNET_ERROR_TYPE_ERROR,
63 "We got here 6!\n");
64
65 are_all_peers_started = GNUNET_NO;
66
67 struct GNUNET_TESTING_Command commands[] = {
68 GNUNET_TESTING_cmd_hello_world_birth ("hello-world-birth-0",
69 &now),
70 GNUNET_TESTING_cmd_hello_world ("hello-world-0","hello-world-birth-0",""),
71 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
72 write_message),
73 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
74 &are_all_peers_started),
75 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
76 write_message)
77 };
78
79 GNUNET_TESTING_run (commands,
80 GNUNET_TIME_UNIT_FOREVER_REL,
81 NULL, /* FIXME: pass continuation! */
82 NULL);
83 LOG (GNUNET_ERROR_TYPE_ERROR,
84 "We got here 7!\n");
85
86}
87
88
89/**
90 * Entry point for the plugin.
91 *
92 * @param cls NULL
93 * @return the exported block API
94 */
95void *
96libgnunet_plugin_testcmd_init (void *cls)
97{
98 struct GNUNET_TESTING_PluginFunctions *api;
99
100 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
101 api->start_testcase = &start_testcase;
102 api->all_peers_started = &all_peers_started;
103 return api;
104}
105
106
107/**
108 * Exit point from the plugin.
109 *
110 * @param cls the return value from #libgnunet_plugin_block_test_init
111 * @return NULL
112 */
113void *
114libgnunet_plugin_testcmd_done (void *cls)
115{
116 struct GNUNET_TESTING_PluginFunctions *api = cls;
117
118 GNUNET_free (api);
119 return NULL;
120}
121
122
123
diff --git a/src/testing/test_testing_topology.c b/src/testing/test_testing_topology.c
deleted file mode 100644
index cfc91e609..000000000
--- a/src/testing/test_testing_topology.c
+++ /dev/null
@@ -1,44 +0,0 @@
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_testcmd.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
31
32int
33main (int argc,
34 char *const *argv)
35{
36 GNUNET_log_setup ("test-topology",
37 "DEBUG",
38 NULL);
39 LOG (GNUNET_ERROR_TYPE_DEBUG,
40 "Test\n");
41 GNUNET_TESTING_get_topo_from_file ("topo.conf");
42 LOG (GNUNET_ERROR_TYPE_DEBUG,
43 "Test2\n");
44}
diff --git a/src/testing/testing.c b/src/testing/testing.c
index 02cedc744..4ccf93c6b 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -33,7 +33,7 @@
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#include "gnunet_testing_netjail_lib.h"
37#include "testing_cmds.h" 37#include "testing_cmds.h"
38 38
39#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__) 39#define LOG(kind, ...) GNUNET_log_from (kind, "testing-api", __VA_ARGS__)
@@ -2102,6 +2102,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2102 struct GNUNET_HashCode hc; 2102 struct GNUNET_HashCode hc;
2103 struct GNUNET_TESTING_NetjailNamespace *namespace; 2103 struct GNUNET_TESTING_NetjailNamespace *namespace;
2104 unsigned int namespace_n, node_m; 2104 unsigned int namespace_n, node_m;
2105 struct GNUNET_TESTING_NodeConnection *node_connections = NULL;
2105 2106
2106 LOG (GNUNET_ERROR_TYPE_DEBUG, 2107 LOG (GNUNET_ERROR_TYPE_DEBUG,
2107 "gaga 1\n"); 2108 "gaga 1\n");
@@ -2121,6 +2122,7 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2121 sizeof (*hkey)); 2122 sizeof (*hkey));
2122 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals, 2123 node = GNUNET_CONTAINER_multishortmap_get (topology->map_globals,
2123 hkey); 2124 hkey);
2125 node_connections = node->node_connections_head;
2124 } 2126 }
2125 else 2127 else
2126 { 2128 {
@@ -2147,10 +2149,11 @@ GNUNET_TESTING_get_connections (unsigned int num, struct
2147 sizeof (*hkey)); 2149 sizeof (*hkey));
2148 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes, 2150 node = GNUNET_CONTAINER_multishortmap_get (namespace->nodes,
2149 hkey); 2151 hkey);
2152 node_connections = node->node_connections_head;
2150 } 2153 }
2151 2154
2152 GNUNET_free (hkey); 2155 GNUNET_free (hkey);
2153 return node->node_connections_head; 2156 return node_connections;
2154} 2157}
2155 2158
2156 2159
@@ -2355,16 +2358,14 @@ GNUNET_TESTING_send_local_test_finished_msg (enum GNUNET_GenericReturnValue rv)
2355 2358
2356 2359
2357/** 2360/**
2358 * Getting the topology from file. 2361 * Parse the topology data.
2359 * 2362 *
2360 * @param filename The name of the topology file. 2363 * @param data The topology data.
2361 * @return The GNUNET_TESTING_NetjailTopology 2364 * @return The GNUNET_TESTING_NetjailTopology
2362 */ 2365 */
2363struct GNUNET_TESTING_NetjailTopology * 2366struct GNUNET_TESTING_NetjailTopology *
2364GNUNET_TESTING_get_topo_from_file (const char *filename) 2367GNUNET_TESTING_get_topo_from_string (char *data)
2365{ 2368{
2366 uint64_t fs;
2367 char *data;
2368 char *token; 2369 char *token;
2369 char *key = NULL; 2370 char *key = NULL;
2370 unsigned int out; 2371 unsigned int out;
@@ -2379,36 +2380,9 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2379 struct GNUNET_ShortHashCode *hkey; 2380 struct GNUNET_ShortHashCode *hkey;
2380 struct GNUNET_HashCode hc; 2381 struct GNUNET_HashCode hc;
2381 2382
2382 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
2383 {
2384 LOG (GNUNET_ERROR_TYPE_ERROR,
2385 _ ("Topology file %s not found\n"),
2386 filename);
2387 return NULL;
2388 }
2389 if (GNUNET_OK !=
2390 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
2391 {
2392 LOG (GNUNET_ERROR_TYPE_ERROR,
2393 _ ("Topology file %s has no data\n"),
2394 filename);
2395 return NULL;
2396 }
2397 data = GNUNET_malloc (fs);
2398 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2399 {
2400 LOG (GNUNET_ERROR_TYPE_ERROR,
2401 _ ("Topology file %s cannot be read\n"),
2402 filename);
2403 GNUNET_free (data);
2404 return NULL;
2405 }
2406
2407 LOG (GNUNET_ERROR_TYPE_DEBUG, 2383 LOG (GNUNET_ERROR_TYPE_DEBUG,
2408 "data: %s\n", 2384 "data %s\n",
2409 data); 2385 data);
2410
2411 data[fs] = '\0';
2412 token = strtok_r (data, "\n", &rest); 2386 token = strtok_r (data, "\n", &rest);
2413 topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology); 2387 topo = GNUNET_new (struct GNUNET_TESTING_NetjailTopology);
2414 topo->map_namespaces = 2388 topo->map_namespaces =
@@ -2626,7 +2600,62 @@ GNUNET_TESTING_get_topo_from_file (const char *filename)
2626 node_connections (token, node); 2600 node_connections (token, node);
2627 } 2601 }
2628 token = strtok_r (NULL, "\n", &rest); 2602 token = strtok_r (NULL, "\n", &rest);
2603 if (NULL != token)
2604 LOG (GNUNET_ERROR_TYPE_ERROR,
2605 "Next token %s\n",
2606 token);
2607 }
2608
2609 return topo;
2610}
2611
2612
2613/**
2614 * Getting the topology from file.
2615 *
2616 * @param filename The name of the topology file.
2617 * @return The GNUNET_TESTING_NetjailTopology
2618 */
2619struct GNUNET_TESTING_NetjailTopology *
2620GNUNET_TESTING_get_topo_from_file (const char *filename)
2621{
2622 uint64_t fs;
2623 char *data;
2624 struct GNUNET_TESTING_NetjailTopology *topo;
2625
2626 if (GNUNET_YES != GNUNET_DISK_file_test (filename))
2627 {
2628 LOG (GNUNET_ERROR_TYPE_ERROR,
2629 _ ("Topology file %s not found\n"),
2630 filename);
2631 return NULL;
2632 }
2633 if (GNUNET_OK !=
2634 GNUNET_DISK_file_size (filename, &fs, GNUNET_YES, GNUNET_YES))
2635 {
2636 LOG (GNUNET_ERROR_TYPE_ERROR,
2637 _ ("Topology file %s has no data\n"),
2638 filename);
2639 return NULL;
2629 } 2640 }
2641 data = GNUNET_malloc (fs);
2642 if (fs != GNUNET_DISK_fn_read (filename, data, fs))
2643 {
2644 LOG (GNUNET_ERROR_TYPE_ERROR,
2645 _ ("Topology file %s cannot be read\n"),
2646 filename);
2647 GNUNET_free (data);
2648 return NULL;
2649 }
2650
2651 LOG (GNUNET_ERROR_TYPE_DEBUG,
2652 "data: %s\n",
2653 data);
2654
2655 data[fs] = '\0';
2656
2657 topo = GNUNET_TESTING_get_topo_from_string (data);
2658
2630 GNUNET_free (data); 2659 GNUNET_free (data);
2631 2660
2632 return topo; 2661 return topo;
diff --git a/src/testing/testing_api_cmd_block_until_all_peers_started.c b/src/testing/testing_api_cmd_block_until_all_peers_started.c
deleted file mode 100644
index 763713e15..000000000
--- a/src/testing/testing_api_cmd_block_until_all_peers_started.c
+++ /dev/null
@@ -1,107 +0,0 @@
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_block_until_all_peers_started.c
23 * @brief cmd to block the interpreter loop until all peers started.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30/**
31 * Generic logging shortcut
32 */
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
34
35/**
36 * Struct with information for callbacks.
37 *
38 */
39struct BlockState
40{
41 /**
42 * Context for our asynchronous completion.
43 */
44 struct GNUNET_TESTING_AsyncContext ac;
45
46 /**
47 * Flag to indicate if all peers have started.
48 *
49 */
50 unsigned int *all_peers_started;
51};
52
53
54/**
55 * The cleanup function of this cmd frees resources the cmd allocated.
56 *
57 */
58static void
59block_until_all_peers_started_cleanup (void *cls)
60{
61 struct BlockState *bs = cls;
62
63 GNUNET_free (bs);
64}
65
66
67/**
68 * This function does nothing but to start the cmd.
69 *
70 */
71static void
72block_until_all_peers_started_run (void *cls,
73 struct GNUNET_TESTING_Interpreter *is)
74{
75 LOG (GNUNET_ERROR_TYPE_DEBUG,
76 "block_until_all_peers_started_run!\n");
77}
78
79
80/**
81 * Create command.
82 *
83 * @param label name for command.
84 * @param all_peers_started Flag which will be set from outside.
85 * @return command.
86 */
87struct GNUNET_TESTING_Command
88GNUNET_TESTING_cmd_block_until_all_peers_started (const char *label,
89 unsigned int *
90 all_peers_started)
91{
92 struct BlockState *bs;
93
94 bs = GNUNET_new (struct BlockState);
95 bs->all_peers_started = all_peers_started;
96 {
97 struct GNUNET_TESTING_Command cmd = {
98 .cls = bs,
99 .label = label,
100 .run = &block_until_all_peers_started_run,
101 .ac = &bs->ac,
102 .cleanup = &block_until_all_peers_started_cleanup
103 };
104
105 return cmd;
106 }
107}
diff --git a/src/testing/testing_api_cmd_block_until_external_trigger.c b/src/testing/testing_api_cmd_block_until_external_trigger.c
index aeb9ffda3..7ff554280 100644
--- a/src/testing/testing_api_cmd_block_until_external_trigger.c
+++ b/src/testing/testing_api_cmd_block_until_external_trigger.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29 30
30/** 31/**
31 * Generic logging shortcut 32 * Generic logging shortcut
diff --git a/src/testing/testing_api_cmd_finish.c b/src/testing/testing_api_cmd_finish.c
index 3ac0871a5..47199d3d6 100644
--- a/src/testing/testing_api_cmd_finish.c
+++ b/src/testing/testing_api_cmd_finish.c
@@ -25,6 +25,8 @@
25#include "platform.h" 25#include "platform.h"
26#include "gnunet_util_lib.h" 26#include "gnunet_util_lib.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
29
28 30
29/** 31/**
30 * Struct to use for command-specific context information closure of a command waiting 32 * Struct to use for command-specific context information closure of a command waiting
diff --git a/src/testing/testing_api_cmd_hello_world.c b/src/testing/testing_api_cmd_hello_world.c
deleted file mode 100644
index 73dcd6dff..000000000
--- a/src/testing/testing_api_cmd_hello_world.c
+++ /dev/null
@@ -1,126 +0,0 @@
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 implementation of a hello world command.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28
29struct HelloWorldState
30{
31 char *message;
32 const char *birthLabel;
33};
34
35
36/**
37 *
38 *
39 * @param cls closure
40 */
41static void
42hello_world_cleanup (void *cls)
43{
44 struct HelloWorldState *hs = cls;
45
46 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
47 "Cleaning up message %s\n",
48 hs->message);
49 GNUNET_free (hs);
50}
51
52
53/**
54 *
55 *
56 * @param cls closure.
57 * @param[out] ret result
58 * @param trait name of the trait.
59 * @param index index number of the object to offer.
60 * @return #GNUNET_OK on success.
61 */
62static enum GNUNET_GenericReturnValue
63hello_world_traits (void *cls,
64 const void **ret,
65 const char *trait,
66 unsigned int index)
67{
68 return GNUNET_NO;
69}
70
71
72/**
73* Run the "hello world" CMD.
74*
75* @param cls closure.
76* @param is interpreter state.
77*/
78static void
79hello_world_run (void *cls,
80 struct GNUNET_TESTING_Interpreter *is)
81{
82 struct HelloWorldState *hs = cls;
83 const struct GNUNET_TESTING_Command *birth_cmd;
84
85 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
86 "%s\n",
87 hs->message);
88 birth_cmd = GNUNET_TESTING_interpreter_lookup_command (is,
89 hs->birthLabel);
90 GNUNET_TESTING_get_trait_what_am_i (birth_cmd,
91 &hs->message);
92 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
93 "Now I am a %s\n",
94 hs->message);
95}
96
97
98/**
99 * Create command.
100 *
101 * @param label name for command.
102 * @param message initial message.
103 * @return command.
104 */
105struct GNUNET_TESTING_Command
106GNUNET_TESTING_cmd_hello_world (const char *label,
107 const char *birthLabel,
108 char *message)
109{
110 struct HelloWorldState *hs;
111
112 hs = GNUNET_new (struct HelloWorldState);
113 hs->message = "Hello World, I was nobody!";
114 hs->birthLabel = birthLabel;
115 {
116 struct GNUNET_TESTING_Command cmd = {
117 .cls = hs,
118 .label = label,
119 .run = &hello_world_run,
120 .cleanup = &hello_world_cleanup,
121 .traits = &hello_world_traits
122 };
123
124 return cmd;
125 }
126}
diff --git a/src/testing/testing_api_cmd_hello_world_birth.c b/src/testing/testing_api_cmd_hello_world_birth.c
deleted file mode 100644
index 8415b99f0..000000000
--- a/src/testing/testing_api_cmd_hello_world_birth.c
+++ /dev/null
@@ -1,161 +0,0 @@
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 implementation of a hello world command.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29
30struct HelloWorldBirthState
31{
32 struct GNUNET_TIME_Absolute *date;
33 char *what_am_i;
34};
35
36/**
37*
38*
39* @param cls closure
40* @param cmd current CMD being cleaned up.
41*/
42static void
43hello_world_birth_cleanup (void *cls)
44{
45 struct HelloWorldBirthState *hbs = cls;
46 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
47 "Finished birth of %s\n",
48 hbs->what_am_i);
49}
50
51
52/**
53*
54*
55* @param cls closure.
56* @param[out] ret result
57* @param trait name of the trait.
58* @param index index number of the object to offer.
59* @return #GNUNET_OK on success.
60*/
61static int
62hello_world_birth_traits (void *cls,
63 const void **ret,
64 const char *trait,
65 unsigned int index)
66{
67 struct HelloWorldBirthState *hbs = cls;
68 const char *what_am_i = hbs->what_am_i;
69
70 struct GNUNET_TESTING_Trait traits[] = {
71 {
72 .index = 0,
73 .trait_name = "what_am_i",
74 .ptr = (const void *) what_am_i,
75 },
76 GNUNET_TESTING_trait_end ()
77 };
78
79 return GNUNET_TESTING_get_trait (traits,
80 ret,
81 trait,
82 index);
83}
84
85
86/**
87* Run the "hello world" CMD.
88*
89* @param cls closure.
90* @param cmd CMD being run.
91* @param is interpreter state.
92*/
93static void
94hello_world_birth_run (void *cls,
95 struct GNUNET_TESTING_Interpreter *is)
96{
97 struct HelloWorldBirthState *hbs = cls;
98 struct GNUNET_TIME_Relative relative;
99
100 relative = GNUNET_TIME_absolute_get_difference (*hbs->date,
101 GNUNET_TIME_absolute_get ());
102
103 if (0 == relative.rel_value_us % 10)
104 {
105 hbs->what_am_i = "creature!";
106 }
107 else if (0 == relative.rel_value_us % 2)
108 {
109 hbs->what_am_i = "girl!";
110 }
111 else
112 {
113 hbs->what_am_i = "boy!";
114 }
115}
116
117
118/**
119 * Offer data from trait
120 *
121 * @param cmd command to extract the message from.
122 * @param pt pointer to message.
123 * @return #GNUNET_OK on success.
124 */
125int
126GNUNET_TESTING_get_trait_what_am_i (const struct GNUNET_TESTING_Command *cmd,
127 char **what_am_i)
128{
129 return cmd->traits (cmd->cls,
130 (const void **) what_am_i,
131 "what_am_i",
132 (unsigned int) 0);
133}
134
135
136/**
137 * Create command.
138 *
139 * @param label name for command.
140 * @param now when the command was started.
141 * @return command.
142 */
143struct GNUNET_TESTING_Command
144GNUNET_TESTING_cmd_hello_world_birth (const char *label,
145 struct GNUNET_TIME_Absolute *now)
146{
147 struct HelloWorldBirthState *hbs;
148
149 hbs = GNUNET_new (struct HelloWorldBirthState);
150 hbs->date = now;
151
152 struct GNUNET_TESTING_Command cmd = {
153 .cls = hbs,
154 .label = label,
155 .run = &hello_world_birth_run,
156 .cleanup = &hello_world_birth_cleanup,
157 .traits = &hello_world_birth_traits
158 };
159
160 return cmd;
161}
diff --git a/src/testing/testing_api_cmd_local_test_finished.c b/src/testing/testing_api_cmd_local_test_finished.c
index 8f8a8230c..709c6b62f 100644
--- a/src/testing/testing_api_cmd_local_test_finished.c
+++ b/src/testing/testing_api_cmd_local_test_finished.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "testing_cmds.h" 30#include "testing_cmds.h"
30 31
31/** 32/**
diff --git a/src/testing/testing_api_cmd_local_test_prepared.c b/src/testing/testing_api_cmd_local_test_prepared.c
index 2554d6fec..9dc7dfa9a 100644
--- a/src/testing/testing_api_cmd_local_test_prepared.c
+++ b/src/testing/testing_api_cmd_local_test_prepared.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "testing_cmds.h" 30#include "testing_cmds.h"
30 31
31/** 32/**
diff --git a/src/testing/testing_api_cmd_netjail_start.c b/src/testing/testing_api_cmd_netjail_start.c
index 35fb90f3c..2ff70c33e 100644
--- a/src/testing/testing_api_cmd_netjail_start.c
+++ b/src/testing/testing_api_cmd_netjail_start.c
@@ -26,8 +26,11 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29 30
30#define NETJAIL_START_SCRIPT "./../testing/netjail_start.sh" 31#define NETJAIL_START_SCRIPT "netjail_start.sh"
32
33#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
31 34
32/** 35/**
33 * Struct to hold information for callbacks. 36 * Struct to hold information for callbacks.
@@ -53,6 +56,10 @@ struct NetJailState
53 */ 56 */
54 char *topology_config; 57 char *topology_config;
55 58
59 /**
60 * Shall we read the topology from file, or from a string.
61 */
62 unsigned int *read_file;
56}; 63};
57 64
58 65
@@ -70,11 +77,15 @@ netjail_start_cleanup (void *cls)
70 77
71 if (NULL != ns->cwh) 78 if (NULL != ns->cwh)
72 { 79 {
80 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
81 "Cancel child\n");
73 GNUNET_wait_child_cancel (ns->cwh); 82 GNUNET_wait_child_cancel (ns->cwh);
74 ns->cwh = NULL; 83 ns->cwh = NULL;
75 } 84 }
76 if (NULL != ns->start_proc) 85 if (NULL != ns->start_proc)
77 { 86 {
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
88 "Kill process\n");
78 GNUNET_assert (0 == 89 GNUNET_assert (0 ==
79 GNUNET_OS_process_kill (ns->start_proc, 90 GNUNET_OS_process_kill (ns->start_proc,
80 SIGKILL)); 91 SIGKILL));
@@ -100,6 +111,7 @@ child_completed_callback (void *cls,
100 111
101 GNUNET_OS_process_destroy (ns->start_proc); 112 GNUNET_OS_process_destroy (ns->start_proc);
102 ns->start_proc = NULL; 113 ns->start_proc = NULL;
114 ns->cwh = NULL;
103 if (0 == exit_code) 115 if (0 == exit_code)
104 { 116 {
105 GNUNET_TESTING_async_finish (&ns->ac); 117 GNUNET_TESTING_async_finish (&ns->ac);
@@ -127,20 +139,28 @@ netjail_start_run (void *cls,
127 struct NetJailState *ns = cls; 139 struct NetJailState *ns = cls;
128 char pid[15]; 140 char pid[15];
129 enum GNUNET_GenericReturnValue helper_check; 141 enum GNUNET_GenericReturnValue helper_check;
142 char *data_dir;
143 char *script_name;
144 char *read_file;
145
146 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
147 GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_START_SCRIPT);
148 GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
130 149
131 // FIXME: NETJAIL_START_SCRIPT like this is bad,
132 // use location from share/gnunet/ of installed
133 // binary in case libgnunettesting is used as a lib!
134 helper_check = GNUNET_OS_check_helper_binary ( 150 helper_check = GNUNET_OS_check_helper_binary (
135 NETJAIL_START_SCRIPT, 151 script_name,
136 GNUNET_YES, 152 GNUNET_YES,
137 NULL); 153 NULL);
138 154
155 LOG (GNUNET_ERROR_TYPE_DEBUG,
156 "script_name %s\n",
157 script_name);
158
139 if (GNUNET_NO == helper_check) 159 if (GNUNET_NO == helper_check)
140 { 160 {
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 161 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
142 "No SUID for %s!\n", 162 "No SUID for %s!\n",
143 NETJAIL_START_SCRIPT); 163 script_name);
144 GNUNET_TESTING_interpreter_fail (is); 164 GNUNET_TESTING_interpreter_fail (is);
145 return; 165 return;
146 } 166 }
@@ -148,7 +168,7 @@ netjail_start_run (void *cls,
148 { 168 {
149 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
150 "%s not found!\n", 170 "%s not found!\n",
151 NETJAIL_START_SCRIPT); 171 script_name);
152 GNUNET_TESTING_interpreter_fail (is); 172 GNUNET_TESTING_interpreter_fail (is);
153 return; 173 return;
154 } 174 }
@@ -159,9 +179,10 @@ netjail_start_run (void *cls,
159 getpid ()); 179 getpid ());
160 { 180 {
161 char *const script_argv[] = { 181 char *const script_argv[] = {
162 NETJAIL_START_SCRIPT, 182 script_name,
163 ns->topology_config, 183 ns->topology_config,
164 pid, 184 pid,
185 read_file,
165 NULL 186 NULL
166 }; 187 };
167 188
@@ -170,7 +191,7 @@ netjail_start_run (void *cls,
170 NULL, 191 NULL,
171 NULL, 192 NULL,
172 NULL, 193 NULL,
173 NETJAIL_START_SCRIPT, 194 script_name,
174 script_argv); 195 script_argv);
175 } 196 }
176 ns->cwh = GNUNET_wait_child (ns->start_proc, 197 ns->cwh = GNUNET_wait_child (ns->start_proc,
@@ -189,12 +210,14 @@ netjail_start_run (void *cls,
189 */ 210 */
190struct GNUNET_TESTING_Command 211struct GNUNET_TESTING_Command
191GNUNET_TESTING_cmd_netjail_start (const char *label, 212GNUNET_TESTING_cmd_netjail_start (const char *label,
192 char *topology_config) 213 char *topology_config,
214 unsigned int *read_file)
193{ 215{
194 struct NetJailState *ns; 216 struct NetJailState *ns;
195 217
196 ns = GNUNET_new (struct NetJailState); 218 ns = GNUNET_new (struct NetJailState);
197 ns->topology_config = topology_config; 219 ns->topology_config = topology_config;
220 ns->read_file = read_file;
198 { 221 {
199 struct GNUNET_TESTING_Command cmd = { 222 struct GNUNET_TESTING_Command cmd = {
200 .cls = ns, 223 .cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_start_testsystem.c b/src/testing/testing_api_cmd_netjail_start_testsystem.c
index c3598d174..89c193de5 100644
--- a/src/testing/testing_api_cmd_netjail_start_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_start_testsystem.c
@@ -25,9 +25,10 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
28#include "testing_cmds.h" 29#include "testing_cmds.h"
29 30
30#define NETJAIL_EXEC_SCRIPT "./../testing/netjail_exec.sh" 31#define NETJAIL_EXEC_SCRIPT "netjail_exec.sh"
31 32
32/** 33/**
33 * Generic logging shortcut 34 * Generic logging shortcut
@@ -83,18 +84,6 @@ struct NetJailState
83 struct GNUNET_TESTING_NetjailTopology *topology; 84 struct GNUNET_TESTING_NetjailTopology *topology;
84 85
85 /** 86 /**
86 * Head of the DLL which stores messages received by the helper.
87 *
88 */
89 struct HelperMessage *hp_messages_head;
90
91 /**
92 * Tail of the DLL which stores messages received by the helper.
93 *
94 */
95 struct HelperMessage *hp_messages_tail;
96
97 /**
98 * Array with handles of helper processes. 87 * Array with handles of helper processes.
99 */ 88 */
100 struct GNUNET_HELPER_Handle **helper; 89 struct GNUNET_HELPER_Handle **helper;
@@ -123,27 +112,6 @@ struct NetJailState
123 */ 112 */
124 unsigned int known; 113 unsigned int known;
125 114
126 /**
127 * The send handle for the helper
128 */
129 // struct GNUNET_HELPER_SendHandle **shandle;
130
131 /**
132 * Size of the array NetJailState#shandle.
133 *
134 */
135 // unsigned int n_shandle;
136
137 /**
138 * The messages send to the helper.
139 */
140 struct GNUNET_MessageHeader **msg;
141
142 /**
143 * Size of the array NetJailState#msg.
144 *
145 */
146 unsigned int n_msg;
147 115
148 /** 116 /**
149 * Number of test environments started. 117 * Number of test environments started.
@@ -176,16 +144,14 @@ struct NetJailState
176 char *plugin_name; 144 char *plugin_name;
177 145
178 /** 146 /**
179 * HEAD of the DLL containing TestingSystemCount. 147 * Shall we read the topology from file, or from a string.
180 *
181 */ 148 */
182 struct TestingSystemCount *tbcs_head; 149 unsigned int *read_file;
183 150
184 /** 151 /**
185 * TAIL of the DLL containing TestingSystemCount. 152 * String with topology data or name of topology file.
186 *
187 */ 153 */
188 struct TestingSystemCount *tbcs_tail; 154 char *topology_data;
189}; 155};
190 156
191/** 157/**
@@ -207,13 +173,7 @@ struct TestingSystemCount
207 /** 173 /**
208 * The send handle for the helper 174 * The send handle for the helper
209 */ 175 */
210 struct GNUNET_HELPER_SendHandle *shandle;// **shandle; 176 struct GNUNET_HELPER_SendHandle *shandle;
211
212 /**
213 * Size of the array NetJailState#shandle.
214 *
215 */
216 // unsigned int n_shandle;
217 177
218 /** 178 /**
219 * The number of the test environment. 179 * The number of the test environment.
@@ -226,6 +186,11 @@ struct TestingSystemCount
226 * 186 *
227 */ 187 */
228 struct NetJailState *ns; 188 struct NetJailState *ns;
189
190 /**
191 * The messages send to the helper.
192 */
193 struct GNUNET_MessageHeader *msg;
229}; 194};
230 195
231/** 196/**
@@ -237,24 +202,7 @@ static void
237netjail_exec_cleanup (void *cls) 202netjail_exec_cleanup (void *cls)
238{ 203{
239 struct NetJailState *ns = cls; 204 struct NetJailState *ns = cls;
240 struct HelperMessage *message_pos;
241 struct TestingSystemCount *tbc_pos;
242 205
243 while (NULL != (message_pos = ns->hp_messages_head))
244 {
245 GNUNET_CONTAINER_DLL_remove (ns->hp_messages_head,
246 ns->hp_messages_tail,
247 message_pos);
248 GNUNET_free (message_pos);
249 }
250 while (NULL != (tbc_pos = ns->tbcs_head))
251 {
252 GNUNET_CONTAINER_DLL_remove (ns->tbcs_head,
253 ns->tbcs_tail,
254 tbc_pos);
255 GNUNET_free (tbc_pos);
256 }
257 GNUNET_TESTING_free_topology (ns->topology);
258 GNUNET_free (ns); 206 GNUNET_free (ns);
259} 207}
260 208
@@ -271,7 +219,6 @@ netjail_exec_traits (void *cls,
271{ 219{
272 struct NetJailState *ns = cls; 220 struct NetJailState *ns = cls;
273 struct GNUNET_HELPER_Handle **helper = ns->helper; 221 struct GNUNET_HELPER_Handle **helper = ns->helper;
274 struct HelperMessage *hp_messages_head = ns->hp_messages_head;
275 222
276 223
277 struct GNUNET_TESTING_Trait traits[] = { 224 struct GNUNET_TESTING_Trait traits[] = {
@@ -280,11 +227,6 @@ netjail_exec_traits (void *cls,
280 .trait_name = "helper_handles", 227 .trait_name = "helper_handles",
281 .ptr = (const void *) helper, 228 .ptr = (const void *) helper,
282 }, 229 },
283 {
284 .index = 1,
285 .trait_name = "hp_msgs_head",
286 .ptr = (const void *) hp_messages_head,
287 },
288 GNUNET_TESTING_trait_end () 230 GNUNET_TESTING_trait_end ()
289 }; 231 };
290 232
@@ -327,12 +269,12 @@ static void
327clear_msg (void *cls, int result) 269clear_msg (void *cls, int result)
328{ 270{
329 struct TestingSystemCount *tbc = cls; 271 struct TestingSystemCount *tbc = cls;
330 struct NetJailState *ns = tbc->ns;
331 272
332 GNUNET_assert (NULL != tbc->shandle);// [tbc->count - 1]); 273 GNUNET_assert (NULL != tbc->shandle);
333 tbc->shandle = NULL;// [tbc->count - 1] = NULL; 274 GNUNET_free (tbc->shandle);
334 GNUNET_free (ns->msg[tbc->count - 1]); 275 tbc->shandle = NULL;
335 ns->msg[tbc->count - 1] = NULL; 276 GNUNET_free (tbc->msg);
277 tbc->msg = NULL;
336} 278}
337 279
338 280
@@ -361,7 +303,7 @@ send_message_to_locals (
361 303
362 helper = ns->helper[tbc->count - 1];// - total_number]; 304 helper = ns->helper[tbc->count - 1];// - total_number];
363 305
364 GNUNET_array_append (ns->msg, ns->n_msg, header); 306
365 307
366 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send ( 308 struct GNUNET_HELPER_SendHandle *sh = GNUNET_HELPER_send (
367 helper, 309 helper,
@@ -427,7 +369,7 @@ static int
427helper_mst (void *cls, const struct GNUNET_MessageHeader *message) 369helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
428{ 370{
429 // struct TestingSystemCount *tbc = cls; 371 // struct TestingSystemCount *tbc = cls;
430 struct NetJailState *ns = cls;// tbc->ns; 372 struct NetJailState *ns = cls;
431 struct HelperMessage *hp_msg; 373 struct HelperMessage *hp_msg;
432 unsigned int total_number = ns->local_m * ns->global_n + ns->known; 374 unsigned int total_number = ns->local_m * ns->global_n + ns->known;
433 // uint16_t message_type = ntohs (message->type); 375 // uint16_t message_type = ntohs (message->type);
@@ -543,11 +485,8 @@ helper_mst (void *cls, const struct GNUNET_MessageHeader *message)
543 } 485 }
544 else 486 else
545 { 487 {
546 hp_msg = GNUNET_new (struct HelperMessage); 488 // We received a message we can not handle.
547 hp_msg->bytes_msg = message->size; 489 GNUNET_assert (0);
548 memcpy (&hp_msg[1], message, message->size);
549 GNUNET_CONTAINER_DLL_insert (ns->hp_messages_head, ns->hp_messages_tail,
550 hp_msg);
551 } 490 }
552 491
553 492
@@ -629,6 +568,7 @@ start_helper (struct NetJailState *ns,
629 char *known_char; 568 char *known_char;
630 char *node_id; 569 char *node_id;
631 char *plugin; 570 char *plugin;
571 char *read_file;
632 pid_t pid; 572 pid_t pid;
633 unsigned int script_num; 573 unsigned int script_num;
634 struct GNUNET_ShortHashCode *hkey; 574 struct GNUNET_ShortHashCode *hkey;
@@ -636,6 +576,9 @@ start_helper (struct NetJailState *ns,
636 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology; 576 struct GNUNET_TESTING_NetjailTopology *topology = ns->topology;
637 struct GNUNET_TESTING_NetjailNode *node; 577 struct GNUNET_TESTING_NetjailNode *node;
638 struct GNUNET_TESTING_NetjailNamespace *namespace; 578 struct GNUNET_TESTING_NetjailNamespace *namespace;
579 char *data_dir;
580 char *script_name;
581 char *topology_data;
639 582
640 583
641 if (0 == n) 584 if (0 == n)
@@ -652,47 +595,31 @@ start_helper (struct NetJailState *ns,
652 GNUNET_asprintf (&node_id, "%06x-%08x\n", 595 GNUNET_asprintf (&node_id, "%06x-%08x\n",
653 pid, 596 pid,
654 script_num); 597 script_num);
598 // GNUNET_asprintf (&topology_data, "'%s'", ns->topology_data);
599 GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
655 600
656 601 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
657 char *const script_argv[] = {NETJAIL_EXEC_SCRIPT, 602 GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_EXEC_SCRIPT);
658 m_char,
659 n_char,
660 GNUNET_OS_get_libexec_binary_path (
661 HELPER_CMDS_BINARY),
662 global_n_char,
663 local_m_char,
664 node_id,
665 NULL};
666
667 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 603 unsigned int helper_check = GNUNET_OS_check_helper_binary (
668 NETJAIL_EXEC_SCRIPT, 604 script_name,
669 GNUNET_YES, 605 GNUNET_YES,
670 NULL); 606 NULL);
671 607
672 tbc = GNUNET_new (struct TestingSystemCount); 608 tbc = GNUNET_new (struct TestingSystemCount);
673 tbc->ns = ns; 609 tbc->ns = ns;
674 if (0 == n)
675 tbc->count = m;
676 else
677 tbc->count = (n - 1) * ns->local_m + m + ns->known;
678
679 GNUNET_CONTAINER_DLL_insert (ns->tbcs_head,
680 ns->tbcs_tail,
681 tbc);
682
683 610
684 if (GNUNET_NO == helper_check) 611 if (GNUNET_NO == helper_check)
685 { 612 {
686 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 613 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
687 "No SUID for %s!\n", 614 "No SUID for %s!\n",
688 NETJAIL_EXEC_SCRIPT); 615 script_name);
689 GNUNET_TESTING_interpreter_fail (ns->is); 616 GNUNET_TESTING_interpreter_fail (ns->is);
690 } 617 }
691 else if (GNUNET_NO == helper_check) 618 else if (GNUNET_NO == helper_check)
692 { 619 {
693 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 620 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
694 "%s not found!\n", 621 "%s not found!\n",
695 NETJAIL_EXEC_SCRIPT); 622 script_name);
696 GNUNET_TESTING_interpreter_fail (ns->is); 623 GNUNET_TESTING_interpreter_fail (ns->is);
697 } 624 }
698 625
@@ -705,17 +632,29 @@ start_helper (struct NetJailState *ns,
705 ns->local_m, 632 ns->local_m,
706 ns->global_n, 633 ns->global_n,
707 ns->known); 634 ns->known);
635 {
636 char *const script_argv[] = {script_name,
637 m_char,
638 n_char,
639 GNUNET_OS_get_libexec_binary_path (
640 HELPER_CMDS_BINARY),
641 global_n_char,
642 local_m_char,
643 node_id,
644 read_file,
645 ns->topology_data,
646 NULL};
647 helper = GNUNET_HELPER_start (
648 GNUNET_YES,
649 script_name,
650 script_argv,
651 &helper_mst,
652 &exp_cb,
653 ns);
654 GNUNET_array_append (ns->helper, ns->n_helper, helper);
655 }
708 656
709 GNUNET_array_append (ns->helper, ns->n_helper, GNUNET_HELPER_start ( 657 tbc->count = ns->n_helper;
710 GNUNET_YES,
711 NETJAIL_EXEC_SCRIPT,
712 script_argv,
713 &helper_mst,
714 &exp_cb,
715 ns));
716
717 helper = ns->helper[tbc->count - 1];
718
719 hkey = GNUNET_new (struct GNUNET_ShortHashCode); 658 hkey = GNUNET_new (struct GNUNET_ShortHashCode);
720 659
721 plugin = topology->plugin; 660 plugin = topology->plugin;
@@ -767,8 +706,6 @@ start_helper (struct NetJailState *ns,
767 706
768 msg = create_helper_init_msg_ (plugin); 707 msg = create_helper_init_msg_ (plugin);
769 708
770 GNUNET_array_append (ns->msg, ns->n_msg, &msg->header);
771
772 // GNUNET_array_append (tbc->shandle, tbc->n_shandle, 709 // GNUNET_array_append (tbc->shandle, tbc->n_shandle,
773 tbc->shandle = GNUNET_HELPER_send ( 710 tbc->shandle = GNUNET_HELPER_send (
774 helper, 711 helper,
@@ -825,24 +762,28 @@ netjail_exec_run (void *cls,
825 * Create command. 762 * Create command.
826 * 763 *
827 * @param label Name for the command. 764 * @param label Name for the command.
828 * @param topology_config Configuration file for the test topology. 765 * @param topology The complete topology information.
766 * @param read_file Flag indicating if the the name of the topology file is send to the helper, or a string with the topology data.
767 * @param topology_data If read_file is GNUNET_NO, topology_data holds the string with the topology.
829 * @return command. 768 * @return command.
830 */ 769 */
831struct GNUNET_TESTING_Command 770struct GNUNET_TESTING_Command
832GNUNET_TESTING_cmd_netjail_start_testing_system (const char *label, 771GNUNET_TESTING_cmd_netjail_start_testing_system (
833 const char *topology_config) 772 const char *label,
773 struct GNUNET_TESTING_NetjailTopology *topology,
774 unsigned int *read_file,
775 char *topology_data)
834{ 776{
835 struct NetJailState *ns; 777 struct NetJailState *ns;
836 778
837 struct GNUNET_TESTING_NetjailTopology *topology =
838 GNUNET_TESTING_get_topo_from_file (topology_config);
839
840 ns = GNUNET_new (struct NetJailState); 779 ns = GNUNET_new (struct NetJailState);
841 ns->local_m = topology->nodes_m; 780 ns->local_m = topology->nodes_m;
842 ns->global_n = topology->namespaces_n; 781 ns->global_n = topology->namespaces_n;
843 ns->known = topology->nodes_x; 782 ns->known = topology->nodes_x;
844 ns->plugin_name = topology->plugin; 783 ns->plugin_name = topology->plugin;
845 ns->topology = topology; 784 ns->topology = topology;
785 ns->read_file = read_file;
786 ns->topology_data = topology_data;
846 787
847 struct GNUNET_TESTING_Command cmd = { 788 struct GNUNET_TESTING_Command cmd = {
848 .cls = ns, 789 .cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_stop.c b/src/testing/testing_api_cmd_netjail_stop.c
index 5033272a3..e3bf7da62 100644
--- a/src/testing/testing_api_cmd_netjail_stop.c
+++ b/src/testing/testing_api_cmd_netjail_stop.c
@@ -26,12 +26,10 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29 30
30 31
31#define NETJAIL_STOP_SCRIPT "./../testing/netjail_stop.sh" 32#define NETJAIL_STOP_SCRIPT "netjail_stop.sh"
32
33// Child Wait handle
34static struct GNUNET_ChildWaitHandle *cwh;
35 33
36/** 34/**
37 * Struct to hold information for callbacks. 35 * Struct to hold information for callbacks.
@@ -44,6 +42,9 @@ struct NetJailState
44 */ 42 */
45 struct GNUNET_TESTING_AsyncContext ac; 43 struct GNUNET_TESTING_AsyncContext ac;
46 44
45 // Child Wait handle
46 struct GNUNET_ChildWaitHandle *cwh;
47
47 /** 48 /**
48 * Configuration file for the test topology. 49 * Configuration file for the test topology.
49 */ 50 */
@@ -54,6 +55,11 @@ struct NetJailState
54 */ 55 */
55 struct GNUNET_OS_Process *stop_proc; 56 struct GNUNET_OS_Process *stop_proc;
56 57
58 /**
59 * Shall we read the topology from file, or from a string.
60 */
61 unsigned int *read_file;
62
57}; 63};
58 64
59 65
@@ -66,10 +72,10 @@ netjail_stop_cleanup (void *cls)
66{ 72{
67 struct NetJailState *ns = cls; 73 struct NetJailState *ns = cls;
68 74
69 if (NULL != cwh) 75 if (NULL != ns->cwh)
70 { 76 {
71 GNUNET_wait_child_cancel (cwh); 77 GNUNET_wait_child_cancel (ns->cwh);
72 cwh = NULL; 78 ns->cwh = NULL;
73 } 79 }
74 if (NULL != ns->stop_proc) 80 if (NULL != ns->stop_proc)
75 { 81 {
@@ -95,7 +101,7 @@ child_completed_callback (void *cls,
95{ 101{
96 struct NetJailState *ns = cls; 102 struct NetJailState *ns = cls;
97 103
98 cwh = NULL; // WTF? globals!?!?! 104 ns->cwh = NULL;
99 GNUNET_OS_process_destroy (ns->stop_proc); 105 GNUNET_OS_process_destroy (ns->stop_proc);
100 ns->stop_proc = NULL; 106 ns->stop_proc = NULL;
101 if (0 == exit_code) 107 if (0 == exit_code)
@@ -121,16 +127,16 @@ netjail_stop_run (void *cls,
121{ 127{
122 struct NetJailState *ns = cls; 128 struct NetJailState *ns = cls;
123 char *pid; 129 char *pid;
130 char *data_dir;
131 char *script_name;
132 char *read_file;
124 133
125 GNUNET_asprintf (&pid, 134
126 "%u", 135 data_dir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_DATADIR);
127 getpid ()); 136 GNUNET_asprintf (&script_name, "%s%s", data_dir, NETJAIL_STOP_SCRIPT);
128 char *const script_argv[] = {NETJAIL_STOP_SCRIPT, 137 GNUNET_asprintf (&read_file, "%u", *(ns->read_file));
129 ns->topology_config,
130 pid,
131 NULL};
132 unsigned int helper_check = GNUNET_OS_check_helper_binary ( 138 unsigned int helper_check = GNUNET_OS_check_helper_binary (
133 NETJAIL_STOP_SCRIPT, 139 script_name,
134 GNUNET_YES, 140 GNUNET_YES,
135 NULL); 141 NULL);
136 142
@@ -138,39 +144,50 @@ netjail_stop_run (void *cls,
138 { 144 {
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
140 "No SUID for %s!\n", 146 "No SUID for %s!\n",
141 NETJAIL_STOP_SCRIPT); 147 script_name);
142 GNUNET_TESTING_interpreter_fail (is); 148 GNUNET_TESTING_interpreter_fail (is);
143 } 149 }
144 else if (GNUNET_NO == helper_check) 150 else if (GNUNET_NO == helper_check)
145 { 151 {
146 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 152 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
147 "%s not found!\n", 153 "%s not found!\n",
148 NETJAIL_STOP_SCRIPT); 154 script_name);
149 GNUNET_TESTING_interpreter_fail (is); 155 GNUNET_TESTING_interpreter_fail (is);
150 } 156 }
151 157
152 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR, 158 GNUNET_asprintf (&pid,
153 NULL, 159 "%u",
154 NULL, 160 getpid ());
155 NULL, 161 {
156 NETJAIL_STOP_SCRIPT, 162 char *const script_argv[] = {script_name,
157 script_argv); 163 ns->topology_config,
158 164 pid,
159 cwh = GNUNET_wait_child (ns->stop_proc, 165 read_file,
160 &child_completed_callback, 166 NULL};
161 ns); 167 ns->stop_proc = GNUNET_OS_start_process_vap (GNUNET_OS_INHERIT_STD_ERR,
162 GNUNET_break (NULL != cwh); 168 NULL,
169 NULL,
170 NULL,
171 script_name,
172 script_argv);
173 }
174 ns->cwh = GNUNET_wait_child (ns->stop_proc,
175 &child_completed_callback,
176 ns);
177 GNUNET_break (NULL != ns->cwh);
163} 178}
164 179
165 180
166struct GNUNET_TESTING_Command 181struct GNUNET_TESTING_Command
167GNUNET_TESTING_cmd_netjail_stop (const char *label, 182GNUNET_TESTING_cmd_netjail_stop (const char *label,
168 char *topology_config) 183 char *topology_config,
184 unsigned int *read_file)
169{ 185{
170 struct NetJailState *ns; 186 struct NetJailState *ns;
171 187
172 ns = GNUNET_new (struct NetJailState); 188 ns = GNUNET_new (struct NetJailState);
173 ns->topology_config = topology_config; 189 ns->topology_config = topology_config;
190 ns->read_file = read_file;
174 { 191 {
175 struct GNUNET_TESTING_Command cmd = { 192 struct GNUNET_TESTING_Command cmd = {
176 .cls = ns, 193 .cls = ns,
diff --git a/src/testing/testing_api_cmd_netjail_stop_testsystem.c b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
index e37e955be..4b52878c4 100644
--- a/src/testing/testing_api_cmd_netjail_stop_testsystem.c
+++ b/src/testing/testing_api_cmd_netjail_stop_testsystem.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
28#include "testing_cmds.h" 29#include "testing_cmds.h"
29 30
30 31
@@ -70,7 +71,6 @@ stop_testing_system_cleanup (void *cls)
70{ 71{
71 struct StopHelperState *shs = cls; 72 struct StopHelperState *shs = cls;
72 73
73 GNUNET_TESTING_free_topology (shs->topology);
74 GNUNET_free (shs); 74 GNUNET_free (shs);
75} 75}
76 76
@@ -124,19 +124,17 @@ stop_testing_system_run (void *cls,
124 * 124 *
125 * @param label name for command. 125 * @param label name for command.
126 * @param helper_start_label label of the cmd to start the test system. 126 * @param helper_start_label label of the cmd to start the test system.
127 * @param topology_config Configuration file for the test topology. 127 * @param topology The complete topology information.
128 * @return command. 128 * @return command.
129 */ 129 */
130struct GNUNET_TESTING_Command 130struct GNUNET_TESTING_Command
131GNUNET_TESTING_cmd_stop_testing_system (const char *label, 131GNUNET_TESTING_cmd_stop_testing_system (
132 const char *helper_start_label, 132 const char *label,
133 const char *topology_config) 133 const char *helper_start_label,
134 struct GNUNET_TESTING_NetjailTopology *topology)
134{ 135{
135 struct StopHelperState *shs; 136 struct StopHelperState *shs;
136 137
137 struct GNUNET_TESTING_NetjailTopology *topology =
138 GNUNET_TESTING_get_topo_from_file (topology_config);
139
140 shs = GNUNET_new (struct StopHelperState); 138 shs = GNUNET_new (struct StopHelperState);
141 shs->helper_start_label = helper_start_label; 139 shs->helper_start_label = helper_start_label;
142 shs->local_m = topology->nodes_m; 140 shs->local_m = topology->nodes_m;
diff --git a/src/testing/testing_api_cmd_send_peer_ready.c b/src/testing/testing_api_cmd_send_peer_ready.c
index 8eef1d8f1..5bbabce51 100644
--- a/src/testing/testing_api_cmd_send_peer_ready.c
+++ b/src/testing/testing_api_cmd_send_peer_ready.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "testing_cmds.h" 30#include "testing_cmds.h"
30 31
31 32
diff --git a/src/testing/testing_api_cmd_system_create.c b/src/testing/testing_api_cmd_system_create.c
index 820adf1bd..275132684 100644
--- a/src/testing/testing_api_cmd_system_create.c
+++ b/src/testing/testing_api_cmd_system_create.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
30 31
31/** 32/**
diff --git a/src/testing/testing_api_cmd_system_destroy.c b/src/testing/testing_api_cmd_system_destroy.c
index 338123d91..cdfc65d53 100644
--- a/src/testing/testing_api_cmd_system_destroy.c
+++ b/src/testing/testing_api_cmd_system_destroy.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_testing_lib.h" 30#include "gnunet_testing_lib.h"
30 31
31 32
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index d281c4ffb..5fe8229e7 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -738,7 +738,9 @@ endif
738endif 738endif
739 739
740check_SCRIPTS= \ 740check_SCRIPTS= \
741 test_transport_simple_send_string.sh \
741 test_transport_simple_send.sh \ 742 test_transport_simple_send.sh \
743 test_transport_simple_send_broadcast.sh \
742 test_transport_udp_backchannel.sh 744 test_transport_udp_backchannel.sh
743 745
744test_transport_start_with_config_SOURCES = \ 746test_transport_start_with_config_SOURCES = \
diff --git a/src/transport/gnunet-communicator-udp.c b/src/transport/gnunet-communicator-udp.c
index 659fd7d26..b7a3b4082 100644
--- a/src/transport/gnunet-communicator-udp.c
+++ b/src/transport/gnunet-communicator-udp.c
@@ -2262,6 +2262,7 @@ static void
2262sock_read (void *cls) 2262sock_read (void *cls)
2263{ 2263{
2264 struct sockaddr_storage sa; 2264 struct sockaddr_storage sa;
2265 struct sockaddr_in *addr_verify;
2265 socklen_t salen = sizeof(sa); 2266 socklen_t salen = sizeof(sa);
2266 char buf[UINT16_MAX]; 2267 char buf[UINT16_MAX];
2267 ssize_t rcvd; 2268 ssize_t rcvd;
@@ -2341,12 +2342,22 @@ sock_read (void *cls)
2341 { 2342 {
2342 const struct UDPBroadcast *ub; 2343 const struct UDPBroadcast *ub;
2343 struct UdpBroadcastSignature uhs; 2344 struct UdpBroadcastSignature uhs;
2345 struct GNUNET_PeerIdentity sender;
2344 2346
2347 addr_verify = GNUNET_memdup (&sa, salen);
2348 addr_verify->sin_port = 0;
2349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2350 "received UDPBroadcast from %s\n",
2351 GNUNET_a2s ((const struct sockaddr *) addr_verify, salen));
2345 ub = (const struct UDPBroadcast *) buf; 2352 ub = (const struct UDPBroadcast *) buf;
2346 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); 2353 uhs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
2347 uhs.purpose.size = htonl (sizeof(uhs)); 2354 uhs.purpose.size = htonl (sizeof(uhs));
2348 uhs.sender = ub->sender; 2355 uhs.sender = ub->sender;
2349 GNUNET_CRYPTO_hash (&sa, salen, &uhs.h_address); 2356 sender = ub->sender;
2357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2358 "checking UDPBroadcastSignature for %s\n",
2359 GNUNET_i2s (&sender));
2360 GNUNET_CRYPTO_hash ((struct sockaddr *) addr_verify, salen, &uhs.h_address);
2350 if (GNUNET_OK == 2361 if (GNUNET_OK ==
2351 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST, 2362 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST,
2352 &uhs, 2363 &uhs,
@@ -2362,10 +2373,23 @@ sock_read (void *cls)
2362 /* use our own mechanism to determine network type */ 2373 /* use our own mechanism to determine network type */
2363 nt = 2374 nt =
2364 GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen); 2375 GNUNET_NT_scanner_get_type (is, (const struct sockaddr *) &sa, salen);
2365 GNUNET_TRANSPORT_application_validate (ah, &ub->sender, nt, addr_s); 2376 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2377 "validating address %s received from UDPBroadcast\n",
2378 GNUNET_i2s (&sender));
2379 GNUNET_TRANSPORT_application_validate (ah, &sender, nt, addr_s);
2366 GNUNET_free (addr_s); 2380 GNUNET_free (addr_s);
2367 return; 2381 return;
2368 } 2382 }
2383 else
2384 {
2385 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2386 "VerifyingPeer %s is verifying UDPBroadcast\n",
2387 GNUNET_i2s (&my_identity));
2388 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2389 "Verifying UDPBroadcast from %s failed\n",
2390 GNUNET_i2s (&ub->sender));
2391 }
2392 GNUNET_free (addr_verify);
2369 /* continue with KX, mostly for statistics... */ 2393 /* continue with KX, mostly for statistics... */
2370 } 2394 }
2371 2395
@@ -3477,7 +3501,7 @@ ifc_broadcast (void *cls)
3477 delay.rel_value_us = 3501 delay.rel_value_us =
3478 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us); 3502 GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, delay.rel_value_us);
3479 bi->broadcast_task = 3503 bi->broadcast_task =
3480 GNUNET_SCHEDULER_add_delayed (INTERFACE_SCAN_FREQUENCY, &ifc_broadcast, bi); 3504 GNUNET_SCHEDULER_add_delayed (delay, &ifc_broadcast, bi);
3481 3505
3482 switch (bi->sa->sa_family) 3506 switch (bi->sa->sa_family)
3483 { 3507 {
@@ -3494,6 +3518,12 @@ ifc_broadcast (void *cls)
3494 sizeof(int))) 3518 sizeof(int)))
3495 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, 3519 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING,
3496 "setsockopt"); 3520 "setsockopt");
3521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3522 "creating UDPBroadcast from %s\n",
3523 GNUNET_i2s (&(bi->bcm.sender)));
3524 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3525 "sending UDPBroadcast to add %s\n",
3526 GNUNET_a2s (bi->ba, bi->salen));
3497 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 3527 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
3498 &bi->bcm, 3528 &bi->bcm,
3499 sizeof(bi->bcm), 3529 sizeof(bi->bcm),
@@ -3521,6 +3551,8 @@ ifc_broadcast (void *cls)
3521 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr; 3551 dst.sin6_addr = bi->mcreq.ipv6mr_multiaddr;
3522 dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id; 3552 dst.sin6_scope_id = ((struct sockaddr_in6 *) bi->ba)->sin6_scope_id;
3523 3553
3554 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3555 "sending UDPBroadcast\n");
3524 sent = GNUNET_NETWORK_socket_sendto (udp_sock, 3556 sent = GNUNET_NETWORK_socket_sendto (udp_sock,
3525 &bi->bcm, 3557 &bi->bcm,
3526 sizeof(bi->bcm), 3558 sizeof(bi->bcm),
@@ -3608,6 +3640,9 @@ iface_proc (void *cls,
3608 ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST); 3640 ubs.purpose.purpose = htonl (GNUNET_SIGNATURE_COMMUNICATOR_UDP_BROADCAST);
3609 ubs.purpose.size = htonl (sizeof(ubs)); 3641 ubs.purpose.size = htonl (sizeof(ubs));
3610 ubs.sender = my_identity; 3642 ubs.sender = my_identity;
3643 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3644 "creating UDPBroadcastSignature for %s\n",
3645 GNUNET_a2s (addr, addrlen));
3611 GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address); 3646 GNUNET_CRYPTO_hash (addr, addrlen, &ubs.h_address);
3612 GNUNET_CRYPTO_eddsa_sign (my_private_key, 3647 GNUNET_CRYPTO_eddsa_sign (my_private_key,
3613 &ubs, 3648 &ubs,
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index a90bef3b5..84199a75f 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -4738,15 +4738,17 @@ send_dv_to_neighbour (void *cls,
4738 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed 4738 * @return expected RTT for transmission, #GNUNET_TIME_UNIT_FOREVER_REL if sending failed
4739 */ 4739 */
4740static struct GNUNET_TIME_Relative 4740static struct GNUNET_TIME_Relative
4741route_control_message_without_fc (const struct GNUNET_PeerIdentity *target, 4741route_control_message_without_fc (struct VirtualLink *vl,
4742// route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4742 const struct GNUNET_MessageHeader *hdr, 4743 const struct GNUNET_MessageHeader *hdr,
4743 enum RouteMessageOptions options) 4744 enum RouteMessageOptions options)
4744{ 4745{
4745 struct VirtualLink *vl; 4746 // struct VirtualLink *vl;
4746 struct Neighbour *n; 4747 struct Neighbour *n;
4747 struct DistanceVector *dv; 4748 struct DistanceVector *dv;
4748 struct GNUNET_TIME_Relative rtt1; 4749 struct GNUNET_TIME_Relative rtt1;
4749 struct GNUNET_TIME_Relative rtt2; 4750 struct GNUNET_TIME_Relative rtt2;
4751 const struct GNUNET_PeerIdentity *target = &vl->target;
4750 4752
4751 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 4753 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
4752 "Trying to route message of type %u to %s without fc\n", 4754 "Trying to route message of type %u to %s without fc\n",
@@ -4754,7 +4756,7 @@ route_control_message_without_fc (const struct GNUNET_PeerIdentity *target,
4754 GNUNET_i2s (target)); 4756 GNUNET_i2s (target));
4755 4757
4756 // TODO Do this elsewhere. vl should be given as parameter to method. 4758 // TODO Do this elsewhere. vl should be given as parameter to method.
4757 vl = lookup_virtual_link (target); 4759 // vl = lookup_virtual_link (target);
4758 GNUNET_assert (NULL != vl); 4760 GNUNET_assert (NULL != vl);
4759 if (NULL == vl) 4761 if (NULL == vl)
4760 return GNUNET_TIME_UNIT_FOREVER_REL; 4762 return GNUNET_TIME_UNIT_FOREVER_REL;
@@ -4892,7 +4894,7 @@ consider_sending_fc (void *cls)
4892 fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used); 4894 fc.outbound_sent = GNUNET_htonll (vl->outbound_fc_window_size_used);
4893 fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size); 4895 fc.outbound_window_size = GNUNET_htonll (vl->outbound_fc_window_size);
4894 fc.sender_time = GNUNET_TIME_absolute_hton (monotime); 4896 fc.sender_time = GNUNET_TIME_absolute_hton (monotime);
4895 rtt = route_control_message_without_fc (&vl->target, &fc.header, RMO_NONE); 4897 rtt = route_control_message_without_fc (vl, &fc.header, RMO_NONE);
4896 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us) 4898 if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us == rtt.rel_value_us)
4897 { 4899 {
4898 rtt = GNUNET_TIME_UNIT_SECONDS; 4900 rtt = GNUNET_TIME_UNIT_SECONDS;
@@ -5086,6 +5088,8 @@ handle_communicator_backchannel (
5086 void *cls, 5088 void *cls,
5087 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb) 5089 const struct GNUNET_TRANSPORT_CommunicatorBackchannel *cb)
5088{ 5090{
5091 struct Neighbour *n;
5092 struct VirtualLink *vl;
5089 struct TransportClient *tc = cls; 5093 struct TransportClient *tc = cls;
5090 const struct GNUNET_MessageHeader *inbox = 5094 const struct GNUNET_MessageHeader *inbox =
5091 (const struct GNUNET_MessageHeader *) &cb[1]; 5095 (const struct GNUNET_MessageHeader *) &cb[1];
@@ -5116,7 +5120,22 @@ handle_communicator_backchannel (
5116 + isize], 5120 + isize],
5117 is, 5121 is,
5118 strlen (is) + 1); 5122 strlen (is) + 1);
5119 route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED); 5123 // route_control_message_without_fc (&cb->pid, &be->header, RMO_DV_ALLOWED);
5124 vl = lookup_virtual_link (&cb->pid);
5125 if (NULL != vl)
5126 {
5127 route_control_message_without_fc (vl, &be->header, RMO_DV_ALLOWED);
5128 }
5129 else
5130 {
5131 /* Use route via neighbour */
5132 n = lookup_neighbour (&cb->pid);
5133 if (NULL != n)
5134 route_via_neighbour (
5135 n,
5136 &be->header,
5137 RMO_NONE);
5138 }
5120 GNUNET_SERVICE_client_continue (tc->client); 5139 GNUNET_SERVICE_client_continue (tc->client);
5121} 5140}
5122 5141
@@ -5540,6 +5559,8 @@ destroy_ack_cummulator (void *cls)
5540static void 5559static void
5541transmit_cummulative_ack_cb (void *cls) 5560transmit_cummulative_ack_cb (void *cls)
5542{ 5561{
5562 struct Neighbour *n;
5563 struct VirtualLink *vl;
5543 struct AcknowledgementCummulator *ac = cls; 5564 struct AcknowledgementCummulator *ac = cls;
5544 char buf[sizeof(struct TransportReliabilityAckMessage) 5565 char buf[sizeof(struct TransportReliabilityAckMessage)
5545 + ac->ack_counter 5566 + ac->ack_counter
@@ -5566,7 +5587,28 @@ transmit_cummulative_ack_cb (void *cls)
5566 ap[i].ack_delay = GNUNET_TIME_relative_hton ( 5587 ap[i].ack_delay = GNUNET_TIME_relative_hton (
5567 GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time)); 5588 GNUNET_TIME_absolute_get_duration (ac->ack_uuids[i].receive_time));
5568 } 5589 }
5569 route_control_message_without_fc (&ac->target, &ack->header, RMO_DV_ALLOWED); 5590 /*route_control_message_without_fc (
5591 &ac->target,
5592 &ack->header,
5593 RMO_DV_ALLOWED);*/
5594 vl = lookup_virtual_link (&ac->target);
5595 if (NULL != vl)
5596 {
5597 route_control_message_without_fc (
5598 vl,
5599 &ack->header,
5600 RMO_DV_ALLOWED);
5601 }
5602 else
5603 {
5604 /* Use route via neighbour */
5605 n = lookup_neighbour (&ac->target);
5606 if (NULL != n)
5607 route_via_neighbour (
5608 n,
5609 &ack->header,
5610 RMO_NONE);
5611 }
5570 ac->num_acks = 0; 5612 ac->num_acks = 0;
5571 ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT, 5613 ac->task = GNUNET_SCHEDULER_add_delayed (ACK_CUMMULATOR_TIMEOUT,
5572 &destroy_ack_cummulator, 5614 &destroy_ack_cummulator,
@@ -6558,6 +6600,8 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
6558 const struct DVPathEntryP *hops, 6600 const struct DVPathEntryP *hops,
6559 struct GNUNET_TIME_Absolute in_time) 6601 struct GNUNET_TIME_Absolute in_time)
6560{ 6602{
6603 struct Neighbour *n;
6604 struct VirtualLink *vl;
6561 struct DVPathEntryP *dhops; 6605 struct DVPathEntryP *dhops;
6562 char buf[sizeof(struct TransportDVLearnMessage) 6606 char buf[sizeof(struct TransportDVLearnMessage)
6563 + (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN; 6607 + (nhops + 1) * sizeof(struct DVPathEntryP)] GNUNET_ALIGN;
@@ -6598,9 +6642,26 @@ forward_dv_learn (const struct GNUNET_PeerIdentity *next_hop,
6598 &dhp, 6642 &dhp,
6599 &dhops[nhops].hop_sig); 6643 &dhops[nhops].hop_sig);
6600 } 6644 }
6601 route_control_message_without_fc (next_hop, 6645 /*route_control_message_without_fc (next_hop,
6602 &fwd->header, 6646 &fwd->header,
6603 RMO_UNCONFIRMED_ALLOWED); 6647 RMO_UNCONFIRMED_ALLOWED);*/
6648 vl = lookup_virtual_link (next_hop);
6649 if (NULL != vl)
6650 {
6651 route_control_message_without_fc (vl,
6652 &fwd->header,
6653 RMO_UNCONFIRMED_ALLOWED);
6654 }
6655 else
6656 {
6657 /* Use route via neighbour */
6658 n = lookup_neighbour (next_hop);
6659 if (NULL != n)
6660 route_via_neighbour (
6661 n,
6662 &fwd->header,
6663 RMO_UNCONFIRMED_ALLOWED);
6664 }
6604} 6665}
6605 6666
6606 6667
@@ -7937,7 +7998,8 @@ handle_validation_challenge (
7937 vl = lookup_virtual_link (&sender); 7998 vl = lookup_virtual_link (&sender);
7938 if (NULL != vl) 7999 if (NULL != vl)
7939 { 8000 {
7940 route_control_message_without_fc (&cmc->im.sender, 8001 // route_control_message_without_fc (&cmc->im.sender,
8002 route_control_message_without_fc (vl,
7941 &tvr.header, 8003 &tvr.header,
7942 RMO_ANYTHING_GOES | RMO_REDUNDANT); 8004 RMO_ANYTHING_GOES | RMO_REDUNDANT);
7943 } 8005 }
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
index c374fc2d0..2c987e601 100644
--- a/src/transport/test_transport_plugin_cmd_simple_send.c
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
28#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h" 30#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h" 31#include "transport-testing2.h"
@@ -213,7 +214,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
213 char *node_ip, 214 char *node_ip,
214 char *m, 215 char *m,
215 char *n, 216 char *n,
216 char *local_m) 217 char *local_m,
218 char *topology_data,
219 unsigned int *read_file)
217{ 220{
218 221
219 unsigned int n_int; 222 unsigned int n_int;
@@ -221,8 +224,16 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
221 unsigned int local_m_int; 224 unsigned int local_m_int;
222 unsigned int num; 225 unsigned int num;
223 struct TestState *ts = GNUNET_new (struct TestState); 226 struct TestState *ts = GNUNET_new (struct TestState);
224 struct GNUNET_TESTING_NetjailTopology *topology = 227 struct GNUNET_TESTING_NetjailTopology *topology;
225 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); 228
229 if (GNUNET_YES == *read_file)
230 {
231 LOG (GNUNET_ERROR_TYPE_DEBUG,
232 "read from file\n");
233 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
234 }
235 else
236 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
226 237
227 ts->topology = topology; 238 ts->topology = topology;
228 239
diff --git a/src/transport/test_transport_plugin_cmd_udp_backchannel.c b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
index f3afbec48..db320844f 100644
--- a/src/transport/test_transport_plugin_cmd_udp_backchannel.c
+++ b/src/transport/test_transport_plugin_cmd_udp_backchannel.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
28#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h" 30#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h" 31#include "transport-testing2.h"
@@ -207,7 +208,9 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
207 char *node_ip, 208 char *node_ip,
208 char *m, 209 char *m,
209 char *n, 210 char *n,
210 char *local_m) 211 char *local_m,
212 char *topology_data,
213 unsigned int *read_file)
211{ 214{
212 215
213 unsigned int n_int; 216 unsigned int n_int;
@@ -216,8 +219,12 @@ start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
216 unsigned int num; 219 unsigned int num;
217 struct TestState *ts = GNUNET_new (struct TestState); 220 struct TestState *ts = GNUNET_new (struct TestState);
218 221
219 struct GNUNET_TESTING_NetjailTopology *topology = 222 struct GNUNET_TESTING_NetjailTopology *topology;
220 GNUNET_TESTING_get_topo_from_file (TOPOLOGY_CONFIG); 223
224 if (GNUNET_YES == *read_file)
225 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
226 else
227 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
221 228
222 ts->topology = topology; 229 ts->topology = topology;
223 230
diff --git a/src/transport/test_transport_simple_send_string.sh b/src/transport/test_transport_simple_send_string.sh
new file mode 100755
index 000000000..018ea55e8
--- /dev/null
+++ b/src/transport/test_transport_simple_send_string.sh
@@ -0,0 +1,16 @@
1#!/bin/bash
2string=$(cat << EOF
3M:2
4N:1
5X:0
6T:libgnunet_test_transport_plugin_cmd_simple_send
7P:1:1|{connect:{P:1:2:tcp}}
8P:1:2|{connect:{P:1:1:tcp}}
9EOF
10)
11if [ "$(sysctl -n kernel.unprivileged_userns_clone)" == 1 ]; then
12 exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_start_with_config -s '$string'"
13else
14 echo -e "Error during test setup: The kernel parameter kernel.unprivileged_userns_clone has to be set to 1! One has to execute\n\n sysctl kernel.unprivileged_userns_clone=1\n"
15 exit 78
16fi
diff --git a/src/transport/test_transport_start_with_config.c b/src/transport/test_transport_start_with_config.c
index 932b0e583..7eb92d629 100644
--- a/src/transport/test_transport_start_with_config.c
+++ b/src/transport/test_transport_start_with_config.c
@@ -25,6 +25,7 @@
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_testing_ng_lib.h" 27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testing_netjail_lib.h"
28#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
29 30
30#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120)
@@ -34,27 +35,86 @@ int
34main (int argc, 35main (int argc,
35 char *const *argv) 36 char *const *argv)
36{ 37{
37 char *topology_config; 38 char *topology_data;
39 char *topology_data_script;
40 struct GNUNET_TESTING_NetjailTopology *topology;
41 unsigned int read_file = GNUNET_YES;
42 int ret;
43 char *rest = NULL;
44 char *token;
45 size_t single_line_len;
46 size_t data_len;
38 47
39 GNUNET_log_setup ("test-netjail", 48 GNUNET_log_setup ("test-netjail",
40 "DEBUG", 49 "DEBUG",
41 NULL); 50 NULL);
42 51
43 topology_config = argv[1]; 52 if (0 == strcmp ("-s", argv[1]))
53 {
54 data_len = strlen (argv[2]);
55 topology_data = GNUNET_malloc (data_len);
56 topology_data_script = GNUNET_malloc (data_len);
57 token = strtok_r (argv[2], "\n", &rest);
58 while (NULL != token)
59 {
60 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
61 "token1 %s\n",
62 token);
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
64 "token2 %s\n",
65 token);
66 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
67 "topology_data %s\n",
68 topology_data);
69 strcat (topology_data_script, token);
70 strcat (topology_data_script, " ");
71 strcat (topology_data, token);
72 strcat (topology_data, "\n");
73 token = strtok_r (NULL, "\n", &rest);
74 }
75 single_line_len = strlen (topology_data);
76 topology_data_script [single_line_len - 1] = '\0';
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "read from string\n");
79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "topology_data %s\n",
81 topology_data);
82 read_file = GNUNET_NO;
83 topology = GNUNET_TESTING_get_topo_from_string (topology_data);
84 }
85 else
86 {
87 topology_data = argv[1];
88 topology_data_script = argv[1];
89 topology = GNUNET_TESTING_get_topo_from_file (topology_data);
90 }
44 91
45 struct GNUNET_TESTING_Command commands[] = { 92 struct GNUNET_TESTING_Command commands[] = {
46 GNUNET_TESTING_cmd_netjail_start ("netjail-start", 93 GNUNET_TESTING_cmd_netjail_start ("netjail-start",
47 topology_config), 94 topology_data_script,
95 &read_file),
48 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed", 96 GNUNET_TESTING_cmd_netjail_start_testing_system ("netjail-start-testbed",
49 topology_config), 97 topology,
98 &read_file,
99 topology_data_script),
50 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed", 100 GNUNET_TESTING_cmd_stop_testing_system ("stop-testbed",
51 "netjail-start-testbed", 101 "netjail-start-testbed",
52 topology_config), 102 topology),
53 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop", 103 GNUNET_TESTING_cmd_netjail_stop ("netjail-stop",
54 topology_config), 104 topology_data_script,
105 &read_file),
55 GNUNET_TESTING_cmd_end () 106 GNUNET_TESTING_cmd_end ()
56 }; 107 };
57 108
58 return GNUNET_TESTING_main (commands, 109 ret = GNUNET_TESTING_main (commands,
59 TIMEOUT); 110 TIMEOUT);
111
112 if (0 == strcmp ("-s", argv[1]))
113 {
114 GNUNET_free (topology_data_script);
115 GNUNET_free (topology_data);
116 }
117 GNUNET_TESTING_free_topology (topology);
118
119 return ret;
60} 120}
diff --git a/src/transport/transport_api_cmd_backchannel_check.c b/src/transport/transport_api_cmd_backchannel_check.c
index 03b231347..529b4690b 100644
--- a/src/transport/transport_api_cmd_backchannel_check.c
+++ b/src/transport/transport_api_cmd_backchannel_check.c
@@ -27,6 +27,7 @@
27#include "gnunet_common.h" 27#include "gnunet_common.h"
28#include "gnunet_util_lib.h" 28#include "gnunet_util_lib.h"
29#include "gnunet_testing_ng_lib.h" 29#include "gnunet_testing_ng_lib.h"
30#include "gnunet_testing_netjail_lib.h"
30#include "gnunet_transport_application_service.h" 31#include "gnunet_transport_application_service.h"
31#include "gnunet_hello_lib.h" 32#include "gnunet_hello_lib.h"
32#include "gnunet_transport_service.h" 33#include "gnunet_transport_service.h"
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 2eb1b0914..b50b63c62 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_transport_application_service.h" 30#include "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h" 31#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h" 32#include "gnunet_transport_service.h"
@@ -91,6 +92,10 @@ connect_peers_run (void *cls,
91 addr = GNUNET_TESTING_get_address (pos_connection, 92 addr = GNUNET_TESTING_get_address (pos_connection,
92 pos_prefix->address_prefix); 93 pos_prefix->address_prefix);
93 peer = GNUNET_TESTING_get_pub_key (num, tl_system); 94 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
95 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
96 "validating peer number %u with identity %s\n",
97 num,
98 GNUNET_i2s (peer));
94 GNUNET_TRANSPORT_application_validate (ah, 99 GNUNET_TRANSPORT_application_validate (ah,
95 peer, 100 peer,
96 nt, 101 nt,
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 9c34c50d7..790139cce 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "transport-testing2.h" 30#include "transport-testing2.h"
30#include "transport-testing-cmds.h" 31#include "transport-testing-cmds.h"
31 32
diff --git a/src/transport/transport_api_cmd_send_simple_v3.c b/src/transport/transport_api_cmd_send_simple_v3.c
deleted file mode 100644
index a4ce2c4e9..000000000
--- a/src/transport/transport_api_cmd_send_simple_v3.c
+++ /dev/null
@@ -1,194 +0,0 @@
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 * Label of the cmd which started the test system.
52 *
53 */
54 const char *create_label;
55
56 /**
57 * The topology we get the connected nodes from.
58 */
59 struct GNUNET_TESTING_NetjailTopology *topology;
60};
61
62
63/**
64 * Trait function of this cmd does nothing.
65 *
66 */
67static int
68send_simple_traits (void *cls,
69 const void **ret,
70 const char *trait,
71 unsigned int index)
72{
73 return GNUNET_OK;
74}
75
76
77/**
78 * The cleanup function of this cmd frees resources the cmd allocated.
79 *
80 */
81static void
82send_simple_cleanup (void *cls,
83 const struct GNUNET_TESTING_Command *cmd)
84{
85 struct SendSimpleState *sss = cls;
86
87 GNUNET_free (sss);
88}
89
90
91/**
92 * The run method of this cmd will send a simple message to the connected peers.
93 *
94 */
95static void
96send_simple_run (void *cls,
97 const struct GNUNET_TESTING_Command *cmd,
98 struct GNUNET_TESTING_Interpreter *is)
99{
100 struct SendSimpleState *sss = cls;
101 struct GNUNET_MQ_Envelope *env;
102 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
103 struct GNUNET_MQ_Handle *mq;
104 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
105 const struct GNUNET_TESTING_Command *peer1_cmd;
106 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
107 struct GNUNET_HashCode hc;
108 struct GNUNET_TESTING_NodeConnection *node_connections_head;
109 struct GNUNET_PeerIdentity *peer;
110 struct GNUNET_CRYPTO_EddsaPublicKey public_key;
111 uint32_t num;
112 struct GNUNET_TESTING_NodeConnection *pos_connection;
113 const struct GNUNET_TESTING_Command *system_cmd;
114 struct GNUNET_TESTING_System *tl_system;
115
116 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
117 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
118 &connected_peers_map);
119
120 system_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->create_label);
121 GNUNET_TESTING_get_trait_test_system (system_cmd,
122 &tl_system);
123
124 node_connections_head = GNUNET_TESTING_get_connections (sss->num,
125 sss->topology);
126
127 for (int i = 0; i < 1; i++)
128 {
129 for (pos_connection = node_connections_head; NULL != pos_connection;
130 pos_connection = pos_connection->next)
131 {
132 num = GNUNET_TESTING_calculate_num (pos_connection, sss->topology);
133 peer = GNUNET_TESTING_get_pub_key (num, tl_system);
134 public_key = peer->public_key;
135 GNUNET_CRYPTO_hash (&public_key, sizeof(public_key), &hc);
136
137 memcpy (key,
138 &hc,
139 sizeof (*key));
140 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
141 key);
142 env = GNUNET_MQ_msg_extra (test,
143 1000 - sizeof(*test),
144 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE);
145 test->num = htonl (sss->num);
146 memset (&test[1],
147 sss->num,
148 1000 - sizeof(*test));
149 GNUNET_MQ_send (mq,
150 env);
151 }
152 }
153
154 GNUNET_free (key);
155
156}
157
158
159/**
160 * Create command.
161 *
162 * @param label name for command.
163 * @param start_peer_label Label of the cmd to start a peer.
164 * @param start_peer_label Label of the cmd which started the test system.
165 * @param num Number globally identifying the node.
166 * @param The topology for the test setup.
167 * @return command.
168 */
169struct GNUNET_TESTING_Command
170GNUNET_TRANSPORT_cmd_send_simple_v3 (const char *label,
171 const char *start_peer_label,
172 const char *create_label,
173 uint32_t num,
174 struct GNUNET_TESTING_NetjailTopology *
175 topology)
176{
177 struct SendSimpleState *sss;
178
179 sss = GNUNET_new (struct SendSimpleState);
180 sss->num = num;
181 sss->start_peer_label = start_peer_label;
182 sss->create_label = create_label;
183 sss->topology = topology;
184
185 struct GNUNET_TESTING_Command cmd = {
186 .cls = sss,
187 .label = label,
188 .run = &send_simple_run,
189 .cleanup = &send_simple_cleanup,
190 .traits = &send_simple_traits
191 };
192
193 return cmd;
194}
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index a026d48cc..60f416f85 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_peerstore_service.h" 30#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h" 31#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h" 32#include "gnunet_transport_application_service.h"
@@ -172,6 +173,7 @@ start_peer_run (void *cls,
172 char *tcp_communicator_unix_path; 173 char *tcp_communicator_unix_path;
173 char *udp_communicator_unix_path; 174 char *udp_communicator_unix_path;
174 char *bindto; 175 char *bindto;
176 char *bindto_udp;
175 177
176 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname)) 178 if (GNUNET_NO == GNUNET_DISK_file_test (sps->cfgname))
177 { 179 {
@@ -207,6 +209,9 @@ start_peer_run (void *cls,
207 "%s:60002", 209 "%s:60002",
208 sps->node_ip); 210 sps->node_ip);
209 211
212 GNUNET_asprintf (&bindto_udp,
213 "2086");
214
210 LOG (GNUNET_ERROR_TYPE_ERROR, 215 LOG (GNUNET_ERROR_TYPE_ERROR,
211 "node_ip %s\n", 216 "node_ip %s\n",
212 bindto); 217 bindto);
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
index dcb982a65..97408b083 100644
--- a/src/transport/transport_api_cmd_stop_peer.c
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -26,6 +26,7 @@
26#include "platform.h" 26#include "platform.h"
27#include "gnunet_util_lib.h" 27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h" 28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_testing_netjail_lib.h"
29#include "gnunet_peerstore_service.h" 30#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h" 31#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h" 32#include "gnunet_transport_application_service.h"