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/test_communicator_unix.c
23 * @brief test the unix communicator
24 * @author Julius Bünger
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"
36 #define LOG(kind, ...) GNUNET_log_from (kind, \
37 "test_transport_communicator_unix", \
42 static struct GNUNET_PeerIdentity peer_id[NUM_PEERS];
45 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS];
47 // static char *addresses[NUM_PEERS];
50 #define PAYLOAD_SIZE 256
52 // static char payload[PAYLOAD_SIZE] = "TEST PAYLOAD";
53 // static char payload[] = "TEST PAYLOAD";
54 static uint32_t payload = 42;
58 communicator_available_cb (void *cls,
60 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
62 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
65 LOG (GNUNET_ERROR_TYPE_DEBUG,
66 "Communicator available. (cc: %u, prefix: %s)\n",
73 add_address_cb (void *cls,
74 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
77 struct GNUNET_TIME_Relative expiration,
79 enum GNUNET_NetworkType nt)
81 LOG (GNUNET_ERROR_TYPE_DEBUG,
82 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n",
84 expiration.rel_value_us,
87 // addresses[1] = GNUNET_strdup (address);
88 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0],
95 * @brief Callback that informs whether the requested queue will be
98 * Implements #GNUNET_TRANSPORT_TESTING_QueueCreateReplyCallback.
100 * @param cls Closure - unused
101 * @param tc_h Communicator handle - unused
102 * @param will_try #GNUNET_YES if queue will be established
103 * #GNUNET_NO if queue will not be established (bogous address)
106 queue_create_reply_cb (void *cls,
108 GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *
112 if (GNUNET_YES == will_try)
113 LOG (GNUNET_ERROR_TYPE_DEBUG,
114 "Queue will be established!\n");
116 LOG (GNUNET_ERROR_TYPE_WARNING,
117 "Queue won't be established (bougus address?)!\n");
122 * @brief Handle opening of queue
124 * Issues sending of test data
126 * Implements #GNUNET_TRANSPORT_TESTING_AddQueueCallback
129 * @param tc_h Communicator handle
130 * @param tc_queue Handle to newly opened queue
133 add_queue_cb (void *cls,
134 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
135 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *
138 LOG (GNUNET_ERROR_TYPE_DEBUG,
140 GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue,
147 * @brief Handle an incoming message
149 * Implements #GNUNET_TRANSPORT_TESTING_IncomingMessageCallback
152 * @param tc_h Handle to the receiving communicator
153 * @param msg Received message
156 incoming_message_cb (void *cls,
157 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle
159 const struct GNUNET_MessageHeader *msg)
165 * @brief Main function called by the scheduler
167 * @param cls Closure - Handle to configuration
172 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
174 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
176 "gnunet-communicator-unix",
177 "test_communicator_1.conf",
178 &communicator_available_cb,
180 &queue_create_reply_cb,
184 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
186 "gnunet-communicator-unix",
187 "test_communicator_2.conf",
188 &communicator_available_cb,
202 char *opt_cfg_filename;
206 struct GNUNET_CONFIGURATION_Handle *cfg;
208 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
209 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
210 GNUNET_GETOPT_option_help (NULL),
211 GNUNET_GETOPT_option_loglevel (&loglev),
212 GNUNET_GETOPT_option_logfile (&logfile),
213 GNUNET_GETOPT_OPTION_END
216 if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix",
221 return GNUNET_SYSERR;
224 xdg = getenv ("XDG_CONFIG_HOME");
226 GNUNET_asprintf (&cfg_filename,
230 GNUNET_OS_project_data_get ()->config_file);
232 cfg_filename = GNUNET_strdup (
233 GNUNET_OS_project_data_get ()->user_config_file);
234 cfg = GNUNET_CONFIGURATION_create ();
235 if (NULL != opt_cfg_filename)
238 GNUNET_DISK_file_test (opt_cfg_filename)) ||
240 GNUNET_CONFIGURATION_load (cfg,
243 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
244 _ ("Malformed configuration file `%s', exit ...\n"),
246 return GNUNET_SYSERR;
252 GNUNET_DISK_file_test (cfg_filename))
255 GNUNET_CONFIGURATION_load (cfg,
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
259 _ ("Malformed configuration file `%s', exit ...\n"),
261 return GNUNET_SYSERR;
267 GNUNET_CONFIGURATION_load (cfg,
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 _ ("Malformed configuration, exit ...\n"));
272 return GNUNET_SYSERR;
276 GNUNET_SCHEDULER_run (&run,