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"
37 * - start two communicators
38 * - act like transport services
39 * - get_server_addresses (service.c)
40 * - open_listen_socket (service.c)
41 * - GNUNET_MQ_queue_for_callbacks (service.c)
42 * - let them communicate
48 #define LOG(kind,...) GNUNET_log_from (kind, "test_transport_communicator_unix", __VA_ARGS__)
52 static struct GNUNET_PeerIdentity peer_id[NUM_PEERS];
54 static struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_hs[NUM_PEERS];
56 //static char *addresses[NUM_PEERS];
59 communicator_available_cb (void *cls,
60 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
61 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
64 LOG (GNUNET_ERROR_TYPE_DEBUG,
65 "Communicator available. (cc: %u, prefix: %s)\n",
72 add_address_cb (void *cls,
73 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
75 struct GNUNET_TIME_Relative expiration,
77 enum GNUNET_NetworkType nt)
79 LOG (GNUNET_ERROR_TYPE_DEBUG,
80 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n",
82 expiration.rel_value_us,
85 //addresses[1] = GNUNET_strdup (address);
86 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0],
93 queue_create_reply_cb (void *cls,
94 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
97 if (GNUNET_YES == success)
98 LOG (GNUNET_ERROR_TYPE_DEBUG,
101 LOG (GNUNET_ERROR_TYPE_DEBUG,
102 "Failed getting queue!\n");
107 add_queue_cb (void *cls,
108 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h)
110 LOG (GNUNET_ERROR_TYPE_DEBUG,
118 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
120 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
122 "test_communicator_1.conf",
123 &communicator_available_cb,
125 &queue_create_reply_cb,
128 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start (
130 "test_communicator_2.conf",
131 &communicator_available_cb,
143 char *opt_cfg_filename;
147 struct GNUNET_CONFIGURATION_Handle *cfg;
149 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
150 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename),
151 GNUNET_GETOPT_option_help (NULL),
152 GNUNET_GETOPT_option_loglevel (&loglev),
153 GNUNET_GETOPT_option_logfile (&logfile),
154 GNUNET_GETOPT_OPTION_END
157 if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix",
162 return GNUNET_SYSERR;
165 xdg = getenv ("XDG_CONFIG_HOME");
167 GNUNET_asprintf (&cfg_filename,
171 GNUNET_OS_project_data_get ()->config_file);
173 cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
174 cfg = GNUNET_CONFIGURATION_create ();
175 if (NULL != opt_cfg_filename)
178 GNUNET_DISK_file_test (opt_cfg_filename)) ||
180 GNUNET_CONFIGURATION_load (cfg,
183 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
184 _("Malformed configuration file `%s', exit ...\n"),
186 return GNUNET_SYSERR;
192 GNUNET_DISK_file_test (cfg_filename))
195 GNUNET_CONFIGURATION_load (cfg,
198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
199 _("Malformed configuration file `%s', exit ...\n"),
201 return GNUNET_SYSERR;
207 GNUNET_CONFIGURATION_load (cfg,
210 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
211 _("Malformed configuration, exit ...\n"));
212 return GNUNET_SYSERR;
216 GNUNET_SCHEDULER_run (&run,