aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/Makefile.am27
-rw-r--r--src/transport/test_communicator_unix.c149
-rw-r--r--src/transport/transport-testing2.c248
-rw-r--r--src/transport/transport-testing2.h74
4 files changed, 493 insertions, 5 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index 53fd9c973..c9b23b6c4 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -141,7 +141,6 @@ endif
141 141
142noinst_PROGRAMS = \ 142noinst_PROGRAMS = \
143 gnunet-transport-profiler \ 143 gnunet-transport-profiler \
144 gnunet-communicator-unix \
145 gnunet-communicator-tcp \ 144 gnunet-communicator-tcp \
146 gnunet-communicator-udp \ 145 gnunet-communicator-udp \
147 gnunet-service-tng \ 146 gnunet-service-tng \
@@ -149,7 +148,8 @@ noinst_PROGRAMS = \
149 $(WLAN_BIN_RECEIVER) 148 $(WLAN_BIN_RECEIVER)
150 149
151if HAVE_TESTING 150if HAVE_TESTING
152TESTING_LIBS = libgnunettransporttesting.la 151TESTING_LIBS = libgnunettransporttesting.la \
152 libgnunettransporttesting2.la
153endif 153endif
154 154
155lib_LTLIBRARIES = \ 155lib_LTLIBRARIES = \
@@ -177,6 +177,14 @@ libgnunettransporttesting_la_LIBADD = \
177libgnunettransporttesting_la_LDFLAGS = \ 177libgnunettransporttesting_la_LDFLAGS = \
178 $(GN_LIB_LDFLAGS) 178 $(GN_LIB_LDFLAGS)
179 179
180libgnunettransporttesting2_la_SOURCES = \
181 transport-testing2.c transport-testing2.h
182libgnunettransporttesting2_la_LIBADD = \
183 libgnunettransport.la \
184 $(top_builddir)/src/util/libgnunetutil.la
185libgnunettransporttesting2_la_LDFLAGS = \
186 $(GN_LIB_LDFLAGS)
187
180libgnunettransport_la_SOURCES = \ 188libgnunettransport_la_SOURCES = \
181 transport.h \ 189 transport.h \
182 transport_api_address_to_string.c \ 190 transport_api_address_to_string.c \
@@ -249,7 +257,8 @@ libexec_PROGRAMS = \
249 $(WLAN_BIN) \ 257 $(WLAN_BIN) \
250 $(WLAN_BIN_DUMMY) \ 258 $(WLAN_BIN_DUMMY) \
251 $(BT_BIN) \ 259 $(BT_BIN) \
252 gnunet-service-transport 260 gnunet-service-transport \
261 gnunet-communicator-unix
253 262
254 263
255 264
@@ -595,7 +604,8 @@ check_PROGRAMS = \
595 $(HTTP_QUOTA_TEST) \ 604 $(HTTP_QUOTA_TEST) \
596 $(HTTPS_QUOTA_TEST) \ 605 $(HTTPS_QUOTA_TEST) \
597 $(WLAN_QUOTA_TEST) \ 606 $(WLAN_QUOTA_TEST) \
598 $(BT_QUOTA_TEST) 607 $(BT_QUOTA_TEST) \
608 test_communicator_unix
599if HAVE_GETOPT_BINARY 609if HAVE_GETOPT_BINARY
600check_PROGRAMS += \ 610check_PROGRAMS += \
601test_transport_api_slow_ats 611test_transport_api_slow_ats
@@ -664,7 +674,8 @@ TESTS = \
664 $(HTTP_API_TIMEOUT_TEST) \ 674 $(HTTP_API_TIMEOUT_TEST) \
665 $(HTTPS_API_TIMEOUT_TEST) \ 675 $(HTTPS_API_TIMEOUT_TEST) \
666 $(WLAN_TIMEOUT_TEST) \ 676 $(WLAN_TIMEOUT_TEST) \
667 $(BT_TIMEOUT_TEST) 677 $(BT_TIMEOUT_TEST) \
678 test_communicator_udp
668if HAVE_GETOPT_BINARY 679if HAVE_GETOPT_BINARY
669TESTS += \ 680TESTS += \
670test_transport_api_slow_ats 681test_transport_api_slow_ats
@@ -778,6 +789,12 @@ test_plugin_udp_LDADD = \
778 $(top_builddir)/src/util/libgnunetutil.la \ 789 $(top_builddir)/src/util/libgnunetutil.la \
779 libgnunettransporttesting.la 790 libgnunettransporttesting.la
780 791
792test_communicator_udp_SOURCES = \
793 test_communicator_udp.c
794test_communicator_udp_LDADD = \
795 libgnunettransporttesting2.la \
796 $(top_builddir)/src/util/libgnunetutil.la
797
781test_plugin_unix_SOURCES = \ 798test_plugin_unix_SOURCES = \
782 test_plugin_transport.c 799 test_plugin_transport.c
783test_plugin_unix_LDADD = \ 800test_plugin_unix_LDADD = \
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c
new file mode 100644
index 000000000..f94587a12
--- /dev/null
+++ b/src/transport/test_communicator_unix.c
@@ -0,0 +1,149 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2019 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_communicator_unix.c
23 * @brief test the unix communicator
24 * @author Julius Bünger
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "transport-testing2.h"
29#include "gnunet_ats_transport_service.h"
30#include "gnunet_signatures.h"
31#include "transport.h"
32
33/**
34 * TODO
35 * - start two communicators
36 * - act like transport services
37 * - get_server_addresses (service.c)
38 * - open_listen_socket (service.c)
39 * - GNUNET_MQ_queue_for_callbacks (service.c)
40 * - let them communicate
41 *
42 */
43
44
45
46#define LOG(kind,...) GNUNET_log_from (kind, "test_transport_communicator_unix", __VA_ARGS__)
47
48static void
49communicator_available (void *cls,
50 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
51{
52 LOG (GNUNET_ERROR_TYPE_DEBUG,
53 "communicator_available()\n");
54}
55
56static void
57run (void *cls)
58{
59 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
60
61 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
62 "transport",
63 cfg,
64 &communicator_available,
65 NULL); /* cls */
66}
67
68int
69main (int argc,
70 char *const *argv)
71{
72 char *cfg_filename;
73 char *opt_cfg_filename;
74 const char *xdg;
75 char *loglev;
76 char *logfile;
77 struct GNUNET_CONFIGURATION_Handle *cfg;
78
79 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
80 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
81 GNUNET_GETOPT_option_help (NULL),
82 GNUNET_GETOPT_option_loglevel (&loglev),
83 GNUNET_GETOPT_option_logfile (&logfile),
84 GNUNET_GETOPT_OPTION_END
85 };
86
87 if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix",
88 loglev,
89 logfile))
90 {
91 GNUNET_break (0);
92 return GNUNET_SYSERR;
93 }
94
95 xdg = getenv ("XDG_CONFIG_HOME");
96 if (NULL != xdg)
97 GNUNET_asprintf (&cfg_filename,
98 "%s%s%s",
99 xdg,
100 DIR_SEPARATOR_STR,
101 GNUNET_OS_project_data_get ()->config_file);
102 else
103 cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
104 cfg = GNUNET_CONFIGURATION_create ();
105 if (NULL != opt_cfg_filename)
106 {
107 if ( (GNUNET_YES !=
108 GNUNET_DISK_file_test (opt_cfg_filename)) ||
109 (GNUNET_SYSERR ==
110 GNUNET_CONFIGURATION_load (cfg,
111 opt_cfg_filename)) )
112 {
113 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
114 _("Malformed configuration file `%s', exit ...\n"),
115 opt_cfg_filename);
116 return GNUNET_SYSERR;
117 }
118 }
119 else
120 {
121 if (GNUNET_YES ==
122 GNUNET_DISK_file_test (cfg_filename))
123 {
124 if (GNUNET_SYSERR ==
125 GNUNET_CONFIGURATION_load (cfg,
126 cfg_filename))
127 {
128 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
129 _("Malformed configuration file `%s', exit ...\n"),
130 cfg_filename);
131 return GNUNET_SYSERR;
132 }
133 }
134 else
135 {
136 if (GNUNET_SYSERR ==
137 GNUNET_CONFIGURATION_load (cfg,
138 NULL))
139 {
140 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
141 _("Malformed configuration, exit ...\n"));
142 return GNUNET_SYSERR;
143 }
144 }
145 }
146 GNUNET_SCHEDULER_run (&run,
147 cfg);
148}
149
diff --git a/src/transport/transport-testing2.c b/src/transport/transport-testing2.c
new file mode 100644
index 000000000..0a7aa1da0
--- /dev/null
+++ b/src/transport/transport-testing2.c
@@ -0,0 +1,248 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2019 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/transport-testing2.c
23 * @brief functions related to testing-tng
24 * @author Christian Grothoff
25 * @author Julius Bünger
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_protocols.h"
30#include "gnunet_constants.h"
31#include "transport-testing2.h"
32#include "gnunet_ats_transport_service.h"
33#include "gnunet_signatures.h"
34#include "transport.h"
35
36
37#define LOG(kind,...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
38
39
40/**
41 * @brief Check whether incoming msg indicating available communicator is
42 * correct
43 *
44 * @param cls Closure
45 * @param msg Message struct
46 *
47 * @return GNUNET_YES in case message is correct
48 */
49static int
50check_communicator_available (void *cls,
51 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
52{
53 LOG (GNUNET_ERROR_TYPE_DEBUG,
54 "check_communicator_available()\n");
55 return GNUNET_YES;
56}
57
58
59/**
60 * @brief Handle new communicator
61 *
62 * @param cls Closure
63 * @param msg Message struct
64 */
65static void
66handle_communicator_available (void *cls,
67 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
68{
69 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available = cls;
70 LOG (GNUNET_ERROR_TYPE_DEBUG,
71 "handle_communicator_available()\n");
72 if (NULL != communicator_available)
73 {
74 LOG (GNUNET_ERROR_TYPE_DEBUG,
75 "calling communicator_available()\n");
76 communicator_available (NULL, msg);
77 }
78 //GNUNET_SERVICE_client_continue (client);
79}
80
81
82/**
83 * @brief Shut down the service
84 *
85 * @param cls Closure - Handle to the service
86 */
87static void
88shutdown_service (void *cls)
89{
90 struct GNUNET_SERVICE_Handle *h = cls;
91
92 GNUNET_SERVICE_stop (h);
93}
94
95
96/**
97 * @brief Start the communicator part of the transport service
98 *
99 * @param communicator_available Callback to be called when a new communicator
100 * becomes available
101 * @param cfg Configuration
102 */
103static void
104transport_communicator_start (GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available,
105 struct GNUNET_CONFIGURATION_Handle *cfg)
106{
107 struct GNUNET_MQ_MessageHandler mh[] = {
108 GNUNET_MQ_hd_var_size (communicator_available,
109 GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR,
110 struct GNUNET_TRANSPORT_CommunicatorAvailableMessage,
111 &communicator_available),
112 //GNUNET_MQ_hd_var_size (communicator_backchannel,
113 // GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL,
114 // struct GNUNET_TRANSPORT_CommunicatorBackchannel,
115 // NULL),
116 //GNUNET_MQ_hd_var_size (add_address,
117 // GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
118 // struct GNUNET_TRANSPORT_AddAddressMessage,
119 // NULL),
120 //GNUNET_MQ_hd_fixed_size (del_address,
121 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
122 // struct GNUNET_TRANSPORT_DelAddressMessage,
123 // NULL),
124 //GNUNET_MQ_hd_var_size (incoming_msg,
125 // GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
126 // struct GNUNET_TRANSPORT_IncomingMessage,
127 // NULL),
128 //GNUNET_MQ_hd_fixed_size (queue_create_ok,
129 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
130 // struct GNUNET_TRANSPORT_CreateQueueResponse,
131 // NULL),
132 //GNUNET_MQ_hd_fixed_size (queue_create_fail,
133 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
134 // struct GNUNET_TRANSPORT_CreateQueueResponse,
135 // NULL),
136 //GNUNET_MQ_hd_var_size (add_queue_message,
137 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
138 // struct GNUNET_TRANSPORT_AddQueueMessage,
139 // NULL),
140 //GNUNET_MQ_hd_fixed_size (del_queue_message,
141 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
142 // struct GNUNET_TRANSPORT_DelQueueMessage,
143 // NULL),
144 //GNUNET_MQ_hd_fixed_size (send_message_ack,
145 // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
146 // struct GNUNET_TRANSPORT_SendMessageToAck,
147 // NULL),
148 };
149 struct GNUNET_SERVICE_Handle *h;
150
151 h = GNUNET_SERVICE_start ("transport",
152 cfg,
153 NULL,
154 NULL,
155 NULL,
156 mh);
157 if (NULL == h)
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "Failed starting service!\n");
160 else
161 {
162 LOG (GNUNET_ERROR_TYPE_DEBUG,
163 "Started service\n");
164 GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h);
165 }
166}
167
168
169/**
170 * @brief Start the communicator
171 *
172 * @param cfgname Name of the communicator
173 */
174static void
175communicator_start (const char *cfgname)
176{
177 char *binary;
178 struct GNUNET_CONFIGURATION_Handle *cfg;
179 struct GNUNET_OS_Process *proc;
180
181 LOG (GNUNET_ERROR_TYPE_DEBUG,
182 "communicator_start\n");
183 binary = GNUNET_OS_get_libexec_binary_path ("gnunet-communicator-unix");
184 cfg = GNUNET_CONFIGURATION_create ();
185 proc =
186 GNUNET_OS_start_process (GNUNET_YES,
187 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
188 NULL, NULL, NULL,
189 binary,
190 "./gnunet-communicator-unix",
191 "-c",
192 cfgname,
193 NULL);
194 if (NULL == proc)
195 {
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "Failed to start communicator!");
198 return;
199 }
200 GNUNET_assert (GNUNET_OK ==
201 GNUNET_CONFIGURATION_load (cfg,
202 cfgname));
203 LOG (GNUNET_ERROR_TYPE_DEBUG,
204 "started communicator\n");
205 GNUNET_free (binary);
206}
207
208
209/**
210 * @brief Start communicator part of transport service and communicator
211 *
212 * @param service_name Name of the service
213 * @param cfg Configuration handle
214 * @param communicator_available Callback that is called when a new
215 * communicator becomes available
216 * @param cb_cls Closure to @p communicator_available
217 *
218 * @return Handle to the communicator duo
219 */
220struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
221GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
222 (const char *service_name,
223 struct GNUNET_CONFIGURATION_Handle *cfg,
224 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available,
225 //GNUNET_TRANSPORT_TESTING_Callback2 cb2,
226 //GNUNET_TRANSPORT_TESTING_Callback3 cb3,
227 //GNUNET_TRANSPORT_TESTING_Callback4 cb4,
228 void *cb_cls)
229{
230
231 /* Start communicator part of service */
232 transport_communicator_start (communicator_available, cfg);
233
234 /* Schedule start communicator */
235 communicator_start ("test_communicator_1.conf");
236}
237
238//void
239//GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
240// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch,
241// const char *address);
242//
243//struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
244//GNUNET_TRANSPORT_TESTING_transport_communicator_send
245// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq,
246// const struct GNUNET_MessageHeader *hdr,
247// GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls);
248
diff --git a/src/transport/transport-testing2.h b/src/transport/transport-testing2.h
new file mode 100644
index 000000000..a6f0348ef
--- /dev/null
+++ b/src/transport/transport-testing2.h
@@ -0,0 +1,74 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2019 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/transport-testing2.h
23 * @brief functions related to testing-tng
24 * @author Christian Grothoff
25 * @author Julius Bünger
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_ats_transport_service.h"
30#include "transport.h"
31
32/**
33 * @brief Function signature for callbacks that are called when new communicators become available
34 *
35 * @param Closure
36 * @param msg Message
37 */
38typedef void
39(*GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback)(void *cls,
40 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg);
41
42
43/**
44 * @brief Start communicator part of transport service and communicator
45 *
46 * @param service_name Name of the service
47 * @param cfg Configuration handle
48 * @param communicator_available Callback that is called when a new
49 * communicator becomes available
50 * @param cb_cls Closure to @p communicator_available
51 *
52 * @return Handle to the communicator duo
53 */
54struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
55GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
56 (const char *service_name,
57 struct GNUNET_CONFIGURATION_Handle *cfg,
58 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available,
59 //GNUNET_TRANSPORT_TESTING_Callback2 cb2,
60 //GNUNET_TRANSPORT_TESTING_Callback3 cb3,
61 //GNUNET_TRANSPORT_TESTING_Callback4 cb4,
62 void *cb_cls);
63
64//void
65//GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
66// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch,
67// const char *address);
68//
69//struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
70//GNUNET_TRANSPORT_TESTING_transport_communicator_send
71// (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq,
72// const struct GNUNET_MessageHeader *hdr,
73// GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls);
74