aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_communicator_unix.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/transport/test_communicator_unix.c')
-rw-r--r--src/transport/test_communicator_unix.c222
1 files changed, 111 insertions, 111 deletions
diff --git a/src/transport/test_communicator_unix.c b/src/transport/test_communicator_unix.c
index fed15b236..77bd4bb38 100644
--- a/src/transport/test_communicator_unix.c
+++ b/src/transport/test_communicator_unix.c
@@ -16,7 +16,7 @@
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file transport/test_communicator_unix.c 22 * @file transport/test_communicator_unix.c
@@ -33,7 +33,7 @@
33#include <inttypes.h> 33#include <inttypes.h>
34 34
35 35
36#define LOG(kind,...) GNUNET_log_from (kind, "test_transport_communicator_unix", __VA_ARGS__) 36#define LOG(kind, ...) GNUNET_log_from(kind, "test_transport_communicator_unix", __VA_ARGS__)
37 37
38#define NUM_PEERS 2 38#define NUM_PEERS 2
39 39
@@ -52,12 +52,12 @@ static uint32_t payload = 42;
52 52
53 53
54static void 54static void
55communicator_available_cb (void *cls, 55communicator_available_cb(void *cls,
56 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 56 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
57 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, 57 enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc,
58 char *address_prefix) 58 char *address_prefix)
59{ 59{
60 LOG (GNUNET_ERROR_TYPE_DEBUG, 60 LOG(GNUNET_ERROR_TYPE_DEBUG,
61 "Communicator available. (cc: %u, prefix: %s)\n", 61 "Communicator available. (cc: %u, prefix: %s)\n",
62 cc, 62 cc,
63 address_prefix); 63 address_prefix);
@@ -65,23 +65,23 @@ communicator_available_cb (void *cls,
65 65
66 66
67static void 67static void
68add_address_cb (void *cls, 68add_address_cb(void *cls,
69 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 69 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
70 const char *address, 70 const char *address,
71 struct GNUNET_TIME_Relative expiration, 71 struct GNUNET_TIME_Relative expiration,
72 uint32_t aid, 72 uint32_t aid,
73 enum GNUNET_NetworkType nt) 73 enum GNUNET_NetworkType nt)
74{ 74{
75 LOG (GNUNET_ERROR_TYPE_DEBUG, 75 LOG(GNUNET_ERROR_TYPE_DEBUG,
76 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n", 76 "New address. (addr: %s, expir: %" PRIu32 ", ID: %" PRIu32 ", nt: %u\n",
77 address, 77 address,
78 expiration.rel_value_us, 78 expiration.rel_value_us,
79 aid, 79 aid,
80 nt); 80 nt);
81 //addresses[1] = GNUNET_strdup (address); 81 //addresses[1] = GNUNET_strdup (address);
82 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue (tc_hs[0], 82 GNUNET_TRANSPORT_TESTING_transport_communicator_open_queue(tc_hs[0],
83 &peer_id[1], 83 &peer_id[1],
84 address); 84 address);
85} 85}
86 86
87 87
@@ -97,15 +97,15 @@ add_address_cb (void *cls,
97 * #GNUNET_NO if queue will not be established (bogous address) 97 * #GNUNET_NO if queue will not be established (bogous address)
98 */ 98 */
99static void 99static void
100queue_create_reply_cb (void *cls, 100queue_create_reply_cb(void *cls,
101 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 101 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
102 int will_try) 102 int will_try)
103{ 103{
104 if (GNUNET_YES == will_try) 104 if (GNUNET_YES == will_try)
105 LOG (GNUNET_ERROR_TYPE_DEBUG, 105 LOG(GNUNET_ERROR_TYPE_DEBUG,
106 "Queue will be established!\n"); 106 "Queue will be established!\n");
107 else 107 else
108 LOG (GNUNET_ERROR_TYPE_WARNING, 108 LOG(GNUNET_ERROR_TYPE_WARNING,
109 "Queue won't be established (bougus address?)!\n"); 109 "Queue won't be established (bougus address?)!\n");
110} 110}
111 111
@@ -122,15 +122,15 @@ queue_create_reply_cb (void *cls,
122 * @param tc_queue Handle to newly opened queue 122 * @param tc_queue Handle to newly opened queue
123 */ 123 */
124static void 124static void
125add_queue_cb (void *cls, 125add_queue_cb(void *cls,
126 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 126 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
127 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue) 127 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorQueue *tc_queue)
128{ 128{
129 LOG (GNUNET_ERROR_TYPE_DEBUG, 129 LOG(GNUNET_ERROR_TYPE_DEBUG,
130 "Got Queue!\n"); 130 "Got Queue!\n");
131 GNUNET_TRANSPORT_TESTING_transport_communicator_send (tc_queue, 131 GNUNET_TRANSPORT_TESTING_transport_communicator_send(tc_queue,
132 &payload, 132 &payload,
133 sizeof (payload)); 133 sizeof(payload));
134} 134}
135 135
136 136
@@ -144,9 +144,9 @@ add_queue_cb (void *cls,
144 * @param msg Received message 144 * @param msg Received message
145 */ 145 */
146void 146void
147incoming_message_cb (void *cls, 147incoming_message_cb(void *cls,
148 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h, 148 struct GNUNET_TRANSPORT_TESTING_TransportCommunicatorHandle *tc_h,
149 const struct GNUNET_MessageHeader *msg) 149 const struct GNUNET_MessageHeader *msg)
150{ 150{
151} 151}
152 152
@@ -157,35 +157,35 @@ incoming_message_cb (void *cls,
157 * @param cls Closure - Handle to configuration 157 * @param cls Closure - Handle to configuration
158 */ 158 */
159static void 159static void
160run (void *cls) 160run(void *cls)
161{ 161{
162 struct GNUNET_CONFIGURATION_Handle *cfg = cls; 162 struct GNUNET_CONFIGURATION_Handle *cfg = cls;
163 163
164 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 164 tc_hs[0] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
165 "transport", 165 "transport",
166 "gnunet-communicator-unix", 166 "gnunet-communicator-unix",
167 "test_communicator_1.conf", 167 "test_communicator_1.conf",
168 &communicator_available_cb, 168 &communicator_available_cb,
169 NULL, 169 NULL,
170 &queue_create_reply_cb, 170 &queue_create_reply_cb,
171 &add_queue_cb, 171 &add_queue_cb,
172 NULL, 172 NULL,
173 NULL); /* cls */ 173 NULL); /* cls */
174 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start ( 174 tc_hs[1] = GNUNET_TRANSPORT_TESTING_transport_communicator_service_start(
175 "transport", 175 "transport",
176 "gnunet-communicator-unix", 176 "gnunet-communicator-unix",
177 "test_communicator_2.conf", 177 "test_communicator_2.conf",
178 &communicator_available_cb, 178 &communicator_available_cb,
179 &add_address_cb, 179 &add_address_cb,
180 NULL, 180 NULL,
181 &add_queue_cb, 181 &add_queue_cb,
182 NULL, 182 NULL,
183 NULL); /* cls */ 183 NULL); /* cls */
184} 184}
185 185
186int 186int
187main (int argc, 187main(int argc,
188 char *const *argv) 188 char *const *argv)
189{ 189{
190 char *cfg_filename; 190 char *cfg_filename;
191 char *opt_cfg_filename; 191 char *opt_cfg_filename;
@@ -195,73 +195,73 @@ main (int argc,
195 struct GNUNET_CONFIGURATION_Handle *cfg; 195 struct GNUNET_CONFIGURATION_Handle *cfg;
196 196
197 struct GNUNET_GETOPT_CommandLineOption service_options[] = { 197 struct GNUNET_GETOPT_CommandLineOption service_options[] = {
198 GNUNET_GETOPT_option_cfgfile (&opt_cfg_filename), 198 GNUNET_GETOPT_option_cfgfile(&opt_cfg_filename),
199 GNUNET_GETOPT_option_help (NULL), 199 GNUNET_GETOPT_option_help(NULL),
200 GNUNET_GETOPT_option_loglevel (&loglev), 200 GNUNET_GETOPT_option_loglevel(&loglev),
201 GNUNET_GETOPT_option_logfile (&logfile), 201 GNUNET_GETOPT_option_logfile(&logfile),
202 GNUNET_GETOPT_OPTION_END 202 GNUNET_GETOPT_OPTION_END
203 }; 203 };
204 204
205 if (GNUNET_OK != GNUNET_log_setup ("test_communicator_unix", 205 if (GNUNET_OK != GNUNET_log_setup("test_communicator_unix",
206 loglev, 206 loglev,
207 logfile)) 207 logfile))
208 { 208 {
209 GNUNET_break (0); 209 GNUNET_break(0);
210 return GNUNET_SYSERR; 210 return GNUNET_SYSERR;
211 } 211 }
212 212
213 xdg = getenv ("XDG_CONFIG_HOME"); 213 xdg = getenv("XDG_CONFIG_HOME");
214 if (NULL != xdg) 214 if (NULL != xdg)
215 GNUNET_asprintf (&cfg_filename, 215 GNUNET_asprintf(&cfg_filename,
216 "%s%s%s", 216 "%s%s%s",
217 xdg, 217 xdg,
218 DIR_SEPARATOR_STR, 218 DIR_SEPARATOR_STR,
219 GNUNET_OS_project_data_get ()->config_file); 219 GNUNET_OS_project_data_get()->config_file);
220 else 220 else
221 cfg_filename = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 221 cfg_filename = GNUNET_strdup(GNUNET_OS_project_data_get()->user_config_file);
222 cfg = GNUNET_CONFIGURATION_create (); 222 cfg = GNUNET_CONFIGURATION_create();
223 if (NULL != opt_cfg_filename) 223 if (NULL != opt_cfg_filename)
224 {
225 if ( (GNUNET_YES !=
226 GNUNET_DISK_file_test (opt_cfg_filename)) ||
227 (GNUNET_SYSERR ==
228 GNUNET_CONFIGURATION_load (cfg,
229 opt_cfg_filename)) )
230 { 224 {
231 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 225 if ((GNUNET_YES !=
232 _("Malformed configuration file `%s', exit ...\n"), 226 GNUNET_DISK_file_test(opt_cfg_filename)) ||
233 opt_cfg_filename); 227 (GNUNET_SYSERR ==
234 return GNUNET_SYSERR; 228 GNUNET_CONFIGURATION_load(cfg,
229 opt_cfg_filename)))
230 {
231 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
232 _("Malformed configuration file `%s', exit ...\n"),
233 opt_cfg_filename);
234 return GNUNET_SYSERR;
235 }
235 } 236 }
236 }
237 else 237 else
238 {
239 if (GNUNET_YES ==
240 GNUNET_DISK_file_test (cfg_filename))
241 {
242 if (GNUNET_SYSERR ==
243 GNUNET_CONFIGURATION_load (cfg,
244 cfg_filename))
245 {
246 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
247 _("Malformed configuration file `%s', exit ...\n"),
248 cfg_filename);
249 return GNUNET_SYSERR;
250 }
251 }
252 else
253 { 238 {
254 if (GNUNET_SYSERR == 239 if (GNUNET_YES ==
255 GNUNET_CONFIGURATION_load (cfg, 240 GNUNET_DISK_file_test(cfg_filename))
256 NULL)) 241 {
257 { 242 if (GNUNET_SYSERR ==
258 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 243 GNUNET_CONFIGURATION_load(cfg,
259 _("Malformed configuration, exit ...\n")); 244 cfg_filename))
260 return GNUNET_SYSERR; 245 {
261 } 246 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
247 _("Malformed configuration file `%s', exit ...\n"),
248 cfg_filename);
249 return GNUNET_SYSERR;
250 }
251 }
252 else
253 {
254 if (GNUNET_SYSERR ==
255 GNUNET_CONFIGURATION_load(cfg,
256 NULL))
257 {
258 GNUNET_log(GNUNET_ERROR_TYPE_ERROR,
259 _("Malformed configuration, exit ...\n"));
260 return GNUNET_SYSERR;
261 }
262 }
262 } 263 }
263 } 264 GNUNET_SCHEDULER_run(&run,
264 GNUNET_SCHEDULER_run (&run, 265 cfg);
265 cfg);
266} 266}
267 267