aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am71
-rw-r--r--src/transport/gnunet-communicator-tcp.c32
-rw-r--r--src/transport/plugin_cmd_simple_send.c188
-rw-r--r--src/transport/test_transport_api2_tcp_node1.conf23
-rw-r--r--src/transport/test_transport_api2_tcp_node2.conf22
-rw-r--r--src/transport/test_transport_api_cmd_simple_send.c80
-rw-r--r--src/transport/test_transport_plugin_cmd_simple_send.c248
-rwxr-xr-xsrc/transport/test_transport_simple_send.sh2
-rw-r--r--src/transport/transport-testing-cmds.h81
-rw-r--r--src/transport/transport-testing-ng.h74
-rw-r--r--src/transport/transport-testing2.h37
-rw-r--r--src/transport/transport_api_cmd_connecting_peers.c118
-rw-r--r--src/transport/transport_api_cmd_send_simple.c82
-rw-r--r--src/transport/transport_api_cmd_start_peer.c274
-rw-r--r--src/transport/transport_api_cmd_stop_peer.c163
15 files changed, 945 insertions, 550 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 3d8fa7774..4ea3b58c4 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -156,21 +156,17 @@ libgnunettransporttesting_la_LIBADD = \
156 $(top_builddir)/src/testing/libgnunettesting.la \ 156 $(top_builddir)/src/testing/libgnunettesting.la \
157 $(top_builddir)/src/arm/libgnunetarm.la \ 157 $(top_builddir)/src/arm/libgnunetarm.la \
158 $(GN_LIBINTL) 158 $(GN_LIBINTL)
159libgnunettransporttesting_la_DEPENDENCIES = \
160 libgnunettransport.la \
161 $(top_builddir)/src/hello/libgnunethello.la \
162 $(top_builddir)/src/ats/libgnunetats.la \
163 $(top_builddir)/src/util/libgnunetutil.la \
164 $(top_builddir)/src/testing/libgnunettesting.la \
165 $(top_builddir)/src/arm/libgnunetarm.la
166libgnunettransporttesting_la_LDFLAGS = \ 159libgnunettransporttesting_la_LDFLAGS = \
167 $(GN_LIB_LDFLAGS) 160 $(GN_LIB_LDFLAGS)
168 161
169libgnunettransporttesting2_la_SOURCES = \ 162libgnunettransporttesting2_la_SOURCES = \
170 transport_api_cmd_connecting_peers.c \ 163 transport_api_cmd_connecting_peers.c \
171 transport_api_cmd_start_peer.c \ 164 transport_api_cmd_start_peer.c \
165 transport_api_cmd_stop_peer.c \
172 transport_api_cmd_send_simple.c \ 166 transport_api_cmd_send_simple.c \
173 transport-testing2.c transport-testing2.h \ 167 transport-testing2.c transport-testing2.h \
168 transport-testing-ng.h \
169 transport-testing-cmds.h \
174 transport-testing-filenames2.c \ 170 transport-testing-filenames2.c \
175 transport-testing-loggers2.c \ 171 transport-testing-loggers2.c \
176 transport-testing-main2.c \ 172 transport-testing-main2.c \
@@ -187,7 +183,8 @@ libgnunettransporttesting2_la_LIBADD = \
187 $(top_builddir)/src/util/libgnunetutil.la 183 $(top_builddir)/src/util/libgnunetutil.la
188libgnunettransporttesting2_la_LDFLAGS = \ 184libgnunettransporttesting2_la_LDFLAGS = \
189 $(GN_LIBINTL) \ 185 $(GN_LIBINTL) \
190 $(GN_LIB_LDFLAGS) 186 $(GN_LIB_LDFLAGS) \
187 -version-info 0:0:0
191 188
192libgnunettransport_la_SOURCES = \ 189libgnunettransport_la_SOURCES = \
193 transport.h \ 190 transport.h \
@@ -205,10 +202,6 @@ libgnunettransport_la_LIBADD = \
205 $(top_builddir)/src/ats/libgnunetats.la \ 202 $(top_builddir)/src/ats/libgnunetats.la \
206 $(top_builddir)/src/util/libgnunetutil.la \ 203 $(top_builddir)/src/util/libgnunetutil.la \
207 $(GN_LIBINTL) 204 $(GN_LIBINTL)
208libgnunettransport_la_DEPENDENCIES = \
209 $(top_builddir)/src/hello/libgnunethello.la \
210 $(top_builddir)/src/ats/libgnunetats.la \
211 $(top_builddir)/src/util/libgnunetutil.la
212libgnunettransport_la_LDFLAGS = \ 205libgnunettransport_la_LDFLAGS = \
213 $(GN_LIB_LDFLAGS) \ 206 $(GN_LIB_LDFLAGS) \
214 -version-info 4:0:2 207 -version-info 4:0:2
@@ -397,23 +390,29 @@ plugin_LTLIBRARIES = \
397 $(HTTP_SERVER_PLUGIN_LA) \ 390 $(HTTP_SERVER_PLUGIN_LA) \
398 $(HTTPS_SERVER_PLUGIN_LA) \ 391 $(HTTPS_SERVER_PLUGIN_LA) \
399 $(WLAN_PLUGIN_LA) \ 392 $(WLAN_PLUGIN_LA) \
400 $(BT_PLUGIN_LA) 393 $(BT_PLUGIN_LA) \
401# libgnunet_plugin_cmd_simple_send.la 394 libgnunet_test_transport_plugin_cmd_simple_send.la
402 395
403#libgnunet_plugin_cmd_simple_send_la_SOURCES = \ 396libgnunet_test_transport_plugin_cmd_simple_send_la_SOURCES = \
404# plugin_cmd_simple_send.c 397 test_transport_plugin_cmd_simple_send.c
405#libgnunet_plugin_cmd_simple_send_la_LIBADD = \ 398libgnunet_test_transport_plugin_cmd_simple_send_la_LIBADD = \
406# $(top_builddir)/src/util/libgnunetutil.la \ 399 libgnunettransporttesting2.la \
407# $(top_builddir)/src/testing/libgnunettesting.la \ 400 libgnunettransportapplication.la \
408# $(top_builddir)/src/statistics/libgnunetstatistics.la \ 401 libgnunettransport.la \
409# $(top_builddir)/src/testbed/libgnunettestbed.la \ 402 $(top_builddir)/src/testing/libgnunettesting.la \
410# libgnunettransporttesting2.la \ 403 $(top_builddir)/src/peerstore/libgnunetpeerstore.la \
411# $(LTLIBINTL) 404 $(top_builddir)/src/statistics/libgnunetstatistics.la \
412#libgnunet_plugin_cmd_simple_send_la_LDFLAGS = \ 405 $(top_builddir)/src/hello/libgnunethello.la \
413# $(GN_PLUGIN_LDFLAGS) 406 $(top_builddir)/src/ats/libgnunetats.la \
407 $(top_builddir)/src/arm/libgnunetarm.la \
408 $(top_builddir)/src/util/libgnunetutil.la \
409 $(LTLIBINTL)
410libgnunet_test_transport_plugin_cmd_simple_send_la_LDFLAGS = \
411 $(GN_PLUGIN_LDFLAGS)
414 412
415if HAVE_EXPERIMENTAL 413if HAVE_EXPERIMENTAL
416plugin_LTLIBRARIES += libgnunet_plugin_transport_udp.la 414plugin_LTLIBRARIES += \
415 libgnunet_plugin_transport_udp.la
417endif 416endif
418 417
419# Note: real plugins of course need to be added 418# Note: real plugins of course need to be added
@@ -557,7 +556,7 @@ libgnunet_plugin_transport_https_server_la_CFLAGS = \
557 556
558if HAVE_TESTING 557if HAVE_TESTING
559check_PROGRAMS = \ 558check_PROGRAMS = \
560 test_transport_api_cmd_simple_send \ 559 test_transport_simple_send \
561 test_transport_address_switch_tcp \ 560 test_transport_address_switch_tcp \
562 test_transport_testing_startstop \ 561 test_transport_testing_startstop \
563 test_transport_testing_restart \ 562 test_transport_testing_restart \
@@ -646,7 +645,6 @@ endif
646if ENABLE_TEST_RUN 645if ENABLE_TEST_RUN
647AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; 646AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME;
648TESTS = \ 647TESTS = \
649 test_transport_api_cmd_simple_send \
650 test_transport_address_switch_tcp \ 648 test_transport_address_switch_tcp \
651 $(HTTP_SWITCH) \ 649 $(HTTP_SWITCH) \
652 $(HTTPS_SWITCH) \ 650 $(HTTPS_SWITCH) \
@@ -699,13 +697,15 @@ TESTS = \
699 $(HTTP_API_TIMEOUT_TEST) \ 697 $(HTTP_API_TIMEOUT_TEST) \
700 $(HTTPS_API_TIMEOUT_TEST) \ 698 $(HTTPS_API_TIMEOUT_TEST) \
701 $(WLAN_TIMEOUT_TEST) \ 699 $(WLAN_TIMEOUT_TEST) \
702 $(BT_TIMEOUT_TEST) 700 $(BT_TIMEOUT_TEST) \
701 $(check_SCRIPTS)
703if HAVE_GETOPT_BINARY 702if HAVE_GETOPT_BINARY
704TESTS += \ 703TESTS += \
705test_transport_api_slow_ats 704test_transport_api_slow_ats
706endif 705endif
707if HAVE_EXPERIMENTAL 706if HAVE_EXPERIMENTAL
708TESTS += \ 707TESTS += \
708 test_transport_simple_send \
709 test_transport_address_switch_udp \ 709 test_transport_address_switch_udp \
710 test_plugin_udp \ 710 test_plugin_udp \
711 test_transport_api_udp \ 711 test_transport_api_udp \
@@ -723,14 +723,17 @@ TESTS += \
723endif 723endif
724endif 724endif
725 725
726test_transport_api_cmd_simple_send_SOURCES = \ 726check_SCRIPTS= \
727 test_transport_api_cmd_simple_send.c 727 test_transport_simple_send.sh
728test_transport_api_cmd_simple_send_LDADD = \ 728
729test_transport_simple_send_SOURCES = \
730 test_transport_simple_send.c
731test_transport_simple_send_LDADD = \
729 $(top_builddir)/src/testing/libgnunettesting.la \ 732 $(top_builddir)/src/testing/libgnunettesting.la \
730 $(top_builddir)/src/util/libgnunetutil.la \ 733 $(top_builddir)/src/util/libgnunetutil.la \
731 $(top_builddir)/src/testbed/libgnunettestbed.la \ 734 $(top_builddir)/src/testbed/libgnunettestbed.la \
732 libgnunettransport.la \
733 $(top_builddir)/src/hello/libgnunethello.la \ 735 $(top_builddir)/src/hello/libgnunethello.la \
736 libgnunettransport.la \
734 libgnunettransporttesting.la 737 libgnunettransporttesting.la
735 738
736test_transport_testing_startstop_SOURCES = \ 739test_transport_testing_startstop_SOURCES = \
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index 1b838bf9c..d8bf7c1a8 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -879,12 +879,15 @@ queue_destroy (struct Queue *queue)
879 struct GNUNET_HashCode h_sock; 879 struct GNUNET_HashCode h_sock;
880 int sockfd; 880 int sockfd;
881 881
882 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock); 882 if (NULL != queue->listen_sock)
883 GNUNET_CRYPTO_hash (&sockfd, 883 {
884 sizeof(int), 884 sockfd = GNUNET_NETWORK_get_fd (queue->listen_sock);
885 &h_sock); 885 GNUNET_CRYPTO_hash (&sockfd,
886 sizeof(int),
887 &h_sock);
886 888
887 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock); 889 lt = GNUNET_CONTAINER_multihashmap_get (lt_map, &h_sock);
890 }
888 891
889 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 "Disconnecting queue for peer `%s'\n", 893 "Disconnecting queue for peer `%s'\n",
@@ -1900,6 +1903,9 @@ queue_read (void *cls)
1900 BUF_SIZE - queue->cread_off); 1903 BUF_SIZE - queue->cread_off);
1901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1904 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1902 "Received %lu bytes from TCP queue\n", rcvd); 1905 "Received %lu bytes from TCP queue\n", rcvd);
1906 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
1907 "transport",
1908 "Received %lu bytes from TCP queue\n", rcvd);
1903 if (-1 == rcvd) 1909 if (-1 == rcvd)
1904 { 1910 {
1905 if ((EAGAIN != errno) && (EINTR != errno)) 1911 if ((EAGAIN != errno) && (EINTR != errno))
@@ -2675,6 +2681,9 @@ proto_read_kx (void *cls)
2675 sizeof(pq->ibuf) - pq->ibuf_off); 2681 sizeof(pq->ibuf) - pq->ibuf_off);
2676 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2682 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2677 "Received %lu bytes for KX\n", rcvd); 2683 "Received %lu bytes for KX\n", rcvd);
2684 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
2685 "transport",
2686 "Received %lu bytes for KX\n", rcvd);
2678 if (-1 == rcvd) 2687 if (-1 == rcvd)
2679 { 2688 {
2680 if ((EAGAIN != errno) && (EINTR != errno)) 2689 if ((EAGAIN != errno) && (EINTR != errno))
@@ -2704,7 +2713,7 @@ proto_read_kx (void *cls)
2704 { 2713 {
2705 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 2714 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2706 "Invalid TCP KX received from %s\n", 2715 "Invalid TCP KX received from %s\n",
2707 GNUNET_a2s (queue->address, queue->address_len)); 2716 GNUNET_a2s (pq->address, pq->address_len));
2708 gcry_cipher_close (queue->in_cipher); 2717 gcry_cipher_close (queue->in_cipher);
2709 GNUNET_free (queue); 2718 GNUNET_free (queue);
2710 free_proto_queue (pq); 2719 free_proto_queue (pq);
@@ -2824,6 +2833,10 @@ queue_read_kx (void *cls)
2824 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2833 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2825 "Received %lu bytes for KX\n", 2834 "Received %lu bytes for KX\n",
2826 rcvd); 2835 rcvd);
2836 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
2837 "transport",
2838 "Received %lu bytes for KX\n",
2839 rcvd);
2827 if (-1 == rcvd) 2840 if (-1 == rcvd)
2828 { 2841 {
2829 if ((EAGAIN != errno) && (EINTR != errno)) 2842 if ((EAGAIN != errno) && (EINTR != errno))
@@ -2918,6 +2931,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address)
2918 2931
2919 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2932 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2920 "Connecting to %s\n", address); 2933 "Connecting to %s\n", address);
2934 GNUNET_log_from_nocheck (GNUNET_ERROR_TYPE_DEBUG,
2935 "transport",
2936 "Connecting to %s\n", address);
2921 if (0 != strncmp (address, 2937 if (0 != strncmp (address,
2922 COMMUNICATOR_ADDRESS_PREFIX "-", 2938 COMMUNICATOR_ADDRESS_PREFIX "-",
2923 strlen (COMMUNICATOR_ADDRESS_PREFIX "-"))) 2939 strlen (COMMUNICATOR_ADDRESS_PREFIX "-")))
@@ -3069,9 +3085,9 @@ do_shutdown (void *cls)
3069 GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL); 3085 GNUNET_CONTAINER_multihashmap_iterate (lt_map, &get_lt_delete_it, NULL);
3070 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL); 3086 GNUNET_CONTAINER_multipeermap_iterate (queue_map, &get_queue_delete_it, NULL);
3071 GNUNET_CONTAINER_multipeermap_destroy (queue_map); 3087 GNUNET_CONTAINER_multipeermap_destroy (queue_map);
3072 GNUNET_TRANSPORT_communicator_address_remove_all (ch);
3073 if (NULL != ch) 3088 if (NULL != ch)
3074 { 3089 {
3090 GNUNET_TRANSPORT_communicator_address_remove_all (ch);
3075 GNUNET_TRANSPORT_communicator_disconnect (ch); 3091 GNUNET_TRANSPORT_communicator_disconnect (ch);
3076 ch = NULL; 3092 ch = NULL;
3077 } 3093 }
@@ -3238,7 +3254,7 @@ init_socket (struct sockaddr *addr,
3238 return GNUNET_SYSERR; 3254 return GNUNET_SYSERR;
3239 } 3255 }
3240 3256
3241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3257 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
3242 "address %s\n", 3258 "address %s\n",
3243 GNUNET_a2s (addr, in_len)); 3259 GNUNET_a2s (addr, in_len));
3244 3260
diff --git a/src/transport/plugin_cmd_simple_send.c b/src/transport/plugin_cmd_simple_send.c
deleted file mode 100644
index 62bb7544b..000000000
--- a/src/transport/plugin_cmd_simple_send.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2014 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30// #include "gnunet_transport_service.h"
31#include "gnunet_testbed_ng_service.h"
32#include "transport-testing2.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39#define BASE_DIR "testdir"
40
41struct GNUNET_MQ_MessageHandler *handlers;
42
43unsigned int are_all_peers_started;
44
45static int
46check_test (void *cls,
47 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
48{
49 return GNUNET_OK;
50}
51
52static void
53handle_test (void *cls,
54 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
55{
56 LOG (GNUNET_ERROR_TYPE_ERROR,
57 "message received\n");
58}
59
60static int
61check_test2 (void *cls,
62 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
63{
64 return GNUNET_OK;
65}
66
67static void
68handle_test2 (void *cls,
69 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
70{
71 LOG (GNUNET_ERROR_TYPE_ERROR,
72 "message received\n");
73}
74
75static void
76all_peers_started ()
77{
78 are_all_peers_started = GNUNET_YES;
79 LOG (GNUNET_ERROR_TYPE_ERROR,
80 "setting are_all_peers_started: %d\n",
81 are_all_peers_started);
82}
83
84static void
85start_testcase (TESTBED_CMD_HELPER_write_cb write_message, char *router_ip,
86 char *node_ip,
87 char *m,
88 char *n)
89{
90 char *testdir;
91 char *cfgname;
92
93 GNUNET_asprintf (&cfgname,
94 "%s%s.conf",
95 "test_transport_api2_tcp_peer",
96 n);
97
98 LOG (GNUNET_ERROR_TYPE_ERROR,
99 "cfgname: %s\n",
100 cfgname);
101
102 testdir = GNUNET_malloc (strlen (BASE_DIR) + strlen (m) + strlen (n)
103 + 1);
104
105 strcpy (testdir, BASE_DIR);
106 strcat (testdir, m);
107 strcat (testdir, n);
108
109 struct GNUNET_MQ_MessageHandler handlers[] = {
110 GNUNET_MQ_hd_var_size (test,
111 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
112 struct GNUNET_TRANSPORT_TESTING_TestMessage,
113 NULL),
114 GNUNET_MQ_hd_var_size (test2,
115 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
116 struct GNUNET_TRANSPORT_TESTING_TestMessage,
117 NULL),
118 GNUNET_MQ_handler_end ()
119 };
120
121 struct GNUNET_TESTING_Command commands[] = {
122 GNUNET_TESTING_cmd_system_create ("system-create-1",
123 testdir),
124 GNUNET_TRANSPORT_cmd_start_peer ("start-peer-1",
125 "system-create-1",
126 m,
127 n,
128 handlers,
129 cfgname),
130 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready-1",
131 write_message),
132 GNUNET_TESTING_cmd_block_until_all_peers_started ("block-1",
133 &are_all_peers_started),
134 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers-1",
135 "start-peer-1",
136 "this is useless"),
137 /*GNUNET_TESTING_cmd_send_simple ("send-simple-1",
138 char *m,
139 char *n,
140 uint32_t num,
141 const char *peer1_label,
142 const char *peer2_label),*/
143 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished-1",
144 write_message)
145 };
146
147 GNUNET_TESTING_run (NULL,
148 commands,
149 GNUNET_TIME_UNIT_FOREVER_REL);
150
151}
152
153
154/**
155 * Entry point for the plugin.
156 *
157 * @param cls NULL
158 * @return the exported block API
159 */
160void *
161libgnunet_plugin_cmd_simple_send_init (void *cls)
162{
163 struct GNUNET_TESTING_PluginFunctions *api;
164
165 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
166 api->start_testcase = &start_testcase;
167 api->all_peers_started = &all_peers_started;
168 return api;
169}
170
171
172/**
173 * Exit point from the plugin.
174 *
175 * @param cls the return value from #libgnunet_plugin_block_test_init
176 * @return NULL
177 */
178void *
179libgnunet_plugin_cmd_simple_send_done (void *cls)
180{
181 struct GNUNET_TESTING_PluginFunctions *api = cls;
182
183 GNUNET_free (api);
184 return NULL;
185}
186
187
188/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_api2_tcp_node1.conf b/src/transport/test_transport_api2_tcp_node1.conf
new file mode 100644
index 000000000..a867ea81a
--- /dev/null
+++ b/src/transport/test_transport_api2_tcp_node1.conf
@@ -0,0 +1,23 @@
1@INLINE@ template_cfg_peer1.conf
2[PATHS]
3GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p1/
4
5[transport]
6BINARY = gnunet-service-tng
7PLUGINS = tcp
8#PREFIX = valgrind --log-file=/tmp/vg_peer1-%p
9UNIXPATH = $GNUNET_RUNTIME_DIR/tng-p1.sock
10
11[communicator-tcp]
12BINARY = gnunet-communicator-tcp
13BINDTO = 192.168.15.1:60002
14DISABLE_V6 = YES
15IMMEDIATE_START = YES
16UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p1.sock
17#PREFIX = valgrind --log-file=/tmp/vg_cpeer1-%p
18
19[peerstore]
20IMMEDIATE_START = YES
21
22#[transport]
23#PREFIX = valgrind
diff --git a/src/transport/test_transport_api2_tcp_node2.conf b/src/transport/test_transport_api2_tcp_node2.conf
new file mode 100644
index 000000000..f94368b3f
--- /dev/null
+++ b/src/transport/test_transport_api2_tcp_node2.conf
@@ -0,0 +1,22 @@
1@INLINE@ template_cfg_peer2.conf
2[PATHS]
3GNUNET_TEST_HOME = $GNUNET_TMP/test-transport/api-tcp-p2/
4
5[transport]
6BINARY = gnunet-service-tng
7#PREFIX = valgrind --log-file=/tmp/vg_peer2-%p
8UNIXPATH = $GNUNET_RUNTIME_DIR/tng-p2.sock
9
10[communicator-tcp]
11BINARY = gnunet-communicator-tcp
12BINDTO = 192.168.15.2:60003
13DISABLE_V6 = YES
14IMMEDIATE_START = YES
15#PREFIX = valgrind --log-file=/tmp/vg_comm2-%p
16UNIXPATH = $GNUNET_RUNTIME_DIR/tcp-comm-p2.sock
17
18[peerstore]
19IMMEDIATE_START = YES
20
21#[transport]
22#PREFIX = valgrind
diff --git a/src/transport/test_transport_api_cmd_simple_send.c b/src/transport/test_transport_api_cmd_simple_send.c
deleted file mode 100644
index 9ae8fcc2b..000000000
--- a/src/transport/test_transport_api_cmd_simple_send.c
+++ /dev/null
@@ -1,80 +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 transport/test_transport_api_cmd_simple_send.c
23 * @brief Test case executing a script which sends a test message between two peers.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_testbed_ng_service.h"
29#include "gnunet_util_lib.h"
30
31
32/**
33 * Main function to run the test cases.
34 *
35 * @param cls not used.
36 *
37 */
38static void
39run (void *cls)
40{
41 struct GNUNET_TESTING_Command commands[] = {
42 GNUNET_TESTBED_cmd_netjail_start ("netjail-start-1",
43 "2",
44 "1"),
45 GNUNET_TESTBED_cmd_netjail_start_testbed ("netjail-start-testbed-1",
46 "2",
47 "1",
48 "libgnunet_plugin_cmd_simple_send"),
49 GNUNET_TESTBED_cmd_stop_testbed ("stop-testbed",
50 "netjail-start-testbed-1",
51 "2",
52 "1"),
53 GNUNET_TESTBED_cmd_netjail_stop ("netjail-stop-1",
54 "2",
55 "1"),
56 GNUNET_TESTING_cmd_end ()
57 };
58
59 GNUNET_TESTING_run (NULL,
60 commands,
61 GNUNET_TIME_UNIT_FOREVER_REL);
62}
63
64
65int
66main (int argc,
67 char *const *argv)
68{
69 int rv = 0;
70
71 GNUNET_log_setup ("test-netjail",
72 "DEBUG",
73 NULL);
74 GNUNET_SCHEDULER_run (&run,
75 NULL);
76
77 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
78 "Test finished!\n");
79 return rv;
80}
diff --git a/src/transport/test_transport_plugin_cmd_simple_send.c b/src/transport/test_transport_plugin_cmd_simple_send.c
new file mode 100644
index 000000000..4b5018b60
--- /dev/null
+++ b/src/transport/test_transport_plugin_cmd_simple_send.c
@@ -0,0 +1,248 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file testbed/plugin_cmd_simple_send.c
23 * @brief a plugin to provide the API for running test cases.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_testing_ng_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_transport_application_service.h"
30#include "transport-testing2.h"
31#include "transport-testing-cmds.h"
32
33/**
34 * Generic logging shortcut
35 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37
38#define BASE_DIR "testdir"
39
40/**
41 * The name for a specific test environment directory.
42 *
43 */
44char *testdir;
45
46/**
47 * The name for the configuration file of the specific node.
48 *
49 */
50char *cfgname;
51
52/**
53 * Flag indicating if all peers have been started.
54 *
55 */
56unsigned int are_all_peers_started;
57
58
59/**
60 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE being
61 * received.
62 *
63 */
64static int
65check_test (void *cls,
66 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
67{
68 return GNUNET_OK;
69}
70
71
72/**
73 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE
74 * being received.
75 *
76 */
77static void
78handle_test (void *cls,
79 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
80{
81 LOG (GNUNET_ERROR_TYPE_ERROR,
82 "message received\n");
83}
84
85
86/**
87 * Function called to check a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
88 * being received.
89 *
90 */
91static int
92check_test2 (void *cls,
93 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
94{
95 return GNUNET_OK;
96}
97
98
99/**
100 * Function called to handle a message of type GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2
101 * being received.
102 *
103 */
104static void
105handle_test2 (void *cls,
106 const struct GNUNET_TRANSPORT_TESTING_TestMessage *message)
107{
108 LOG (GNUNET_ERROR_TYPE_ERROR,
109 "message received\n");
110}
111
112
113/**
114 * Callback to set the flag indicating all peers started. Will be called via the plugin api.
115 *
116 */
117static void
118all_peers_started ()
119{
120 are_all_peers_started = GNUNET_YES;
121 LOG (GNUNET_ERROR_TYPE_ERROR,
122 "setting are_all_peers_started: %d\n",
123 are_all_peers_started);
124}
125
126
127/**
128 * Function to start a local test case.
129 *
130 * @param write_message Callback to send a message to the master loop.
131 * @param router_ip Global address of the network namespace.
132 * @param node_ip Local address of a node i a network namespace.
133 * @param m The number of the node in a network namespace.
134 * @param n The number of the network namespace.
135 * @param local_m The number of nodes in a network namespace.
136 */
137static void
138start_testcase (TESTING_CMD_HELPER_write_cb write_message, char *router_ip,
139 char *node_ip,
140 char *m,
141 char *n,
142 char *local_m)
143{
144
145 GNUNET_asprintf (&cfgname,
146 "test_transport_api2_tcp_node%s.conf",
147 n);
148
149 LOG (GNUNET_ERROR_TYPE_ERROR,
150 "plugin cfgname: %s\n",
151 cfgname);
152
153 LOG (GNUNET_ERROR_TYPE_ERROR,
154 "node ip: %s\n",
155 node_ip);
156
157 GNUNET_asprintf (&testdir,
158 "%s%s%s",
159 BASE_DIR,
160 m,
161 n);
162
163 struct GNUNET_MQ_MessageHandler handlers[] = {
164 GNUNET_MQ_hd_var_size (test,
165 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE,
166 struct GNUNET_TRANSPORT_TESTING_TestMessage,
167 NULL),
168 GNUNET_MQ_hd_var_size (test2,
169 GNUNET_TRANSPORT_TESTING_SIMPLE_MTYPE2,
170 struct GNUNET_TRANSPORT_TESTING_TestMessage,
171 NULL),
172 GNUNET_MQ_handler_end ()
173 };
174
175 struct GNUNET_TESTING_Command commands[] = {
176 GNUNET_TESTING_cmd_system_create ("system-create",
177 testdir),
178 GNUNET_TRANSPORT_cmd_start_peer ("start-peer",
179 "system-create",
180 m,
181 n,
182 local_m,
183 handlers,
184 cfgname),
185 GNUNET_TESTING_cmd_send_peer_ready ("send-peer-ready",
186 write_message),
187 GNUNET_TESTING_cmd_block_until_all_peers_started ("block",
188 &are_all_peers_started),
189 GNUNET_TRANSPORT_cmd_connect_peers ("connect-peers",
190 "start-peer"),
191 GNUNET_TRANSPORT_cmd_send_simple ("send-simple",
192 m,
193 n,
194 (atoi (n) - 1) * atoi (local_m) + atoi (
195 m),
196 "start-peer"),
197 GNUNET_TRANSPORT_cmd_stop_peer ("stop-peer",
198 "start-peer"),
199 GNUNET_TESTING_cmd_system_destroy ("system-destroy",
200 "system-create"),
201 GNUNET_TESTING_cmd_local_test_finished ("local-test-finished",
202 write_message)
203 };
204
205 GNUNET_TESTING_run (NULL,
206 commands,
207 GNUNET_TIME_UNIT_FOREVER_REL);
208
209}
210
211
212/**
213 * Entry point for the plugin.
214 *
215 * @param cls NULL
216 * @return the exported block API
217 */
218void *
219libgnunet_test_transport_plugin_cmd_simple_send_init (void *cls)
220{
221 struct GNUNET_TESTING_PluginFunctions *api;
222
223 api = GNUNET_new (struct GNUNET_TESTING_PluginFunctions);
224 api->start_testcase = &start_testcase;
225 api->all_peers_started = &all_peers_started;
226 return api;
227}
228
229
230/**
231 * Exit point from the plugin.
232 *
233 * @param cls the return value from #libgnunet_test_transport_plugin_block_test_init
234 * @return NULL
235 */
236void *
237libgnunet_test_transport_plugin_cmd_simple_send_done (void *cls)
238{
239 struct GNUNET_TESTING_PluginFunctions *api = cls;
240
241 GNUNET_free (api);
242 GNUNET_free (testdir);
243 GNUNET_free (cfgname);
244 return NULL;
245}
246
247
248/* end of plugin_cmd_simple_send.c */
diff --git a/src/transport/test_transport_simple_send.sh b/src/transport/test_transport_simple_send.sh
new file mode 100755
index 000000000..25d5b6797
--- /dev/null
+++ b/src/transport/test_transport_simple_send.sh
@@ -0,0 +1,2 @@
1#!/bin/bash
2exec unshare -r -nmU bash -c "mount -t tmpfs --make-rshared tmpfs /run/netns; ./test_transport_simple_send"
diff --git a/src/transport/transport-testing-cmds.h b/src/transport/transport-testing-cmds.h
new file mode 100644
index 000000000..1461a3d4d
--- /dev/null
+++ b/src/transport/transport-testing-cmds.h
@@ -0,0 +1,81 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file transport-testing.h
23 * @brief testing lib for transport service
24 * @author Matthias Wachs
25 * @author Christian Grothoff
26 */
27#ifndef TRANSPORT_TESTING_CMDS_H
28#define TRANSPORT_TESTING_CMDS_H
29#include "gnunet_testing_lib.h"
30
31struct GNUNET_TESTING_Command
32GNUNET_TRANSPORT_cmd_start_peer (const char *label,
33 const char *system_label,
34 char *m,
35 char *n,
36 char *local_m,
37 struct GNUNET_MQ_MessageHandler *handlers,
38 const char *cfgname);
39
40struct GNUNET_TESTING_Command
41GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
42 const char *start_label);
43
44struct GNUNET_TESTING_Command
45GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
46 const char *start_peer_label);
47
48struct GNUNET_TESTING_Command
49GNUNET_TRANSPORT_cmd_send_simple (const char *label,
50 char *m,
51 char *n,
52 uint32_t num,
53 const char *start_peer_label);
54
55int
56GNUNET_TRANSPORT_get_trait_peer_id (const struct
57 GNUNET_TESTING_Command *cmd,
58 struct GNUNET_PeerIdentity **id);
59
60int
61GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
62 GNUNET_TESTING_Command
63 *cmd,
64 struct
65 GNUNET_CONTAINER_MultiShortmap *
66 *
67 connected_peers_map);
68int
69GNUNET_TRANSPORT_get_trait_hello_size (const struct
70 GNUNET_TESTING_Command
71 *cmd,
72 size_t **hello_size);
73
74int
75GNUNET_TRANSPORT_get_trait_hello (const struct
76 GNUNET_TESTING_Command
77 *cmd,
78 char **hello);
79
80#endif
81/* end of transport_testing.h */
diff --git a/src/transport/transport-testing-ng.h b/src/transport/transport-testing-ng.h
index cd5ba65a9..cd4e1f3fe 100644
--- a/src/transport/transport-testing-ng.h
+++ b/src/transport/transport-testing-ng.h
@@ -22,50 +22,86 @@
22 * @author t3sserakt 22 * @author t3sserakt
23 */ 23 */
24 24
25struct TngState 25struct StartPeerState
26{ 26{
27 /** 27 /**
28 * Handle to operation 28 * Receive callback
29 */ 29 */
30 struct GNUNET_TESTBED_Operation *operation; 30 struct GNUNET_MQ_MessageHandler *handlers;
31
32 const char *cfgname;
33
34 /**
35 * Peer's configuration
36 */
37 struct GNUNET_CONFIGURATION_Handle *cfg;
38
39 struct GNUNET_TESTING_Peer *peer;
31 40
32 /** 41 /**
33 * Flag indicating if service is ready. 42 * Peer identity
34 */ 43 */
35 int service_ready; 44 struct GNUNET_PeerIdentity id;
36 45
37 /** 46 /**
38 * Abort task identifier 47 * Peer's transport service handle
39 */ 48 */
40 struct GNUNET_SCHEDULER_Task *abort_task; 49 struct GNUNET_TRANSPORT_CoreHandle *th;
41 50
42 /** 51 /**
43 * Label of peer command. 52 * Application handle
44 */ 53 */
45 const char *peer_label; 54 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
46 55
47 /** 56 /**
48 * Name of service to start. 57 * Peer's PEERSTORE Handle
49 */ 58 */
50 const char *servicename; 59 struct GNUNET_PEERSTORE_Handle *ph;
51 60
52 /** 61 /**
53 * Peer identity of the system. 62 * Hello get task
54 */ 63 */
55 struct GNUNET_PeerIdentity *peer_identity; 64 struct GNUNET_SCHEDULER_Task *rh_task;
56 65
57 /** 66 /**
58 * Message handler for transport service. 67 * Peer's transport get hello handle to retrieve peer's HELLO message
59 */ 68 */
60 const struct GNUNET_MQ_MessageHandler *handlers; 69 struct GNUNET_PEERSTORE_IterateContext *pic;
61 70
62 /** 71 /**
63 * Notify connect callback 72 * Hello
64 */ 73 */
65 GNUNET_TRANSPORT_NotifyConnect nc; 74 char *hello;
75
76 /**
77 * Hello size
78 */
79 size_t hello_size;
80
81 char *m;
82
83 char *n;
84
85 char *local_m;
86
87 unsigned int finished;
88
89 const char *system_label;
66 90
67 /** 91 /**
68 * Closure for the @a nc callback 92 * An unique number to identify the peer
69 */ 93 */
70 void *cb_cls; 94 unsigned int no;
95
96 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
97
98 struct GNUNET_TESTING_System *tl_system;
99
71}; 100};
101
102
103int
104GNUNET_TRANSPORT_get_trait_state (const struct
105 GNUNET_TESTING_Command
106 *cmd,
107 struct StartPeerState **sps);
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
index a6732e308..e2167ca7e 100644
--- a/src/transport/transport-testing2.h
+++ b/src/transport/transport-testing2.h
@@ -920,42 +920,5 @@ GNUNET_TRANSPORT_TESTING_get_test_plugin_name (const char *executable,
920char * 920char *
921GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file); 921GNUNET_TRANSPORT_TESTING_get_test_source_name (const char *file);
922 922
923struct GNUNET_TESTING_Command
924GNUNET_TRANSPORT_cmd_start_peer (const char *label,
925 const char *system_label,
926 char *m,
927 char *n,
928 struct GNUNET_MQ_MessageHandler *handlers,
929 const char *cfgname);
930
931struct GNUNET_TESTING_Command
932GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
933 const char *peer1_label,
934 const char *peer2_label);
935
936int
937GNUNET_TRANSPORT_get_trait_peer_id (const struct
938 GNUNET_TESTING_Command *cmd,
939 struct GNUNET_PeerIdentity **id);
940
941int
942GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
943 GNUNET_TESTING_Command
944 *cmd,
945 struct
946 GNUNET_CONTAINER_MultiPeerMap **
947 connected_peers_map);
948int
949GNUNET_TRANSPORT_get_trait_hello_size (const struct
950 GNUNET_TESTING_Command
951 *cmd,
952 size_t **hello_size);
953
954int
955GNUNET_TRANSPORT_get_trait_hello (const struct
956 GNUNET_TESTING_Command
957 *cmd,
958 char **hello);
959
960#endif 923#endif
961/* end of transport_testing.h */ 924/* end of transport_testing.h */
diff --git a/src/transport/transport_api_cmd_connecting_peers.c b/src/transport/transport_api_cmd_connecting_peers.c
index 0f2154c46..34b3d5925 100644
--- a/src/transport/transport_api_cmd_connecting_peers.c
+++ b/src/transport/transport_api_cmd_connecting_peers.c
@@ -29,20 +29,37 @@
29#include "gnunet_transport_application_service.h" 29#include "gnunet_transport_application_service.h"
30#include "gnunet_hello_lib.h" 30#include "gnunet_hello_lib.h"
31#include "gnunet_transport_service.h" 31#include "gnunet_transport_service.h"
32#include "transport-testing-cmds.h"
32 33
33/** 34/**
34 * Generic logging shortcut 35 * Generic logging shortcut
35 */ 36 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37 38
39/**
40 * Struct to store information needed in callbacks.
41 *
42 */
38struct ConnectPeersState 43struct ConnectPeersState
39{ 44{
40 const char *peer1_label; 45 /**
41 46 * Label of the cmd to start a peer.
42 const char *peer2_label; 47 *
48 */
49 const char *start_peer_label;
50
51 /**
52 * The peer identity of this peer.
53 *
54 */
55 struct GNUNET_PeerIdentity *id;
43}; 56};
44 57
45 58
59/**
60 * The run method of this cmd will connect to peers.
61 *
62 */
46static void 63static void
47connect_peers_run (void *cls, 64connect_peers_run (void *cls,
48 const struct GNUNET_TESTING_Command *cmd, 65 const struct GNUNET_TESTING_Command *cmd,
@@ -50,25 +67,43 @@ connect_peers_run (void *cls,
50{ 67{
51 struct ConnectPeersState *cps = cls; 68 struct ConnectPeersState *cps = cls;
52 const struct GNUNET_TESTING_Command *peer1_cmd; 69 const struct GNUNET_TESTING_Command *peer1_cmd;
53 const struct GNUNET_TESTING_Command *peer2_cmd; 70 // const struct GNUNET_TESTING_Command *peer2_cmd;
54 struct GNUNET_TRANSPORT_ApplicationHandle *ah; 71 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
55 struct GNUNET_PeerIdentity *id; 72 struct GNUNET_PeerIdentity *peer = GNUNET_new (struct GNUNET_PeerIdentity);
56 char *addr; 73 char *addr;
57 struct GNUNET_TIME_Absolute t; 74 // struct GNUNET_TIME_Absolute t;
58 char *hello; 75 char *hello;
59 size_t *hello_size; 76 // size_t *hello_size;
60 enum GNUNET_NetworkType nt = 0; 77 enum GNUNET_NetworkType nt = 0;
78 char *peer_id;
79 struct GNUNET_PeerIdentity *id;
61 80
62 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); 81 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
63 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd, 82 GNUNET_TRANSPORT_get_trait_application_handle (peer1_cmd,
64 &ah); 83 &ah);
65 84
66 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd, 85 GNUNET_TRANSPORT_get_trait_hello (peer1_cmd,
67 &hello); 86 &hello);
68 87
69 LOG (GNUNET_ERROR_TYPE_ERROR, 88 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd,
70 "hello: %s\n", 89 &id);
71 hello); 90
91 if (strstr (hello, "60002") != NULL)
92 {
93 addr = "tcp-192.168.15.2:60003";
94 peer_id = "F2F3X9G1YNCTXKK7A4J6M4ZM4BBSKC9DEXZVHCWQ475M0C7PNWCG";
95 }
96 else
97 {
98 addr = "tcp-192.168.15.1:60002";
99 peer_id = "4TTC9WBSVP9RJT6DVEZ7E0TDW7TQXC11NR1EMR2F8ARS87WZ2730";
100 }
101
102 GNUNET_CRYPTO_eddsa_public_key_from_string (peer_id,
103 strlen (peer_id),
104 &peer->public_key);
105
106 cps->id = peer;
72 107
73 // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers. 108 // TODO This does not work, because the other peer is running in another local loop. We need to message between different local loops. For now we will create the hello manually with the known information about the other local peers.
74 // --------------------------------------------- 109 // ---------------------------------------------
@@ -84,50 +119,63 @@ connect_peers_run (void *cls,
84 *hello_size, 119 *hello_size,
85 id, 120 id,
86 &nt, 121 &nt,
87 &t); 122 &t);*/
123
124 // ----------------------------------------------
88 125
89 //----------------------------------------------
90 126
91 GNUNET_TRANSPORT_application_validate (ah, 127 GNUNET_TRANSPORT_application_validate (ah,
92 id, 128 peer,
93 nt, 129 nt,
94 addr);*/ 130 addr);
95} 131}
96 132
97 133
134/**
135 * The finish function of this cmd will check if the peer we are trying to connect to is in the connected peers map of the start peer cmd for this peer.
136 *
137 */
98static int 138static int
99connect_peers_finish (void *cls, 139connect_peers_finish (void *cls,
100 GNUNET_SCHEDULER_TaskCallback cont, 140 GNUNET_SCHEDULER_TaskCallback cont,
101 void *cont_cls) 141 void *cont_cls)
102{ 142{
103 /*struct ConnectPeersState *cps = cls; 143 struct ConnectPeersState *cps = cls;
104 const struct GNUNET_TESTING_Command *peer1_cmd; 144 const struct GNUNET_TESTING_Command *peer1_cmd;
105 const struct GNUNET_TESTING_Command *peer2_cmd; 145 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
106 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
107 unsigned int ret; 146 unsigned int ret;
108 struct GNUNET_PeerIdentity *id; 147 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
148 struct GNUNET_HashCode hc;
149 int node_number;
109 150
110 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer1_label); 151 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->start_peer_label);
111 GNUNET_TRANSPORT_get_trait_peer_id (peer1_cmd, 152 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
112 &id); 153 &connected_peers_map);
113 154
114 peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (cps->peer2_label); 155 node_number = 1;
115 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer2_cmd, 156 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
116 &connected_peers_map);
117 157
118 ret = GNUNET_CONTAINER_multipeermap_contains (connected_peers_map, 158 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
119 id); 159 memcpy (key,
160 &hc,
161 sizeof (*key));
162 ret = GNUNET_CONTAINER_multishortmap_contains (connected_peers_map,
163 key);
120 164
121 if (GNUNET_YES == ret) 165 if (GNUNET_YES == ret)
122 { 166 {
123 cont (cont_cls); 167 cont (cont_cls);
124 } 168 }
125 169
126 return ret;*/ 170 GNUNET_free (key);
127 return GNUNET_OK; 171 return ret;
128} 172}
129 173
130 174
175/**
176 * Trait function of this cmd does nothing.
177 *
178 */
131static int 179static int
132connect_peers_traits (void *cls, 180connect_peers_traits (void *cls,
133 const void **ret, 181 const void **ret,
@@ -138,12 +186,17 @@ connect_peers_traits (void *cls,
138} 186}
139 187
140 188
189/**
190 * The cleanup function of this cmd frees resources the cmd allocated.
191 *
192 */
141static void 193static void
142connect_peers_cleanup (void *cls, 194connect_peers_cleanup (void *cls,
143 const struct GNUNET_TESTING_Command *cmd) 195 const struct GNUNET_TESTING_Command *cmd)
144{ 196{
145 struct ConnectPeersState *cps = cls; 197 struct ConnectPeersState *cps = cls;
146 198
199 GNUNET_free (cps->id);
147 GNUNET_free (cps); 200 GNUNET_free (cps);
148} 201}
149 202
@@ -152,18 +205,17 @@ connect_peers_cleanup (void *cls,
152 * Create command. 205 * Create command.
153 * 206 *
154 * @param label name for command. 207 * @param label name for command.
208 * @param start_peer_label Label of the cmd to start a peer.
155 * @return command. 209 * @return command.
156 */ 210 */
157struct GNUNET_TESTING_Command 211struct GNUNET_TESTING_Command
158GNUNET_TRANSPORT_cmd_connect_peers (const char *label, 212GNUNET_TRANSPORT_cmd_connect_peers (const char *label,
159 const char *peer1_label, 213 const char *start_peer_label)
160 const char *peer2_label)
161{ 214{
162 struct ConnectPeersState *cps; 215 struct ConnectPeersState *cps;
163 216
164 cps = GNUNET_new (struct ConnectPeersState); 217 cps = GNUNET_new (struct ConnectPeersState);
165 cps->peer1_label = peer1_label; 218 cps->start_peer_label = start_peer_label;
166 cps->peer2_label = peer2_label;
167 219
168 220
169 struct GNUNET_TESTING_Command cmd = { 221 struct GNUNET_TESTING_Command cmd = {
diff --git a/src/transport/transport_api_cmd_send_simple.c b/src/transport/transport_api_cmd_send_simple.c
index 4a60f1a12..f9e515c0f 100644
--- a/src/transport/transport_api_cmd_send_simple.c
+++ b/src/transport/transport_api_cmd_send_simple.c
@@ -26,21 +26,45 @@
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 "transport-testing.h" 29#include "transport-testing2.h"
30#include "transport-testing-cmds.h"
30 31
32/**
33 * Struct to hold information for callbacks.
34 *
35 */
31struct SendSimpleState 36struct SendSimpleState
32{ 37{
38 /**
39 * The number of the local node of the actual network namespace.
40 *
41 */
33 char *m; 42 char *m;
34 43
44 /**
45 * The number of the actual namespace.
46 *
47 */
35 char *n; 48 char *n;
36 49
50 /**
51 * Number globally identifying the node.
52 *
53 */
37 uint32_t num; 54 uint32_t num;
38 55
39 const char *peer1_label; 56 /**
40 57 * Label of the cmd to start a peer.
41 const char *peer2_label; 58 *
59 */
60 const char *start_peer_label;
42}; 61};
43 62
63
64/**
65 * Trait function of this cmd does nothing.
66 *
67 */
44static int 68static int
45send_simple_traits (void *cls, 69send_simple_traits (void *cls,
46 const void **ret, 70 const void **ret,
@@ -51,6 +75,10 @@ send_simple_traits (void *cls,
51} 75}
52 76
53 77
78/**
79 * The cleanup function of this cmd frees resources the cmd allocated.
80 *
81 */
54static void 82static void
55send_simple_cleanup (void *cls, 83send_simple_cleanup (void *cls,
56 const struct GNUNET_TESTING_Command *cmd) 84 const struct GNUNET_TESTING_Command *cmd)
@@ -61,6 +89,10 @@ send_simple_cleanup (void *cls,
61} 89}
62 90
63 91
92/**
93 * The run method of this cmd will send a simple message to the connected peer.
94 *
95 */
64static void 96static void
65send_simple_run (void *cls, 97send_simple_run (void *cls,
66 const struct GNUNET_TESTING_Command *cmd, 98 const struct GNUNET_TESTING_Command *cmd,
@@ -70,21 +102,24 @@ send_simple_run (void *cls,
70 struct GNUNET_MQ_Envelope *env; 102 struct GNUNET_MQ_Envelope *env;
71 struct GNUNET_TRANSPORT_TESTING_TestMessage *test; 103 struct GNUNET_TRANSPORT_TESTING_TestMessage *test;
72 struct GNUNET_MQ_Handle *mq; 104 struct GNUNET_MQ_Handle *mq;
73 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map; 105 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map;
74 struct GNUNET_PeerIdentity *id;
75 const struct GNUNET_TESTING_Command *peer1_cmd; 106 const struct GNUNET_TESTING_Command *peer1_cmd;
76 const struct GNUNET_TESTING_Command *peer2_cmd; 107 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
108 struct GNUNET_HashCode hc;
109 int node_number;
77 110
78 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer1_label); 111 peer1_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->start_peer_label);
79 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd, 112 GNUNET_TRANSPORT_get_trait_connected_peers_map (peer1_cmd,
80 &connected_peers_map); 113 &connected_peers_map);
81 114
82 peer2_cmd = GNUNET_TESTING_interpreter_lookup_command (sss->peer2_label); 115 node_number = 1;
83 GNUNET_TRANSPORT_get_trait_peer_id (peer2_cmd, 116 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
84 &id); 117 memcpy (key,
118 &hc,
119 sizeof (*key));
85 120
86 mq = GNUNET_CONTAINER_multipeermap_get (connected_peers_map, 121 mq = GNUNET_CONTAINER_multishortmap_get (connected_peers_map,
87 id); 122 key);
88 123
89 env = GNUNET_MQ_msg_extra (test, 124 env = GNUNET_MQ_msg_extra (test,
90 2600 - sizeof(*test), 125 2600 - sizeof(*test),
@@ -93,12 +128,9 @@ send_simple_run (void *cls,
93 memset (&test[1], 128 memset (&test[1],
94 sss->num, 129 sss->num,
95 2600 - sizeof(*test)); 130 2600 - sizeof(*test));
96 /*GNUNET_MQ_notify_sent (env,
97 cont,
98 cont_cls);*/
99 GNUNET_MQ_send (mq, 131 GNUNET_MQ_send (mq,
100 env); 132 env);
101 133 GNUNET_free (key);
102 134
103} 135}
104 136
@@ -107,15 +139,18 @@ send_simple_run (void *cls,
107 * Create command. 139 * Create command.
108 * 140 *
109 * @param label name for command. 141 * @param label name for command.
142 * @param m The number of the local node of the actual network namespace.
143 * @param n The number of the actual namespace.
144 * @param num Number globally identifying the node.
145 * @param start_peer_label Label of the cmd to start a peer.
110 * @return command. 146 * @return command.
111 */ 147 */
112struct GNUNET_TESTING_Command 148struct GNUNET_TESTING_Command
113GNUNET_TESTING_cmd_send_simple (const char *label, 149GNUNET_TRANSPORT_cmd_send_simple (const char *label,
114 char *m, 150 char *m,
115 char *n, 151 char *n,
116 uint32_t num, 152 uint32_t num,
117 const char *peer1_label, 153 const char *start_peer_label)
118 const char *peer2_label)
119{ 154{
120 struct SendSimpleState *sss; 155 struct SendSimpleState *sss;
121 156
@@ -123,6 +158,7 @@ GNUNET_TESTING_cmd_send_simple (const char *label,
123 sss->m = m; 158 sss->m = m;
124 sss->n = n; 159 sss->n = n;
125 sss->num = num; 160 sss->num = num;
161 sss->start_peer_label = start_peer_label;
126 162
127 struct GNUNET_TESTING_Command cmd = { 163 struct GNUNET_TESTING_Command cmd = {
128 .cls = sss, 164 .cls = sss,
diff --git a/src/transport/transport_api_cmd_start_peer.c b/src/transport/transport_api_cmd_start_peer.c
index c9af497ae..729d981c0 100644
--- a/src/transport/transport_api_cmd_start_peer.c
+++ b/src/transport/transport_api_cmd_start_peer.c
@@ -29,91 +29,22 @@
29#include "gnunet_peerstore_service.h" 29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h" 30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h" 31#include "gnunet_transport_application_service.h"
32#include "transport-testing-ng.h"
32 33
33/** 34/**
34 * Generic logging shortcut 35 * Generic logging shortcut
35 */ 36 */
36#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__) 37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
37 38
38struct StartPeerState
39{
40 /**
41 * Receive callback
42 */
43 struct GNUNET_MQ_MessageHandler *handlers;
44
45 const char *cfgname;
46
47 /**
48 * Peer's configuration
49 */
50 struct GNUNET_CONFIGURATION_Handle *cfg;
51
52 struct GNUNET_TESTING_Peer *peer;
53
54 /**
55 * Peer identity
56 */
57 struct GNUNET_PeerIdentity *id;
58
59 /**
60 * Peer's transport service handle
61 */
62 struct GNUNET_TRANSPORT_CoreHandle *th;
63
64 /**
65 * Application handle
66 */
67 struct GNUNET_TRANSPORT_ApplicationHandle *ah;
68
69 /**
70 * Peer's PEERSTORE Handle
71 */
72 struct GNUNET_PEERSTORE_Handle *ph;
73
74 /**
75 * Hello get task
76 */
77 struct GNUNET_SCHEDULER_Task *rh_task;
78
79 /**
80 * Peer's transport get hello handle to retrieve peer's HELLO message
81 */
82 struct GNUNET_PEERSTORE_IterateContext *pic;
83
84 /**
85 * Hello
86 */
87 char *hello;
88
89 /**
90 * Hello size
91 */
92 size_t hello_size;
93
94 char *m;
95
96 char *n;
97
98 unsigned int finished;
99
100 const char *system_label;
101
102 /**
103 * An unique number to identify the peer
104 */
105 unsigned int no;
106
107 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map;
108
109 struct GNUNET_TESTING_System *tl_system;
110
111};
112
113 39
114static void 40static void
115retrieve_hello (void *cls); 41retrieve_hello (void *cls);
116 42
43
44/**
45 * Callback delivering the hello of this peer from peerstore.
46 *
47 */
117static void 48static void
118hello_iter_cb (void *cb_cls, 49hello_iter_cb (void *cb_cls,
119 const struct GNUNET_PEERSTORE_Record *record, 50 const struct GNUNET_PEERSTORE_Record *record,
@@ -138,6 +69,11 @@ hello_iter_cb (void *cb_cls,
138} 69}
139 70
140 71
72/**
73 * Function to start the retrieval task to retrieve the hello of this peer
74 * from the peerstore.
75 *
76 */
141static void 77static void
142retrieve_hello (void *cls) 78retrieve_hello (void *cls)
143{ 79{
@@ -145,13 +81,18 @@ retrieve_hello (void *cls)
145 sps->rh_task = NULL; 81 sps->rh_task = NULL;
146 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph, 82 sps->pic = GNUNET_PEERSTORE_iterate (sps->ph,
147 "transport", 83 "transport",
148 sps->id, 84 &sps->id,
149 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY, 85 GNUNET_PEERSTORE_TRANSPORT_HELLO_KEY,
150 hello_iter_cb, 86 hello_iter_cb,
151 sps); 87 sps);
152 88
153} 89}
154 90
91
92/**
93 * This function checks StartPeerState#finished, which is set when the hello was retrieved.
94 *
95 */
155static int 96static int
156start_peer_finish (void *cls, 97start_peer_finish (void *cls,
157 GNUNET_SCHEDULER_TaskCallback cont, 98 GNUNET_SCHEDULER_TaskCallback cont,
@@ -168,6 +109,10 @@ start_peer_finish (void *cls,
168} 109}
169 110
170 111
112/**
113 * Disconnect callback for the connection to the core service.
114 *
115 */
171static void 116static void
172notify_disconnect (void *cls, 117notify_disconnect (void *cls,
173 const struct GNUNET_PeerIdentity *peer, 118 const struct GNUNET_PeerIdentity *peer,
@@ -179,38 +124,57 @@ notify_disconnect (void *cls,
179 "Peer %s disconnected from peer %u (`%s')\n", 124 "Peer %s disconnected from peer %u (`%s')\n",
180 GNUNET_i2s (peer), 125 GNUNET_i2s (peer),
181 sps->no, 126 sps->no,
182 GNUNET_i2s (sps->id)); 127 GNUNET_i2s (&sps->id));
183 128
184} 129}
185 130
186 131
132/**
133 * Connect callback for the connection to the core service.
134 *
135 */
187static void * 136static void *
188notify_connect (void *cls, 137notify_connect (void *cls,
189 const struct GNUNET_PeerIdentity *peer, 138 const struct GNUNET_PeerIdentity *peer,
190 struct GNUNET_MQ_Handle *mq) 139 struct GNUNET_MQ_Handle *mq)
191{ 140{
192 struct StartPeerState *sps = cls; 141 struct StartPeerState *sps = cls;
142 struct GNUNET_ShortHashCode *key = GNUNET_new (struct GNUNET_ShortHashCode);
143 struct GNUNET_HashCode hc;
144 int node_number;
193 145
194 146 void *ret = NULL;
195 void *ret;
196 147
197 148
198 LOG (GNUNET_ERROR_TYPE_DEBUG, 149 LOG (GNUNET_ERROR_TYPE_DEBUG,
199 "Peer %s connected to peer %u (`%s')\n", 150 "Peer %s connected to peer %u (`%s')\n",
200 GNUNET_i2s (peer), 151 GNUNET_i2s (peer),
201 sps->no, 152 sps->no,
202 GNUNET_i2s (sps->id)); 153 GNUNET_i2s (&sps->id));
154
155 // TODO we need to store with a key identifying the netns node in the future. For now we have only one connecting node.
156 node_number = 1;
157 GNUNET_CRYPTO_hash (&node_number, sizeof(node_number), &hc);
158
203 159
204 GNUNET_CONTAINER_multipeermap_put (sps->connected_peers_map, 160 memcpy (key,
205 peer, 161 &hc,
206 mq, 162 sizeof (*key));
207 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 163 GNUNET_CONTAINER_multishortmap_put (sps->connected_peers_map,
164 key,
165 mq,
166 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
208 167
168 GNUNET_free (key);
209 // TODO what does the handler function need? 169 // TODO what does the handler function need?
210 return ret; 170 return ret;
211} 171}
212 172
213 173
174/**
175 * The run method of this cmd will start all services of a peer to test the transport service.
176 *
177 */
214static void 178static void
215start_peer_run (void *cls, 179start_peer_run (void *cls,
216 const struct GNUNET_TESTING_Command *cmd, 180 const struct GNUNET_TESTING_Command *cmd,
@@ -251,6 +215,7 @@ start_peer_run (void *cls,
251 sps->cfgname); 215 sps->cfgname);
252 GNUNET_CONFIGURATION_destroy (sps->cfg); 216 GNUNET_CONFIGURATION_destroy (sps->cfg);
253 GNUNET_TESTING_interpreter_fail (); 217 GNUNET_TESTING_interpreter_fail ();
218 return;
254 } 219 }
255 220
256 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system, 221 sps->peer = GNUNET_TESTING_peer_configure (sps->tl_system,
@@ -266,6 +231,7 @@ start_peer_run (void *cls,
266 emsg); 231 emsg);
267 GNUNET_free (emsg); 232 GNUNET_free (emsg);
268 GNUNET_TESTING_interpreter_fail (); 233 GNUNET_TESTING_interpreter_fail ();
234 return;
269 } 235 }
270 236
271 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer)) 237 if (GNUNET_OK != GNUNET_TESTING_peer_start (sps->peer))
@@ -275,13 +241,16 @@ start_peer_run (void *cls,
275 sps->cfgname); 241 sps->cfgname);
276 GNUNET_free (emsg); 242 GNUNET_free (emsg);
277 GNUNET_TESTING_interpreter_fail (); 243 GNUNET_TESTING_interpreter_fail ();
244 return;
278 } 245 }
279 246
280 memset (&dummy, 247 memset (&dummy,
281 '\0', 248 '\0',
282 sizeof(dummy)); 249 sizeof(dummy));
250
283 GNUNET_TESTING_peer_get_identity (sps->peer, 251 GNUNET_TESTING_peer_get_identity (sps->peer,
284 sps->id); 252 &sps->id);
253
285 if (0 == memcmp (&dummy, 254 if (0 == memcmp (&dummy,
286 &sps->id, 255 &sps->id,
287 sizeof(struct GNUNET_PeerIdentity))) 256 sizeof(struct GNUNET_PeerIdentity)))
@@ -291,11 +260,13 @@ start_peer_run (void *cls,
291 sps->no); 260 sps->no);
292 GNUNET_free (emsg); 261 GNUNET_free (emsg);
293 GNUNET_TESTING_interpreter_fail (); 262 GNUNET_TESTING_interpreter_fail ();
263 return;
294 } 264 }
295 LOG (GNUNET_ERROR_TYPE_DEBUG, 265 LOG (GNUNET_ERROR_TYPE_DEBUG,
296 "Peer %u configured with identity `%s'\n", 266 "Peer %u configured with identity `%s'\n",
297 sps->no, 267 sps->no,
298 GNUNET_i2s_full (sps->id)); 268 GNUNET_i2s_full (&sps->id));
269
299 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg, 270 sps->th = GNUNET_TRANSPORT_core_connect (sps->cfg,
300 NULL, 271 NULL,
301 sps->handlers, 272 sps->handlers,
@@ -310,7 +281,9 @@ start_peer_run (void *cls,
310 emsg); 281 emsg);
311 GNUNET_free (emsg); 282 GNUNET_free (emsg);
312 GNUNET_TESTING_interpreter_fail (); 283 GNUNET_TESTING_interpreter_fail ();
284 return;
313 } 285 }
286
314 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg); 287 sps->ph = GNUNET_PEERSTORE_connect (sps->cfg);
315 if (NULL == sps->th) 288 if (NULL == sps->th)
316 { 289 {
@@ -320,7 +293,9 @@ start_peer_run (void *cls,
320 emsg); 293 emsg);
321 GNUNET_free (emsg); 294 GNUNET_free (emsg);
322 GNUNET_TESTING_interpreter_fail (); 295 GNUNET_TESTING_interpreter_fail ();
296 return;
323 } 297 }
298
324 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg); 299 sps->ah = GNUNET_TRANSPORT_application_init (sps->cfg);
325 if (NULL == sps->ah) 300 if (NULL == sps->ah)
326 { 301 {
@@ -330,32 +305,22 @@ start_peer_run (void *cls,
330 emsg); 305 emsg);
331 GNUNET_free (emsg); 306 GNUNET_free (emsg);
332 GNUNET_TESTING_interpreter_fail (); 307 GNUNET_TESTING_interpreter_fail ();
308 return;
333 } 309 }
334 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps); 310 sps->rh_task = GNUNET_SCHEDULER_add_now (retrieve_hello, sps);
335} 311}
336 312
337 313
314/**
315 * The cleanup function of this cmd frees resources the cmd allocated.
316 *
317 */
338static void 318static void
339start_peer_cleanup (void *cls, 319start_peer_cleanup (void *cls,
340 const struct GNUNET_TESTING_Command *cmd) 320 const struct GNUNET_TESTING_Command *cmd)
341{ 321{
342 struct StartPeerState *sps = cls; 322 struct StartPeerState *sps = cls;
343 323
344 if (NULL != sps->rh_task)
345 GNUNET_SCHEDULER_cancel (sps->rh_task);
346 sps->rh_task = NULL;
347 if (NULL != sps->ah)
348 {
349 GNUNET_TRANSPORT_application_done (sps->ah);
350 sps->ah = NULL;
351 }
352 if (NULL != sps->ph)
353 {
354 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
355 "Disconnecting from PEERSTORE service\n");
356 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
357 sps->ph = NULL;
358 }
359 if (NULL != sps->handlers) 324 if (NULL != sps->handlers)
360 { 325 {
361 GNUNET_free (sps->handlers); 326 GNUNET_free (sps->handlers);
@@ -366,34 +331,16 @@ start_peer_cleanup (void *cls,
366 GNUNET_CONFIGURATION_destroy (sps->cfg); 331 GNUNET_CONFIGURATION_destroy (sps->cfg);
367 sps->cfg = NULL; 332 sps->cfg = NULL;
368 } 333 }
369 if (NULL != sps->peer)
370 {
371 if (GNUNET_OK !=
372 GNUNET_TESTING_peer_stop (sps->peer))
373 {
374 LOG (GNUNET_ERROR_TYPE_DEBUG,
375 "Testing lib failed to stop peer %u (`%s')\n",
376 sps->no,
377 GNUNET_i2s (sps->id));
378 }
379 GNUNET_TESTING_peer_destroy (sps->peer);
380 sps->peer = NULL;
381 }
382 if (NULL != sps->th)
383 {
384 GNUNET_TRANSPORT_core_disconnect (sps->th);
385 sps->th = NULL;
386 }
387 if (NULL != sps->tl_system)
388 {
389 GNUNET_free (sps->tl_system);
390 }
391 GNUNET_free (sps->hello); 334 GNUNET_free (sps->hello);
392 GNUNET_free (sps->connected_peers_map); 335 GNUNET_free (sps->connected_peers_map);
393 GNUNET_free (sps); 336 GNUNET_free (sps);
394} 337}
395 338
396 339
340/**
341 * This function prepares an array with traits.
342 *
343 */
397static int 344static int
398start_peer_traits (void *cls, 345start_peer_traits (void *cls,
399 const void **ret, 346 const void **ret,
@@ -402,8 +349,8 @@ start_peer_traits (void *cls,
402{ 349{
403 struct StartPeerState *sps = cls; 350 struct StartPeerState *sps = cls;
404 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah; 351 struct GNUNET_TRANSPORT_ApplicationHandle *ah = sps->ah;
405 struct GNUNET_PeerIdentity *id = sps->id; 352 struct GNUNET_PeerIdentity *id = &sps->id;
406 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map = 353 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
407 sps->connected_peers_map; 354 sps->connected_peers_map;
408 char *hello = sps->hello; 355 char *hello = sps->hello;
409 size_t hello_size = sps->hello_size; 356 size_t hello_size = sps->hello_size;
@@ -435,6 +382,11 @@ start_peer_traits (void *cls,
435 .trait_name = "hello_size", 382 .trait_name = "hello_size",
436 .ptr = (const void *) hello_size, 383 .ptr = (const void *) hello_size,
437 }, 384 },
385 {
386 .index = 5,
387 .trait_name = "state",
388 .ptr = (const void *) sps,
389 },
438 GNUNET_TESTING_trait_end () 390 GNUNET_TESTING_trait_end ()
439 }; 391 };
440 392
@@ -444,6 +396,34 @@ start_peer_traits (void *cls,
444 index); 396 index);
445} 397}
446 398
399
400/**
401 * Function to get the trait with the struct StartPeerState.
402 *
403 * @param[out] sps struct StartPeerState.
404 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
405 *
406 */
407int
408GNUNET_TRANSPORT_get_trait_state (const struct
409 GNUNET_TESTING_Command
410 *cmd,
411 struct StartPeerState **sps)
412{
413 return cmd->traits (cmd->cls,
414 (const void **) sps,
415 "state",
416 (unsigned int) 5);
417}
418
419
420/**
421 * Function to get the trait with the size of the hello.
422 *
423 * @param[out] hello_size size of hello.
424 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
425 *
426 */
447int 427int
448GNUNET_TRANSPORT_get_trait_hello_size (const struct 428GNUNET_TRANSPORT_get_trait_hello_size (const struct
449 GNUNET_TESTING_Command 429 GNUNET_TESTING_Command
@@ -456,6 +436,14 @@ GNUNET_TRANSPORT_get_trait_hello_size (const struct
456 (unsigned int) 4); 436 (unsigned int) 4);
457} 437}
458 438
439
440/**
441 * Function to get the trait with the hello.
442 *
443 * @param[out] hello The hello for the peer.
444 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
445 *
446 */
459int 447int
460GNUNET_TRANSPORT_get_trait_hello (const struct 448GNUNET_TRANSPORT_get_trait_hello (const struct
461 GNUNET_TESTING_Command 449 GNUNET_TESTING_Command
@@ -468,12 +456,21 @@ GNUNET_TRANSPORT_get_trait_hello (const struct
468 (unsigned int) 3); 456 (unsigned int) 3);
469} 457}
470 458
459
460/**
461 * Function to get the trait with the map of connected peers.
462 *
463 * @param[out] connected_peers_map The map with connected peers.
464 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
465 *
466 */
471int 467int
472GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct 468GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
473 GNUNET_TESTING_Command 469 GNUNET_TESTING_Command
474 *cmd, 470 *cmd,
475 struct 471 struct
476 GNUNET_CONTAINER_MultiPeerMap ** 472 GNUNET_CONTAINER_MultiShortmap *
473 *
477 connected_peers_map) 474 connected_peers_map)
478{ 475{
479 return cmd->traits (cmd->cls, 476 return cmd->traits (cmd->cls,
@@ -483,6 +480,12 @@ GNUNET_TRANSPORT_get_trait_connected_peers_map (const struct
483} 480}
484 481
485 482
483/**
484 * Function to get the trait with the transport application handle.
485 *
486 * @param[out] ah The application handle.
487 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
488 */
486int 489int
487GNUNET_TRANSPORT_get_trait_application_handle (const struct 490GNUNET_TRANSPORT_get_trait_application_handle (const struct
488 GNUNET_TESTING_Command *cmd, 491 GNUNET_TESTING_Command *cmd,
@@ -497,6 +500,12 @@ GNUNET_TRANSPORT_get_trait_application_handle (const struct
497} 500}
498 501
499 502
503/**
504 * Function to get the trait with the peer id.
505 *
506 * @param[out] id The peer id.
507 * @return #GNUNET_OK if no error occurred, #GNUNET_SYSERR otherwise.
508 */
500int 509int
501GNUNET_TRANSPORT_get_trait_peer_id (const struct 510GNUNET_TRANSPORT_get_trait_peer_id (const struct
502 GNUNET_TESTING_Command *cmd, 511 GNUNET_TESTING_Command *cmd,
@@ -513,6 +522,12 @@ GNUNET_TRANSPORT_get_trait_peer_id (const struct
513 * Create command. 522 * Create command.
514 * 523 *
515 * @param label name for command. 524 * @param label name for command.
525 * @param system_label Label of the cmd to setup a test environment.
526 * @param m The number of the local node of the actual network namespace.
527 * @param n The number of the actual namespace.
528 * @param local_m Number of local nodes in each namespace.
529 * @param handlers Handler for messages received by this peer.
530 * @param cfgname Configuration file name for this peer.
516 * @return command. 531 * @return command.
517 */ 532 */
518struct GNUNET_TESTING_Command 533struct GNUNET_TESTING_Command
@@ -520,17 +535,20 @@ GNUNET_TRANSPORT_cmd_start_peer (const char *label,
520 const char *system_label, 535 const char *system_label,
521 char *m, 536 char *m,
522 char *n, 537 char *n,
538 char *local_m,
523 struct GNUNET_MQ_MessageHandler *handlers, 539 struct GNUNET_MQ_MessageHandler *handlers,
524 const char *cfgname) 540 const char *cfgname)
525{ 541{
526 struct StartPeerState *sps; 542 struct StartPeerState *sps;
527 struct GNUNET_CONTAINER_MultiPeerMap *connected_peers_map = 543 struct GNUNET_CONTAINER_MultiShortmap *connected_peers_map =
528 GNUNET_CONTAINER_multipeermap_create (1,GNUNET_NO); 544 GNUNET_CONTAINER_multishortmap_create (1,GNUNET_NO);
529 unsigned int i; 545 unsigned int i;
530 546
531 sps = GNUNET_new (struct StartPeerState); 547 sps = GNUNET_new (struct StartPeerState);
532 sps->m = m; 548 sps->m = m;
533 sps->n = n; 549 sps->n = n;
550 sps->local_m = local_m;
551 sps->no = (atoi (n) - 1) * atoi (sps->local_m) + atoi (m);
534 sps->system_label = system_label; 552 sps->system_label = system_label;
535 sps->connected_peers_map = connected_peers_map; 553 sps->connected_peers_map = connected_peers_map;
536 sps->cfgname = cfgname; 554 sps->cfgname = cfgname;
diff --git a/src/transport/transport_api_cmd_stop_peer.c b/src/transport/transport_api_cmd_stop_peer.c
new file mode 100644
index 000000000..7a0050a63
--- /dev/null
+++ b/src/transport/transport_api_cmd_stop_peer.c
@@ -0,0 +1,163 @@
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_stop_peer.c
23 * @brief cmd to stop a peer.
24 * @author t3sserakt
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testing_ng_lib.h"
29#include "gnunet_peerstore_service.h"
30#include "gnunet_transport_core_service.h"
31#include "gnunet_transport_application_service.h"
32#include "transport-testing-ng.h"
33
34/**
35 * Generic logging shortcut
36 */
37#define LOG(kind, ...) GNUNET_log (kind, __VA_ARGS__)
38
39
40/**
41 * Struct to hold information for callbacks.
42 *
43 */
44struct StopPeerState
45{
46 // Label of the cmd to start the peer.
47 const char *start_label;
48};
49
50
51/**
52 * The run method of this cmd will stop all services of a peer which were used to test the transport service.
53 *
54 */
55static void
56stop_peer_run (void *cls,
57 const struct GNUNET_TESTING_Command *cmd,
58 struct GNUNET_TESTING_Interpreter *is)
59{
60 struct StopPeerState *stop_ps = cls;
61 struct StartPeerState *sps;
62 const struct GNUNET_TESTING_Command *start_cmd;
63
64 start_cmd = GNUNET_TESTING_interpreter_lookup_command (stop_ps->start_label);
65 GNUNET_TRANSPORT_get_trait_state (start_cmd,
66 &sps);
67
68 if (NULL != sps->pic)
69 {
70 GNUNET_PEERSTORE_iterate_cancel (sps->pic);
71 sps->pic = NULL;
72 }
73 if (NULL != sps->th)
74 {
75 GNUNET_TRANSPORT_core_disconnect (sps->th);
76 sps->th = NULL;
77 }
78 if (NULL != sps->ah)
79 {
80 GNUNET_TRANSPORT_application_done (sps->ah);
81 sps->ah = NULL;
82 }
83 if (NULL != sps->ph)
84 {
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Disconnecting from PEERSTORE service\n");
87 GNUNET_PEERSTORE_disconnect (sps->ph, GNUNET_NO);
88 sps->ph = NULL;
89 }
90 if (NULL != sps->peer)
91 {
92 if (GNUNET_OK !=
93 GNUNET_TESTING_peer_stop (sps->peer))
94 {
95 LOG (GNUNET_ERROR_TYPE_ERROR,
96 "Testing lib failed to stop peer %u (`%s')\n",
97 sps->no,
98 GNUNET_i2s (&sps->id));
99 }
100 GNUNET_TESTING_peer_destroy (sps->peer);
101 sps->peer = NULL;
102 }
103 if (NULL != sps->rh_task)
104 GNUNET_SCHEDULER_cancel (sps->rh_task);
105 sps->rh_task = NULL;
106
107}
108
109
110/**
111 * The cleanup function of this cmd frees resources the cmd allocated.
112 *
113 */
114static void
115stop_peer_cleanup (void *cls,
116 const struct GNUNET_TESTING_Command *cmd)
117{
118 struct StopPeerState *sps = cls;
119
120 GNUNET_free (sps);
121}
122
123
124/**
125 * Trait function of this cmd does nothing.
126 *
127 */
128static int
129stop_peer_traits (void *cls,
130 const void **ret,
131 const char *trait,
132 unsigned int index)
133{
134 return GNUNET_OK;
135}
136
137
138/**
139 * Create command.
140 *
141 * @param label name for command.
142 * @param start_label Label of the cmd to start the peer.
143 * @return command.
144 */
145struct GNUNET_TESTING_Command
146GNUNET_TRANSPORT_cmd_stop_peer (const char *label,
147 const char *start_label)
148{
149 struct StopPeerState *sps;
150
151 sps = GNUNET_new (struct StopPeerState);
152 sps->start_label = start_label;
153
154 struct GNUNET_TESTING_Command cmd = {
155 .cls = sps,
156 .label = label,
157 .run = &stop_peer_run,
158 .cleanup = &stop_peer_cleanup,
159 .traits = &stop_peer_traits
160 };
161
162 return cmd;
163}