2 This file is part of GNUnet.
3 Copyright (C) 2019 GNUnet e.V.
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.
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.
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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file transport/transport-testing2.c
23 * @brief functions related to testing-tng
24 * @author Christian Grothoff
25 * @author Julius Bünger
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"
37 #define LOG(kind,...) GNUNET_log_from (kind, "transport-testing2", __VA_ARGS__)
41 * @brief Check whether incoming msg indicating available communicator is
45 * @param msg Message struct
47 * @return GNUNET_YES in case message is correct
50 check_communicator_available (void *cls,
51 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
53 LOG (GNUNET_ERROR_TYPE_DEBUG,
54 "check_communicator_available()\n");
60 * @brief Handle new communicator
63 * @param msg Message struct
66 handle_communicator_available (void *cls,
67 const struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *msg)
69 GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available = cls;
70 LOG (GNUNET_ERROR_TYPE_DEBUG,
71 "handle_communicator_available()\n");
72 if (NULL != communicator_available)
74 LOG (GNUNET_ERROR_TYPE_DEBUG,
75 "calling communicator_available()\n");
76 communicator_available (NULL, msg);
78 //GNUNET_SERVICE_client_continue (client);
83 * @brief Shut down the service
85 * @param cls Closure - Handle to the service
88 shutdown_service (void *cls)
90 struct GNUNET_SERVICE_Handle *h = cls;
92 GNUNET_SERVICE_stop (h);
97 * @brief Start the communicator part of the transport service
99 * @param communicator_available Callback to be called when a new communicator
101 * @param cfg Configuration
104 transport_communicator_start (GNUNET_TRANSPORT_TESTING_CommunicatorAvailableCallback communicator_available,
105 struct GNUNET_CONFIGURATION_Handle *cfg)
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,
116 //GNUNET_MQ_hd_var_size (add_address,
117 // GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS,
118 // struct GNUNET_TRANSPORT_AddAddressMessage,
120 //GNUNET_MQ_hd_fixed_size (del_address,
121 // GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS,
122 // struct GNUNET_TRANSPORT_DelAddressMessage,
124 //GNUNET_MQ_hd_var_size (incoming_msg,
125 // GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG,
126 // struct GNUNET_TRANSPORT_IncomingMessage,
128 //GNUNET_MQ_hd_fixed_size (queue_create_ok,
129 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK,
130 // struct GNUNET_TRANSPORT_CreateQueueResponse,
132 //GNUNET_MQ_hd_fixed_size (queue_create_fail,
133 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL,
134 // struct GNUNET_TRANSPORT_CreateQueueResponse,
136 //GNUNET_MQ_hd_var_size (add_queue_message,
137 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP,
138 // struct GNUNET_TRANSPORT_AddQueueMessage,
140 //GNUNET_MQ_hd_fixed_size (del_queue_message,
141 // GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN,
142 // struct GNUNET_TRANSPORT_DelQueueMessage,
144 //GNUNET_MQ_hd_fixed_size (send_message_ack,
145 // GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK,
146 // struct GNUNET_TRANSPORT_SendMessageToAck,
149 struct GNUNET_SERVICE_Handle *h;
151 h = GNUNET_SERVICE_start ("transport",
158 LOG (GNUNET_ERROR_TYPE_ERROR,
159 "Failed starting service!\n");
162 LOG (GNUNET_ERROR_TYPE_DEBUG,
163 "Started service\n");
164 GNUNET_SCHEDULER_add_shutdown (&shutdown_service, h);
170 * @brief Start the communicator
172 * @param cfgname Name of the communicator
175 communicator_start (const char *cfgname)
178 struct GNUNET_CONFIGURATION_Handle *cfg;
179 struct GNUNET_OS_Process *proc;
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 ();
186 GNUNET_OS_start_process (GNUNET_YES,
187 GNUNET_OS_INHERIT_STD_OUT_AND_ERR,
190 "./gnunet-communicator-unix",
196 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
197 "Failed to start communicator!");
200 GNUNET_assert (GNUNET_OK ==
201 GNUNET_CONFIGURATION_load (cfg,
203 LOG (GNUNET_ERROR_TYPE_DEBUG,
204 "started communicator\n");
205 GNUNET_free (binary);
210 * @brief Start communicator part of transport service and communicator
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
218 * @return Handle to the communicator duo
220 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
221 GNUNET_TRANSPORT_TESTING_transport_communicator_service_start
222 (const char *service_name,
223 const char *cfg_filename,
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,
230 struct GNUNET_CONFIGURATION_Handle *cfg;
232 cfg = GNUNET_CONFIGURATION_create ();
233 if ( (GNUNET_SYSERR ==
234 GNUNET_CONFIGURATION_load (cfg,
237 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
238 _("Malformed configuration file `%s', exit ...\n"),
242 /* Start communicator part of service */
243 transport_communicator_start (communicator_available, cfg);
245 /* Schedule start communicator */
246 communicator_start ("test_communicator_1.conf");
250 //GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue
251 // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tch,
252 // const char *address);
254 //struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorTransmission *
255 //GNUNET_TRANSPORT_TESTING_transport_communicator_send
256 // (struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tcq,
257 // const struct GNUNET_MessageHeader *hdr,
258 // GNUNET_TRANSPORT_TESTING_SuccessStatus cb, void *cb_cls);