diff options
author | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-06 22:46:29 +0000 |
commit | 6e599264ad13e8fc105493d74d7c11d46f8739ed (patch) | |
tree | 169bef1ecbade5a659831fb169f3ae6943af127f /src/nat-auto | |
parent | 4f13bc15113021ebf71d5d81e99bc29f8a07fc9c (diff) | |
download | gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.tar.gz gnunet-6e599264ad13e8fc105493d74d7c11d46f8739ed.zip |
first step to remove plibc
Diffstat (limited to 'src/nat-auto')
-rw-r--r-- | src/nat-auto/gnunet-nat-auto.c | 149 | ||||
-rw-r--r-- | src/nat-auto/nat_auto_api_test.c | 226 |
2 files changed, 150 insertions, 225 deletions
diff --git a/src/nat-auto/gnunet-nat-auto.c b/src/nat-auto/gnunet-nat-auto.c index bd8f4ff45..106d60228 100644 --- a/src/nat-auto/gnunet-nat-auto.c +++ b/src/nat-auto/gnunet-nat-auto.c | |||
@@ -116,14 +116,9 @@ auto_conf_iter (void *cls, | |||
116 | { | 116 | { |
117 | struct GNUNET_CONFIGURATION_Handle *new_cfg = cls; | 117 | struct GNUNET_CONFIGURATION_Handle *new_cfg = cls; |
118 | 118 | ||
119 | PRINTF ("%s: %s\n", | 119 | printf ("%s: %s\n", option, value); |
120 | option, | ||
121 | value); | ||
122 | if (NULL != new_cfg) | 120 | if (NULL != new_cfg) |
123 | GNUNET_CONFIGURATION_set_value_string (new_cfg, | 121 | GNUNET_CONFIGURATION_set_value_string (new_cfg, section, option, value); |
124 | section, | ||
125 | option, | ||
126 | value); | ||
127 | } | 122 | } |
128 | 123 | ||
129 | 124 | ||
@@ -138,9 +133,9 @@ auto_conf_iter (void *cls, | |||
138 | */ | 133 | */ |
139 | static void | 134 | static void |
140 | auto_config_cb (void *cls, | 135 | auto_config_cb (void *cls, |
141 | const struct GNUNET_CONFIGURATION_Handle *diff, | 136 | const struct GNUNET_CONFIGURATION_Handle *diff, |
142 | enum GNUNET_NAT_StatusCode result, | 137 | enum GNUNET_NAT_StatusCode result, |
143 | enum GNUNET_NAT_Type type) | 138 | enum GNUNET_NAT_Type type) |
144 | { | 139 | { |
145 | const char *nat_type; | 140 | const char *nat_type; |
146 | char unknown_type[64]; | 141 | char unknown_type[64]; |
@@ -162,24 +157,21 @@ auto_config_cb (void *cls, | |||
162 | nat_type = "NAT but UPNP opened the ports"; | 157 | nat_type = "NAT but UPNP opened the ports"; |
163 | break; | 158 | break; |
164 | default: | 159 | default: |
165 | SPRINTF (unknown_type, | 160 | sprintf (unknown_type, "NAT unknown, type %u", type); |
166 | "NAT unknown, type %u", | ||
167 | type); | ||
168 | nat_type = unknown_type; | 161 | nat_type = unknown_type; |
169 | break; | 162 | break; |
170 | } | 163 | } |
171 | 164 | ||
172 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 165 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
173 | "NAT status: %s/%s\n", | 166 | "NAT status: %s/%s\n", |
174 | GNUNET_NAT_AUTO_status2string (result), | 167 | GNUNET_NAT_AUTO_status2string (result), |
175 | nat_type); | 168 | nat_type); |
176 | 169 | ||
177 | if (NULL == diff) | 170 | if (NULL == diff) |
178 | return; | 171 | return; |
179 | 172 | ||
180 | /* Shortcut: if there are no changes suggested, bail out early. */ | 173 | /* Shortcut: if there are no changes suggested, bail out early. */ |
181 | if (GNUNET_NO == | 174 | if (GNUNET_NO == GNUNET_CONFIGURATION_is_dirty (diff)) |
182 | GNUNET_CONFIGURATION_is_dirty (diff)) | ||
183 | { | 175 | { |
184 | test_finished (); | 176 | test_finished (); |
185 | return; | 177 | return; |
@@ -190,7 +182,7 @@ auto_config_cb (void *cls, | |||
190 | new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL; | 182 | new_cfg = write_cfg ? GNUNET_CONFIGURATION_dup (cfg) : NULL; |
191 | 183 | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
193 | _("Suggested configuration changes:\n")); | 185 | _ ("Suggested configuration changes:\n")); |
194 | GNUNET_CONFIGURATION_iterate_section_values (diff, | 186 | GNUNET_CONFIGURATION_iterate_section_values (diff, |
195 | "nat", | 187 | "nat", |
196 | &auto_conf_iter, | 188 | &auto_conf_iter, |
@@ -202,29 +194,22 @@ auto_config_cb (void *cls, | |||
202 | { | 194 | { |
203 | struct GNUNET_CONFIGURATION_Handle *def_cfg; | 195 | struct GNUNET_CONFIGURATION_Handle *def_cfg; |
204 | 196 | ||
205 | GNUNET_CONFIGURATION_set_value_string (new_cfg, | 197 | GNUNET_CONFIGURATION_set_value_string (new_cfg, "ARM", "CONFIG", NULL); |
206 | "ARM", | ||
207 | "CONFIG", | ||
208 | NULL); | ||
209 | def_cfg = GNUNET_CONFIGURATION_create (); | 198 | def_cfg = GNUNET_CONFIGURATION_create (); |
210 | GNUNET_break (GNUNET_OK == | 199 | GNUNET_break (GNUNET_OK == GNUNET_CONFIGURATION_load (def_cfg, NULL)); |
211 | GNUNET_CONFIGURATION_load (def_cfg, | ||
212 | NULL)); | ||
213 | if (GNUNET_OK != | 200 | if (GNUNET_OK != |
214 | GNUNET_CONFIGURATION_write_diffs (def_cfg, | 201 | GNUNET_CONFIGURATION_write_diffs (def_cfg, new_cfg, cfg_file)) |
215 | new_cfg, | ||
216 | cfg_file)) | ||
217 | { | 202 | { |
218 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 203 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
219 | _("Failed to write configuration to `%s'\n"), | 204 | _ ("Failed to write configuration to `%s'\n"), |
220 | cfg_file); | 205 | cfg_file); |
221 | global_ret = 1; | 206 | global_ret = 1; |
222 | } | 207 | } |
223 | else | 208 | else |
224 | { | 209 | { |
225 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 210 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, |
226 | _("Wrote updated configuration to `%s'\n"), | 211 | _ ("Wrote updated configuration to `%s'\n"), |
227 | cfg_file); | 212 | cfg_file); |
228 | } | 213 | } |
229 | GNUNET_CONFIGURATION_destroy (def_cfg); | 214 | GNUNET_CONFIGURATION_destroy (def_cfg); |
230 | } | 215 | } |
@@ -243,12 +228,10 @@ auto_config_cb (void *cls, | |||
243 | * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code | 228 | * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code |
244 | */ | 229 | */ |
245 | static void | 230 | static void |
246 | test_report_cb (void *cls, | 231 | test_report_cb (void *cls, enum GNUNET_NAT_StatusCode result) |
247 | enum GNUNET_NAT_StatusCode result) | ||
248 | { | 232 | { |
249 | nt = NULL; | 233 | nt = NULL; |
250 | PRINTF ("NAT test result: %s\n", | 234 | printf ("NAT test result: %s\n", GNUNET_NAT_AUTO_status2string (result)); |
251 | GNUNET_NAT_AUTO_status2string (result)); | ||
252 | test_finished (); | 235 | test_finished (); |
253 | } | 236 | } |
254 | 237 | ||
@@ -291,22 +274,18 @@ run (void *cls, | |||
291 | cfg_file = cfgfile; | 274 | cfg_file = cfgfile; |
292 | cfg = c; | 275 | cfg = c; |
293 | 276 | ||
294 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 277 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); |
295 | NULL); | ||
296 | 278 | ||
297 | if (do_auto) | 279 | if (do_auto) |
298 | { | 280 | { |
299 | ah = GNUNET_NAT_AUTO_autoconfig_start (c, | 281 | ah = GNUNET_NAT_AUTO_autoconfig_start (c, &auto_config_cb, NULL); |
300 | &auto_config_cb, | ||
301 | NULL); | ||
302 | } | 282 | } |
303 | 283 | ||
304 | if (use_tcp && use_udp) | 284 | if (use_tcp && use_udp) |
305 | { | 285 | { |
306 | if (do_auto) | 286 | if (do_auto) |
307 | return; | 287 | return; |
308 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, | 288 | GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE, "Cannot use TCP and UDP\n"); |
309 | "Cannot use TCP and UDP\n"); | ||
310 | global_ret = 1; | 289 | global_ret = 1; |
311 | return; | 290 | return; |
312 | } | 291 | } |
@@ -319,10 +298,10 @@ run (void *cls, | |||
319 | if (NULL != section_name) | 298 | if (NULL != section_name) |
320 | { | 299 | { |
321 | nt = GNUNET_NAT_AUTO_test_start (c, | 300 | nt = GNUNET_NAT_AUTO_test_start (c, |
322 | proto, | 301 | proto, |
323 | section_name, | 302 | section_name, |
324 | &test_report_cb, | 303 | &test_report_cb, |
325 | NULL); | 304 | NULL); |
326 | } | 305 | } |
327 | test_finished (); | 306 | test_finished (); |
328 | } | 307 | } |
@@ -336,53 +315,47 @@ run (void *cls, | |||
336 | * @return 0 on success, -1 on error | 315 | * @return 0 on success, -1 on error |
337 | */ | 316 | */ |
338 | int | 317 | int |
339 | main (int argc, | 318 | main (int argc, char *const argv[]) |
340 | char *const argv[]) | ||
341 | { | 319 | { |
342 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 320 | struct GNUNET_GETOPT_CommandLineOption options[] = |
343 | GNUNET_GETOPT_option_flag ('a', | 321 | {GNUNET_GETOPT_option_flag ('a', |
344 | "auto", | 322 | "auto", |
345 | gettext_noop ("run autoconfiguration"), | 323 | gettext_noop ("run autoconfiguration"), |
346 | &do_auto), | 324 | &do_auto), |
347 | 325 | ||
348 | GNUNET_GETOPT_option_string ('S', | 326 | GNUNET_GETOPT_option_string ( |
349 | "section", | 327 | 'S', |
350 | "NAME", | 328 | "section", |
351 | gettext_noop ("section name providing the configuration for the adapter"), | 329 | "NAME", |
352 | §ion_name), | 330 | gettext_noop ( |
353 | 331 | "section name providing the configuration for the adapter"), | |
354 | GNUNET_GETOPT_option_flag ('t', | 332 | §ion_name), |
355 | "tcp", | 333 | |
356 | gettext_noop ("use TCP"), | 334 | GNUNET_GETOPT_option_flag ('t', "tcp", gettext_noop ("use TCP"), &use_tcp), |
357 | &use_tcp), | 335 | |
358 | 336 | GNUNET_GETOPT_option_flag ('u', "udp", gettext_noop ("use UDP"), &use_udp), | |
359 | GNUNET_GETOPT_option_flag ('u', | 337 | |
360 | "udp", | 338 | GNUNET_GETOPT_option_flag ( |
361 | gettext_noop ("use UDP"), | 339 | 'w', |
362 | &use_udp), | 340 | "write", |
363 | 341 | gettext_noop ("write configuration file (for autoconfiguration)"), | |
364 | GNUNET_GETOPT_option_flag ('w', | 342 | &write_cfg), |
365 | "write", | 343 | GNUNET_GETOPT_OPTION_END}; |
366 | gettext_noop ("write configuration file (for autoconfiguration)"), | 344 | |
367 | &write_cfg), | 345 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
368 | GNUNET_GETOPT_OPTION_END | ||
369 | }; | ||
370 | |||
371 | if (GNUNET_OK != | ||
372 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
373 | &argc, &argv)) | ||
374 | return 2; | 346 | return 2; |
375 | if (GNUNET_OK != | 347 | if (GNUNET_OK != |
376 | GNUNET_PROGRAM_run (argc, argv, | 348 | GNUNET_PROGRAM_run (argc, |
377 | "gnunet-nat-auto [options]", | 349 | argv, |
378 | _("GNUnet NAT traversal autoconfiguration"), | 350 | "gnunet-nat-auto [options]", |
379 | options, | 351 | _ ("GNUnet NAT traversal autoconfiguration"), |
352 | options, | ||
380 | &run, | 353 | &run, |
381 | NULL)) | 354 | NULL)) |
382 | { | 355 | { |
383 | global_ret = 1; | 356 | global_ret = 1; |
384 | } | 357 | } |
385 | GNUNET_free ((void*) argv); | 358 | GNUNET_free ((void *) argv); |
386 | return global_ret; | 359 | return global_ret; |
387 | } | 360 | } |
388 | 361 | ||
diff --git a/src/nat-auto/nat_auto_api_test.c b/src/nat-auto/nat_auto_api_test.c index 1511d91ba..56a2b8d72 100644 --- a/src/nat-auto/nat_auto_api_test.c +++ b/src/nat-auto/nat_auto_api_test.c | |||
@@ -28,9 +28,10 @@ | |||
28 | #include "gnunet_nat_auto_service.h" | 28 | #include "gnunet_nat_auto_service.h" |
29 | #include "nat-auto.h" | 29 | #include "nat-auto.h" |
30 | 30 | ||
31 | #define LOG(kind,...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__) |
32 | 32 | ||
33 | #define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 33 | #define NAT_SERVER_TIMEOUT \ |
34 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | ||
34 | 35 | ||
35 | /** | 36 | /** |
36 | * Entry we keep for each incoming connection. | 37 | * Entry we keep for each incoming connection. |
@@ -88,7 +89,6 @@ struct ClientActivity | |||
88 | * Handle to overall NAT test. | 89 | * Handle to overall NAT test. |
89 | */ | 90 | */ |
90 | struct GNUNET_NAT_AUTO_Test *h; | 91 | struct GNUNET_NAT_AUTO_Test *h; |
91 | |||
92 | }; | 92 | }; |
93 | 93 | ||
94 | 94 | ||
@@ -184,9 +184,7 @@ struct GNUNET_NAT_AUTO_Test | |||
184 | * @param addrlen actual lenght of the @a addr | 184 | * @param addrlen actual lenght of the @a addr |
185 | */ | 185 | */ |
186 | static void | 186 | static void |
187 | reversal_cb (void *cls, | 187 | reversal_cb (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
188 | const struct sockaddr *addr, | ||
189 | socklen_t addrlen) | ||
190 | { | 188 | { |
191 | struct GNUNET_NAT_AUTO_Test *h = cls; | 189 | struct GNUNET_NAT_AUTO_Test *h = cls; |
192 | const struct sockaddr_in *sa; | 190 | const struct sockaddr_in *sa; |
@@ -198,11 +196,10 @@ reversal_cb (void *cls, | |||
198 | { | 196 | { |
199 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 197 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
200 | "Received connection reversal request for wrong port\n"); | 198 | "Received connection reversal request for wrong port\n"); |
201 | return; /* wrong port */ | 199 | return; /* wrong port */ |
202 | } | 200 | } |
203 | /* report success */ | 201 | /* report success */ |
204 | h->report (h->report_cls, | 202 | h->report (h->report_cls, GNUNET_NAT_ERROR_SUCCESS); |
205 | GNUNET_NAT_ERROR_SUCCESS); | ||
206 | } | 203 | } |
207 | 204 | ||
208 | 205 | ||
@@ -220,22 +217,17 @@ do_udp_read (void *cls) | |||
220 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 217 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
221 | 218 | ||
222 | tc = GNUNET_SCHEDULER_get_task_context (); | 219 | tc = GNUNET_SCHEDULER_get_task_context (); |
223 | tst->ltask = | 220 | tst->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
224 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 221 | tst->lsock, |
225 | tst->lsock, | 222 | &do_udp_read, |
226 | &do_udp_read, | 223 | tst); |
227 | tst); | ||
228 | if ((NULL != tc->write_ready) && | 224 | if ((NULL != tc->write_ready) && |
229 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 225 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, tst->lsock)) && |
230 | tst->lsock)) && | ||
231 | (sizeof (data) == | 226 | (sizeof (data) == |
232 | GNUNET_NETWORK_socket_recv (tst->lsock, | 227 | GNUNET_NETWORK_socket_recv (tst->lsock, &data, sizeof (data)))) |
233 | &data, | ||
234 | sizeof (data)))) | ||
235 | { | 228 | { |
236 | if (data == tst->data) | 229 | if (data == tst->data) |
237 | tst->report (tst->report_cls, | 230 | tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS); |
238 | GNUNET_NAT_ERROR_SUCCESS); | ||
239 | else | 231 | else |
240 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 232 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
241 | "Received data mismatches expected value\n"); | 233 | "Received data mismatches expected value\n"); |
@@ -263,20 +255,14 @@ do_read (void *cls) | |||
263 | tc = GNUNET_SCHEDULER_get_task_context (); | 255 | tc = GNUNET_SCHEDULER_get_task_context (); |
264 | na->rtask = NULL; | 256 | na->rtask = NULL; |
265 | tst = na->h; | 257 | tst = na->h; |
266 | GNUNET_CONTAINER_DLL_remove (tst->na_head, | 258 | GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, na); |
267 | tst->na_tail, | ||
268 | na); | ||
269 | if ((NULL != tc->write_ready) && | 259 | if ((NULL != tc->write_ready) && |
270 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, | 260 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, na->sock)) && |
271 | na->sock)) && | ||
272 | (sizeof (data) == | 261 | (sizeof (data) == |
273 | GNUNET_NETWORK_socket_recv (na->sock, | 262 | GNUNET_NETWORK_socket_recv (na->sock, &data, sizeof (data)))) |
274 | &data, | ||
275 | sizeof (data)))) | ||
276 | { | 263 | { |
277 | if (data == tst->data) | 264 | if (data == tst->data) |
278 | tst->report (tst->report_cls, | 265 | tst->report (tst->report_cls, GNUNET_NAT_ERROR_SUCCESS); |
279 | GNUNET_NAT_ERROR_SUCCESS); | ||
280 | else | 266 | else |
281 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 267 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
282 | "Received data does not match expected value\n"); | 268 | "Received data does not match expected value\n"); |
@@ -306,28 +292,22 @@ do_accept (void *cls) | |||
306 | tst->lsock, | 292 | tst->lsock, |
307 | &do_accept, | 293 | &do_accept, |
308 | tst); | 294 | tst); |
309 | s = GNUNET_NETWORK_socket_accept (tst->lsock, | 295 | s = GNUNET_NETWORK_socket_accept (tst->lsock, NULL, NULL); |
310 | NULL, | ||
311 | NULL); | ||
312 | if (NULL == s) | 296 | if (NULL == s) |
313 | { | 297 | { |
314 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, | 298 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_INFO, "accept"); |
315 | "accept"); | 299 | return; /* odd error */ |
316 | return; /* odd error */ | ||
317 | } | 300 | } |
318 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 301 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
319 | "Got an inbound connection, waiting for data\n"); | 302 | "Got an inbound connection, waiting for data\n"); |
320 | wl = GNUNET_new (struct NatActivity); | 303 | wl = GNUNET_new (struct NatActivity); |
321 | wl->sock = s; | 304 | wl->sock = s; |
322 | wl->h = tst; | 305 | wl->h = tst; |
323 | wl->rtask = | 306 | wl->rtask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
324 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 307 | wl->sock, |
325 | wl->sock, | 308 | &do_read, |
326 | &do_read, | 309 | wl); |
327 | wl); | 310 | GNUNET_CONTAINER_DLL_insert (tst->na_head, tst->na_tail, wl); |
328 | GNUNET_CONTAINER_DLL_insert (tst->na_head, | ||
329 | tst->na_tail, | ||
330 | wl); | ||
331 | } | 311 | } |
332 | 312 | ||
333 | 313 | ||
@@ -339,15 +319,12 @@ do_accept (void *cls) | |||
339 | * @param error error code | 319 | * @param error error code |
340 | */ | 320 | */ |
341 | static void | 321 | static void |
342 | mq_error_handler (void *cls, | 322 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
343 | enum GNUNET_MQ_Error error) | ||
344 | { | 323 | { |
345 | struct ClientActivity *ca = cls; | 324 | struct ClientActivity *ca = cls; |
346 | struct GNUNET_NAT_AUTO_Test *tst = ca->h; | 325 | struct GNUNET_NAT_AUTO_Test *tst = ca->h; |
347 | 326 | ||
348 | GNUNET_CONTAINER_DLL_remove (tst->ca_head, | 327 | GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, ca); |
349 | tst->ca_tail, | ||
350 | ca); | ||
351 | GNUNET_MQ_destroy (ca->mq); | 328 | GNUNET_MQ_destroy (ca->mq); |
352 | GNUNET_free (ca); | 329 | GNUNET_free (ca); |
353 | } | 330 | } |
@@ -367,7 +344,7 @@ mq_error_handler (void *cls, | |||
367 | */ | 344 | */ |
368 | static void | 345 | static void |
369 | addr_cb (void *cls, | 346 | addr_cb (void *cls, |
370 | void **app_ctx, | 347 | void **app_ctx, |
371 | int add_remove, | 348 | int add_remove, |
372 | enum GNUNET_NAT_AddressClass ac, | 349 | enum GNUNET_NAT_AddressClass ac, |
373 | const struct sockaddr *addr, | 350 | const struct sockaddr *addr, |
@@ -385,15 +362,13 @@ addr_cb (void *cls, | |||
385 | if (addrlen != sizeof (struct sockaddr_in)) | 362 | if (addrlen != sizeof (struct sockaddr_in)) |
386 | { | 363 | { |
387 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 364 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
388 | "NAT test ignores IPv6 address `%s' returned from NAT library\n", | 365 | "NAT test ignores IPv6 address `%s' returned from NAT library\n", |
389 | GNUNET_a2s (addr, | 366 | GNUNET_a2s (addr, addrlen)); |
390 | addrlen)); | 367 | return; /* ignore IPv6 here */ |
391 | return; /* ignore IPv6 here */ | ||
392 | } | 368 | } |
393 | LOG (GNUNET_ERROR_TYPE_INFO, | 369 | LOG (GNUNET_ERROR_TYPE_INFO, |
394 | "Asking gnunet-nat-server to connect to `%s'\n", | 370 | "Asking gnunet-nat-server to connect to `%s'\n", |
395 | GNUNET_a2s (addr, | 371 | GNUNET_a2s (addr, addrlen)); |
396 | addrlen)); | ||
397 | 372 | ||
398 | ca = GNUNET_new (struct ClientActivity); | 373 | ca = GNUNET_new (struct ClientActivity); |
399 | ca->h = h; | 374 | ca->h = h; |
@@ -406,21 +381,17 @@ addr_cb (void *cls, | |||
406 | { | 381 | { |
407 | GNUNET_free (ca); | 382 | GNUNET_free (ca); |
408 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 383 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
409 | _("Failed to connect to `gnunet-nat-server'\n")); | 384 | _ ("Failed to connect to `gnunet-nat-server'\n")); |
410 | return; | 385 | return; |
411 | } | 386 | } |
412 | GNUNET_CONTAINER_DLL_insert (h->ca_head, | 387 | GNUNET_CONTAINER_DLL_insert (h->ca_head, h->ca_tail, ca); |
413 | h->ca_tail, | ||
414 | ca); | ||
415 | sa = (const struct sockaddr_in *) addr; | 388 | sa = (const struct sockaddr_in *) addr; |
416 | env = GNUNET_MQ_msg (msg, | 389 | env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_NAT_TEST); |
417 | GNUNET_MESSAGE_TYPE_NAT_TEST); | ||
418 | msg->dst_ipv4 = sa->sin_addr.s_addr; | 390 | msg->dst_ipv4 = sa->sin_addr.s_addr; |
419 | msg->dport = sa->sin_port; | 391 | msg->dport = sa->sin_port; |
420 | msg->data = h->data; | 392 | msg->data = h->data; |
421 | msg->is_tcp = htonl ((uint32_t) (h->proto == IPPROTO_TCP)); | 393 | msg->is_tcp = htonl ((uint32_t) (h->proto == IPPROTO_TCP)); |
422 | GNUNET_MQ_send (ca->mq, | 394 | GNUNET_MQ_send (ca->mq, env); |
423 | env); | ||
424 | } | 395 | } |
425 | 396 | ||
426 | 397 | ||
@@ -437,8 +408,7 @@ do_fail (void *cls) | |||
437 | struct GNUNET_NAT_AUTO_Test *nh = cls; | 408 | struct GNUNET_NAT_AUTO_Test *nh = cls; |
438 | 409 | ||
439 | nh->ttask = NULL; | 410 | nh->ttask = NULL; |
440 | nh->report (nh->report_cls, | 411 | nh->report (nh->report_cls, nh->status); |
441 | nh->status); | ||
442 | } | 412 | } |
443 | 413 | ||
444 | 414 | ||
@@ -455,30 +425,25 @@ do_fail (void *cls) | |||
455 | */ | 425 | */ |
456 | struct GNUNET_NAT_AUTO_Test * | 426 | struct GNUNET_NAT_AUTO_Test * |
457 | GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | 427 | GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, |
458 | uint8_t proto, | 428 | uint8_t proto, |
459 | const char *section_name, | 429 | const char *section_name, |
460 | GNUNET_NAT_TestCallback report, | 430 | GNUNET_NAT_TestCallback report, |
461 | void *report_cls) | 431 | void *report_cls) |
462 | { | 432 | { |
463 | struct GNUNET_NAT_AUTO_Test *nh; | 433 | struct GNUNET_NAT_AUTO_Test *nh; |
464 | unsigned long long bnd_port; | 434 | unsigned long long bnd_port; |
465 | struct sockaddr_in sa; | 435 | struct sockaddr_in sa; |
466 | const struct sockaddr *addrs[] = { | 436 | const struct sockaddr *addrs[] = {(const struct sockaddr *) &sa}; |
467 | (const struct sockaddr *) &sa | 437 | const socklen_t addrlens[] = {sizeof (sa)}; |
468 | }; | 438 | |
469 | const socklen_t addrlens[] = { | 439 | if ((GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, |
470 | sizeof (sa) | 440 | section_name, |
471 | }; | 441 | "PORT", |
472 | 442 | &bnd_port)) || | |
473 | if ( (GNUNET_OK != | 443 | (bnd_port > 65535)) |
474 | GNUNET_CONFIGURATION_get_value_number (cfg, | ||
475 | section_name, | ||
476 | "PORT", | ||
477 | &bnd_port)) || | ||
478 | (bnd_port > 65535) ) | ||
479 | { | 444 | { |
480 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 445 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
481 | _("Failed to find valid PORT in section `%s'\n"), | 446 | _ ("Failed to find valid PORT in section `%s'\n"), |
482 | section_name); | 447 | section_name); |
483 | return NULL; | 448 | return NULL; |
484 | } | 449 | } |
@@ -499,67 +464,60 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
499 | nh->status = GNUNET_NAT_ERROR_SUCCESS; | 464 | nh->status = GNUNET_NAT_ERROR_SUCCESS; |
500 | if (0 == bnd_port) | 465 | if (0 == bnd_port) |
501 | { | 466 | { |
502 | nh->nat | 467 | nh->nat = GNUNET_NAT_register (cfg, |
503 | = GNUNET_NAT_register (cfg, | 468 | section_name, |
504 | section_name, | 469 | proto, |
505 | proto, | 470 | 0, |
506 | 0, NULL, NULL, | 471 | NULL, |
507 | &addr_cb, | 472 | NULL, |
508 | &reversal_cb, | 473 | &addr_cb, |
509 | nh); | 474 | &reversal_cb, |
475 | nh); | ||
510 | } | 476 | } |
511 | else | 477 | else |
512 | { | 478 | { |
513 | nh->lsock | 479 | nh->lsock = |
514 | = GNUNET_NETWORK_socket_create (AF_INET, | 480 | GNUNET_NETWORK_socket_create (AF_INET, |
515 | (IPPROTO_UDP == proto) | 481 | (IPPROTO_UDP == proto) ? SOCK_DGRAM |
516 | ? SOCK_DGRAM | 482 | : SOCK_STREAM, |
517 | : SOCK_STREAM, | 483 | proto); |
518 | proto); | 484 | if ((NULL == nh->lsock) || |
519 | if ( (NULL == nh->lsock) || | 485 | (GNUNET_OK != GNUNET_NETWORK_socket_bind (nh->lsock, |
520 | (GNUNET_OK != | 486 | (const struct sockaddr *) &sa, |
521 | GNUNET_NETWORK_socket_bind (nh->lsock, | 487 | sizeof (sa)))) |
522 | (const struct sockaddr *) &sa, | ||
523 | sizeof (sa)))) | ||
524 | { | 488 | { |
525 | LOG (GNUNET_ERROR_TYPE_ERROR, | 489 | LOG (GNUNET_ERROR_TYPE_ERROR, |
526 | _("Failed to create socket bound to `%s' for NAT test: %s\n"), | 490 | _ ("Failed to create socket bound to `%s' for NAT test: %s\n"), |
527 | GNUNET_a2s ((const struct sockaddr *) &sa, | 491 | GNUNET_a2s ((const struct sockaddr *) &sa, sizeof (sa)), |
528 | sizeof (sa)), | 492 | strerror (errno)); |
529 | STRERROR (errno)); | ||
530 | if (NULL != nh->lsock) | 493 | if (NULL != nh->lsock) |
531 | { | 494 | { |
532 | GNUNET_NETWORK_socket_close (nh->lsock); | 495 | GNUNET_NETWORK_socket_close (nh->lsock); |
533 | nh->lsock = NULL; | 496 | nh->lsock = NULL; |
534 | } | 497 | } |
535 | nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; | 498 | nh->status = GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR; |
536 | nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, | 499 | nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, nh); |
537 | nh); | ||
538 | return nh; | 500 | return nh; |
539 | } | 501 | } |
540 | if (IPPROTO_TCP == proto) | 502 | if (IPPROTO_TCP == proto) |
541 | { | 503 | { |
542 | GNUNET_break (GNUNET_OK == | 504 | GNUNET_break (GNUNET_OK == GNUNET_NETWORK_socket_listen (nh->lsock, 5)); |
543 | GNUNET_NETWORK_socket_listen (nh->lsock, | 505 | nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
544 | 5)); | 506 | nh->lsock, |
545 | nh->ltask = | 507 | &do_accept, |
546 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 508 | nh); |
547 | nh->lsock, | ||
548 | &do_accept, | ||
549 | nh); | ||
550 | } | 509 | } |
551 | else | 510 | else |
552 | { | 511 | { |
553 | nh->ltask = | 512 | nh->ltask = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, |
554 | GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, | 513 | nh->lsock, |
555 | nh->lsock, | 514 | &do_udp_read, |
556 | &do_udp_read, | 515 | nh); |
557 | nh); | ||
558 | } | 516 | } |
559 | LOG (GNUNET_ERROR_TYPE_INFO, | 517 | LOG (GNUNET_ERROR_TYPE_INFO, |
560 | "NAT test listens on port %llu (%s)\n", | 518 | "NAT test listens on port %llu (%s)\n", |
561 | bnd_port, | 519 | bnd_port, |
562 | (IPPROTO_TCP == proto) ? "tcp" : "udp"); | 520 | (IPPROTO_TCP == proto) ? "tcp" : "udp"); |
563 | nh->nat = GNUNET_NAT_register (cfg, | 521 | nh->nat = GNUNET_NAT_register (cfg, |
564 | section_name, | 522 | section_name, |
565 | proto, | 523 | proto, |
@@ -572,7 +530,7 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
572 | if (NULL == nh->nat) | 530 | if (NULL == nh->nat) |
573 | { | 531 | { |
574 | LOG (GNUNET_ERROR_TYPE_INFO, | 532 | LOG (GNUNET_ERROR_TYPE_INFO, |
575 | _("NAT test failed to start NAT library\n")); | 533 | _ ("NAT test failed to start NAT library\n")); |
576 | if (NULL != nh->ltask) | 534 | if (NULL != nh->ltask) |
577 | { | 535 | { |
578 | GNUNET_SCHEDULER_cancel (nh->ltask); | 536 | GNUNET_SCHEDULER_cancel (nh->ltask); |
@@ -584,8 +542,7 @@ GNUNET_NAT_AUTO_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
584 | nh->lsock = NULL; | 542 | nh->lsock = NULL; |
585 | } | 543 | } |
586 | nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; | 544 | nh->status = GNUNET_NAT_ERROR_NAT_REGISTER_FAILED; |
587 | nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, | 545 | nh->ttask = GNUNET_SCHEDULER_add_now (&do_fail, nh); |
588 | nh); | ||
589 | return nh; | 546 | return nh; |
590 | } | 547 | } |
591 | } | 548 | } |
@@ -604,21 +561,16 @@ GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst) | |||
604 | struct NatActivity *pos; | 561 | struct NatActivity *pos; |
605 | struct ClientActivity *cpos; | 562 | struct ClientActivity *cpos; |
606 | 563 | ||
607 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 564 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n"); |
608 | "Stopping NAT test\n"); | ||
609 | while (NULL != (cpos = tst->ca_head)) | 565 | while (NULL != (cpos = tst->ca_head)) |
610 | { | 566 | { |
611 | GNUNET_CONTAINER_DLL_remove (tst->ca_head, | 567 | GNUNET_CONTAINER_DLL_remove (tst->ca_head, tst->ca_tail, cpos); |
612 | tst->ca_tail, | ||
613 | cpos); | ||
614 | GNUNET_MQ_destroy (cpos->mq); | 568 | GNUNET_MQ_destroy (cpos->mq); |
615 | GNUNET_free (cpos); | 569 | GNUNET_free (cpos); |
616 | } | 570 | } |
617 | while (NULL != (pos = tst->na_head)) | 571 | while (NULL != (pos = tst->na_head)) |
618 | { | 572 | { |
619 | GNUNET_CONTAINER_DLL_remove (tst->na_head, | 573 | GNUNET_CONTAINER_DLL_remove (tst->na_head, tst->na_tail, pos); |
620 | tst->na_tail, | ||
621 | pos); | ||
622 | GNUNET_SCHEDULER_cancel (pos->rtask); | 574 | GNUNET_SCHEDULER_cancel (pos->rtask); |
623 | GNUNET_NETWORK_socket_close (pos->sock); | 575 | GNUNET_NETWORK_socket_close (pos->sock); |
624 | GNUNET_free (pos); | 576 | GNUNET_free (pos); |