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