diff options
author | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
---|---|---|
committer | ng0 <ng0@n0.is> | 2019-09-08 12:33:09 +0000 |
commit | d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch) | |
tree | 9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/pt | |
parent | a0fce305c565c0937d917a92712f15e9c5736260 (diff) | |
download | gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip |
uncrustify as demanded.
Diffstat (limited to 'src/pt')
-rw-r--r-- | src/pt/gnunet-daemon-pt.c | 1115 | ||||
-rw-r--r-- | src/pt/test_gns_vpn.c | 902 | ||||
-rw-r--r-- | src/pt/test_gnunet_vpn.c | 521 |
3 files changed, 1270 insertions, 1268 deletions
diff --git a/src/pt/gnunet-daemon-pt.c b/src/pt/gnunet-daemon-pt.c index 99cbfebf8..ad22eaab8 100644 --- a/src/pt/gnunet-daemon-pt.c +++ b/src/pt/gnunet-daemon-pt.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 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 | * @file pt/gnunet-daemon-pt.c | 21 | * @file pt/gnunet-daemon-pt.c |
22 | * @brief tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet) | 22 | * @brief tool to manipulate DNS and VPN services to perform protocol translation (IPvX over GNUnet) |
@@ -58,8 +58,7 @@ | |||
58 | /** | 58 | /** |
59 | * Which group of DNS records are we currently processing? | 59 | * Which group of DNS records are we currently processing? |
60 | */ | 60 | */ |
61 | enum RequestGroup | 61 | enum RequestGroup { |
62 | { | ||
63 | /** | 62 | /** |
64 | * DNS answers | 63 | * DNS answers |
65 | */ | 64 | */ |
@@ -85,8 +84,7 @@ enum RequestGroup | |||
85 | /** | 84 | /** |
86 | * Information tracked per DNS reply that we are processing. | 85 | * Information tracked per DNS reply that we are processing. |
87 | */ | 86 | */ |
88 | struct ReplyContext | 87 | struct ReplyContext { |
89 | { | ||
90 | /** | 88 | /** |
91 | * Handle to submit the final result. | 89 | * Handle to submit the final result. |
92 | */ | 90 | */ |
@@ -116,7 +114,6 @@ struct ReplyContext | |||
116 | * Group that is being modified | 114 | * Group that is being modified |
117 | */ | 115 | */ |
118 | enum RequestGroup group; | 116 | enum RequestGroup group; |
119 | |||
120 | }; | 117 | }; |
121 | 118 | ||
122 | 119 | ||
@@ -125,9 +122,7 @@ struct ReplyContext | |||
125 | * as a DNS exit. We try to keep a few channels open and a few | 122 | * as a DNS exit. We try to keep a few channels open and a few |
126 | * peers in reserve. | 123 | * peers in reserve. |
127 | */ | 124 | */ |
128 | struct CadetExit | 125 | struct CadetExit { |
129 | { | ||
130 | |||
131 | /** | 126 | /** |
132 | * Kept in a DLL. | 127 | * Kept in a DLL. |
133 | */ | 128 | */ |
@@ -178,7 +173,6 @@ struct CadetExit | |||
178 | * Size of the window, 0 if we are busy. | 173 | * Size of the window, 0 if we are busy. |
179 | */ | 174 | */ |
180 | /* unsigned */ int idle; | 175 | /* unsigned */ int idle; |
181 | |||
182 | }; | 176 | }; |
183 | 177 | ||
184 | 178 | ||
@@ -186,8 +180,7 @@ struct CadetExit | |||
186 | /** | 180 | /** |
187 | * State we keep for a request that is going out via CADET. | 181 | * State we keep for a request that is going out via CADET. |
188 | */ | 182 | */ |
189 | struct RequestContext | 183 | struct RequestContext { |
190 | { | ||
191 | /** | 184 | /** |
192 | * We keep these in a DLL. | 185 | * We keep these in a DLL. |
193 | */ | 186 | */ |
@@ -227,7 +220,6 @@ struct RequestContext | |||
227 | * ID of the original DNS request (used to match the reply). | 220 | * ID of the original DNS request (used to match the reply). |
228 | */ | 221 | */ |
229 | uint16_t dns_id; | 222 | uint16_t dns_id; |
230 | |||
231 | }; | 223 | }; |
232 | 224 | ||
233 | 225 | ||
@@ -310,7 +302,7 @@ static unsigned int dns_exit_available; | |||
310 | * We are short on cadet exits, try to open another one. | 302 | * We are short on cadet exits, try to open another one. |
311 | */ | 303 | */ |
312 | static void | 304 | static void |
313 | try_open_exit (void); | 305 | try_open_exit(void); |
314 | 306 | ||
315 | 307 | ||
316 | /** | 308 | /** |
@@ -323,24 +315,24 @@ try_open_exit (void); | |||
323 | * @return weight of the channel | 315 | * @return weight of the channel |
324 | */ | 316 | */ |
325 | static uint32_t | 317 | static uint32_t |
326 | get_channel_weight (struct CadetExit *exit) | 318 | get_channel_weight(struct CadetExit *exit) |
327 | { | 319 | { |
328 | uint32_t dropped; | 320 | uint32_t dropped; |
329 | uint32_t drop_percent; | 321 | uint32_t drop_percent; |
330 | uint32_t good_percent; | 322 | uint32_t good_percent; |
331 | 323 | ||
332 | GNUNET_assert (exit->num_transmitted >= exit->num_answered); | 324 | GNUNET_assert(exit->num_transmitted >= exit->num_answered); |
333 | dropped = exit->num_transmitted - exit->num_answered; | 325 | dropped = exit->num_transmitted - exit->num_answered; |
334 | if (exit->num_transmitted > 0) | 326 | if (exit->num_transmitted > 0) |
335 | drop_percent = (uint32_t) ((100LL * dropped) / exit->num_transmitted); | 327 | drop_percent = (uint32_t)((100LL * dropped) / exit->num_transmitted); |
336 | else | 328 | else |
337 | drop_percent = 50; /* no data */ | 329 | drop_percent = 50; /* no data */ |
338 | if ( (exit->num_transmitted > 20) && | 330 | if ((exit->num_transmitted > 20) && |
339 | (drop_percent > 25) ) | 331 | (drop_percent > 25)) |
340 | return 0; /* statistically significant, and > 25% loss, die */ | 332 | return 0; /* statistically significant, and > 25% loss, die */ |
341 | good_percent = 100 - drop_percent; | 333 | good_percent = 100 - drop_percent; |
342 | GNUNET_assert (0 != good_percent); | 334 | GNUNET_assert(0 != good_percent); |
343 | if ( UINT32_MAX / good_percent / good_percent < exit->num_transmitted) | 335 | if (UINT32_MAX / good_percent / good_percent < exit->num_transmitted) |
344 | return UINT32_MAX; /* formula below would overflow */ | 336 | return UINT32_MAX; /* formula below would overflow */ |
345 | return 1 + good_percent * good_percent * exit->num_transmitted; | 337 | return 1 + good_percent * good_percent * exit->num_transmitted; |
346 | } | 338 | } |
@@ -358,7 +350,7 @@ get_channel_weight (struct CadetExit *exit) | |||
358 | * exit that we should use to queue a message with | 350 | * exit that we should use to queue a message with |
359 | */ | 351 | */ |
360 | static struct CadetExit * | 352 | static struct CadetExit * |
361 | choose_exit () | 353 | choose_exit() |
362 | { | 354 | { |
363 | struct CadetExit *pos; | 355 | struct CadetExit *pos; |
364 | uint64_t total_transmitted; | 356 | uint64_t total_transmitted; |
@@ -367,36 +359,36 @@ choose_exit () | |||
367 | 359 | ||
368 | total_transmitted = 0; | 360 | total_transmitted = 0; |
369 | for (pos = exit_head; NULL != pos; pos = pos->next) | 361 | for (pos = exit_head; NULL != pos; pos = pos->next) |
370 | { | 362 | { |
371 | if (NULL == pos->cadet_channel) | 363 | if (NULL == pos->cadet_channel) |
372 | break; | 364 | break; |
373 | channel_weight = get_channel_weight (pos); | 365 | channel_weight = get_channel_weight(pos); |
374 | total_transmitted += channel_weight; | ||
375 | /* double weight for idle channels */ | ||
376 | if (0 != pos->idle) | ||
377 | total_transmitted += channel_weight; | 366 | total_transmitted += channel_weight; |
378 | } | 367 | /* double weight for idle channels */ |
368 | if (0 != pos->idle) | ||
369 | total_transmitted += channel_weight; | ||
370 | } | ||
379 | if (0 == total_transmitted) | 371 | if (0 == total_transmitted) |
380 | { | 372 | { |
381 | /* no channels available, or only a very bad one... */ | 373 | /* no channels available, or only a very bad one... */ |
382 | return exit_head; | 374 | return exit_head; |
383 | } | 375 | } |
384 | selected_offset = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, | 376 | selected_offset = GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, |
385 | total_transmitted); | 377 | total_transmitted); |
386 | total_transmitted = 0; | 378 | total_transmitted = 0; |
387 | for (pos = exit_head; NULL != pos; pos = pos->next) | 379 | for (pos = exit_head; NULL != pos; pos = pos->next) |
388 | { | 380 | { |
389 | if (NULL == pos->cadet_channel) | 381 | if (NULL == pos->cadet_channel) |
390 | break; | 382 | break; |
391 | channel_weight = get_channel_weight (pos); | 383 | channel_weight = get_channel_weight(pos); |
392 | total_transmitted += channel_weight; | ||
393 | /* double weight for idle channels */ | ||
394 | if (0 != pos->idle) | ||
395 | total_transmitted += channel_weight; | 384 | total_transmitted += channel_weight; |
396 | if (total_transmitted > selected_offset) | 385 | /* double weight for idle channels */ |
397 | return pos; | 386 | if (0 != pos->idle) |
398 | } | 387 | total_transmitted += channel_weight; |
399 | GNUNET_break (0); | 388 | if (total_transmitted > selected_offset) |
389 | return pos; | ||
390 | } | ||
391 | GNUNET_break(0); | ||
400 | return NULL; | 392 | return NULL; |
401 | } | 393 | } |
402 | 394 | ||
@@ -408,33 +400,33 @@ choose_exit () | |||
408 | * @param rc context to process | 400 | * @param rc context to process |
409 | */ | 401 | */ |
410 | static void | 402 | static void |
411 | finish_request (struct ReplyContext *rc) | 403 | finish_request(struct ReplyContext *rc) |
412 | { | 404 | { |
413 | char *buf; | 405 | char *buf; |
414 | size_t buf_len; | 406 | size_t buf_len; |
415 | 407 | ||
416 | if (GNUNET_SYSERR == | 408 | if (GNUNET_SYSERR == |
417 | GNUNET_DNSPARSER_pack (rc->dns, | 409 | GNUNET_DNSPARSER_pack(rc->dns, |
418 | MAX_DNS_SIZE, | 410 | MAX_DNS_SIZE, |
419 | &buf, | 411 | &buf, |
420 | &buf_len)) | 412 | &buf_len)) |
421 | { | 413 | { |
422 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 414 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
423 | _("Failed to pack DNS request. Dropping.\n")); | 415 | _("Failed to pack DNS request. Dropping.\n")); |
424 | GNUNET_DNS_request_drop (rc->rh); | 416 | GNUNET_DNS_request_drop(rc->rh); |
425 | } | 417 | } |
426 | else | 418 | else |
427 | { | 419 | { |
428 | GNUNET_STATISTICS_update (stats, | 420 | GNUNET_STATISTICS_update(stats, |
429 | gettext_noop ("# DNS requests mapped to VPN"), | 421 | gettext_noop("# DNS requests mapped to VPN"), |
430 | 1, GNUNET_NO); | 422 | 1, GNUNET_NO); |
431 | GNUNET_DNS_request_answer (rc->rh, | 423 | GNUNET_DNS_request_answer(rc->rh, |
432 | buf_len, | 424 | buf_len, |
433 | buf); | 425 | buf); |
434 | GNUNET_free (buf); | 426 | GNUNET_free(buf); |
435 | } | 427 | } |
436 | GNUNET_DNSPARSER_free_packet (rc->dns); | 428 | GNUNET_DNSPARSER_free_packet(rc->dns); |
437 | GNUNET_free (rc); | 429 | GNUNET_free(rc); |
438 | } | 430 | } |
439 | 431 | ||
440 | 432 | ||
@@ -446,7 +438,7 @@ finish_request (struct ReplyContext *rc) | |||
446 | * @param rc context to process | 438 | * @param rc context to process |
447 | */ | 439 | */ |
448 | static void | 440 | static void |
449 | submit_request (struct ReplyContext *rc); | 441 | submit_request(struct ReplyContext *rc); |
450 | 442 | ||
451 | 443 | ||
452 | /** | 444 | /** |
@@ -465,44 +457,46 @@ submit_request (struct ReplyContext *rc); | |||
465 | * specified target peer; NULL on error | 457 | * specified target peer; NULL on error |
466 | */ | 458 | */ |
467 | static void | 459 | static void |
468 | vpn_allocation_callback (void *cls, | 460 | vpn_allocation_callback(void *cls, |
469 | int af, | 461 | int af, |
470 | const void *address) | 462 | const void *address) |
471 | { | 463 | { |
472 | struct ReplyContext *rc = cls; | 464 | struct ReplyContext *rc = cls; |
473 | 465 | ||
474 | rc->rr = NULL; | 466 | rc->rr = NULL; |
475 | if (af == AF_UNSPEC) | 467 | if (af == AF_UNSPEC) |
476 | { | 468 | { |
477 | GNUNET_DNS_request_drop (rc->rh); | 469 | GNUNET_DNS_request_drop(rc->rh); |
478 | GNUNET_DNSPARSER_free_packet (rc->dns); | 470 | GNUNET_DNSPARSER_free_packet(rc->dns); |
479 | GNUNET_free (rc); | 471 | GNUNET_free(rc); |
480 | return; | 472 | return; |
481 | } | 473 | } |
482 | GNUNET_STATISTICS_update (stats, | 474 | GNUNET_STATISTICS_update(stats, |
483 | gettext_noop ("# DNS records modified"), | 475 | gettext_noop("# DNS records modified"), |
484 | 1, | 476 | 1, |
485 | GNUNET_NO); | 477 | GNUNET_NO); |
486 | switch (rc->rec->type) | 478 | switch (rc->rec->type) |
487 | { | 479 | { |
488 | case GNUNET_DNSPARSER_TYPE_A: | 480 | case GNUNET_DNSPARSER_TYPE_A: |
489 | GNUNET_assert (AF_INET == af); | 481 | GNUNET_assert(AF_INET == af); |
490 | GNUNET_memcpy (rc->rec->data.raw.data, | 482 | GNUNET_memcpy(rc->rec->data.raw.data, |
491 | address, | 483 | address, |
492 | sizeof (struct in_addr)); | 484 | sizeof(struct in_addr)); |
493 | break; | 485 | break; |
494 | case GNUNET_DNSPARSER_TYPE_AAAA: | 486 | |
495 | GNUNET_assert (AF_INET6 == af); | 487 | case GNUNET_DNSPARSER_TYPE_AAAA: |
496 | GNUNET_memcpy (rc->rec->data.raw.data, | 488 | GNUNET_assert(AF_INET6 == af); |
497 | address, | 489 | GNUNET_memcpy(rc->rec->data.raw.data, |
498 | sizeof (struct in6_addr)); | 490 | address, |
499 | break; | 491 | sizeof(struct in6_addr)); |
500 | default: | 492 | break; |
501 | GNUNET_assert (0); | 493 | |
502 | return; | 494 | default: |
503 | } | 495 | GNUNET_assert(0); |
496 | return; | ||
497 | } | ||
504 | rc->rec = NULL; | 498 | rc->rec = NULL; |
505 | submit_request (rc); | 499 | submit_request(rc); |
506 | } | 500 | } |
507 | 501 | ||
508 | 502 | ||
@@ -516,33 +510,35 @@ vpn_allocation_callback (void *cls, | |||
516 | * @param rec record to modify | 510 | * @param rec record to modify |
517 | */ | 511 | */ |
518 | static void | 512 | static void |
519 | modify_address (struct ReplyContext *rc, | 513 | modify_address(struct ReplyContext *rc, |
520 | struct GNUNET_DNSPARSER_Record *rec) | 514 | struct GNUNET_DNSPARSER_Record *rec) |
521 | { | 515 | { |
522 | int af; | 516 | int af; |
523 | 517 | ||
524 | switch (rec->type) | 518 | switch (rec->type) |
525 | { | 519 | { |
526 | case GNUNET_DNSPARSER_TYPE_A: | 520 | case GNUNET_DNSPARSER_TYPE_A: |
527 | af = AF_INET; | 521 | af = AF_INET; |
528 | GNUNET_assert (rec->data.raw.data_len == sizeof (struct in_addr)); | 522 | GNUNET_assert(rec->data.raw.data_len == sizeof(struct in_addr)); |
529 | break; | 523 | break; |
530 | case GNUNET_DNSPARSER_TYPE_AAAA: | 524 | |
531 | af = AF_INET6; | 525 | case GNUNET_DNSPARSER_TYPE_AAAA: |
532 | GNUNET_assert (rec->data.raw.data_len == sizeof (struct in6_addr)); | 526 | af = AF_INET6; |
533 | break; | 527 | GNUNET_assert(rec->data.raw.data_len == sizeof(struct in6_addr)); |
534 | default: | 528 | break; |
535 | GNUNET_assert (0); | 529 | |
536 | return; | 530 | default: |
537 | } | 531 | GNUNET_assert(0); |
532 | return; | ||
533 | } | ||
538 | rc->rec = rec; | 534 | rc->rec = rec; |
539 | rc->rr = GNUNET_VPN_redirect_to_ip (vpn_handle, | 535 | rc->rr = GNUNET_VPN_redirect_to_ip(vpn_handle, |
540 | af, | 536 | af, |
541 | af, | 537 | af, |
542 | rec->data.raw.data, | 538 | rec->data.raw.data, |
543 | GNUNET_TIME_relative_to_absolute (TIMEOUT), | 539 | GNUNET_TIME_relative_to_absolute(TIMEOUT), |
544 | &vpn_allocation_callback, | 540 | &vpn_allocation_callback, |
545 | rc); | 541 | rc); |
546 | } | 542 | } |
547 | 543 | ||
548 | 544 | ||
@@ -554,60 +550,65 @@ modify_address (struct ReplyContext *rc, | |||
554 | * @param rc context to process | 550 | * @param rc context to process |
555 | */ | 551 | */ |
556 | static void | 552 | static void |
557 | submit_request (struct ReplyContext *rc) | 553 | submit_request(struct ReplyContext *rc) |
558 | { | 554 | { |
559 | struct GNUNET_DNSPARSER_Record *ra; | 555 | struct GNUNET_DNSPARSER_Record *ra; |
560 | unsigned int ra_len; | 556 | unsigned int ra_len; |
561 | unsigned int i; | 557 | unsigned int i; |
562 | 558 | ||
563 | while (1) | 559 | while (1) |
564 | { | ||
565 | switch (rc->group) | ||
566 | { | 560 | { |
567 | case ANSWERS: | 561 | switch (rc->group) |
568 | ra = rc->dns->answers; | 562 | { |
569 | ra_len = rc->dns->num_answers; | 563 | case ANSWERS: |
570 | break; | 564 | ra = rc->dns->answers; |
571 | case AUTHORITY_RECORDS: | 565 | ra_len = rc->dns->num_answers; |
572 | ra = rc->dns->authority_records; | 566 | break; |
573 | ra_len = rc->dns->num_authority_records; | 567 | |
574 | break; | 568 | case AUTHORITY_RECORDS: |
575 | case ADDITIONAL_RECORDS: | 569 | ra = rc->dns->authority_records; |
576 | ra = rc->dns->additional_records; | 570 | ra_len = rc->dns->num_authority_records; |
577 | ra_len = rc->dns->num_additional_records; | 571 | break; |
578 | break; | 572 | |
579 | case END: | 573 | case ADDITIONAL_RECORDS: |
580 | finish_request (rc); | 574 | ra = rc->dns->additional_records; |
581 | return; | 575 | ra_len = rc->dns->num_additional_records; |
582 | default: | 576 | break; |
583 | GNUNET_assert (0); | 577 | |
578 | case END: | ||
579 | finish_request(rc); | ||
580 | return; | ||
581 | |||
582 | default: | ||
583 | GNUNET_assert(0); | ||
584 | } | ||
585 | for (i = rc->offset; i < ra_len; i++) | ||
586 | { | ||
587 | switch (ra[i].type) | ||
588 | { | ||
589 | case GNUNET_DNSPARSER_TYPE_A: | ||
590 | if (ipv4_pt) | ||
591 | { | ||
592 | rc->offset = i + 1; | ||
593 | modify_address(rc, | ||
594 | &ra[i]); | ||
595 | return; | ||
596 | } | ||
597 | break; | ||
598 | |||
599 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
600 | if (ipv6_pt) | ||
601 | { | ||
602 | rc->offset = i + 1; | ||
603 | modify_address(rc, | ||
604 | &ra[i]); | ||
605 | return; | ||
606 | } | ||
607 | break; | ||
608 | } | ||
609 | } | ||
610 | rc->group++; | ||
584 | } | 611 | } |
585 | for (i=rc->offset;i<ra_len;i++) | ||
586 | { | ||
587 | switch (ra[i].type) | ||
588 | { | ||
589 | case GNUNET_DNSPARSER_TYPE_A: | ||
590 | if (ipv4_pt) | ||
591 | { | ||
592 | rc->offset = i + 1; | ||
593 | modify_address (rc, | ||
594 | &ra[i]); | ||
595 | return; | ||
596 | } | ||
597 | break; | ||
598 | case GNUNET_DNSPARSER_TYPE_AAAA: | ||
599 | if (ipv6_pt) | ||
600 | { | ||
601 | rc->offset = i + 1; | ||
602 | modify_address (rc, | ||
603 | &ra[i]); | ||
604 | return; | ||
605 | } | ||
606 | break; | ||
607 | } | ||
608 | } | ||
609 | rc->group++; | ||
610 | } | ||
611 | } | 612 | } |
612 | 613 | ||
613 | 614 | ||
@@ -619,25 +620,26 @@ submit_request (struct ReplyContext *rc) | |||
619 | * @return #GNUNET_YES if any of the given records require protocol-translation | 620 | * @return #GNUNET_YES if any of the given records require protocol-translation |
620 | */ | 621 | */ |
621 | static int | 622 | static int |
622 | work_test (const struct GNUNET_DNSPARSER_Record *ra, | 623 | work_test(const struct GNUNET_DNSPARSER_Record *ra, |
623 | unsigned int ra_len) | 624 | unsigned int ra_len) |
624 | { | 625 | { |
625 | unsigned int i; | 626 | unsigned int i; |
626 | 627 | ||
627 | for (i=0;i<ra_len;i++) | 628 | for (i = 0; i < ra_len; i++) |
628 | { | ||
629 | switch (ra[i].type) | ||
630 | { | 629 | { |
631 | case GNUNET_DNSPARSER_TYPE_A: | 630 | switch (ra[i].type) |
632 | if (ipv4_pt) | 631 | { |
633 | return GNUNET_YES; | 632 | case GNUNET_DNSPARSER_TYPE_A: |
634 | break; | 633 | if (ipv4_pt) |
635 | case GNUNET_DNSPARSER_TYPE_AAAA: | 634 | return GNUNET_YES; |
636 | if (ipv6_pt) | 635 | break; |
637 | return GNUNET_YES; | 636 | |
638 | break; | 637 | case GNUNET_DNSPARSER_TYPE_AAAA: |
638 | if (ipv6_pt) | ||
639 | return GNUNET_YES; | ||
640 | break; | ||
641 | } | ||
639 | } | 642 | } |
640 | } | ||
641 | return GNUNET_NO; | 643 | return GNUNET_NO; |
642 | } | 644 | } |
643 | 645 | ||
@@ -654,46 +656,46 @@ work_test (const struct GNUNET_DNSPARSER_Record *ra, | |||
654 | * @param request udp payload of the DNS request | 656 | * @param request udp payload of the DNS request |
655 | */ | 657 | */ |
656 | static void | 658 | static void |
657 | dns_post_request_handler (void *cls, | 659 | dns_post_request_handler(void *cls, |
658 | struct GNUNET_DNS_RequestHandle *rh, | 660 | struct GNUNET_DNS_RequestHandle *rh, |
659 | size_t request_length, | 661 | size_t request_length, |
660 | const char *request) | 662 | const char *request) |
661 | { | 663 | { |
662 | struct GNUNET_DNSPARSER_Packet *dns; | 664 | struct GNUNET_DNSPARSER_Packet *dns; |
663 | struct ReplyContext *rc; | 665 | struct ReplyContext *rc; |
664 | int work; | 666 | int work; |
665 | 667 | ||
666 | GNUNET_STATISTICS_update (stats, | 668 | GNUNET_STATISTICS_update(stats, |
667 | gettext_noop ("# DNS replies intercepted"), | 669 | gettext_noop("# DNS replies intercepted"), |
668 | 1, GNUNET_NO); | 670 | 1, GNUNET_NO); |
669 | dns = GNUNET_DNSPARSER_parse (request, | 671 | dns = GNUNET_DNSPARSER_parse(request, |
670 | request_length); | 672 | request_length); |
671 | if (NULL == dns) | 673 | if (NULL == dns) |
672 | { | 674 | { |
673 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 675 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
674 | _("Failed to parse DNS request. Dropping.\n")); | 676 | _("Failed to parse DNS request. Dropping.\n")); |
675 | GNUNET_DNS_request_drop (rh); | 677 | GNUNET_DNS_request_drop(rh); |
676 | return; | 678 | return; |
677 | } | 679 | } |
678 | work = GNUNET_NO; | 680 | work = GNUNET_NO; |
679 | work |= work_test (dns->answers, | 681 | work |= work_test(dns->answers, |
680 | dns->num_answers); | 682 | dns->num_answers); |
681 | work |= work_test (dns->authority_records, | 683 | work |= work_test(dns->authority_records, |
682 | dns->num_authority_records); | 684 | dns->num_authority_records); |
683 | work |= work_test (dns->additional_records, | 685 | work |= work_test(dns->additional_records, |
684 | dns->num_additional_records); | 686 | dns->num_additional_records); |
685 | if (! work) | 687 | if (!work) |
686 | { | 688 | { |
687 | GNUNET_DNS_request_forward (rh); | 689 | GNUNET_DNS_request_forward(rh); |
688 | GNUNET_DNSPARSER_free_packet (dns); | 690 | GNUNET_DNSPARSER_free_packet(dns); |
689 | return; | 691 | return; |
690 | } | 692 | } |
691 | rc = GNUNET_new (struct ReplyContext); | 693 | rc = GNUNET_new(struct ReplyContext); |
692 | rc->rh = rh; | 694 | rc->rh = rh; |
693 | rc->dns = dns; | 695 | rc->dns = dns; |
694 | rc->offset = 0; | 696 | rc->offset = 0; |
695 | rc->group = ANSWERS; | 697 | rc->group = ANSWERS; |
696 | submit_request (rc); | 698 | submit_request(rc); |
697 | } | 699 | } |
698 | 700 | ||
699 | 701 | ||
@@ -703,41 +705,41 @@ dns_post_request_handler (void *cls, | |||
703 | * @param cls the `struct RequestContext` to abort | 705 | * @param cls the `struct RequestContext` to abort |
704 | */ | 706 | */ |
705 | static void | 707 | static void |
706 | timeout_request (void *cls) | 708 | timeout_request(void *cls) |
707 | { | 709 | { |
708 | struct RequestContext *rc = cls; | 710 | struct RequestContext *rc = cls; |
709 | struct CadetExit *exit = rc->exit; | 711 | struct CadetExit *exit = rc->exit; |
710 | 712 | ||
711 | GNUNET_STATISTICS_update (stats, | 713 | GNUNET_STATISTICS_update(stats, |
712 | gettext_noop ("# DNS requests dropped (timeout)"), | 714 | gettext_noop("# DNS requests dropped (timeout)"), |
713 | 1, | 715 | 1, |
714 | GNUNET_NO); | 716 | GNUNET_NO); |
715 | GNUNET_DNS_request_drop (rc->rh); | 717 | GNUNET_DNS_request_drop(rc->rh); |
716 | GNUNET_free (rc); | 718 | GNUNET_free(rc); |
717 | if ( (0 == get_channel_weight (exit)) && | 719 | if ((0 == get_channel_weight(exit)) && |
718 | (NULL == exit->receive_queue_head) ) | 720 | (NULL == exit->receive_queue_head)) |
719 | { | 721 | { |
720 | /* this straw broke the camel's back: this channel now has | 722 | /* this straw broke the camel's back: this channel now has |
721 | such a low score that it will not be used; close it! */ | 723 | such a low score that it will not be used; close it! */ |
722 | GNUNET_CADET_channel_destroy (exit->cadet_channel); | 724 | GNUNET_CADET_channel_destroy(exit->cadet_channel); |
723 | exit->cadet_channel = NULL; | 725 | exit->cadet_channel = NULL; |
724 | GNUNET_CONTAINER_DLL_remove (exit_head, | 726 | GNUNET_CONTAINER_DLL_remove(exit_head, |
725 | exit_tail, | 727 | exit_tail, |
726 | exit); | 728 | exit); |
727 | GNUNET_CONTAINER_DLL_insert_tail (exit_head, | 729 | GNUNET_CONTAINER_DLL_insert_tail(exit_head, |
728 | exit_tail, | 730 | exit_tail, |
729 | exit); | 731 | exit); |
730 | /* go back to semi-innocent: mark as not great, but | 732 | /* go back to semi-innocent: mark as not great, but |
731 | avoid a prohibitively negative score (see | 733 | avoid a prohibitively negative score (see |
732 | #get_channel_weight(), which checks for a certain | 734 | #get_channel_weight(), which checks for a certain |
733 | minimum number of transmissions before making | 735 | minimum number of transmissions before making |
734 | up an opinion) */ | 736 | up an opinion) */ |
735 | exit->num_transmitted = 5; | 737 | exit->num_transmitted = 5; |
736 | exit->num_answered = 0; | 738 | exit->num_answered = 0; |
737 | dns_exit_available--; | 739 | dns_exit_available--; |
738 | /* now try to open an alternative exit */ | 740 | /* now try to open an alternative exit */ |
739 | try_open_exit (); | 741 | try_open_exit(); |
740 | } | 742 | } |
741 | } | 743 | } |
742 | 744 | ||
743 | 745 | ||
@@ -753,10 +755,10 @@ timeout_request (void *cls) | |||
753 | * @param request udp payload of the DNS request | 755 | * @param request udp payload of the DNS request |
754 | */ | 756 | */ |
755 | static void | 757 | static void |
756 | dns_pre_request_handler (void *cls, | 758 | dns_pre_request_handler(void *cls, |
757 | struct GNUNET_DNS_RequestHandle *rh, | 759 | struct GNUNET_DNS_RequestHandle *rh, |
758 | size_t request_length, | 760 | size_t request_length, |
759 | const char *request) | 761 | const char *request) |
760 | { | 762 | { |
761 | struct RequestContext *rc; | 763 | struct RequestContext *rc; |
762 | struct GNUNET_MQ_Envelope *env; | 764 | struct GNUNET_MQ_Envelope *env; |
@@ -764,54 +766,54 @@ dns_pre_request_handler (void *cls, | |||
764 | struct GNUNET_TUN_DnsHeader dns; | 766 | struct GNUNET_TUN_DnsHeader dns; |
765 | struct CadetExit *exit; | 767 | struct CadetExit *exit; |
766 | 768 | ||
767 | GNUNET_STATISTICS_update (stats, | 769 | GNUNET_STATISTICS_update(stats, |
768 | gettext_noop ("# DNS requests intercepted"), | 770 | gettext_noop("# DNS requests intercepted"), |
769 | 1, GNUNET_NO); | 771 | 1, GNUNET_NO); |
770 | if (0 == dns_exit_available) | 772 | if (0 == dns_exit_available) |
771 | { | 773 | { |
772 | GNUNET_STATISTICS_update (stats, | 774 | GNUNET_STATISTICS_update(stats, |
773 | gettext_noop ("# DNS requests dropped (DNS cadet channel down)"), | 775 | gettext_noop("# DNS requests dropped (DNS cadet channel down)"), |
774 | 1, GNUNET_NO); | 776 | 1, GNUNET_NO); |
775 | GNUNET_DNS_request_drop (rh); | 777 | GNUNET_DNS_request_drop(rh); |
776 | return; | 778 | return; |
777 | } | 779 | } |
778 | if (request_length < sizeof (dns)) | 780 | if (request_length < sizeof(dns)) |
779 | { | 781 | { |
780 | GNUNET_STATISTICS_update (stats, | 782 | GNUNET_STATISTICS_update(stats, |
781 | gettext_noop ("# DNS requests dropped (malformed)"), | 783 | gettext_noop("# DNS requests dropped (malformed)"), |
782 | 1, GNUNET_NO); | 784 | 1, GNUNET_NO); |
783 | GNUNET_DNS_request_drop (rh); | 785 | GNUNET_DNS_request_drop(rh); |
784 | return; | 786 | return; |
785 | } | 787 | } |
786 | exit = choose_exit (); | 788 | exit = choose_exit(); |
787 | GNUNET_assert (NULL != exit); | 789 | GNUNET_assert(NULL != exit); |
788 | GNUNET_assert (NULL != exit->cadet_channel); | 790 | GNUNET_assert(NULL != exit->cadet_channel); |
789 | 791 | ||
790 | env = GNUNET_MQ_msg_extra (hdr, | 792 | env = GNUNET_MQ_msg_extra(hdr, |
791 | request_length, | 793 | request_length, |
792 | GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET); | 794 | GNUNET_MESSAGE_TYPE_VPN_DNS_TO_INTERNET); |
793 | GNUNET_memcpy (&hdr[1], | 795 | GNUNET_memcpy(&hdr[1], |
794 | request, | 796 | request, |
795 | request_length); | 797 | request_length); |
796 | rc = GNUNET_new (struct RequestContext); | 798 | rc = GNUNET_new(struct RequestContext); |
797 | rc->exit = exit; | 799 | rc->exit = exit; |
798 | rc->rh = rh; | 800 | rc->rh = rh; |
799 | rc->timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 801 | rc->timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
800 | &timeout_request, | 802 | &timeout_request, |
801 | rc); | 803 | rc); |
802 | GNUNET_memcpy (&dns, | 804 | GNUNET_memcpy(&dns, |
803 | request, | 805 | request, |
804 | sizeof (dns)); | 806 | sizeof(dns)); |
805 | rc->dns_id = dns.id; | 807 | rc->dns_id = dns.id; |
806 | rc->env = env; | 808 | rc->env = env; |
807 | GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, | 809 | GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head, |
808 | exit->receive_queue_tail, | 810 | exit->receive_queue_tail, |
809 | rc); | 811 | rc); |
810 | if (0 < exit->idle) | 812 | if (0 < exit->idle) |
811 | exit->idle--; | 813 | exit->idle--; |
812 | exit->num_transmitted++; | 814 | exit->num_transmitted++; |
813 | GNUNET_MQ_send (GNUNET_CADET_get_mq (exit->cadet_channel), | 815 | GNUNET_MQ_send(GNUNET_CADET_get_mq(exit->cadet_channel), |
814 | GNUNET_MQ_env_copy (env)); | 816 | GNUNET_MQ_env_copy(env)); |
815 | } | 817 | } |
816 | 818 | ||
817 | 819 | ||
@@ -820,8 +822,7 @@ GNUNET_NETWORK_STRUCT_BEGIN | |||
820 | /** | 822 | /** |
821 | * Message with a DNS response. | 823 | * Message with a DNS response. |
822 | */ | 824 | */ |
823 | struct DnsResponseMessage | 825 | struct DnsResponseMessage { |
824 | { | ||
825 | /** | 826 | /** |
826 | * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET | 827 | * GNUnet header, of type #GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET |
827 | */ | 828 | */ |
@@ -846,8 +847,8 @@ GNUNET_NETWORK_STRUCT_END | |||
846 | * #GNUNET_SYSERR to close it (signal serious error) | 847 | * #GNUNET_SYSERR to close it (signal serious error) |
847 | */ | 848 | */ |
848 | static int | 849 | static int |
849 | check_dns_response (void *cls, | 850 | check_dns_response(void *cls, |
850 | const struct DnsResponseMessage *msg) | 851 | const struct DnsResponseMessage *msg) |
851 | { | 852 | { |
852 | return GNUNET_OK; /* all OK */ | 853 | return GNUNET_OK; /* all OK */ |
853 | } | 854 | } |
@@ -860,38 +861,38 @@ check_dns_response (void *cls, | |||
860 | * @param msg the actual message | 861 | * @param msg the actual message |
861 | */ | 862 | */ |
862 | static void | 863 | static void |
863 | handle_dns_response (void *cls, | 864 | handle_dns_response(void *cls, |
864 | const struct DnsResponseMessage *msg) | 865 | const struct DnsResponseMessage *msg) |
865 | { | 866 | { |
866 | struct CadetExit *exit = cls; | 867 | struct CadetExit *exit = cls; |
867 | size_t mlen; | 868 | size_t mlen; |
868 | struct RequestContext *rc; | 869 | struct RequestContext *rc; |
869 | 870 | ||
870 | mlen = ntohs (msg->header.size) - sizeof (*msg); | 871 | mlen = ntohs(msg->header.size) - sizeof(*msg); |
871 | for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next) | 872 | for (rc = exit->receive_queue_head; NULL != rc; rc = rc->next) |
872 | { | ||
873 | if (msg->dns.id == rc->dns_id) | ||
874 | { | 873 | { |
875 | GNUNET_STATISTICS_update (stats, | 874 | if (msg->dns.id == rc->dns_id) |
876 | gettext_noop ("# DNS replies received"), | 875 | { |
877 | 1, | 876 | GNUNET_STATISTICS_update(stats, |
878 | GNUNET_NO); | 877 | gettext_noop("# DNS replies received"), |
879 | GNUNET_DNS_request_answer (rc->rh, | 878 | 1, |
880 | mlen + sizeof (struct GNUNET_TUN_DnsHeader), | 879 | GNUNET_NO); |
881 | (const void*) &msg->dns); | 880 | GNUNET_DNS_request_answer(rc->rh, |
882 | GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, | 881 | mlen + sizeof(struct GNUNET_TUN_DnsHeader), |
883 | exit->receive_queue_tail, | 882 | (const void*)&msg->dns); |
884 | rc); | 883 | GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head, |
885 | GNUNET_SCHEDULER_cancel (rc->timeout_task); | 884 | exit->receive_queue_tail, |
886 | GNUNET_MQ_discard (rc->env); | 885 | rc); |
887 | GNUNET_free (rc); | 886 | GNUNET_SCHEDULER_cancel(rc->timeout_task); |
888 | exit->num_answered++; | 887 | GNUNET_MQ_discard(rc->env); |
889 | return; | 888 | GNUNET_free(rc); |
889 | exit->num_answered++; | ||
890 | return; | ||
891 | } | ||
890 | } | 892 | } |
891 | } | 893 | GNUNET_STATISTICS_update(stats, |
892 | GNUNET_STATISTICS_update (stats, | 894 | gettext_noop("# DNS replies dropped (too late?)"), |
893 | gettext_noop ("# DNS replies dropped (too late?)"), | 895 | 1, GNUNET_NO); |
894 | 1, GNUNET_NO); | ||
895 | } | 896 | } |
896 | 897 | ||
897 | 898 | ||
@@ -901,20 +902,20 @@ handle_dns_response (void *cls, | |||
901 | * @param exit cadet exit to abort requests for | 902 | * @param exit cadet exit to abort requests for |
902 | */ | 903 | */ |
903 | static void | 904 | static void |
904 | abort_all_requests (struct CadetExit *exit) | 905 | abort_all_requests(struct CadetExit *exit) |
905 | { | 906 | { |
906 | struct RequestContext *rc; | 907 | struct RequestContext *rc; |
907 | 908 | ||
908 | while (NULL != (rc = exit->receive_queue_head)) | 909 | while (NULL != (rc = exit->receive_queue_head)) |
909 | { | 910 | { |
910 | GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, | 911 | GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head, |
911 | exit->receive_queue_tail, | 912 | exit->receive_queue_tail, |
912 | rc); | 913 | rc); |
913 | GNUNET_DNS_request_drop (rc->rh); | 914 | GNUNET_DNS_request_drop(rc->rh); |
914 | GNUNET_SCHEDULER_cancel (rc->timeout_task); | 915 | GNUNET_SCHEDULER_cancel(rc->timeout_task); |
915 | GNUNET_MQ_discard (rc->env); | 916 | GNUNET_MQ_discard(rc->env); |
916 | GNUNET_free (rc); | 917 | GNUNET_free(rc); |
917 | } | 918 | } |
918 | } | 919 | } |
919 | 920 | ||
920 | 921 | ||
@@ -924,60 +925,60 @@ abort_all_requests (struct CadetExit *exit) | |||
924 | * @param cls closure, NULL | 925 | * @param cls closure, NULL |
925 | */ | 926 | */ |
926 | static void | 927 | static void |
927 | cleanup (void *cls) | 928 | cleanup(void *cls) |
928 | { | 929 | { |
929 | struct CadetExit *exit; | 930 | struct CadetExit *exit; |
930 | 931 | ||
931 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 932 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
932 | "Protocol translation daemon is shutting down now\n"); | 933 | "Protocol translation daemon is shutting down now\n"); |
933 | if (NULL != vpn_handle) | 934 | if (NULL != vpn_handle) |
934 | { | 935 | { |
935 | GNUNET_VPN_disconnect (vpn_handle); | 936 | GNUNET_VPN_disconnect(vpn_handle); |
936 | vpn_handle = NULL; | 937 | vpn_handle = NULL; |
937 | } | 938 | } |
938 | while (NULL != (exit = exit_head)) | 939 | while (NULL != (exit = exit_head)) |
939 | { | ||
940 | GNUNET_CONTAINER_DLL_remove (exit_head, | ||
941 | exit_tail, | ||
942 | exit); | ||
943 | if (NULL != exit->cadet_channel) | ||
944 | { | 940 | { |
945 | GNUNET_CADET_channel_destroy (exit->cadet_channel); | 941 | GNUNET_CONTAINER_DLL_remove(exit_head, |
946 | exit->cadet_channel = NULL; | 942 | exit_tail, |
943 | exit); | ||
944 | if (NULL != exit->cadet_channel) | ||
945 | { | ||
946 | GNUNET_CADET_channel_destroy(exit->cadet_channel); | ||
947 | exit->cadet_channel = NULL; | ||
948 | } | ||
949 | abort_all_requests(exit); | ||
950 | GNUNET_free(exit); | ||
947 | } | 951 | } |
948 | abort_all_requests (exit); | ||
949 | GNUNET_free (exit); | ||
950 | } | ||
951 | if (NULL != cadet_handle) | 952 | if (NULL != cadet_handle) |
952 | { | 953 | { |
953 | GNUNET_CADET_disconnect (cadet_handle); | 954 | GNUNET_CADET_disconnect(cadet_handle); |
954 | cadet_handle = NULL; | 955 | cadet_handle = NULL; |
955 | } | 956 | } |
956 | if (NULL != dns_post_handle) | 957 | if (NULL != dns_post_handle) |
957 | { | 958 | { |
958 | GNUNET_DNS_disconnect (dns_post_handle); | 959 | GNUNET_DNS_disconnect(dns_post_handle); |
959 | dns_post_handle = NULL; | 960 | dns_post_handle = NULL; |
960 | } | 961 | } |
961 | if (NULL != dns_pre_handle) | 962 | if (NULL != dns_pre_handle) |
962 | { | 963 | { |
963 | GNUNET_DNS_disconnect (dns_pre_handle); | 964 | GNUNET_DNS_disconnect(dns_pre_handle); |
964 | dns_pre_handle = NULL; | 965 | dns_pre_handle = NULL; |
965 | } | 966 | } |
966 | if (NULL != stats) | 967 | if (NULL != stats) |
967 | { | 968 | { |
968 | GNUNET_STATISTICS_destroy (stats, GNUNET_YES); | 969 | GNUNET_STATISTICS_destroy(stats, GNUNET_YES); |
969 | stats = NULL; | 970 | stats = NULL; |
970 | } | 971 | } |
971 | if (NULL != dht_get) | 972 | if (NULL != dht_get) |
972 | { | 973 | { |
973 | GNUNET_DHT_get_stop (dht_get); | 974 | GNUNET_DHT_get_stop(dht_get); |
974 | dht_get = NULL; | 975 | dht_get = NULL; |
975 | } | 976 | } |
976 | if (NULL != dht) | 977 | if (NULL != dht) |
977 | { | 978 | { |
978 | GNUNET_DHT_disconnect (dht); | 979 | GNUNET_DHT_disconnect(dht); |
979 | dht = NULL; | 980 | dht = NULL; |
980 | } | 981 | } |
981 | } | 982 | } |
982 | 983 | ||
983 | 984 | ||
@@ -993,8 +994,8 @@ cleanup (void *cls) | |||
993 | * with the channel is stored | 994 | * with the channel is stored |
994 | */ | 995 | */ |
995 | static void | 996 | static void |
996 | cadet_channel_end_cb (void *cls, | 997 | cadet_channel_end_cb(void *cls, |
997 | const struct GNUNET_CADET_Channel *channel) | 998 | const struct GNUNET_CADET_Channel *channel) |
998 | { | 999 | { |
999 | struct CadetExit *exit = cls; | 1000 | struct CadetExit *exit = cls; |
1000 | struct CadetExit *alt; | 1001 | struct CadetExit *alt; |
@@ -1005,20 +1006,20 @@ cadet_channel_end_cb (void *cls, | |||
1005 | /* open alternative channels */ | 1006 | /* open alternative channels */ |
1006 | /* our channel is now closed, move our requests to an alternative | 1007 | /* our channel is now closed, move our requests to an alternative |
1007 | channel */ | 1008 | channel */ |
1008 | alt = choose_exit (); | 1009 | alt = choose_exit(); |
1009 | while (NULL != (rc = exit->receive_queue_head)) | 1010 | while (NULL != (rc = exit->receive_queue_head)) |
1010 | { | 1011 | { |
1011 | GNUNET_CONTAINER_DLL_remove (exit->receive_queue_head, | 1012 | GNUNET_CONTAINER_DLL_remove(exit->receive_queue_head, |
1012 | exit->receive_queue_tail, | 1013 | exit->receive_queue_tail, |
1013 | rc); | 1014 | rc); |
1014 | rc->exit = alt; | 1015 | rc->exit = alt; |
1015 | GNUNET_CONTAINER_DLL_insert (alt->receive_queue_head, | 1016 | GNUNET_CONTAINER_DLL_insert(alt->receive_queue_head, |
1016 | alt->receive_queue_tail, | 1017 | alt->receive_queue_tail, |
1017 | rc); | 1018 | rc); |
1018 | GNUNET_MQ_send (GNUNET_CADET_get_mq (alt->cadet_channel), | 1019 | GNUNET_MQ_send(GNUNET_CADET_get_mq(alt->cadet_channel), |
1019 | GNUNET_MQ_env_copy (rc->env)); | 1020 | GNUNET_MQ_env_copy(rc->env)); |
1020 | } | 1021 | } |
1021 | try_open_exit (); | 1022 | try_open_exit(); |
1022 | } | 1023 | } |
1023 | 1024 | ||
1024 | 1025 | ||
@@ -1030,9 +1031,9 @@ cadet_channel_end_cb (void *cls, | |||
1030 | * @param window_size how much capacity do we have | 1031 | * @param window_size how much capacity do we have |
1031 | */ | 1032 | */ |
1032 | static void | 1033 | static void |
1033 | channel_idle_notify_cb (void *cls, | 1034 | channel_idle_notify_cb(void *cls, |
1034 | const struct GNUNET_CADET_Channel *channel, | 1035 | const struct GNUNET_CADET_Channel *channel, |
1035 | int window_size) | 1036 | int window_size) |
1036 | { | 1037 | { |
1037 | struct CadetExit *pos = cls; | 1038 | struct CadetExit *pos = cls; |
1038 | 1039 | ||
@@ -1044,69 +1045,69 @@ channel_idle_notify_cb (void *cls, | |||
1044 | * We are short on cadet exits, try to open another one. | 1045 | * We are short on cadet exits, try to open another one. |
1045 | */ | 1046 | */ |
1046 | static void | 1047 | static void |
1047 | try_open_exit () | 1048 | try_open_exit() |
1048 | { | 1049 | { |
1049 | struct CadetExit *pos; | 1050 | struct CadetExit *pos; |
1050 | uint32_t candidate_count; | 1051 | uint32_t candidate_count; |
1051 | uint32_t candidate_selected; | 1052 | uint32_t candidate_selected; |
1052 | struct GNUNET_HashCode port; | 1053 | struct GNUNET_HashCode port; |
1053 | 1054 | ||
1054 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, | 1055 | GNUNET_CRYPTO_hash(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER, |
1055 | strlen (GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), | 1056 | strlen(GNUNET_APPLICATION_PORT_INTERNET_RESOLVER), |
1056 | &port); | 1057 | &port); |
1057 | candidate_count = 0; | 1058 | candidate_count = 0; |
1058 | for (pos = exit_head; NULL != pos; pos = pos->next) | 1059 | for (pos = exit_head; NULL != pos; pos = pos->next) |
1059 | if (NULL == pos->cadet_channel) | 1060 | if (NULL == pos->cadet_channel) |
1060 | candidate_count++; | 1061 | candidate_count++; |
1061 | if (0 == candidate_count) | 1062 | if (0 == candidate_count) |
1062 | { | 1063 | { |
1063 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1064 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
1064 | "No DNS exits available yet.\n"); | 1065 | "No DNS exits available yet.\n"); |
1065 | return; | 1066 | return; |
1066 | } | 1067 | } |
1067 | candidate_selected = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | 1068 | candidate_selected = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, |
1068 | candidate_count); | 1069 | candidate_count); |
1069 | candidate_count = 0; | 1070 | candidate_count = 0; |
1070 | for (pos = exit_head; NULL != pos; pos = pos->next) | 1071 | for (pos = exit_head; NULL != pos; pos = pos->next) |
1071 | if (NULL == pos->cadet_channel) | 1072 | if (NULL == pos->cadet_channel) |
1072 | { | ||
1073 | candidate_count++; | ||
1074 | if (candidate_selected < candidate_count) | ||
1075 | { | 1073 | { |
1076 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 1074 | candidate_count++; |
1077 | GNUNET_MQ_hd_var_size (dns_response, | 1075 | if (candidate_selected < candidate_count) |
1078 | GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET, | 1076 | { |
1079 | struct DnsResponseMessage, | 1077 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
1080 | pos), | 1078 | GNUNET_MQ_hd_var_size(dns_response, |
1081 | GNUNET_MQ_handler_end () | 1079 | GNUNET_MESSAGE_TYPE_VPN_DNS_FROM_INTERNET, |
1082 | }; | 1080 | struct DnsResponseMessage, |
1083 | 1081 | pos), | |
1084 | 1082 | GNUNET_MQ_handler_end() | |
1085 | /* move to the head of the DLL */ | 1083 | }; |
1086 | pos->cadet_channel | 1084 | |
1087 | = GNUNET_CADET_channel_create (cadet_handle, | 1085 | |
1088 | pos, | 1086 | /* move to the head of the DLL */ |
1089 | &pos->peer, | 1087 | pos->cadet_channel |
1090 | &port, | 1088 | = GNUNET_CADET_channel_create(cadet_handle, |
1091 | &channel_idle_notify_cb, | 1089 | pos, |
1092 | &cadet_channel_end_cb, | 1090 | &pos->peer, |
1093 | cadet_handlers); | 1091 | &port, |
1094 | if (NULL == pos->cadet_channel) | 1092 | &channel_idle_notify_cb, |
1095 | { | 1093 | &cadet_channel_end_cb, |
1096 | GNUNET_break (0); | 1094 | cadet_handlers); |
1097 | continue; | 1095 | if (NULL == pos->cadet_channel) |
1098 | } | 1096 | { |
1099 | GNUNET_CONTAINER_DLL_remove (exit_head, | 1097 | GNUNET_break(0); |
1100 | exit_tail, | 1098 | continue; |
1101 | pos); | 1099 | } |
1102 | GNUNET_CONTAINER_DLL_insert (exit_head, | 1100 | GNUNET_CONTAINER_DLL_remove(exit_head, |
1103 | exit_tail, | 1101 | exit_tail, |
1104 | pos); | 1102 | pos); |
1105 | dns_exit_available++; | 1103 | GNUNET_CONTAINER_DLL_insert(exit_head, |
1106 | return; | 1104 | exit_tail, |
1105 | pos); | ||
1106 | dns_exit_available++; | ||
1107 | return; | ||
1108 | } | ||
1107 | } | 1109 | } |
1108 | } | 1110 | GNUNET_assert(NULL == exit_head); |
1109 | GNUNET_assert (NULL == exit_head); | ||
1110 | } | 1111 | } |
1111 | 1112 | ||
1112 | 1113 | ||
@@ -1130,42 +1131,42 @@ try_open_exit () | |||
1130 | * @param data pointer to the result data | 1131 | * @param data pointer to the result data |
1131 | */ | 1132 | */ |
1132 | static void | 1133 | static void |
1133 | handle_dht_result (void *cls, | 1134 | handle_dht_result(void *cls, |
1134 | struct GNUNET_TIME_Absolute exp, | 1135 | struct GNUNET_TIME_Absolute exp, |
1135 | const struct GNUNET_HashCode *key, | 1136 | const struct GNUNET_HashCode *key, |
1136 | const struct GNUNET_PeerIdentity *get_path, | 1137 | const struct GNUNET_PeerIdentity *get_path, |
1137 | unsigned int get_path_length, | 1138 | unsigned int get_path_length, |
1138 | const struct GNUNET_PeerIdentity *put_path, | 1139 | const struct GNUNET_PeerIdentity *put_path, |
1139 | unsigned int put_path_length, | 1140 | unsigned int put_path_length, |
1140 | enum GNUNET_BLOCK_Type type, | 1141 | enum GNUNET_BLOCK_Type type, |
1141 | size_t size, const void *data) | 1142 | size_t size, const void *data) |
1142 | { | 1143 | { |
1143 | const struct GNUNET_DNS_Advertisement *ad; | 1144 | const struct GNUNET_DNS_Advertisement *ad; |
1144 | struct CadetExit *exit; | 1145 | struct CadetExit *exit; |
1145 | 1146 | ||
1146 | if (sizeof (struct GNUNET_DNS_Advertisement) != size) | 1147 | if (sizeof(struct GNUNET_DNS_Advertisement) != size) |
1147 | { | 1148 | { |
1148 | GNUNET_break (0); | 1149 | GNUNET_break(0); |
1149 | return; | 1150 | return; |
1150 | } | 1151 | } |
1151 | ad = data; | 1152 | ad = data; |
1152 | for (exit = exit_head; NULL != exit; exit = exit->next) | 1153 | for (exit = exit_head; NULL != exit; exit = exit->next) |
1153 | if (0 == GNUNET_memcmp (&ad->peer, | 1154 | if (0 == GNUNET_memcmp(&ad->peer, |
1154 | &exit->peer)) | 1155 | &exit->peer)) |
1155 | break; | 1156 | break; |
1156 | if (NULL == exit) | 1157 | if (NULL == exit) |
1157 | { | 1158 | { |
1158 | exit = GNUNET_new (struct CadetExit); | 1159 | exit = GNUNET_new(struct CadetExit); |
1159 | exit->peer = ad->peer; | 1160 | exit->peer = ad->peer; |
1160 | /* channel is closed, so insert at the end */ | 1161 | /* channel is closed, so insert at the end */ |
1161 | GNUNET_CONTAINER_DLL_insert_tail (exit_head, | 1162 | GNUNET_CONTAINER_DLL_insert_tail(exit_head, |
1162 | exit_tail, | 1163 | exit_tail, |
1163 | exit); | 1164 | exit); |
1164 | } | 1165 | } |
1165 | exit->expiration = GNUNET_TIME_absolute_max (exit->expiration, | 1166 | exit->expiration = GNUNET_TIME_absolute_max(exit->expiration, |
1166 | GNUNET_TIME_absolute_ntoh (ad->expiration_time)); | 1167 | GNUNET_TIME_absolute_ntoh(ad->expiration_time)); |
1167 | if (dns_exit_available < MAX_OPEN_TUNNELS) | 1168 | if (dns_exit_available < MAX_OPEN_TUNNELS) |
1168 | try_open_exit (); | 1169 | try_open_exit(); |
1169 | } | 1170 | } |
1170 | 1171 | ||
1171 | 1172 | ||
@@ -1178,102 +1179,102 @@ handle_dht_result (void *cls, | |||
1178 | * @param cfg_ configuration | 1179 | * @param cfg_ configuration |
1179 | */ | 1180 | */ |
1180 | static void | 1181 | static void |
1181 | run (void *cls, char *const *args GNUNET_UNUSED, | 1182 | run(void *cls, char *const *args GNUNET_UNUSED, |
1182 | const char *cfgfile GNUNET_UNUSED, | 1183 | const char *cfgfile GNUNET_UNUSED, |
1183 | const struct GNUNET_CONFIGURATION_Handle *cfg_) | 1184 | const struct GNUNET_CONFIGURATION_Handle *cfg_) |
1184 | { | 1185 | { |
1185 | struct GNUNET_HashCode dns_key; | 1186 | struct GNUNET_HashCode dns_key; |
1186 | 1187 | ||
1187 | cfg = cfg_; | 1188 | cfg = cfg_; |
1188 | stats = GNUNET_STATISTICS_create ("pt", | 1189 | stats = GNUNET_STATISTICS_create("pt", |
1189 | cfg); | 1190 | cfg); |
1190 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1191 | ipv4_pt = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
1191 | "pt", | 1192 | "pt", |
1192 | "TUNNEL_IPV4"); | 1193 | "TUNNEL_IPV4"); |
1193 | ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1194 | ipv6_pt = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
1194 | "pt", | 1195 | "pt", |
1195 | "TUNNEL_IPV6"); | 1196 | "TUNNEL_IPV6"); |
1196 | dns_channel = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1197 | dns_channel = GNUNET_CONFIGURATION_get_value_yesno(cfg, |
1197 | "pt", | 1198 | "pt", |
1198 | "TUNNEL_DNS"); | 1199 | "TUNNEL_DNS"); |
1199 | if (! (ipv4_pt || ipv6_pt || dns_channel)) | 1200 | if (!(ipv4_pt || ipv6_pt || dns_channel)) |
1200 | { | ||
1201 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1202 | _("No useful service enabled. Exiting.\n")); | ||
1203 | GNUNET_SCHEDULER_shutdown (); | ||
1204 | return; | ||
1205 | } | ||
1206 | GNUNET_SCHEDULER_add_shutdown (&cleanup, cls); | ||
1207 | if (ipv4_pt || ipv6_pt) | ||
1208 | { | ||
1209 | dns_post_handle | ||
1210 | = GNUNET_DNS_connect (cfg, | ||
1211 | GNUNET_DNS_FLAG_POST_RESOLUTION, | ||
1212 | &dns_post_request_handler, | ||
1213 | NULL); | ||
1214 | if (NULL == dns_post_handle) | ||
1215 | { | 1201 | { |
1216 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1202 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1217 | _("Failed to connect to %s service. Exiting.\n"), | 1203 | _("No useful service enabled. Exiting.\n")); |
1218 | "DNS"); | 1204 | GNUNET_SCHEDULER_shutdown(); |
1219 | GNUNET_SCHEDULER_shutdown (); | ||
1220 | return; | 1205 | return; |
1221 | } | 1206 | } |
1222 | vpn_handle = GNUNET_VPN_connect (cfg); | 1207 | GNUNET_SCHEDULER_add_shutdown(&cleanup, cls); |
1223 | if (NULL == vpn_handle) | 1208 | if (ipv4_pt || ipv6_pt) |
1224 | { | 1209 | { |
1225 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1210 | dns_post_handle |
1226 | _("Failed to connect to %s service. Exiting.\n"), | 1211 | = GNUNET_DNS_connect(cfg, |
1227 | "VPN"); | 1212 | GNUNET_DNS_FLAG_POST_RESOLUTION, |
1228 | GNUNET_SCHEDULER_shutdown (); | 1213 | &dns_post_request_handler, |
1229 | return; | 1214 | NULL); |
1215 | if (NULL == dns_post_handle) | ||
1216 | { | ||
1217 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1218 | _("Failed to connect to %s service. Exiting.\n"), | ||
1219 | "DNS"); | ||
1220 | GNUNET_SCHEDULER_shutdown(); | ||
1221 | return; | ||
1222 | } | ||
1223 | vpn_handle = GNUNET_VPN_connect(cfg); | ||
1224 | if (NULL == vpn_handle) | ||
1225 | { | ||
1226 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1227 | _("Failed to connect to %s service. Exiting.\n"), | ||
1228 | "VPN"); | ||
1229 | GNUNET_SCHEDULER_shutdown(); | ||
1230 | return; | ||
1231 | } | ||
1230 | } | 1232 | } |
1231 | } | ||
1232 | if (dns_channel) | 1233 | if (dns_channel) |
1233 | { | ||
1234 | dns_pre_handle | ||
1235 | = GNUNET_DNS_connect (cfg, | ||
1236 | GNUNET_DNS_FLAG_PRE_RESOLUTION, | ||
1237 | &dns_pre_request_handler, | ||
1238 | NULL); | ||
1239 | if (NULL == dns_pre_handle) | ||
1240 | { | 1234 | { |
1241 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1235 | dns_pre_handle |
1242 | _("Failed to connect to %s service. Exiting.\n"), | 1236 | = GNUNET_DNS_connect(cfg, |
1243 | "DNS"); | 1237 | GNUNET_DNS_FLAG_PRE_RESOLUTION, |
1244 | GNUNET_SCHEDULER_shutdown (); | 1238 | &dns_pre_request_handler, |
1245 | return; | 1239 | NULL); |
1246 | } | 1240 | if (NULL == dns_pre_handle) |
1247 | cadet_handle = GNUNET_CADET_connect (cfg); | 1241 | { |
1248 | if (NULL == cadet_handle) | 1242 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1249 | { | 1243 | _("Failed to connect to %s service. Exiting.\n"), |
1250 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1244 | "DNS"); |
1251 | _("Failed to connect to %s service. Exiting.\n"), | 1245 | GNUNET_SCHEDULER_shutdown(); |
1252 | "CADET"); | 1246 | return; |
1253 | GNUNET_SCHEDULER_shutdown (); | 1247 | } |
1254 | return; | 1248 | cadet_handle = GNUNET_CADET_connect(cfg); |
1255 | } | 1249 | if (NULL == cadet_handle) |
1256 | dht = GNUNET_DHT_connect (cfg, 1); | 1250 | { |
1257 | if (NULL == dht) | 1251 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
1258 | { | 1252 | _("Failed to connect to %s service. Exiting.\n"), |
1259 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1253 | "CADET"); |
1260 | _("Failed to connect to %s service. Exiting.\n"), | 1254 | GNUNET_SCHEDULER_shutdown(); |
1261 | "DHT"); | 1255 | return; |
1262 | GNUNET_SCHEDULER_shutdown (); | 1256 | } |
1263 | return; | 1257 | dht = GNUNET_DHT_connect(cfg, 1); |
1258 | if (NULL == dht) | ||
1259 | { | ||
1260 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, | ||
1261 | _("Failed to connect to %s service. Exiting.\n"), | ||
1262 | "DHT"); | ||
1263 | GNUNET_SCHEDULER_shutdown(); | ||
1264 | return; | ||
1265 | } | ||
1266 | GNUNET_CRYPTO_hash("dns", | ||
1267 | strlen("dns"), | ||
1268 | &dns_key); | ||
1269 | dht_get = GNUNET_DHT_get_start(dht, | ||
1270 | GNUNET_BLOCK_TYPE_DNS, | ||
1271 | &dns_key, | ||
1272 | 1, | ||
1273 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
1274 | NULL, 0, | ||
1275 | &handle_dht_result, | ||
1276 | NULL); | ||
1264 | } | 1277 | } |
1265 | GNUNET_CRYPTO_hash ("dns", | ||
1266 | strlen ("dns"), | ||
1267 | &dns_key); | ||
1268 | dht_get = GNUNET_DHT_get_start (dht, | ||
1269 | GNUNET_BLOCK_TYPE_DNS, | ||
1270 | &dns_key, | ||
1271 | 1, | ||
1272 | GNUNET_DHT_RO_DEMULTIPLEX_EVERYWHERE, | ||
1273 | NULL, 0, | ||
1274 | &handle_dht_result, | ||
1275 | NULL); | ||
1276 | } | ||
1277 | } | 1278 | } |
1278 | 1279 | ||
1279 | 1280 | ||
@@ -1285,30 +1286,30 @@ run (void *cls, char *const *args GNUNET_UNUSED, | |||
1285 | * @return 0 ok, 1 on error | 1286 | * @return 0 ok, 1 on error |
1286 | */ | 1287 | */ |
1287 | int | 1288 | int |
1288 | main (int argc, | 1289 | main(int argc, |
1289 | char *const *argv) | 1290 | char *const *argv) |
1290 | { | 1291 | { |
1291 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { | 1292 | static const struct GNUNET_GETOPT_CommandLineOption options[] = { |
1292 | GNUNET_GETOPT_OPTION_END | 1293 | GNUNET_GETOPT_OPTION_END |
1293 | }; | 1294 | }; |
1294 | int ret; | 1295 | int ret; |
1295 | 1296 | ||
1296 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, | 1297 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, |
1297 | argv, | 1298 | argv, |
1298 | &argc, | 1299 | &argc, |
1299 | &argv)) | 1300 | &argv)) |
1300 | return 2; | 1301 | return 2; |
1301 | ret = (GNUNET_OK == | 1302 | ret = (GNUNET_OK == |
1302 | GNUNET_PROGRAM_run (argc, | 1303 | GNUNET_PROGRAM_run(argc, |
1303 | argv, | 1304 | argv, |
1304 | "gnunet-daemon-pt", | 1305 | "gnunet-daemon-pt", |
1305 | gettext_noop ("Daemon to run to perform IP protocol translation to GNUnet"), | 1306 | gettext_noop("Daemon to run to perform IP protocol translation to GNUnet"), |
1306 | options, | 1307 | options, |
1307 | &run, | 1308 | &run, |
1308 | NULL)) | 1309 | NULL)) |
1309 | ? 0 | 1310 | ? 0 |
1310 | : 1; | 1311 | : 1; |
1311 | GNUNET_free ((void*) argv); | 1312 | GNUNET_free((void*)argv); |
1312 | return ret; | 1313 | return ret; |
1313 | } | 1314 | } |
1314 | 1315 | ||
diff --git a/src/pt/test_gns_vpn.c b/src/pt/test_gns_vpn.c index 90405fe37..8a6e3e6d4 100644 --- a/src/pt/test_gns_vpn.c +++ b/src/pt/test_gns_vpn.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 test_gns_vpn.c | 22 | * @file test_gns_vpn.c |
@@ -49,7 +49,7 @@ | |||
49 | #define PORT 8080 | 49 | #define PORT 8080 |
50 | #define TEST_DOMAIN "www.gnu" | 50 | #define TEST_DOMAIN "www.gnu" |
51 | 51 | ||
52 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 52 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 30) |
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Return value for #main(). | 55 | * Return value for #main(). |
@@ -96,8 +96,7 @@ static int src_af; | |||
96 | static int use_v6; | 96 | static int use_v6; |
97 | 97 | ||
98 | 98 | ||
99 | struct CBC | 99 | struct CBC { |
100 | { | ||
101 | char buf[1024]; | 100 | char buf[1024]; |
102 | size_t pos; | 101 | size_t pos; |
103 | }; | 102 | }; |
@@ -106,102 +105,102 @@ static struct CBC cbc; | |||
106 | 105 | ||
107 | 106 | ||
108 | static size_t | 107 | static size_t |
109 | copy_buffer (void *ptr, | 108 | copy_buffer(void *ptr, |
110 | size_t size, | 109 | size_t size, |
111 | size_t nmemb, | 110 | size_t nmemb, |
112 | void *ctx) | 111 | void *ctx) |
113 | { | 112 | { |
114 | struct CBC *cbc = ctx; | 113 | struct CBC *cbc = ctx; |
115 | 114 | ||
116 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) | 115 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) |
117 | return 0; /* overflow */ | 116 | return 0; /* overflow */ |
118 | GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | 117 | GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb); |
119 | cbc->pos += size * nmemb; | 118 | cbc->pos += size * nmemb; |
120 | return size * nmemb; | 119 | return size * nmemb; |
121 | } | 120 | } |
122 | 121 | ||
123 | 122 | ||
124 | static int | 123 | static int |
125 | mhd_ahc (void *cls, | 124 | mhd_ahc(void *cls, |
126 | struct MHD_Connection *connection, | 125 | struct MHD_Connection *connection, |
127 | const char *url, | 126 | const char *url, |
128 | const char *method, | 127 | const char *method, |
129 | const char *version, | 128 | const char *version, |
130 | const char *upload_data, size_t *upload_data_size, | 129 | const char *upload_data, size_t *upload_data_size, |
131 | void **unused) | 130 | void **unused) |
132 | { | 131 | { |
133 | static int ptr; | 132 | static int ptr; |
134 | struct MHD_Response *response; | 133 | struct MHD_Response *response; |
135 | int ret; | 134 | int ret; |
136 | 135 | ||
137 | if (0 != strcmp ("GET", method)) | 136 | if (0 != strcmp("GET", method)) |
138 | return MHD_NO; /* unexpected method */ | 137 | return MHD_NO; /* unexpected method */ |
139 | if (&ptr != *unused) | 138 | if (&ptr != *unused) |
140 | { | 139 | { |
141 | *unused = &ptr; | 140 | *unused = &ptr; |
142 | return MHD_YES; | 141 | return MHD_YES; |
143 | } | 142 | } |
144 | *unused = NULL; | 143 | *unused = NULL; |
145 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); | 144 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MHD sends respose for request to URL `%s'\n", url); |
146 | response = MHD_create_response_from_buffer (strlen (url), | 145 | response = MHD_create_response_from_buffer(strlen(url), |
147 | (void *) url, | 146 | (void *)url, |
148 | MHD_RESPMEM_MUST_COPY); | 147 | MHD_RESPMEM_MUST_COPY); |
149 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 148 | ret = MHD_queue_response(connection, MHD_HTTP_OK, response); |
150 | MHD_destroy_response (response); | 149 | MHD_destroy_response(response); |
151 | if (ret == MHD_NO) | 150 | if (ret == MHD_NO) |
152 | abort (); | 151 | abort(); |
153 | return ret; | 152 | return ret; |
154 | } | 153 | } |
155 | 154 | ||
156 | 155 | ||
157 | static void | 156 | static void |
158 | do_shutdown (void *cls) | 157 | do_shutdown(void *cls) |
159 | { | 158 | { |
160 | if (NULL != mhd_task_id) | 159 | if (NULL != mhd_task_id) |
161 | { | 160 | { |
162 | GNUNET_SCHEDULER_cancel (mhd_task_id); | 161 | GNUNET_SCHEDULER_cancel(mhd_task_id); |
163 | mhd_task_id = NULL; | 162 | mhd_task_id = NULL; |
164 | } | 163 | } |
165 | if (NULL != curl_task_id) | 164 | if (NULL != curl_task_id) |
166 | { | 165 | { |
167 | GNUNET_SCHEDULER_cancel (curl_task_id); | 166 | GNUNET_SCHEDULER_cancel(curl_task_id); |
168 | curl_task_id = NULL; | 167 | curl_task_id = NULL; |
169 | } | 168 | } |
170 | if (NULL != timeout_task) | 169 | if (NULL != timeout_task) |
171 | { | 170 | { |
172 | GNUNET_SCHEDULER_cancel (timeout_task); | 171 | GNUNET_SCHEDULER_cancel(timeout_task); |
173 | timeout_task = NULL; | 172 | timeout_task = NULL; |
174 | } | 173 | } |
175 | if (NULL != mhd) | 174 | if (NULL != mhd) |
176 | { | 175 | { |
177 | MHD_stop_daemon (mhd); | 176 | MHD_stop_daemon(mhd); |
178 | mhd = NULL; | 177 | mhd = NULL; |
179 | } | 178 | } |
180 | if (NULL != identity) | 179 | if (NULL != identity) |
181 | { | 180 | { |
182 | GNUNET_IDENTITY_disconnect (identity); | 181 | GNUNET_IDENTITY_disconnect(identity); |
183 | identity = NULL; | 182 | identity = NULL; |
184 | } | 183 | } |
185 | if (NULL != qe) | 184 | if (NULL != qe) |
186 | { | 185 | { |
187 | GNUNET_NAMESTORE_cancel (qe); | 186 | GNUNET_NAMESTORE_cancel(qe); |
188 | qe = NULL; | 187 | qe = NULL; |
189 | } | 188 | } |
190 | if (NULL != namestore) | 189 | if (NULL != namestore) |
191 | { | 190 | { |
192 | GNUNET_NAMESTORE_disconnect (namestore); | 191 | GNUNET_NAMESTORE_disconnect(namestore); |
193 | namestore = NULL; | 192 | namestore = NULL; |
194 | } | 193 | } |
195 | GNUNET_free_non_null (url); | 194 | GNUNET_free_non_null(url); |
196 | url = NULL; | 195 | url = NULL; |
197 | } | 196 | } |
198 | 197 | ||
199 | 198 | ||
200 | static void | 199 | static void |
201 | do_timeout (void *cls) | 200 | do_timeout(void *cls) |
202 | { | 201 | { |
203 | timeout_task = NULL; | 202 | timeout_task = NULL; |
204 | GNUNET_SCHEDULER_shutdown (); | 203 | GNUNET_SCHEDULER_shutdown(); |
205 | } | 204 | } |
206 | 205 | ||
207 | 206 | ||
@@ -209,19 +208,19 @@ do_timeout (void *cls) | |||
209 | * Function to run the HTTP client. | 208 | * Function to run the HTTP client. |
210 | */ | 209 | */ |
211 | static void | 210 | static void |
212 | curl_main (void); | 211 | curl_main(void); |
213 | 212 | ||
214 | 213 | ||
215 | static void | 214 | static void |
216 | curl_task (void *cls) | 215 | curl_task(void *cls) |
217 | { | 216 | { |
218 | curl_task_id = NULL; | 217 | curl_task_id = NULL; |
219 | curl_main (); | 218 | curl_main(); |
220 | } | 219 | } |
221 | 220 | ||
222 | 221 | ||
223 | static void | 222 | static void |
224 | curl_main () | 223 | curl_main() |
225 | { | 224 | { |
226 | fd_set rs; | 225 | fd_set rs; |
227 | fd_set ws; | 226 | fd_set ws; |
@@ -235,102 +234,102 @@ curl_main () | |||
235 | struct CURLMsg *msg; | 234 | struct CURLMsg *msg; |
236 | 235 | ||
237 | max = 0; | 236 | max = 0; |
238 | FD_ZERO (&rs); | 237 | FD_ZERO(&rs); |
239 | FD_ZERO (&ws); | 238 | FD_ZERO(&ws); |
240 | FD_ZERO (&es); | 239 | FD_ZERO(&es); |
241 | curl_multi_perform (multi, &running); | 240 | curl_multi_perform(multi, &running); |
242 | if (running == 0) | 241 | if (running == 0) |
243 | { | ||
244 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | ||
245 | if (msg->msg == CURLMSG_DONE) | ||
246 | { | ||
247 | if (msg->data.result != CURLE_OK) | ||
248 | { | ||
249 | fprintf (stderr, | ||
250 | "%s failed at %s:%d: `%s'\n", | ||
251 | "curl_multi_perform", | ||
252 | __FILE__, | ||
253 | __LINE__, curl_easy_strerror (msg->data.result)); | ||
254 | global_ret = 1; | ||
255 | } | ||
256 | } | ||
257 | curl_multi_remove_handle (multi, curl); | ||
258 | curl_multi_cleanup (multi); | ||
259 | curl_easy_cleanup (curl); | ||
260 | curl = NULL; | ||
261 | multi = NULL; | ||
262 | if (cbc.pos != strlen ("/hello_world")) | ||
263 | { | 242 | { |
264 | GNUNET_break (0); | 243 | GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running))); |
265 | global_ret = 2; | 244 | if (msg->msg == CURLMSG_DONE) |
266 | } | 245 | { |
267 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | 246 | if (msg->data.result != CURLE_OK) |
268 | { | 247 | { |
269 | GNUNET_break (0); | 248 | fprintf(stderr, |
270 | global_ret = 3; | 249 | "%s failed at %s:%d: `%s'\n", |
250 | "curl_multi_perform", | ||
251 | __FILE__, | ||
252 | __LINE__, curl_easy_strerror(msg->data.result)); | ||
253 | global_ret = 1; | ||
254 | } | ||
255 | } | ||
256 | curl_multi_remove_handle(multi, curl); | ||
257 | curl_multi_cleanup(multi); | ||
258 | curl_easy_cleanup(curl); | ||
259 | curl = NULL; | ||
260 | multi = NULL; | ||
261 | if (cbc.pos != strlen("/hello_world")) | ||
262 | { | ||
263 | GNUNET_break(0); | ||
264 | global_ret = 2; | ||
265 | } | ||
266 | if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) | ||
267 | { | ||
268 | GNUNET_break(0); | ||
269 | global_ret = 3; | ||
270 | } | ||
271 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, | ||
272 | "Download complete, shutting down!\n"); | ||
273 | GNUNET_SCHEDULER_shutdown(); | ||
274 | return; | ||
271 | } | 275 | } |
272 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 276 | GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max)); |
273 | "Download complete, shutting down!\n"); | 277 | if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || |
274 | GNUNET_SCHEDULER_shutdown (); | 278 | (-1 == timeout)) |
275 | return; | ||
276 | } | ||
277 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | ||
278 | if ( (CURLM_OK != curl_multi_timeout (multi, &timeout)) || | ||
279 | (-1 == timeout) ) | ||
280 | delay = GNUNET_TIME_UNIT_SECONDS; | 279 | delay = GNUNET_TIME_UNIT_SECONDS; |
281 | else | 280 | else |
282 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int) timeout); | 281 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, (unsigned int)timeout); |
283 | GNUNET_NETWORK_fdset_copy_native (&nrs, | 282 | GNUNET_NETWORK_fdset_copy_native(&nrs, |
284 | &rs, | 283 | &rs, |
285 | max + 1); | 284 | max + 1); |
286 | GNUNET_NETWORK_fdset_copy_native (&nws, | 285 | GNUNET_NETWORK_fdset_copy_native(&nws, |
287 | &ws, | 286 | &ws, |
288 | max + 1); | 287 | max + 1); |
289 | curl_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 288 | curl_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
290 | delay, | 289 | delay, |
291 | &nrs, | 290 | &nrs, |
292 | &nws, | 291 | &nws, |
293 | &curl_task, | 292 | &curl_task, |
294 | NULL); | 293 | NULL); |
295 | } | 294 | } |
296 | 295 | ||
297 | 296 | ||
298 | static void | 297 | static void |
299 | start_curl (void *cls) | 298 | start_curl(void *cls) |
300 | { | 299 | { |
301 | CURLcode ec; | 300 | CURLcode ec; |
302 | 301 | ||
303 | curl_task_id = NULL; | 302 | curl_task_id = NULL; |
304 | GNUNET_asprintf (&url, | 303 | GNUNET_asprintf(&url, |
305 | "http://%s/hello_world", | 304 | "http://%s/hello_world", |
306 | TEST_DOMAIN); | 305 | TEST_DOMAIN); |
307 | curl = curl_easy_init (); | 306 | curl = curl_easy_init(); |
308 | curl_easy_setopt (curl, CURLOPT_URL, url); | 307 | curl_easy_setopt(curl, CURLOPT_URL, url); |
309 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | 308 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ©_buffer); |
310 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | 309 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc); |
311 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | 310 | curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); |
312 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | 311 | curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L); |
313 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 150L); | 312 | curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 150L); |
314 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | 313 | curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
315 | if (CURLE_OK != | 314 | if (CURLE_OK != |
316 | (ec = curl_easy_setopt (curl, | 315 | (ec = curl_easy_setopt(curl, |
317 | CURLOPT_DNS_SERVERS, | 316 | CURLOPT_DNS_SERVERS, |
318 | "127.0.0.1:53"))) | 317 | "127.0.0.1:53"))) |
319 | { | 318 | { |
320 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 319 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, |
321 | "curl build without support for CURLOPT_DNS_SERVERS (%s), cannot run test\n", | 320 | "curl build without support for CURLOPT_DNS_SERVERS (%s), cannot run test\n", |
322 | curl_easy_strerror (ec)); | 321 | curl_easy_strerror(ec)); |
323 | global_ret = 77; | 322 | global_ret = 77; |
324 | GNUNET_SCHEDULER_shutdown (); | 323 | GNUNET_SCHEDULER_shutdown(); |
325 | return; | 324 | return; |
326 | } | 325 | } |
327 | multi = curl_multi_init (); | 326 | multi = curl_multi_init(); |
328 | GNUNET_assert (multi != NULL); | 327 | GNUNET_assert(multi != NULL); |
329 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | 328 | GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl)); |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 329 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
331 | "Beginning HTTP download from `%s'\n", | 330 | "Beginning HTTP download from `%s'\n", |
332 | url); | 331 | url); |
333 | curl_main (); | 332 | curl_main(); |
334 | } | 333 | } |
335 | 334 | ||
336 | 335 | ||
@@ -347,28 +346,28 @@ start_curl (void *cls) | |||
347 | * specified target peer; NULL on error | 346 | * specified target peer; NULL on error |
348 | */ | 347 | */ |
349 | static void | 348 | static void |
350 | commence_testing (void *cls, | 349 | commence_testing(void *cls, |
351 | int32_t success, | 350 | int32_t success, |
352 | const char *emsg) | 351 | const char *emsg) |
353 | { | 352 | { |
354 | qe = NULL; | 353 | qe = NULL; |
355 | if ( (NULL != emsg) && | 354 | if ((NULL != emsg) && |
356 | (GNUNET_YES != success) ) | 355 | (GNUNET_YES != success)) |
357 | { | 356 | { |
358 | fprintf (stderr, | 357 | fprintf(stderr, |
359 | "NS failed to create record %s\n", | 358 | "NS failed to create record %s\n", |
360 | emsg); | 359 | emsg); |
361 | GNUNET_SCHEDULER_shutdown (); | 360 | GNUNET_SCHEDULER_shutdown(); |
362 | return; | 361 | return; |
363 | } | 362 | } |
364 | 363 | ||
365 | /* wait a little bit before downloading, as we just created the record */ | 364 | /* wait a little bit before downloading, as we just created the record */ |
366 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 365 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
367 | "Launching cURL request\n"); | 366 | "Launching cURL request\n"); |
368 | curl_task_id | 367 | curl_task_id |
369 | = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 368 | = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
370 | &start_curl, | 369 | &start_curl, |
371 | NULL); | 370 | NULL); |
372 | } | 371 | } |
373 | 372 | ||
374 | 373 | ||
@@ -376,20 +375,20 @@ commence_testing (void *cls, | |||
376 | * Function to keep the HTTP server running. | 375 | * Function to keep the HTTP server running. |
377 | */ | 376 | */ |
378 | static void | 377 | static void |
379 | mhd_main (void); | 378 | mhd_main(void); |
380 | 379 | ||
381 | 380 | ||
382 | static void | 381 | static void |
383 | mhd_task (void *cls) | 382 | mhd_task(void *cls) |
384 | { | 383 | { |
385 | mhd_task_id = NULL; | 384 | mhd_task_id = NULL; |
386 | MHD_run (mhd); | 385 | MHD_run(mhd); |
387 | mhd_main (); | 386 | mhd_main(); |
388 | } | 387 | } |
389 | 388 | ||
390 | 389 | ||
391 | static void | 390 | static void |
392 | mhd_main () | 391 | mhd_main() |
393 | { | 392 | { |
394 | struct GNUNET_NETWORK_FDSet nrs; | 393 | struct GNUNET_NETWORK_FDSet nrs; |
395 | struct GNUNET_NETWORK_FDSet nws; | 394 | struct GNUNET_NETWORK_FDSet nws; |
@@ -400,30 +399,30 @@ mhd_main () | |||
400 | unsigned MHD_LONG_LONG timeout; | 399 | unsigned MHD_LONG_LONG timeout; |
401 | struct GNUNET_TIME_Relative delay; | 400 | struct GNUNET_TIME_Relative delay; |
402 | 401 | ||
403 | GNUNET_assert (NULL == mhd_task_id); | 402 | GNUNET_assert(NULL == mhd_task_id); |
404 | FD_ZERO (&rs); | 403 | FD_ZERO(&rs); |
405 | FD_ZERO (&ws); | 404 | FD_ZERO(&ws); |
406 | FD_ZERO (&es); | 405 | FD_ZERO(&es); |
407 | max_fd = -1; | 406 | max_fd = -1; |
408 | GNUNET_assert (MHD_YES == | 407 | GNUNET_assert(MHD_YES == |
409 | MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); | 408 | MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd)); |
410 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) | 409 | if (MHD_YES == MHD_get_timeout(mhd, &timeout)) |
411 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 410 | delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
412 | (unsigned int) timeout); | 411 | (unsigned int)timeout); |
413 | else | 412 | else |
414 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 413 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
415 | GNUNET_NETWORK_fdset_copy_native (&nrs, | 414 | GNUNET_NETWORK_fdset_copy_native(&nrs, |
416 | &rs, | 415 | &rs, |
417 | max_fd + 1); | 416 | max_fd + 1); |
418 | GNUNET_NETWORK_fdset_copy_native (&nws, | 417 | GNUNET_NETWORK_fdset_copy_native(&nws, |
419 | &ws, | 418 | &ws, |
420 | max_fd + 1); | 419 | max_fd + 1); |
421 | mhd_task_id = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 420 | mhd_task_id = GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
422 | delay, | 421 | delay, |
423 | &nrs, | 422 | &nrs, |
424 | &nws, | 423 | &nws, |
425 | &mhd_task, | 424 | &mhd_task, |
426 | NULL); | 425 | NULL); |
427 | } | 426 | } |
428 | 427 | ||
429 | 428 | ||
@@ -436,22 +435,22 @@ mhd_main () | |||
436 | * @param flags open flags (O_RDONLY, O_WRONLY) | 435 | * @param flags open flags (O_RDONLY, O_WRONLY) |
437 | */ | 436 | */ |
438 | static void | 437 | static void |
439 | open_dev_null (int target_fd, | 438 | open_dev_null(int target_fd, |
440 | int flags) | 439 | int flags) |
441 | { | 440 | { |
442 | int fd; | 441 | int fd; |
443 | 442 | ||
444 | fd = open ("/dev/null", flags); | 443 | fd = open("/dev/null", flags); |
445 | if (-1 == fd) | 444 | if (-1 == fd) |
446 | abort (); | 445 | abort(); |
447 | if (fd == target_fd) | 446 | if (fd == target_fd) |
448 | return; | 447 | return; |
449 | if (-1 == dup2 (fd, target_fd)) | 448 | if (-1 == dup2(fd, target_fd)) |
450 | { | 449 | { |
451 | (void) close (fd); | 450 | (void)close(fd); |
452 | abort (); | 451 | abort(); |
453 | } | 452 | } |
454 | (void) close (fd); | 453 | (void)close(fd); |
455 | } | 454 | } |
456 | 455 | ||
457 | 456 | ||
@@ -463,55 +462,56 @@ open_dev_null (int target_fd, | |||
463 | * @return 0 on success, 1 on any error | 462 | * @return 0 on success, 1 on any error |
464 | */ | 463 | */ |
465 | static int | 464 | static int |
466 | fork_and_exec (const char *file, | 465 | fork_and_exec(const char *file, |
467 | char *const cmd[]) | 466 | char *const cmd[]) |
468 | { | 467 | { |
469 | int status; | 468 | int status; |
470 | pid_t pid; | 469 | pid_t pid; |
471 | pid_t ret; | 470 | pid_t ret; |
472 | 471 | ||
473 | pid = fork (); | 472 | pid = fork(); |
474 | if (-1 == pid) | 473 | if (-1 == pid) |
475 | { | 474 | { |
476 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 475 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
477 | "fork"); | 476 | "fork"); |
478 | return 1; | 477 | return 1; |
479 | } | 478 | } |
480 | if (0 == pid) | 479 | if (0 == pid) |
481 | { | 480 | { |
482 | /* we are the child process */ | 481 | /* we are the child process */ |
483 | /* close stdin/stdout to not cause interference | 482 | /* close stdin/stdout to not cause interference |
484 | with the helper's main protocol! */ | 483 | with the helper's main protocol! */ |
485 | (void) close (0); | 484 | (void)close(0); |
486 | open_dev_null (0, O_RDONLY); | 485 | open_dev_null(0, O_RDONLY); |
487 | (void) close (1); | 486 | (void)close(1); |
488 | open_dev_null (1, O_WRONLY); | 487 | open_dev_null(1, O_WRONLY); |
489 | (void) execv (file, cmd); | 488 | (void)execv(file, cmd); |
490 | /* can only get here on error */ | 489 | /* can only get here on error */ |
491 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 490 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, |
492 | "exec", | 491 | "exec", |
493 | file); | 492 | file); |
494 | _exit (1); | 493 | _exit(1); |
495 | } | 494 | } |
496 | /* keep running waitpid as long as the only error we get is 'EINTR' */ | 495 | /* keep running waitpid as long as the only error we get is 'EINTR' */ |
497 | while ( (-1 == (ret = waitpid (pid, &status, 0))) && | 496 | while ((-1 == (ret = waitpid(pid, &status, 0))) && |
498 | (errno == EINTR) ); | 497 | (errno == EINTR)) |
498 | ; | ||
499 | if (-1 == ret) | 499 | if (-1 == ret) |
500 | { | 500 | { |
501 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, | 501 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, |
502 | "waitpid"); | 502 | "waitpid"); |
503 | return 1; | 503 | return 1; |
504 | } | 504 | } |
505 | if (! (WIFEXITED (status) && | 505 | if (!(WIFEXITED(status) && |
506 | (0 == WEXITSTATUS (status))) ) | 506 | (0 == WEXITSTATUS(status)))) |
507 | { | 507 | { |
508 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 508 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
509 | "Process `%s` returned status code %d/%d.\n", | 509 | "Process `%s` returned status code %d/%d.\n", |
510 | file, | 510 | file, |
511 | WIFEXITED (status), | 511 | WIFEXITED(status), |
512 | WEXITSTATUS (status)); | 512 | WEXITSTATUS(status)); |
513 | return 1; | 513 | return 1; |
514 | } | 514 | } |
515 | /* child process completed and returned success, we're happy */ | 515 | /* child process completed and returned success, we're happy */ |
516 | return 0; | 516 | return 0; |
517 | } | 517 | } |
@@ -553,10 +553,10 @@ fork_and_exec (const char *file, | |||
553 | * must thus no longer be used | 553 | * must thus no longer be used |
554 | */ | 554 | */ |
555 | static void | 555 | static void |
556 | identity_cb (void *cls, | 556 | identity_cb(void *cls, |
557 | struct GNUNET_IDENTITY_Ego *ego, | 557 | struct GNUNET_IDENTITY_Ego *ego, |
558 | void **ctx, | 558 | void **ctx, |
559 | const char *name) | 559 | const char *name) |
560 | { | 560 | { |
561 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; | 561 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key; |
562 | struct GNUNET_GNSRECORD_Data rd; | 562 | struct GNUNET_GNSRECORD_Data rd; |
@@ -566,59 +566,59 @@ identity_cb (void *cls, | |||
566 | if (NULL == name) | 566 | if (NULL == name) |
567 | return; | 567 | return; |
568 | if (NULL == ego) | 568 | if (NULL == ego) |
569 | { | ||
570 | if (NULL == qe) | ||
571 | { | 569 | { |
572 | fprintf (stderr, | 570 | if (NULL == qe) |
573 | "Failed to find master-zone ego\n"); | 571 | { |
574 | GNUNET_SCHEDULER_shutdown (); | 572 | fprintf(stderr, |
573 | "Failed to find master-zone ego\n"); | ||
574 | GNUNET_SCHEDULER_shutdown(); | ||
575 | return; | ||
576 | } | ||
577 | GNUNET_IDENTITY_disconnect(identity); | ||
578 | identity = NULL; | ||
575 | return; | 579 | return; |
576 | } | 580 | } |
577 | GNUNET_IDENTITY_disconnect (identity); | 581 | GNUNET_assert(NULL != name); |
578 | identity = NULL; | 582 | if (0 != strcmp(name, |
579 | return; | 583 | "master-zone")) |
580 | } | 584 | { |
581 | GNUNET_assert (NULL != name); | 585 | fprintf(stderr, |
582 | if (0 != strcmp (name, | 586 | "Unexpected name %s\n", |
583 | "master-zone")) | 587 | name); |
584 | { | 588 | return; |
585 | fprintf (stderr, | 589 | } |
586 | "Unexpected name %s\n", | 590 | zone_key = GNUNET_IDENTITY_ego_get_private_key(ego); |
587 | name); | ||
588 | return; | ||
589 | } | ||
590 | zone_key = GNUNET_IDENTITY_ego_get_private_key (ego); | ||
591 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; | 591 | rd.expiration_time = GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us; |
592 | peername = GNUNET_strdup (GNUNET_i2s_full (&id)); | 592 | peername = GNUNET_strdup(GNUNET_i2s_full(&id)); |
593 | GNUNET_asprintf (&rd_string, | 593 | GNUNET_asprintf(&rd_string, |
594 | "6 %s %s", | 594 | "6 %s %s", |
595 | peername, | 595 | peername, |
596 | "www"); | 596 | "www"); |
597 | GNUNET_free (peername); | 597 | GNUNET_free(peername); |
598 | GNUNET_assert (GNUNET_OK == | 598 | GNUNET_assert(GNUNET_OK == |
599 | GNUNET_GNSRECORD_string_to_value (GNUNET_GNSRECORD_TYPE_VPN, | 599 | GNUNET_GNSRECORD_string_to_value(GNUNET_GNSRECORD_TYPE_VPN, |
600 | rd_string, | 600 | rd_string, |
601 | (void**) &rd.data, | 601 | (void**)&rd.data, |
602 | &rd.data_size)); | 602 | &rd.data_size)); |
603 | rd.record_type = GNUNET_GNSRECORD_TYPE_VPN; | 603 | rd.record_type = GNUNET_GNSRECORD_TYPE_VPN; |
604 | 604 | ||
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 605 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
606 | "Creating `www` record\n"); | 606 | "Creating `www` record\n"); |
607 | qe = GNUNET_NAMESTORE_records_store (namestore, | 607 | qe = GNUNET_NAMESTORE_records_store(namestore, |
608 | zone_key, | 608 | zone_key, |
609 | "www", | 609 | "www", |
610 | 1, &rd, | 610 | 1, &rd, |
611 | &commence_testing, | 611 | &commence_testing, |
612 | NULL); | 612 | NULL); |
613 | GNUNET_free ((void**)rd.data); | 613 | GNUNET_free((void**)rd.data); |
614 | GNUNET_free (rd_string); | 614 | GNUNET_free(rd_string); |
615 | } | 615 | } |
616 | 616 | ||
617 | 617 | ||
618 | static void | 618 | static void |
619 | run (void *cls, | 619 | run(void *cls, |
620 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 620 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
621 | struct GNUNET_TESTING_Peer *peer) | 621 | struct GNUNET_TESTING_Peer *peer) |
622 | { | 622 | { |
623 | enum MHD_FLAG flags; | 623 | enum MHD_FLAG flags; |
624 | 624 | ||
@@ -628,19 +628,19 @@ run (void *cls, | |||
628 | char *bin_arm; | 628 | char *bin_arm; |
629 | char *config; | 629 | char *config; |
630 | 630 | ||
631 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 631 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
632 | "Test logic starting...\n"); | 632 | "Test logic starting...\n"); |
633 | if (GNUNET_OK != | 633 | if (GNUNET_OK != |
634 | GNUNET_CONFIGURATION_get_value_string (cfg, | 634 | GNUNET_CONFIGURATION_get_value_string(cfg, |
635 | "arm", | 635 | "arm", |
636 | "CONFIG", | 636 | "CONFIG", |
637 | &config)) | 637 | &config)) |
638 | { | 638 | { |
639 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 639 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
640 | "Failed to locate configuration file. Skipping test.\n"); | 640 | "Failed to locate configuration file. Skipping test.\n"); |
641 | GNUNET_SCHEDULER_shutdown (); | 641 | GNUNET_SCHEDULER_shutdown(); |
642 | return; | 642 | return; |
643 | } | 643 | } |
644 | 644 | ||
645 | char *const identity_args[] = | 645 | char *const identity_args[] = |
646 | { | 646 | { |
@@ -680,187 +680,187 @@ run (void *cls, | |||
680 | NULL | 680 | NULL |
681 | }; | 681 | }; |
682 | 682 | ||
683 | GNUNET_TESTING_peer_get_identity (peer, | 683 | GNUNET_TESTING_peer_get_identity(peer, |
684 | &id); | 684 | &id); |
685 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 685 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, |
686 | NULL); | 686 | NULL); |
687 | timeout_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 687 | timeout_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
688 | &do_timeout, | 688 | &do_timeout, |
689 | NULL); | 689 | NULL); |
690 | bin = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_BINDIR); | 690 | bin = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_BINDIR); |
691 | GNUNET_asprintf (&bin_identity, | 691 | GNUNET_asprintf(&bin_identity, |
692 | "%s/%s", | 692 | "%s/%s", |
693 | bin, | 693 | bin, |
694 | "gnunet-identity"); | 694 | "gnunet-identity"); |
695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 695 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
696 | "Creating `master-zone` ego\n"); | 696 | "Creating `master-zone` ego\n"); |
697 | if (0 != fork_and_exec (bin_identity, identity_args)) | 697 | if (0 != fork_and_exec(bin_identity, identity_args)) |
698 | { | 698 | { |
699 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 699 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
700 | "Failed to run `gnunet-identity -C`. Skipping test.\n"); | 700 | "Failed to run `gnunet-identity -C`. Skipping test.\n"); |
701 | GNUNET_SCHEDULER_shutdown (); | 701 | GNUNET_SCHEDULER_shutdown(); |
702 | GNUNET_free (bin_identity); | 702 | GNUNET_free(bin_identity); |
703 | GNUNET_free (config); | 703 | GNUNET_free(config); |
704 | GNUNET_free (bin); | 704 | GNUNET_free(bin); |
705 | return; | 705 | return; |
706 | } | 706 | } |
707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 707 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
708 | "Setting `master-zone` ego as default for `gns-master` and `dns2gns`\n"); | 708 | "Setting `master-zone` ego as default for `gns-master` and `dns2gns`\n"); |
709 | if (0 != fork_and_exec (bin_identity, identity2_args)) | 709 | if (0 != fork_and_exec(bin_identity, identity2_args)) |
710 | { | 710 | { |
711 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 711 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
712 | "Failed to run `gnunet-identity -e`. Skipping test.\n"); | 712 | "Failed to run `gnunet-identity -e`. Skipping test.\n"); |
713 | GNUNET_SCHEDULER_shutdown (); | 713 | GNUNET_SCHEDULER_shutdown(); |
714 | GNUNET_free (bin_identity); | 714 | GNUNET_free(bin_identity); |
715 | GNUNET_free (config); | 715 | GNUNET_free(config); |
716 | GNUNET_free (bin); | 716 | GNUNET_free(bin); |
717 | return; | 717 | return; |
718 | } | 718 | } |
719 | if (0 != fork_and_exec (bin_identity, identity3_args)) | 719 | if (0 != fork_and_exec(bin_identity, identity3_args)) |
720 | { | 720 | { |
721 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 721 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
722 | "Failed to run `gnunet-identity -e`. Skipping test.\n"); | 722 | "Failed to run `gnunet-identity -e`. Skipping test.\n"); |
723 | GNUNET_SCHEDULER_shutdown (); | 723 | GNUNET_SCHEDULER_shutdown(); |
724 | GNUNET_free (bin_identity); | 724 | GNUNET_free(bin_identity); |
725 | GNUNET_free (config); | 725 | GNUNET_free(config); |
726 | GNUNET_free (bin); | 726 | GNUNET_free(bin); |
727 | return; | 727 | return; |
728 | } | 728 | } |
729 | GNUNET_free (bin_identity); | 729 | GNUNET_free(bin_identity); |
730 | 730 | ||
731 | /* do lookup just to launch GNS service */ | 731 | /* do lookup just to launch GNS service */ |
732 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 732 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
733 | "Resolving `www.gnu` zone entry to launch GNS (will yield no answer yet)\n"); | 733 | "Resolving `www.gnu` zone entry to launch GNS (will yield no answer yet)\n"); |
734 | GNUNET_asprintf (&bin_gns, | 734 | GNUNET_asprintf(&bin_gns, |
735 | "%s/%s", | 735 | "%s/%s", |
736 | bin, | 736 | bin, |
737 | "gnunet-gns"); | 737 | "gnunet-gns"); |
738 | if (0 != fork_and_exec (bin_gns, | 738 | if (0 != fork_and_exec(bin_gns, |
739 | gns_args)) | 739 | gns_args)) |
740 | { | 740 | { |
741 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 741 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
742 | "Failed to run `gnunet-gns -u. Skipping test.\n"); | 742 | "Failed to run `gnunet-gns -u. Skipping test.\n"); |
743 | GNUNET_SCHEDULER_shutdown (); | 743 | GNUNET_SCHEDULER_shutdown(); |
744 | GNUNET_free (bin_gns); | 744 | GNUNET_free(bin_gns); |
745 | GNUNET_free (config); | 745 | GNUNET_free(config); |
746 | GNUNET_free (bin); | 746 | GNUNET_free(bin); |
747 | return; | 747 | return; |
748 | } | 748 | } |
749 | GNUNET_free (bin_gns); | 749 | GNUNET_free(bin_gns); |
750 | 750 | ||
751 | GNUNET_asprintf (&bin_arm, | 751 | GNUNET_asprintf(&bin_arm, |
752 | "%s/%s", | 752 | "%s/%s", |
753 | bin, | 753 | bin, |
754 | "gnunet-arm"); | 754 | "gnunet-arm"); |
755 | if (0 != fork_and_exec (bin_arm, | 755 | if (0 != fork_and_exec(bin_arm, |
756 | arm_args)) | 756 | arm_args)) |
757 | { | 757 | { |
758 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 758 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, |
759 | "Failed to run `gnunet-arm -i dns2gns. Skipping test.\n"); | 759 | "Failed to run `gnunet-arm -i dns2gns. Skipping test.\n"); |
760 | GNUNET_SCHEDULER_shutdown (); | 760 | GNUNET_SCHEDULER_shutdown(); |
761 | GNUNET_free (bin_arm); | 761 | GNUNET_free(bin_arm); |
762 | GNUNET_free (config); | 762 | GNUNET_free(config); |
763 | GNUNET_free (bin); | 763 | GNUNET_free(bin); |
764 | return; | 764 | return; |
765 | } | 765 | } |
766 | GNUNET_free (bin_arm); | 766 | GNUNET_free(bin_arm); |
767 | 767 | ||
768 | GNUNET_free (config); | 768 | GNUNET_free(config); |
769 | GNUNET_free (bin); | 769 | GNUNET_free(bin); |
770 | sleep (1); /* give dns2gns chance to really run */ | 770 | sleep(1); /* give dns2gns chance to really run */ |
771 | 771 | ||
772 | namestore = GNUNET_NAMESTORE_connect (cfg); | 772 | namestore = GNUNET_NAMESTORE_connect(cfg); |
773 | GNUNET_assert (NULL != namestore); | 773 | GNUNET_assert(NULL != namestore); |
774 | flags = MHD_USE_DEBUG; | 774 | flags = MHD_USE_DEBUG; |
775 | if (GNUNET_YES == use_v6) | 775 | if (GNUNET_YES == use_v6) |
776 | flags |= MHD_USE_DUAL_STACK; | 776 | flags |= MHD_USE_DUAL_STACK; |
777 | mhd = MHD_start_daemon (flags, | 777 | mhd = MHD_start_daemon(flags, |
778 | PORT, | 778 | PORT, |
779 | NULL, NULL, | 779 | NULL, NULL, |
780 | &mhd_ahc, NULL, | 780 | &mhd_ahc, NULL, |
781 | MHD_OPTION_END); | 781 | MHD_OPTION_END); |
782 | GNUNET_assert (NULL != mhd); | 782 | GNUNET_assert(NULL != mhd); |
783 | mhd_main (); | 783 | mhd_main(); |
784 | 784 | ||
785 | identity = GNUNET_IDENTITY_connect (cfg, | 785 | identity = GNUNET_IDENTITY_connect(cfg, |
786 | &identity_cb, | 786 | &identity_cb, |
787 | NULL); | 787 | NULL); |
788 | } | 788 | } |
789 | 789 | ||
790 | 790 | ||
791 | int | 791 | int |
792 | main (int argc, | 792 | main(int argc, |
793 | char *const *argv) | 793 | char *const *argv) |
794 | { | 794 | { |
795 | char *bin_vpn; | 795 | char *bin_vpn; |
796 | char *bin_exit; | 796 | char *bin_exit; |
797 | 797 | ||
798 | GNUNET_log_setup ("test-gns-vpn", | 798 | GNUNET_log_setup("test-gns-vpn", |
799 | "WARNING", | 799 | "WARNING", |
800 | NULL); | 800 | NULL); |
801 | if (0 != ACCESS ("/dev/net/tun", R_OK)) | 801 | if (0 != ACCESS("/dev/net/tun", R_OK)) |
802 | { | 802 | { |
803 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 803 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, |
804 | "access", | 804 | "access", |
805 | "/dev/net/tun"); | 805 | "/dev/net/tun"); |
806 | fprintf (stderr, | 806 | fprintf(stderr, |
807 | "WARNING: System unable to run test, skipping.\n"); | 807 | "WARNING: System unable to run test, skipping.\n"); |
808 | return 77; | 808 | return 77; |
809 | } | 809 | } |
810 | 810 | ||
811 | bin_vpn = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); | 811 | bin_vpn = GNUNET_OS_get_libexec_binary_path("gnunet-helper-vpn"); |
812 | bin_exit = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit"); | 812 | bin_exit = GNUNET_OS_get_libexec_binary_path("gnunet-helper-exit"); |
813 | if ( (0 != geteuid ()) && | 813 | if ((0 != geteuid()) && |
814 | ( (GNUNET_YES != | 814 | ((GNUNET_YES != |
815 | GNUNET_OS_check_helper_binary (bin_vpn, | 815 | GNUNET_OS_check_helper_binary(bin_vpn, |
816 | GNUNET_YES, | 816 | GNUNET_YES, |
817 | "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) || //ipv4 only please! | 817 | "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0")) || //ipv4 only please! |
818 | (GNUNET_YES != | 818 | (GNUNET_YES != |
819 | GNUNET_OS_check_helper_binary (bin_exit, | 819 | GNUNET_OS_check_helper_binary(bin_exit, |
820 | GNUNET_YES, | 820 | GNUNET_YES, |
821 | "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")) ) ) //no nat, ipv4 only | 821 | "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only |
822 | { | 822 | { |
823 | fprintf (stderr, | 823 | fprintf(stderr, |
824 | "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n"); | 824 | "WARNING: gnunet-helper-{exit,vpn} binaries in $PATH are not SUID, refusing to run test (as it would have to fail).\n"); |
825 | fprintf (stderr, | 825 | fprintf(stderr, |
826 | "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n"); | 826 | "Change $PATH ('.' in $PATH before $GNUNET_PREFIX/bin is problematic) or permissions (run 'make install' as root) to fix this!\n"); |
827 | GNUNET_free (bin_vpn); | 827 | GNUNET_free(bin_vpn); |
828 | GNUNET_free (bin_exit); | 828 | GNUNET_free(bin_exit); |
829 | return 77; | 829 | return 77; |
830 | } | 830 | } |
831 | GNUNET_free (bin_vpn); | 831 | GNUNET_free(bin_vpn); |
832 | GNUNET_free (bin_exit); | 832 | GNUNET_free(bin_exit); |
833 | 833 | ||
834 | dest_ip = "169.254.86.1"; | 834 | dest_ip = "169.254.86.1"; |
835 | dest_af = AF_INET; | 835 | dest_af = AF_INET; |
836 | src_af = AF_INET; | 836 | src_af = AF_INET; |
837 | 837 | ||
838 | if (GNUNET_OK == GNUNET_NETWORK_test_pf (PF_INET6)) | 838 | if (GNUNET_OK == GNUNET_NETWORK_test_pf(PF_INET6)) |
839 | use_v6 = GNUNET_YES; | 839 | use_v6 = GNUNET_YES; |
840 | else | 840 | else |
841 | use_v6 = GNUNET_NO; | 841 | use_v6 = GNUNET_NO; |
842 | 842 | ||
843 | if ( (GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) || | 843 | if ((GNUNET_OK != GNUNET_NETWORK_test_pf(src_af)) || |
844 | (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af)) ) | 844 | (GNUNET_OK != GNUNET_NETWORK_test_pf(dest_af))) |
845 | { | 845 | { |
846 | fprintf (stderr, | 846 | fprintf(stderr, |
847 | "Required address families not supported by this system, skipping test.\n"); | 847 | "Required address families not supported by this system, skipping test.\n"); |
848 | return 77; | 848 | return 77; |
849 | } | 849 | } |
850 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 850 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
851 | { | 851 | { |
852 | fprintf (stderr, "failed to initialize curl\n"); | 852 | fprintf(stderr, "failed to initialize curl\n"); |
853 | return 2; | 853 | return 2; |
854 | } | 854 | } |
855 | 855 | ||
856 | 856 | ||
857 | if (0 != | 857 | if (0 != |
858 | GNUNET_TESTING_peer_run ("test_gns_vpn", | 858 | GNUNET_TESTING_peer_run("test_gns_vpn", |
859 | "test_gns_vpn.conf", | 859 | "test_gns_vpn.conf", |
860 | &run, | 860 | &run, |
861 | NULL)) | 861 | NULL)) |
862 | return 1; | 862 | return 1; |
863 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); | 863 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-vpn"); |
864 | return global_ret; | 864 | return global_ret; |
865 | } | 865 | } |
866 | 866 | ||
diff --git a/src/pt/test_gnunet_vpn.c b/src/pt/test_gnunet_vpn.c index 7cc77fe24..ae5910824 100644 --- a/src/pt/test_gnunet_vpn.c +++ b/src/pt/test_gnunet_vpn.c | |||
@@ -11,12 +11,12 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 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/>. | 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 test_gnunet_vpn.c | 22 | * @file test_gnunet_vpn.c |
@@ -32,7 +32,7 @@ | |||
32 | 32 | ||
33 | #define PORT 48080 | 33 | #define PORT 48080 |
34 | 34 | ||
35 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) | 35 | #define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300) |
36 | 36 | ||
37 | 37 | ||
38 | /** | 38 | /** |
@@ -74,8 +74,7 @@ static int dest_af; | |||
74 | static int src_af; | 74 | static int src_af; |
75 | 75 | ||
76 | 76 | ||
77 | struct CBC | 77 | struct CBC { |
78 | { | ||
79 | char buf[1024]; | 78 | char buf[1024]; |
80 | size_t pos; | 79 | size_t pos; |
81 | }; | 80 | }; |
@@ -84,87 +83,87 @@ static struct CBC cbc; | |||
84 | 83 | ||
85 | 84 | ||
86 | static size_t | 85 | static size_t |
87 | copy_buffer (void *ptr, size_t size, size_t nmemb, void *ctx) | 86 | copy_buffer(void *ptr, size_t size, size_t nmemb, void *ctx) |
88 | { | 87 | { |
89 | struct CBC *cbc = ctx; | 88 | struct CBC *cbc = ctx; |
90 | 89 | ||
91 | if (cbc->pos + size * nmemb > sizeof (cbc->buf)) | 90 | if (cbc->pos + size * nmemb > sizeof(cbc->buf)) |
92 | return 0; /* overflow */ | 91 | return 0; /* overflow */ |
93 | GNUNET_memcpy (&cbc->buf[cbc->pos], ptr, size * nmemb); | 92 | GNUNET_memcpy(&cbc->buf[cbc->pos], ptr, size * nmemb); |
94 | cbc->pos += size * nmemb; | 93 | cbc->pos += size * nmemb; |
95 | return size * nmemb; | 94 | return size * nmemb; |
96 | } | 95 | } |
97 | 96 | ||
98 | 97 | ||
99 | static int | 98 | static int |
100 | mhd_ahc (void *cls, | 99 | mhd_ahc(void *cls, |
101 | struct MHD_Connection *connection, | 100 | struct MHD_Connection *connection, |
102 | const char *url, | 101 | const char *url, |
103 | const char *method, | 102 | const char *method, |
104 | const char *version, | 103 | const char *version, |
105 | const char *upload_data, | 104 | const char *upload_data, |
106 | size_t * upload_data_size, | 105 | size_t * upload_data_size, |
107 | void **unused) | 106 | void **unused) |
108 | { | 107 | { |
109 | static int ptr; | 108 | static int ptr; |
110 | struct MHD_Response *response; | 109 | struct MHD_Response *response; |
111 | int ret; | 110 | int ret; |
112 | 111 | ||
113 | if (0 != strcmp ("GET", method)) | 112 | if (0 != strcmp("GET", method)) |
114 | return MHD_NO; /* unexpected method */ | 113 | return MHD_NO; /* unexpected method */ |
115 | if (&ptr != *unused) | 114 | if (&ptr != *unused) |
116 | { | 115 | { |
117 | *unused = &ptr; | 116 | *unused = &ptr; |
118 | return MHD_YES; | 117 | return MHD_YES; |
119 | } | 118 | } |
120 | *unused = NULL; | 119 | *unused = NULL; |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 120 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
122 | "MHD sends respose for request to URL `%s'\n", url); | 121 | "MHD sends respose for request to URL `%s'\n", url); |
123 | response = | 122 | response = |
124 | MHD_create_response_from_buffer (strlen (url), (void *) url, | 123 | MHD_create_response_from_buffer(strlen(url), (void *)url, |
125 | MHD_RESPMEM_MUST_COPY); | 124 | MHD_RESPMEM_MUST_COPY); |
126 | ret = MHD_queue_response (connection, MHD_HTTP_OK, response); | 125 | ret = MHD_queue_response(connection, MHD_HTTP_OK, response); |
127 | MHD_destroy_response (response); | 126 | MHD_destroy_response(response); |
128 | if (ret == MHD_NO) | 127 | if (ret == MHD_NO) |
129 | abort (); | 128 | abort(); |
130 | return ret; | 129 | return ret; |
131 | } | 130 | } |
132 | 131 | ||
133 | 132 | ||
134 | static void | 133 | static void |
135 | do_shutdown (void *cls) | 134 | do_shutdown(void *cls) |
136 | { | 135 | { |
137 | if (NULL != mhd_task_id) | 136 | if (NULL != mhd_task_id) |
138 | { | 137 | { |
139 | GNUNET_SCHEDULER_cancel (mhd_task_id); | 138 | GNUNET_SCHEDULER_cancel(mhd_task_id); |
140 | mhd_task_id = NULL; | 139 | mhd_task_id = NULL; |
141 | } | 140 | } |
142 | if (NULL != curl_task_id) | 141 | if (NULL != curl_task_id) |
143 | { | 142 | { |
144 | GNUNET_SCHEDULER_cancel (curl_task_id); | 143 | GNUNET_SCHEDULER_cancel(curl_task_id); |
145 | curl_task_id = NULL; | 144 | curl_task_id = NULL; |
146 | } | 145 | } |
147 | if (NULL != timeout_task_id) | 146 | if (NULL != timeout_task_id) |
148 | { | 147 | { |
149 | GNUNET_SCHEDULER_cancel (timeout_task_id); | 148 | GNUNET_SCHEDULER_cancel(timeout_task_id); |
150 | timeout_task_id = NULL; | 149 | timeout_task_id = NULL; |
151 | } | 150 | } |
152 | if (NULL != mhd) | 151 | if (NULL != mhd) |
153 | { | 152 | { |
154 | MHD_stop_daemon (mhd); | 153 | MHD_stop_daemon(mhd); |
155 | mhd = NULL; | 154 | mhd = NULL; |
156 | } | 155 | } |
157 | if (NULL != rr) | 156 | if (NULL != rr) |
158 | { | 157 | { |
159 | GNUNET_VPN_cancel_request (rr); | 158 | GNUNET_VPN_cancel_request(rr); |
160 | rr = NULL; | 159 | rr = NULL; |
161 | } | 160 | } |
162 | if (NULL != vpn) | 161 | if (NULL != vpn) |
163 | { | 162 | { |
164 | GNUNET_VPN_disconnect (vpn); | 163 | GNUNET_VPN_disconnect(vpn); |
165 | vpn = NULL; | 164 | vpn = NULL; |
166 | } | 165 | } |
167 | GNUNET_free_non_null (url); | 166 | GNUNET_free_non_null(url); |
168 | url = NULL; | 167 | url = NULL; |
169 | } | 168 | } |
170 | 169 | ||
@@ -173,7 +172,7 @@ do_shutdown (void *cls) | |||
173 | * Function to run the HTTP client. | 172 | * Function to run the HTTP client. |
174 | */ | 173 | */ |
175 | static void | 174 | static void |
176 | curl_main (void *cls) | 175 | curl_main(void *cls) |
177 | { | 176 | { |
178 | fd_set rs; | 177 | fd_set rs; |
179 | fd_set ws; | 178 | fd_set ws; |
@@ -188,55 +187,55 @@ curl_main (void *cls) | |||
188 | 187 | ||
189 | curl_task_id = NULL; | 188 | curl_task_id = NULL; |
190 | max = 0; | 189 | max = 0; |
191 | FD_ZERO (&rs); | 190 | FD_ZERO(&rs); |
192 | FD_ZERO (&ws); | 191 | FD_ZERO(&ws); |
193 | FD_ZERO (&es); | 192 | FD_ZERO(&es); |
194 | curl_multi_perform (multi, &running); | 193 | curl_multi_perform(multi, &running); |
195 | if (running == 0) | 194 | if (running == 0) |
196 | { | ||
197 | GNUNET_assert (NULL != (msg = curl_multi_info_read (multi, &running))); | ||
198 | if (msg->msg == CURLMSG_DONE) | ||
199 | { | 195 | { |
200 | if (msg->data.result != CURLE_OK) | 196 | GNUNET_assert(NULL != (msg = curl_multi_info_read(multi, &running))); |
201 | { | 197 | if (msg->msg == CURLMSG_DONE) |
202 | fprintf (stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform", | 198 | { |
203 | __FILE__, __LINE__, curl_easy_strerror (msg->data.result)); | 199 | if (msg->data.result != CURLE_OK) |
204 | global_ret = 1; | 200 | { |
205 | } | 201 | fprintf(stderr, "%s failed at %s:%d: `%s'\n", "curl_multi_perform", |
202 | __FILE__, __LINE__, curl_easy_strerror(msg->data.result)); | ||
203 | global_ret = 1; | ||
204 | } | ||
205 | } | ||
206 | curl_multi_remove_handle(multi, curl); | ||
207 | curl_multi_cleanup(multi); | ||
208 | curl_easy_cleanup(curl); | ||
209 | curl = NULL; | ||
210 | multi = NULL; | ||
211 | if (cbc.pos != strlen("/hello_world")) | ||
212 | { | ||
213 | GNUNET_break(0); | ||
214 | global_ret = 2; | ||
215 | } | ||
216 | if (0 != strncmp("/hello_world", cbc.buf, strlen("/hello_world"))) | ||
217 | { | ||
218 | GNUNET_break(0); | ||
219 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, | ||
220 | "You might want to check if your host-based firewall is blocking the connections.\n"); | ||
221 | global_ret = 3; | ||
222 | } | ||
223 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | ||
224 | GNUNET_SCHEDULER_shutdown(); | ||
225 | return; | ||
206 | } | 226 | } |
207 | curl_multi_remove_handle (multi, curl); | 227 | GNUNET_assert(CURLM_OK == curl_multi_fdset(multi, &rs, &ws, &es, &max)); |
208 | curl_multi_cleanup (multi); | 228 | if ((CURLM_OK != curl_multi_timeout(multi, &timeout)) || (-1 == timeout)) |
209 | curl_easy_cleanup (curl); | ||
210 | curl = NULL; | ||
211 | multi = NULL; | ||
212 | if (cbc.pos != strlen ("/hello_world")) | ||
213 | { | ||
214 | GNUNET_break (0); | ||
215 | global_ret = 2; | ||
216 | } | ||
217 | if (0 != strncmp ("/hello_world", cbc.buf, strlen ("/hello_world"))) | ||
218 | { | ||
219 | GNUNET_break (0); | ||
220 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
221 | "You might want to check if your host-based firewall is blocking the connections.\n"); | ||
222 | global_ret = 3; | ||
223 | } | ||
224 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Download complete, shutting down!\n"); | ||
225 | GNUNET_SCHEDULER_shutdown (); | ||
226 | return; | ||
227 | } | ||
228 | GNUNET_assert (CURLM_OK == curl_multi_fdset (multi, &rs, &ws, &es, &max)); | ||
229 | if ((CURLM_OK != curl_multi_timeout (multi, &timeout)) || (-1 == timeout)) | ||
230 | delay = GNUNET_TIME_UNIT_SECONDS; | 229 | delay = GNUNET_TIME_UNIT_SECONDS; |
231 | else | 230 | else |
232 | delay = | 231 | delay = |
233 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 232 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
234 | (unsigned int) timeout); | 233 | (unsigned int)timeout); |
235 | GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max + 1); | 234 | GNUNET_NETWORK_fdset_copy_native(&nrs, &rs, max + 1); |
236 | GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max + 1); | 235 | GNUNET_NETWORK_fdset_copy_native(&nws, &ws, max + 1); |
237 | curl_task_id = | 236 | curl_task_id = |
238 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, | 237 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, |
239 | &nrs, &nws, &curl_main, NULL); | 238 | &nrs, &nws, &curl_main, NULL); |
240 | } | 239 | } |
241 | 240 | ||
242 | 241 | ||
@@ -254,53 +253,53 @@ curl_main (void *cls) | |||
254 | * specified target peer; NULL on error | 253 | * specified target peer; NULL on error |
255 | */ | 254 | */ |
256 | static void | 255 | static void |
257 | allocation_cb (void *cls, int af, const void *address) | 256 | allocation_cb(void *cls, int af, const void *address) |
258 | { | 257 | { |
259 | char ips[INET6_ADDRSTRLEN]; | 258 | char ips[INET6_ADDRSTRLEN]; |
260 | 259 | ||
261 | rr = NULL; | 260 | rr = NULL; |
262 | if (src_af != af) | 261 | if (src_af != af) |
263 | { | 262 | { |
264 | fprintf (stderr, | 263 | fprintf(stderr, |
265 | "VPN failed to allocate appropriate address\n"); | 264 | "VPN failed to allocate appropriate address\n"); |
266 | GNUNET_SCHEDULER_shutdown (); | 265 | GNUNET_SCHEDULER_shutdown(); |
267 | return; | 266 | return; |
268 | } | 267 | } |
269 | if (AF_INET6 == af) | 268 | if (AF_INET6 == af) |
270 | GNUNET_asprintf (&url, | 269 | GNUNET_asprintf(&url, |
271 | "http://[%s]:%u/hello_world", | 270 | "http://[%s]:%u/hello_world", |
272 | inet_ntop (af, | 271 | inet_ntop(af, |
273 | address, | 272 | address, |
274 | ips, | 273 | ips, |
275 | sizeof (ips)), | 274 | sizeof(ips)), |
276 | (unsigned int) PORT); | 275 | (unsigned int)PORT); |
277 | else | 276 | else |
278 | GNUNET_asprintf (&url, | 277 | GNUNET_asprintf(&url, |
279 | "http://%s:%u/hello_world", | 278 | "http://%s:%u/hello_world", |
280 | inet_ntop (af, | 279 | inet_ntop(af, |
281 | address, | 280 | address, |
282 | ips, | 281 | ips, |
283 | sizeof (ips)), | 282 | sizeof(ips)), |
284 | (unsigned int) PORT); | 283 | (unsigned int)PORT); |
285 | curl = curl_easy_init (); | 284 | curl = curl_easy_init(); |
286 | curl_easy_setopt (curl, CURLOPT_URL, url); | 285 | curl_easy_setopt(curl, CURLOPT_URL, url); |
287 | curl_easy_setopt (curl, CURLOPT_WRITEFUNCTION, ©_buffer); | 286 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, ©_buffer); |
288 | curl_easy_setopt (curl, CURLOPT_WRITEDATA, &cbc); | 287 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, &cbc); |
289 | curl_easy_setopt (curl, CURLOPT_FAILONERROR, 1); | 288 | curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1); |
290 | curl_easy_setopt (curl, CURLOPT_TIMEOUT, 150L); | 289 | curl_easy_setopt(curl, CURLOPT_TIMEOUT, 150L); |
291 | curl_easy_setopt (curl, CURLOPT_CONNECTTIMEOUT, 15L); | 290 | curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 15L); |
292 | curl_easy_setopt (curl, CURLOPT_NOSIGNAL, 1); | 291 | curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); |
293 | curl_easy_setopt (curl, CURLOPT_VERBOSE, 0); | 292 | curl_easy_setopt(curl, CURLOPT_VERBOSE, 0); |
294 | 293 | ||
295 | multi = curl_multi_init (); | 294 | multi = curl_multi_init(); |
296 | GNUNET_assert (multi != NULL); | 295 | GNUNET_assert(multi != NULL); |
297 | GNUNET_assert (CURLM_OK == curl_multi_add_handle (multi, curl)); | 296 | GNUNET_assert(CURLM_OK == curl_multi_add_handle(multi, curl)); |
298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 297 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, |
299 | "Beginning HTTP download from `%s'\n", | 298 | "Beginning HTTP download from `%s'\n", |
300 | url); | 299 | url); |
301 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, | 300 | GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, |
302 | &curl_main, | 301 | &curl_main, |
303 | NULL); | 302 | NULL); |
304 | } | 303 | } |
305 | 304 | ||
306 | 305 | ||
@@ -308,30 +307,30 @@ allocation_cb (void *cls, int af, const void *address) | |||
308 | * Function to keep the HTTP server running. | 307 | * Function to keep the HTTP server running. |
309 | */ | 308 | */ |
310 | static void | 309 | static void |
311 | mhd_main (void); | 310 | mhd_main(void); |
312 | 311 | ||
313 | 312 | ||
314 | static void | 313 | static void |
315 | mhd_task (void *cls) | 314 | mhd_task(void *cls) |
316 | { | 315 | { |
317 | mhd_task_id = NULL; | 316 | mhd_task_id = NULL; |
318 | MHD_run (mhd); | 317 | MHD_run(mhd); |
319 | mhd_main (); | 318 | mhd_main(); |
320 | } | 319 | } |
321 | 320 | ||
322 | 321 | ||
323 | static void | 322 | static void |
324 | do_timeout (void *cls) | 323 | do_timeout(void *cls) |
325 | { | 324 | { |
326 | timeout_task_id = NULL; | 325 | timeout_task_id = NULL; |
327 | GNUNET_SCHEDULER_shutdown (); | 326 | GNUNET_SCHEDULER_shutdown(); |
328 | GNUNET_break (0); | 327 | GNUNET_break(0); |
329 | global_ret = 1; | 328 | global_ret = 1; |
330 | } | 329 | } |
331 | 330 | ||
332 | 331 | ||
333 | static void | 332 | static void |
334 | mhd_main () | 333 | mhd_main() |
335 | { | 334 | { |
336 | struct GNUNET_NETWORK_FDSet nrs; | 335 | struct GNUNET_NETWORK_FDSet nrs; |
337 | struct GNUNET_NETWORK_FDSet nws; | 336 | struct GNUNET_NETWORK_FDSet nws; |
@@ -342,76 +341,78 @@ mhd_main () | |||
342 | unsigned MHD_LONG_LONG timeout; | 341 | unsigned MHD_LONG_LONG timeout; |
343 | struct GNUNET_TIME_Relative delay; | 342 | struct GNUNET_TIME_Relative delay; |
344 | 343 | ||
345 | GNUNET_assert (NULL == mhd_task_id); | 344 | GNUNET_assert(NULL == mhd_task_id); |
346 | FD_ZERO (&rs); | 345 | FD_ZERO(&rs); |
347 | FD_ZERO (&ws); | 346 | FD_ZERO(&ws); |
348 | FD_ZERO (&es); | 347 | FD_ZERO(&es); |
349 | max_fd = -1; | 348 | max_fd = -1; |
350 | GNUNET_assert (MHD_YES == MHD_get_fdset (mhd, &rs, &ws, &es, &max_fd)); | 349 | GNUNET_assert(MHD_YES == MHD_get_fdset(mhd, &rs, &ws, &es, &max_fd)); |
351 | if (MHD_YES == MHD_get_timeout (mhd, &timeout)) | 350 | if (MHD_YES == MHD_get_timeout(mhd, &timeout)) |
352 | delay = | 351 | delay = |
353 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, | 352 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, |
354 | (unsigned int) timeout); | 353 | (unsigned int)timeout); |
355 | else | 354 | else |
356 | delay = GNUNET_TIME_UNIT_FOREVER_REL; | 355 | delay = GNUNET_TIME_UNIT_FOREVER_REL; |
357 | GNUNET_NETWORK_fdset_copy_native (&nrs, &rs, max_fd + 1); | 356 | GNUNET_NETWORK_fdset_copy_native(&nrs, &rs, max_fd + 1); |
358 | GNUNET_NETWORK_fdset_copy_native (&nws, &ws, max_fd + 1); | 357 | GNUNET_NETWORK_fdset_copy_native(&nws, &ws, max_fd + 1); |
359 | mhd_task_id = | 358 | mhd_task_id = |
360 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, | 359 | GNUNET_SCHEDULER_add_select(GNUNET_SCHEDULER_PRIORITY_DEFAULT, delay, |
361 | &nrs, &nws, &mhd_task, NULL); | 360 | &nrs, &nws, &mhd_task, NULL); |
362 | } | 361 | } |
363 | 362 | ||
364 | 363 | ||
365 | static void | 364 | static void |
366 | run (void *cls, | 365 | run(void *cls, |
367 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 366 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
368 | struct GNUNET_TESTING_Peer *peer) | 367 | struct GNUNET_TESTING_Peer *peer) |
369 | { | 368 | { |
370 | struct in_addr v4; | 369 | struct in_addr v4; |
371 | struct in6_addr v6; | 370 | struct in6_addr v6; |
372 | void *addr; | 371 | void *addr; |
373 | enum MHD_FLAG flags; | 372 | enum MHD_FLAG flags; |
374 | 373 | ||
375 | vpn = GNUNET_VPN_connect (cfg); | 374 | vpn = GNUNET_VPN_connect(cfg); |
376 | GNUNET_assert (NULL != vpn); | 375 | GNUNET_assert(NULL != vpn); |
377 | flags = MHD_USE_DEBUG; | 376 | flags = MHD_USE_DEBUG; |
378 | if (AF_INET6 == dest_af) | 377 | if (AF_INET6 == dest_af) |
379 | flags |= MHD_USE_IPv6; | 378 | flags |= MHD_USE_IPv6; |
380 | mhd = | 379 | mhd = |
381 | MHD_start_daemon (flags, PORT, NULL, NULL, &mhd_ahc, NULL, | 380 | MHD_start_daemon(flags, PORT, NULL, NULL, &mhd_ahc, NULL, |
382 | MHD_OPTION_END); | 381 | MHD_OPTION_END); |
383 | 382 | ||
384 | 383 | ||
385 | GNUNET_assert (NULL != mhd); | 384 | GNUNET_assert(NULL != mhd); |
386 | mhd_main (); | 385 | mhd_main(); |
387 | addr = NULL; | 386 | addr = NULL; |
388 | switch (dest_af) | 387 | switch (dest_af) |
389 | { | 388 | { |
390 | case AF_INET: | 389 | case AF_INET: |
391 | GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v4)); | 390 | GNUNET_assert(1 == inet_pton(dest_af, dest_ip, &v4)); |
392 | addr = &v4; | 391 | addr = &v4; |
393 | break; | 392 | break; |
394 | case AF_INET6: | 393 | |
395 | GNUNET_assert (1 == inet_pton (dest_af, dest_ip, &v6)); | 394 | case AF_INET6: |
396 | addr = &v6; | 395 | GNUNET_assert(1 == inet_pton(dest_af, dest_ip, &v6)); |
397 | break; | 396 | addr = &v6; |
398 | default: | 397 | break; |
399 | GNUNET_assert (0); | 398 | |
400 | } | 399 | default: |
401 | rr = GNUNET_VPN_redirect_to_ip (vpn, src_af, dest_af, addr, | 400 | GNUNET_assert(0); |
402 | GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb, | 401 | } |
403 | NULL); | 402 | rr = GNUNET_VPN_redirect_to_ip(vpn, src_af, dest_af, addr, |
403 | GNUNET_TIME_UNIT_FOREVER_ABS, &allocation_cb, | ||
404 | NULL); | ||
404 | timeout_task_id = | 405 | timeout_task_id = |
405 | GNUNET_SCHEDULER_add_delayed (TIMEOUT, | 406 | GNUNET_SCHEDULER_add_delayed(TIMEOUT, |
406 | &do_timeout, | 407 | &do_timeout, |
407 | NULL); | ||
408 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | ||
409 | NULL); | 408 | NULL); |
409 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, | ||
410 | NULL); | ||
410 | } | 411 | } |
411 | 412 | ||
412 | 413 | ||
413 | int | 414 | int |
414 | main (int argc, char *const *argv) | 415 | main(int argc, char *const *argv) |
415 | { | 416 | { |
416 | const char *type; | 417 | const char *type; |
417 | const char *bin; | 418 | const char *bin; |
@@ -420,90 +421,90 @@ main (int argc, char *const *argv) | |||
420 | int ret = 0; | 421 | int ret = 0; |
421 | 422 | ||
422 | #ifndef MINGW | 423 | #ifndef MINGW |
423 | if (0 != ACCESS ("/dev/net/tun", R_OK)) | 424 | if (0 != ACCESS("/dev/net/tun", R_OK)) |
424 | { | 425 | { |
425 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | 426 | GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, |
426 | "access", | 427 | "access", |
427 | "/dev/net/tun"); | 428 | "/dev/net/tun"); |
428 | fprintf (stderr, | 429 | fprintf(stderr, |
429 | "WARNING: System unable to run test, skipping.\n"); | 430 | "WARNING: System unable to run test, skipping.\n"); |
430 | return 77; | 431 | return 77; |
431 | } | 432 | } |
432 | #endif | 433 | #endif |
433 | vpn_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-vpn"); | 434 | vpn_binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-vpn"); |
434 | exit_binary = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-exit"); | 435 | exit_binary = GNUNET_OS_get_libexec_binary_path("gnunet-helper-exit"); |
435 | if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please! | 436 | if ((GNUNET_YES != (ret = GNUNET_OS_check_helper_binary(vpn_binary, GNUNET_YES, "-d gnunet-vpn - - 169.1.3.3.7 255.255.255.0"))) || //ipv4 only please! |
436 | (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary (exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only | 437 | (GNUNET_YES != (ret = GNUNET_OS_check_helper_binary(exit_binary, GNUNET_YES, "-d gnunet-vpn - - - 169.1.3.3.7 255.255.255.0")))) //no nat, ipv4 only |
437 | { | 438 | { |
438 | GNUNET_free (vpn_binary); | 439 | GNUNET_free(vpn_binary); |
439 | GNUNET_free (exit_binary); | 440 | GNUNET_free(exit_binary); |
440 | fprintf (stderr, | 441 | fprintf(stderr, |
441 | "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret); | 442 | "WARNING: gnunet-helper-{exit,vpn} binaries are not SUID, refusing to run test (as it would have to fail). %d\n", ret); |
442 | return 77; | 443 | return 77; |
443 | } | 444 | } |
444 | 445 | ||
445 | GNUNET_free (vpn_binary); | 446 | GNUNET_free(vpn_binary); |
446 | GNUNET_free (exit_binary); | 447 | GNUNET_free(exit_binary); |
447 | bin = argv[0]; | 448 | bin = argv[0]; |
448 | if (NULL != strstr (bin, "lt-")) | 449 | if (NULL != strstr(bin, "lt-")) |
449 | bin = strstr (bin, "lt-") + 4; | 450 | bin = strstr(bin, "lt-") + 4; |
450 | type = strstr (bin, "-"); | 451 | type = strstr(bin, "-"); |
451 | if (NULL == type) | 452 | if (NULL == type) |
452 | { | 453 | { |
453 | fprintf (stderr, | 454 | fprintf(stderr, |
454 | "invalid binary name\n"); | 455 | "invalid binary name\n"); |
455 | return 1; | 456 | return 1; |
456 | } | 457 | } |
457 | type++; | 458 | type++; |
458 | /* on Windows, .exe is suffixed to these binaries, | 459 | /* on Windows, .exe is suffixed to these binaries, |
459 | * thus cease comparison after the 6th char. | 460 | * thus cease comparison after the 6th char. |
460 | */ | 461 | */ |
461 | if (0 == strncmp (type, "4_to_6",6)) | 462 | if (0 == strncmp(type, "4_to_6", 6)) |
462 | { | 463 | { |
463 | dest_ip = "FC5A:04E1:C2BA::1"; | 464 | dest_ip = "FC5A:04E1:C2BA::1"; |
464 | dest_af = AF_INET6; | 465 | dest_af = AF_INET6; |
465 | src_af = AF_INET; | 466 | src_af = AF_INET; |
466 | } | 467 | } |
467 | else if (0 == strncmp (type, "6_to_4",6)) | 468 | else if (0 == strncmp(type, "6_to_4", 6)) |
468 | { | 469 | { |
469 | dest_ip = "169.254.86.1"; | 470 | dest_ip = "169.254.86.1"; |
470 | dest_af = AF_INET; | 471 | dest_af = AF_INET; |
471 | src_af = AF_INET6; | 472 | src_af = AF_INET6; |
472 | } | 473 | } |
473 | else if (0 == strncmp (type, "4_over",6)) | 474 | else if (0 == strncmp(type, "4_over", 6)) |
474 | { | 475 | { |
475 | dest_ip = "169.254.86.1"; | 476 | dest_ip = "169.254.86.1"; |
476 | dest_af = AF_INET; | 477 | dest_af = AF_INET; |
477 | src_af = AF_INET; | 478 | src_af = AF_INET; |
478 | } | 479 | } |
479 | else if (0 == strncmp (type, "6_over",6)) | 480 | else if (0 == strncmp(type, "6_over", 6)) |
480 | { | 481 | { |
481 | dest_ip = "FC5A:04E1:C2BA::1"; | 482 | dest_ip = "FC5A:04E1:C2BA::1"; |
482 | dest_af = AF_INET6; | 483 | dest_af = AF_INET6; |
483 | src_af = AF_INET6; | 484 | src_af = AF_INET6; |
484 | } | 485 | } |
485 | else | 486 | else |
486 | { | 487 | { |
487 | fprintf (stderr, "invalid binary suffix `%s'\n", type); | 488 | fprintf(stderr, "invalid binary suffix `%s'\n", type); |
488 | return 1; | 489 | return 1; |
489 | } | 490 | } |
490 | if ((GNUNET_OK != GNUNET_NETWORK_test_pf (src_af)) || | 491 | if ((GNUNET_OK != GNUNET_NETWORK_test_pf(src_af)) || |
491 | (GNUNET_OK != GNUNET_NETWORK_test_pf (dest_af))) | 492 | (GNUNET_OK != GNUNET_NETWORK_test_pf(dest_af))) |
492 | { | 493 | { |
493 | fprintf (stderr, | 494 | fprintf(stderr, |
494 | "Required address families not supported by this system, skipping test.\n"); | 495 | "Required address families not supported by this system, skipping test.\n"); |
495 | return 0; | 496 | return 0; |
496 | } | 497 | } |
497 | if (0 != curl_global_init (CURL_GLOBAL_WIN32)) | 498 | if (0 != curl_global_init(CURL_GLOBAL_WIN32)) |
498 | { | 499 | { |
499 | fprintf (stderr, "failed to initialize curl\n"); | 500 | fprintf(stderr, "failed to initialize curl\n"); |
500 | return 2; | 501 | return 2; |
501 | } | 502 | } |
502 | if (0 != | 503 | if (0 != |
503 | GNUNET_TESTING_peer_run ("test-gnunet-vpn", "test_gnunet_vpn.conf", &run, | 504 | GNUNET_TESTING_peer_run("test-gnunet-vpn", "test_gnunet_vpn.conf", &run, |
504 | NULL)) | 505 | NULL)) |
505 | return 1; | 506 | return 1; |
506 | GNUNET_DISK_directory_remove ("/tmp/gnunet-test-vpn"); | 507 | GNUNET_DISK_directory_remove("/tmp/gnunet-test-vpn"); |
507 | return global_ret; | 508 | return global_ret; |
508 | } | 509 | } |
509 | 510 | ||